diff --git a/app/models/gpg_key.rb b/app/models/gpg_key.rb index 16de0b542d7a20cfee78b2c8e73aa6411162251c..d77051850f318982de9fa85e705899bfc608dab8 100644 --- a/app/models/gpg_key.rb +++ b/app/models/gpg_key.rb @@ -21,6 +21,11 @@ class GpgKey < ActiveRecord::Base write_attribute(:key, value) end + def emails + raw_key = GPGME::Key.get(fingerprint) + raw_key.uids.map(&:email) + end + private def extract_fingerprint diff --git a/spec/factories/gpg_keys.rb b/spec/factories/gpg_keys.rb new file mode 100644 index 0000000000000000000000000000000000000000..e43a3c19672e238923c0271fc1a0c66551888d51 --- /dev/null +++ b/spec/factories/gpg_keys.rb @@ -0,0 +1,7 @@ +require_relative '../support/gpg_helpers' + +FactoryGirl.define do + factory :gpg_key do + key GpgHelpers.public_key + end +end diff --git a/spec/models/gpg_key_spec.rb b/spec/models/gpg_key_spec.rb index 02623c52fa60af4d05bf425dfa827c63c447db8e..24ef291a02179267355696b6aa051921de441a84 100644 --- a/spec/models/gpg_key_spec.rb +++ b/spec/models/gpg_key_spec.rb @@ -38,4 +38,12 @@ describe GpgKey do expect(described_class.new(key: " #{key} ").key).to eq(key) end end + + describe '#emails' do + it 'returns the emails from the gpg key' do + gpg_key = create :gpg_key + + expect(gpg_key.emails).to match_array %w(mail@koffeinfrei.org lex@panter.ch) + end + end end