about summary refs log tree commit diff
diff options
context:
space:
mode:
authorEugen Rochko <eugen@zeonfederated.com>2018-05-02 15:45:24 +0200
committerGitHub <noreply@github.com>2018-05-02 15:45:24 +0200
commitc5dcd7d836d53ede4751405ec5701f9f3b48102c (patch)
treead8705b51c70cb7f80eff4724f0de708cad10762
parent965345316fb3fef640a6bcc463d09d4a38b28608 (diff)
Speed up test suite by not generating RSA keys in test environment (#7296)
One RSA keypair for all fabricated test accounts is enough
-rw-r--r--app/models/account.rb4
-rw-r--r--spec/fabricators/account_fabricator.rb8
-rw-r--r--spec/models/account_spec.rb3
3 files changed, 11 insertions, 4 deletions
diff --git a/app/models/account.rb b/app/models/account.rb
index 647b5c358..0cd2a10d5 100644
--- a/app/models/account.rb
+++ b/app/models/account.rb
@@ -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
diff --git a/spec/fabricators/account_fabricator.rb b/spec/fabricators/account_fabricator.rb
index 446f8ea27..7aa983f82 100644
--- a/spec/fabricators/account_fabricator.rb
+++ b/spec/fabricators/account_fabricator.rb
@@ -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
diff --git a/spec/models/account_spec.rb b/spec/models/account_spec.rb
index fb7ddfa83..3aaaa55eb 100644
--- a/spec/models/account_spec.rb
+++ b/spec/models/account_spec.rb
@@ -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