diff options
author | Alexis Reigel <mail@koffeinfrei.org> | 2017-07-06 12:15:31 +0300 |
---|---|---|
committer | Alexis Reigel <mail@koffeinfrei.org> | 2017-07-27 16:43:37 +0300 |
commit | b66e3726dc377c2bb5c92983db4ec4c8d27237c4 (patch) | |
tree | 109dad78823663104daa8f63862c0c3a89211672 /spec | |
parent | 7f03282f0ff45948d3d27efe007ba77e24e19fa5 (diff) |
also update gpg_signatures when gpg_key is null
Diffstat (limited to 'spec')
-rw-r--r-- | spec/lib/gitlab/gpg/invalid_gpg_signature_updater_spec.rb | 70 |
1 files changed, 55 insertions, 15 deletions
diff --git a/spec/lib/gitlab/gpg/invalid_gpg_signature_updater_spec.rb b/spec/lib/gitlab/gpg/invalid_gpg_signature_updater_spec.rb index c16f15bf4bf..5a81a86b93c 100644 --- a/spec/lib/gitlab/gpg/invalid_gpg_signature_updater_spec.rb +++ b/spec/lib/gitlab/gpg/invalid_gpg_signature_updater_spec.rb @@ -19,29 +19,60 @@ RSpec.describe Gitlab::Gpg::InvalidGpgSignatureUpdater do create :commit, git_commit: raw_commit, project: project end - let!(:gpg_signature) do - create :gpg_signature, - project: project, - commit_sha: commit_sha, - gpg_key: nil, - gpg_key_primary_keyid: GpgHelpers::User1.primary_keyid, - valid_signature: false - end - before do allow_any_instance_of(GpgSignature).to receive(:commit).and_return(commit) end + context 'gpg signature did have an associated gpg key which was removed later' do + let!(:user) { create :user, email: GpgHelpers::User1.emails.first } + + let!(:valid_gpg_signature) do + create :gpg_signature, + project: project, + commit_sha: commit_sha, + gpg_key: nil, + gpg_key_primary_keyid: GpgHelpers::User1.primary_keyid, + valid_signature: true + end + + it 'assigns the gpg key to the signature when the missing gpg key is added' do + # InvalidGpgSignatureUpdater is called by the after_create hook + gpg_key = create :gpg_key, + key: GpgHelpers::User1.public_key, + user: user + + expect(valid_gpg_signature.reload.gpg_key).to eq gpg_key + end + + it 'does not assign the gpg key when an unrelated gpg key is added' do + # InvalidGpgSignatureUpdater is called by the after_create hook + create :gpg_key, + key: GpgHelpers::User2.public_key, + user: user + + expect(valid_gpg_signature.reload.gpg_key).to be_nil + end + end + context 'gpg signature did not have an associated gpg key' do let!(:user) { create :user, email: GpgHelpers::User1.emails.first } + let!(:invalid_gpg_signature) do + create :gpg_signature, + project: project, + commit_sha: commit_sha, + gpg_key: nil, + gpg_key_primary_keyid: GpgHelpers::User1.primary_keyid, + valid_signature: false + end + it 'updates the signature to being valid when the missing gpg key is added' do # InvalidGpgSignatureUpdater is called by the after_create hook create :gpg_key, key: GpgHelpers::User1.public_key, user: user - expect(gpg_signature.reload.valid_signature).to be_truthy + expect(invalid_gpg_signature.reload.valid_signature).to be_truthy end it 'keeps the signature at being invalid when an unrelated gpg key is added' do @@ -50,7 +81,7 @@ RSpec.describe Gitlab::Gpg::InvalidGpgSignatureUpdater do key: GpgHelpers::User2.public_key, user: user - expect(gpg_signature.reload.valid_signature).to be_falsey + expect(invalid_gpg_signature.reload.valid_signature).to be_falsey end end @@ -61,17 +92,26 @@ RSpec.describe Gitlab::Gpg::InvalidGpgSignatureUpdater do end end + let!(:invalid_gpg_signature) do + create :gpg_signature, + project: project, + commit_sha: commit_sha, + gpg_key: nil, + gpg_key_primary_keyid: GpgHelpers::User1.primary_keyid, + valid_signature: false + end + it 'updates the signature to being valid when the user updates the email address' do create :gpg_key, key: GpgHelpers::User1.public_key, user: user - expect(gpg_signature.reload.valid_signature).to be_falsey + expect(invalid_gpg_signature.reload.valid_signature).to be_falsey # InvalidGpgSignatureUpdater is called by the after_update hook user.update_attributes!(email: GpgHelpers::User1.emails.first) - expect(gpg_signature.reload.valid_signature).to be_truthy + expect(invalid_gpg_signature.reload.valid_signature).to be_truthy end it 'keeps the signature at being invalid when the changed email address is still unrelated' do @@ -79,12 +119,12 @@ RSpec.describe Gitlab::Gpg::InvalidGpgSignatureUpdater do key: GpgHelpers::User1.public_key, user: user - expect(gpg_signature.reload.valid_signature).to be_falsey + expect(invalid_gpg_signature.reload.valid_signature).to be_falsey # InvalidGpgSignatureUpdater is called by the after_update hook user.update_attributes!(email: 'still.unrelated@example.com') - expect(gpg_signature.reload.valid_signature).to be_falsey + expect(invalid_gpg_signature.reload.valid_signature).to be_falsey end end end |