gitlab-org--gitlab-foss/spec/lib/gitlab/gpg_spec.rb

65 lines
1.8 KiB
Ruby
Raw Normal View History

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-24 19:07:57 +00:00
describe '.emails_from_key' do
it 'returns the emails' do
expect(
described_class.emails_from_key(GpgHelpers::User1.public_key)
).to eq GpgHelpers::User1.emails
end
it 'returns an empty array when the key is invalid' do
expect(
described_class.emails_from_key('bogus')
).to eq []
end
end
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-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 []
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-23 13:07:51 +00:00
Gitlab::Gpg.remove_from_keychain(GpgHelpers::User1.fingerprint)
2017-02-23 13:07:51 +00:00
expect(GPGME::Key.find(:public, GpgHelpers::User1.fingerprint)).to eq []
end
2017-02-22 16:20:42 +00:00
end
end
2017-02-24 19:07:57 +00:00
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