diff options
author | Douwe Maan <douwe@gitlab.com> | 2018-02-19 09:09:25 +0000 |
---|---|---|
committer | Douwe Maan <douwe@gitlab.com> | 2018-02-19 09:09:25 +0000 |
commit | 586816aece7cf3a96d0f4948d5dbf2a8e2a9a187 (patch) | |
tree | 4f6490b96eeb5ebdd6bb4b87a91d01c5c07104d9 | |
parent | 637ab60c608cd531c1cc8ad130c7606ca2716ba6 (diff) | |
parent | fdad576838c16d0ae7d181e85a5889d8ae4e5014 (diff) | |
download | gitlab-ce-586816aece7cf3a96d0f4948d5dbf2a8e2a9a187.tar.gz |
Merge branch 'sh-fix-geo-error-500-gpg-commit' into 'master'
Fix Error 500 when viewing a commit with a GPG signature in Geo
Closes gitlab-ee#4825
See merge request gitlab-org/gitlab-ce!17207
-rw-r--r-- | changelogs/unreleased/sh-fix-geo-error-500-gpg-commit.yml | 5 | ||||
-rw-r--r-- | lib/gitlab/gpg/commit.rb | 4 | ||||
-rw-r--r-- | spec/lib/gitlab/gpg/commit_spec.rb | 26 |
3 files changed, 33 insertions, 2 deletions
diff --git a/changelogs/unreleased/sh-fix-geo-error-500-gpg-commit.yml b/changelogs/unreleased/sh-fix-geo-error-500-gpg-commit.yml new file mode 100644 index 00000000000..5b4bbe0dc7a --- /dev/null +++ b/changelogs/unreleased/sh-fix-geo-error-500-gpg-commit.yml @@ -0,0 +1,5 @@ +--- +title: Fix Error 500 when viewing a commit with a GPG signature in Geo +merge_request: +author: +type: fixed diff --git a/lib/gitlab/gpg/commit.rb b/lib/gitlab/gpg/commit.rb index 672b5579dfd..90dd569aaf8 100644 --- a/lib/gitlab/gpg/commit.rb +++ b/lib/gitlab/gpg/commit.rb @@ -60,7 +60,9 @@ module Gitlab def create_cached_signature! using_keychain do |gpg_key| - GpgSignature.create!(attributes(gpg_key)) + signature = GpgSignature.new(attributes(gpg_key)) + signature.save! unless Gitlab::Database.read_only? + signature end end diff --git a/spec/lib/gitlab/gpg/commit_spec.rb b/spec/lib/gitlab/gpg/commit_spec.rb index e3bf2801406..67c62458f0f 100644 --- a/spec/lib/gitlab/gpg/commit_spec.rb +++ b/spec/lib/gitlab/gpg/commit_spec.rb @@ -49,7 +49,9 @@ describe Gitlab::Gpg::Commit do end it 'returns a valid signature' do - expect(described_class.new(commit).signature).to have_attributes( + signature = described_class.new(commit).signature + + expect(signature).to have_attributes( commit_sha: commit_sha, project: project, gpg_key: gpg_key, @@ -58,9 +60,31 @@ describe Gitlab::Gpg::Commit do gpg_key_user_email: GpgHelpers::User1.emails.first, verification_status: 'verified' ) + expect(signature.persisted?).to be_truthy end it_behaves_like 'returns the cached signature on second call' + + context 'read-only mode' do + before do + allow(Gitlab::Database).to receive(:read_only?).and_return(true) + end + + it 'does not create a cached signature' do + signature = described_class.new(commit).signature + + expect(signature).to have_attributes( + commit_sha: commit_sha, + project: project, + gpg_key: gpg_key, + gpg_key_primary_keyid: GpgHelpers::User1.primary_keyid, + gpg_key_user_name: GpgHelpers::User1.names.first, + gpg_key_user_email: GpgHelpers::User1.emails.first, + verification_status: 'verified' + ) + expect(signature.persisted?).to be_falsey + end + end end context 'commit signed with a subkey' do |