diff options
author | Alexis Reigel <mail@koffeinfrei.org> | 2017-06-15 13:43:04 +0300 |
---|---|---|
committer | Alexis Reigel <mail@koffeinfrei.org> | 2017-07-27 16:42:53 +0300 |
commit | 5d5fd4babe4cb75c7f8f9f18cc86c63a0fa58d16 (patch) | |
tree | 928b5582a8119277bc61605175399820e555a374 | |
parent | 34810acd6c3d4dd27f43f6f07e47b4e06bb95f82 (diff) |
store gpg_key_primary_keyid for unknown gpg keys
we need to store the keyid to be able to update the signature later in
case the missing key is added later.
-rw-r--r-- | app/models/gpg_signature.rb | 1 | ||||
-rw-r--r-- | lib/gitlab/gpg/commit.rb | 6 | ||||
-rw-r--r-- | spec/lib/gitlab/gpg/commit_spec.rb | 2 | ||||
-rw-r--r-- | spec/models/gpg_signature_spec.rb | 1 |
4 files changed, 7 insertions, 3 deletions
diff --git a/app/models/gpg_signature.rb b/app/models/gpg_signature.rb index 03294354d91..4fe9c3210ff 100644 --- a/app/models/gpg_signature.rb +++ b/app/models/gpg_signature.rb @@ -4,4 +4,5 @@ class GpgSignature < ActiveRecord::Base validates :commit_sha, presence: true validates :project, presence: true + validates :gpg_key_primary_keyid, presence: true end diff --git a/lib/gitlab/gpg/commit.rb b/lib/gitlab/gpg/commit.rb index 2b61caaebb5..8d2e6269618 100644 --- a/lib/gitlab/gpg/commit.rb +++ b/lib/gitlab/gpg/commit.rb @@ -43,12 +43,14 @@ module Gitlab end def create_cached_signature!(gpg_key) + verified_signature_result = verified_signature + GpgSignature.create!( commit_sha: commit.sha, project: commit.project, gpg_key: gpg_key, - gpg_key_primary_keyid: gpg_key&.primary_keyid, - valid_signature: !!(gpg_key && gpg_key.verified? && verified_signature.valid?) + gpg_key_primary_keyid: gpg_key&.primary_keyid || verified_signature_result.fingerprint, + valid_signature: !!(gpg_key && gpg_key.verified? && verified_signature_result.valid?) ) end end diff --git a/spec/lib/gitlab/gpg/commit_spec.rb b/spec/lib/gitlab/gpg/commit_spec.rb index 539e6d4641f..448b16a656e 100644 --- a/spec/lib/gitlab/gpg/commit_spec.rb +++ b/spec/lib/gitlab/gpg/commit_spec.rb @@ -100,7 +100,7 @@ RSpec.describe Gitlab::Gpg::Commit do commit_sha: '0beec7b5ea3f0fdbc95d0dd47f3c5bc275da8a33', project: project, gpg_key: nil, - gpg_key_primary_keyid: nil, + gpg_key_primary_keyid: GpgHelpers::User1.primary_keyid, valid_signature: false ) end diff --git a/spec/models/gpg_signature_spec.rb b/spec/models/gpg_signature_spec.rb index d2720c41694..b3f84262874 100644 --- a/spec/models/gpg_signature_spec.rb +++ b/spec/models/gpg_signature_spec.rb @@ -10,5 +10,6 @@ RSpec.describe GpgSignature do subject { described_class.new } it { is_expected.to validate_presence_of(:commit_sha) } it { is_expected.to validate_presence_of(:project) } + it { is_expected.to validate_presence_of(:gpg_key_primary_keyid) } end end |