Browse Source

Speed up test suite by not generating RSA keys in test environment (#7296)

One RSA keypair for all fabricated test accounts is enough
pull/4/head
Eugen Rochko 6 years ago
committed by GitHub
parent
commit
c5dcd7d836
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 4 deletions
  1. +2
    -2
      app/models/account.rb
  2. +7
    -1
      spec/fabricators/account_fabricator.rb
  3. +2
    -1
      spec/models/account_spec.rb

+ 2
- 2
app/models/account.rb View File

@ -406,9 +406,9 @@ class Account < ApplicationRecord
end
def generate_keys
return unless local?
return unless local? && !Rails.env.test?
keypair = OpenSSL::PKey::RSA.new(Rails.env.test? ? 512 : 2048)
keypair = OpenSSL::PKey::RSA.new(2048)
self.private_key = keypair.to_pem
self.public_key = keypair.public_key.to_pem
end

+ 7
- 1
spec/fabricators/account_fabricator.rb View File

@ -1,4 +1,10 @@
keypair = OpenSSL::PKey::RSA.new(2048)
public_key = keypair.public_key.to_pem
private_key = keypair.to_pem
Fabricator(:account) do
username { sequence(:username) { |i| "#{Faker::Internet.user_name(nil, %w(_))}#{i}" } }
username { sequence(:username) { |i| "#{Faker::Internet.user_name(nil, %w(_))}#{i}" } }
last_webfingered_at { Time.now.utc }
public_key { public_key }
private_key { private_key}
end

+ 2
- 1
spec/models/account_spec.rb View File

@ -815,7 +815,8 @@ RSpec.describe Account, type: :model do
end
context 'when is local' do
it 'generates keys' do
# Test disabled because test environment omits autogenerating keys for performance
xit 'generates keys' do
account = Account.create!(domain: nil, username: Faker::Internet.user_name(nil, ['_']))
expect(account.keypair.private?).to eq true
end

Loading…
Cancel
Save