Commit 5d5fd4ba authored by Alexis Reigel's avatar Alexis Reigel

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.
parent 34810acd
...@@ -4,4 +4,5 @@ class GpgSignature < ActiveRecord::Base ...@@ -4,4 +4,5 @@ class GpgSignature < ActiveRecord::Base
validates :commit_sha, presence: true validates :commit_sha, presence: true
validates :project, presence: true validates :project, presence: true
validates :gpg_key_primary_keyid, presence: true
end end
...@@ -43,12 +43,14 @@ module Gitlab ...@@ -43,12 +43,14 @@ module Gitlab
end end
def create_cached_signature!(gpg_key) def create_cached_signature!(gpg_key)
verified_signature_result = verified_signature
GpgSignature.create!( GpgSignature.create!(
commit_sha: commit.sha, commit_sha: commit.sha,
project: commit.project, project: commit.project,
gpg_key: gpg_key, gpg_key: gpg_key,
gpg_key_primary_keyid: gpg_key&.primary_keyid, gpg_key_primary_keyid: gpg_key&.primary_keyid || verified_signature_result.fingerprint,
valid_signature: !!(gpg_key && gpg_key.verified? && verified_signature.valid?) valid_signature: !!(gpg_key && gpg_key.verified? && verified_signature_result.valid?)
) )
end end
end end
......
...@@ -100,7 +100,7 @@ RSpec.describe Gitlab::Gpg::Commit do ...@@ -100,7 +100,7 @@ RSpec.describe Gitlab::Gpg::Commit do
commit_sha: '0beec7b5ea3f0fdbc95d0dd47f3c5bc275da8a33', commit_sha: '0beec7b5ea3f0fdbc95d0dd47f3c5bc275da8a33',
project: project, project: project,
gpg_key: nil, gpg_key: nil,
gpg_key_primary_keyid: nil, gpg_key_primary_keyid: GpgHelpers::User1.primary_keyid,
valid_signature: false valid_signature: false
) )
end end
......
...@@ -10,5 +10,6 @@ RSpec.describe GpgSignature do ...@@ -10,5 +10,6 @@ RSpec.describe GpgSignature do
subject { described_class.new } subject { described_class.new }
it { is_expected.to validate_presence_of(:commit_sha) } it { is_expected.to validate_presence_of(:commit_sha) }
it { is_expected.to validate_presence_of(:project) } it { is_expected.to validate_presence_of(:project) }
it { is_expected.to validate_presence_of(:gpg_key_primary_keyid) }
end end
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment