2017-02-22 16:20:42 +00:00
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
describe Gitlab::Gpg do
|
|
|
|
describe '.fingerprints_from_key' do
|
|
|
|
it 'returns the fingerprint' do
|
|
|
|
expect(
|
2017-02-23 11:02:36 +00:00
|
|
|
described_class.fingerprints_from_key(GpgHelpers::User1.public_key)
|
2017-02-23 13:07:51 +00:00
|
|
|
).to eq [GpgHelpers::User1.fingerprint]
|
2017-02-22 16:20:42 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns an empty array when the key is invalid' do
|
|
|
|
expect(
|
|
|
|
described_class.fingerprints_from_key('bogus')
|
|
|
|
).to eq []
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-02-22 17:36:25 +00:00
|
|
|
describe '.add_to_keychain', :gpg do
|
|
|
|
it 'stores the key in the keychain' do
|
2017-02-23 13:07:51 +00:00
|
|
|
expect(GPGME::Key.find(:public, GpgHelpers::User1.fingerprint)).to eq []
|
2017-02-22 17:36:25 +00:00
|
|
|
|
2017-02-23 11:02:36 +00:00
|
|
|
Gitlab::Gpg.add_to_keychain(GpgHelpers::User1.public_key)
|
2017-02-22 17:36:25 +00:00
|
|
|
|
2017-02-23 13:07:51 +00:00
|
|
|
expect(GPGME::Key.find(:public, GpgHelpers::User1.fingerprint)).not_to eq []
|
2017-02-22 17:36:25 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '.remove_from_keychain', :gpg do
|
|
|
|
it 'removes the key from the keychain' do
|
2017-02-23 11:02:36 +00:00
|
|
|
Gitlab::Gpg.add_to_keychain(GpgHelpers::User1.public_key)
|
2017-02-23 13:07:51 +00:00
|
|
|
expect(GPGME::Key.find(:public, GpgHelpers::User1.fingerprint)).not_to eq []
|
2017-02-22 17:36:25 +00:00
|
|
|
|
2017-02-23 13:07:51 +00:00
|
|
|
Gitlab::Gpg.remove_from_keychain(GpgHelpers::User1.fingerprint)
|
2017-02-22 17:36:25 +00:00
|
|
|
|
2017-02-23 13:07:51 +00:00
|
|
|
expect(GPGME::Key.find(:public, GpgHelpers::User1.fingerprint)).to eq []
|
2017-02-22 17:36:25 +00:00
|
|
|
end
|
2017-02-22 16:20:42 +00:00
|
|
|
end
|
|
|
|
end
|