From 7b7cd6f69d59092a55fc8b293edf09638fba20d9 Mon Sep 17 00:00:00 2001 From: Alexis Reigel <mail@koffeinfrei.org> Date: Wed, 22 Feb 2017 15:37:49 +0100 Subject: [PATCH] add emails method to GgpKey --- app/models/gpg_key.rb | 5 +++++ spec/factories/gpg_keys.rb | 7 +++++++ spec/models/gpg_key_spec.rb | 8 ++++++++ 3 files changed, 20 insertions(+) create mode 100644 spec/factories/gpg_keys.rb diff --git a/app/models/gpg_key.rb b/app/models/gpg_key.rb index 16de0b542d7..d77051850f3 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 00000000000..e43a3c19672 --- /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 02623c52fa6..24ef291a021 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 -- GitLab