summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/models/gpg_key.rb4
-rw-r--r--lib/gitlab/gpg.rb16
-rw-r--r--spec/lib/gitlab/gpg_spec.rb34
-rw-r--r--spec/models/gpg_key_spec.rb8
4 files changed, 32 insertions, 30 deletions
diff --git a/app/models/gpg_key.rb b/app/models/gpg_key.rb
index 146ca2f2705..1101dbae4a9 100644
--- a/app/models/gpg_key.rb
+++ b/app/models/gpg_key.rb
@@ -40,10 +40,10 @@ class GpgKey < ActiveRecord::Base
end
def add_to_keychain
- Gitlab::Gpg.add_to_keychain(key)
+ Gitlab::Gpg::CurrentKeyChain.add(key)
end
def remove_from_keychain
- Gitlab::Gpg.remove_from_keychain(fingerprint)
+ Gitlab::Gpg::CurrentKeyChain.remove(fingerprint)
end
end
diff --git a/lib/gitlab/gpg.rb b/lib/gitlab/gpg.rb
index 73a4b691cff..f478f1ae5d8 100644
--- a/lib/gitlab/gpg.rb
+++ b/lib/gitlab/gpg.rb
@@ -5,6 +5,14 @@ module Gitlab
module CurrentKeyChain
extend self
+ def add(key)
+ GPGME::Key.import(key)
+ end
+
+ def remove(fingerprint)
+ GPGME::Key.get(fingerprint).delete!
+ end
+
def emails(fingerprint)
GPGME::Key.find(:public, fingerprint).flat_map { |raw_key| raw_key.uids.map(&:email) }
end
@@ -32,14 +40,6 @@ module Gitlab
end
end
- def add_to_keychain(key)
- GPGME::Key.import(key)
- end
-
- def remove_from_keychain(fingerprint)
- GPGME::Key.get(fingerprint).delete!
- end
-
def using_tmp_keychain
Dir.mktmpdir do |dir|
@original_dirs ||= [GPGME::Engine.dirinfo('homedir')]
diff --git a/spec/lib/gitlab/gpg_spec.rb b/spec/lib/gitlab/gpg_spec.rb
index 2a55e7d89de..c0df719c0c2 100644
--- a/spec/lib/gitlab/gpg_spec.rb
+++ b/spec/lib/gitlab/gpg_spec.rb
@@ -28,37 +28,37 @@ describe Gitlab::Gpg do
).to eq []
end
end
+end
+
+describe Gitlab::Gpg::CurrentKeyChain, :gpg do
+ describe '.emails' do
+ it 'returns the emails' do
+ Gitlab::Gpg::CurrentKeyChain.add(GpgHelpers::User2.public_key)
+
+ expect(
+ described_class.emails(GpgHelpers::User2.fingerprint)
+ ).to match_array GpgHelpers::User2.emails
+ end
+ end
- describe '.add_to_keychain', :gpg do
+ describe '.add', :gpg do
it 'stores the key in the keychain' do
expect(GPGME::Key.find(:public, GpgHelpers::User1.fingerprint)).to eq []
- Gitlab::Gpg.add_to_keychain(GpgHelpers::User1.public_key)
+ Gitlab::Gpg::CurrentKeyChain.add(GpgHelpers::User1.public_key)
expect(GPGME::Key.find(:public, GpgHelpers::User1.fingerprint)).not_to eq []
end
end
- describe '.remove_from_keychain', :gpg do
+ describe '.remove', :gpg do
it 'removes the key from the keychain' do
- Gitlab::Gpg.add_to_keychain(GpgHelpers::User1.public_key)
+ Gitlab::Gpg::CurrentKeyChain.add(GpgHelpers::User1.public_key)
expect(GPGME::Key.find(:public, GpgHelpers::User1.fingerprint)).not_to eq []
- Gitlab::Gpg.remove_from_keychain(GpgHelpers::User1.fingerprint)
+ Gitlab::Gpg::CurrentKeyChain.remove(GpgHelpers::User1.fingerprint)
expect(GPGME::Key.find(:public, GpgHelpers::User1.fingerprint)).to eq []
end
end
end
-
-describe Gitlab::Gpg::CurrentKeyChain, :gpg do
- describe '.emails' do
- it 'returns the emails' do
- Gitlab::Gpg.add_to_keychain(GpgHelpers::User2.public_key)
-
- expect(
- described_class.emails(GpgHelpers::User2.fingerprint)
- ).to match_array GpgHelpers::User2.emails
- end
- end
-end
diff --git a/spec/models/gpg_key_spec.rb b/spec/models/gpg_key_spec.rb
index 889396c19c3..e8c41299937 100644
--- a/spec/models/gpg_key_spec.rb
+++ b/spec/models/gpg_key_spec.rb
@@ -24,17 +24,19 @@ describe GpgKey do
describe 'add_to_keychain' do
it 'calls add_to_keychain after create' do
- expect(Gitlab::Gpg).to receive(:add_to_keychain).with(GpgHelpers::User1.public_key)
+ expect(Gitlab::Gpg::CurrentKeyChain).to receive(:add).with(GpgHelpers::User1.public_key)
create :gpg_key
end
end
describe 'remove_from_keychain' do
it 'calls remove_from_keychain after destroy' do
- allow(Gitlab::Gpg).to receive :add_to_keychain
+ allow(Gitlab::Gpg::CurrentKeyChain).to receive :add
gpg_key = create :gpg_key
- expect(Gitlab::Gpg).to receive(:remove_from_keychain).with(GpgHelpers::User1.fingerprint)
+ expect(
+ Gitlab::Gpg::CurrentKeyChain
+ ).to receive(:remove).with(GpgHelpers::User1.fingerprint)
gpg_key.destroy!
end