Skip to content
Snippets Groups Projects
Commit 0668521b authored by Alexis Reigel's avatar Alexis Reigel
Browse files

move current keychain methods to namespace

parent 0e3d3d60
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -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
Loading
Loading
@@ -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
Loading
Loading
@@ -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')]
Loading
Loading
Loading
Loading
@@ -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
Loading
Loading
@@ -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
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment