Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexis Reigel <mail@koffeinfrei.org>2017-02-28 17:25:12 +0300
committerAlexis Reigel <mail@koffeinfrei.org>2017-07-27 16:42:04 +0300
commit8bd94a7304d392ad030295b5dfcd84c0100eddd1 (patch)
tree0e08bcdb460ad21c25646f686a42f4b743bf0129 /spec/models/gpg_key_spec.rb
parentc1281982bd7975b45bed5b8e2c5ef5e242ea18fd (diff)
remove gpg from keychain when user's email changes
Diffstat (limited to 'spec/models/gpg_key_spec.rb')
-rw-r--r--spec/models/gpg_key_spec.rb80
1 files changed, 56 insertions, 24 deletions
diff --git a/spec/models/gpg_key_spec.rb b/spec/models/gpg_key_spec.rb
index 4292892da4f..18746ad9d88 100644
--- a/spec/models/gpg_key_spec.rb
+++ b/spec/models/gpg_key_spec.rb
@@ -22,33 +22,16 @@ describe GpgKey do
end
end
- describe 'add_to_keychain' do
- context "user's email matches one of the key's emails" do
- it 'calls .add after create' do
- expect(Gitlab::Gpg::CurrentKeyChain).to receive(:add).with(GpgHelpers::User2.public_key)
- user = create :user, email: GpgHelpers::User2.emails.first
- create :gpg_key, user: user, key: GpgHelpers::User2.public_key
- end
+ describe 'synchronize_keychain' do
+ it 'calls #synchronize_keychain after create' do
+ gpg_key = build :gpg_key
+ expect(gpg_key).to receive(:synchronize_keychain)
+ gpg_key.save!
end
- context "user's email does not match one of the key's emails" do
- it 'does not call .add after create' do
- expect(Gitlab::Gpg::CurrentKeyChain).not_to receive(:add)
- user = create :user
- create :gpg_key, user: user, key: GpgHelpers::User2.public_key
- end
- end
- end
-
- describe 'remove_from_keychain' do
- it 'calls remove_from_keychain after destroy' do
- allow(Gitlab::Gpg::CurrentKeyChain).to receive :add
+ it 'calls #remove_from_keychain after destroy' do
gpg_key = create :gpg_key
-
- expect(
- Gitlab::Gpg::CurrentKeyChain
- ).to receive(:remove).with(GpgHelpers::User1.fingerprint)
-
+ expect(gpg_key).to receive(:synchronize_keychain)
gpg_key.destroy!
end
end
@@ -76,6 +59,15 @@ describe GpgKey do
end
end
+ describe '#emails_in_keychain', :gpg do
+ it 'returns the emails from the keychain' do
+ user = create :user, email: GpgHelpers::User1.emails.first
+ gpg_key = create :gpg_key, key: GpgHelpers::User1.public_key, user: user
+
+ expect(gpg_key.emails_in_keychain).to eq GpgHelpers::User1.emails
+ end
+ end
+
describe '#emails_with_verified_status', :gpg do
context 'key is in the keychain' do
it 'email is verified if the user has the matching email' do
@@ -104,6 +96,46 @@ describe GpgKey do
end
end
+ describe '#synchronize_keychain', :gpg do
+ context "user's email matches one of the key's emails" do
+ it 'adds the key to the keychain' do
+ user = create :user, email: GpgHelpers::User1.emails.first
+ gpg_key = create :gpg_key, user: user
+
+ expect(gpg_key).to receive(:add_to_keychain)
+
+ gpg_key.synchronize_keychain
+ end
+ end
+
+ context "user's email does not match one of the key's emails" do
+ it 'does not add the key to the keychain' do
+ user = create :user, email: 'stepanie@cole.us'
+ gpg_key = create :gpg_key, user: user
+
+ expect(gpg_key).to receive(:remove_from_keychain)
+
+ gpg_key.synchronize_keychain
+ end
+ end
+ end
+
+ describe '#add_to_keychain', :gpg do
+ it 'calls .add_to_keychain' do
+ expect(Gitlab::Gpg::CurrentKeyChain).to receive(:add).with(GpgHelpers::User2.public_key)
+ gpg_key = create :gpg_key, key: GpgHelpers::User2.public_key
+ gpg_key.send(:add_to_keychain)
+ end
+ end
+
+ describe '#remove_from_keychain', :gpg do
+ it 'calls .remove_from_keychain' do
+ allow(Gitlab::Gpg::CurrentKeyChain).to receive(:remove).with(GpgHelpers::User2.fingerprint)
+ gpg_key = create :gpg_key, key: GpgHelpers::User2.public_key
+ gpg_key.send(:remove_from_keychain)
+ end
+ end
+
describe 'notification' do
include EmailHelpers