diff options
author | Alexis Reigel <mail@koffeinfrei.org> | 2017-06-15 11:28:28 +0300 |
---|---|---|
committer | Alexis Reigel <mail@koffeinfrei.org> | 2017-07-27 16:42:53 +0300 |
commit | 34810acd6c3d4dd27f43f6f07e47b4e06bb95f82 (patch) | |
tree | 85e29ac5cb80247e5d8236453170100dd2047cd2 /spec/lib/gitlab/gpg | |
parent | 7b616d39efaa7cba933d17dfae010d393c18d057 (diff) |
move signature cache read to Gpg::Commit
as we write the cache in the gpg commit class already the read should
also happen there.
This also removes all logic from the main commit class, which just
proxies the call to the Gpg::Commit now.
Diffstat (limited to 'spec/lib/gitlab/gpg')
-rw-r--r-- | spec/lib/gitlab/gpg/commit_spec.rb | 61 |
1 files changed, 49 insertions, 12 deletions
diff --git a/spec/lib/gitlab/gpg/commit_spec.rb b/spec/lib/gitlab/gpg/commit_spec.rb index 2a583dc1bd5..539e6d4641f 100644 --- a/spec/lib/gitlab/gpg/commit_spec.rb +++ b/spec/lib/gitlab/gpg/commit_spec.rb @@ -11,19 +11,21 @@ RSpec.describe Gitlab::Gpg::Commit do end context 'known and verified public key' do - it 'returns a valid signature' do - gpg_key = create :gpg_key, key: GpgHelpers::User1.public_key, user: create(:user, email: GpgHelpers::User1.emails.first) + let!(:gpg_key) do + create :gpg_key, key: GpgHelpers::User1.public_key, user: create(:user, email: GpgHelpers::User1.emails.first) + end + let!(:commit) do raw_commit = double(:raw_commit, signature: [ GpgHelpers::User1.signed_commit_signature, GpgHelpers::User1.signed_commit_base_data ], sha: '0beec7b5ea3f0fdbc95d0dd47f3c5bc275da8a33') allow(raw_commit).to receive :save! - commit = create :commit, - git_commit: raw_commit, - project: project + create :commit, git_commit: raw_commit, project: project + end + it 'returns a valid signature' do expect(described_class.new(commit).signature).to have_attributes( commit_sha: '0beec7b5ea3f0fdbc95d0dd47f3c5bc275da8a33', project: project, @@ -32,22 +34,33 @@ RSpec.describe Gitlab::Gpg::Commit do valid_signature: true ) end + + it 'returns the cached signature on second call' do + gpg_commit = described_class.new(commit) + + expect(gpg_commit).to receive(:verified_signature).twice.and_call_original + gpg_commit.signature + + # consecutive call + expect(gpg_commit).not_to receive(:verified_signature).and_call_original + gpg_commit.signature + end end context 'known but unverified public key' do - it 'returns an invalid signature' do - gpg_key = create :gpg_key, key: GpgHelpers::User1.public_key + let!(:gpg_key) { create :gpg_key, key: GpgHelpers::User1.public_key } + let!(:commit) do raw_commit = double(:raw_commit, signature: [ GpgHelpers::User1.signed_commit_signature, GpgHelpers::User1.signed_commit_base_data ], sha: '0beec7b5ea3f0fdbc95d0dd47f3c5bc275da8a33') allow(raw_commit).to receive :save! - commit = create :commit, - git_commit: raw_commit, - project: project + create :commit, git_commit: raw_commit, project: project + end + it 'returns an invalid signature' do expect(described_class.new(commit).signature).to have_attributes( commit_sha: '0beec7b5ea3f0fdbc95d0dd47f3c5bc275da8a33', project: project, @@ -56,20 +69,33 @@ RSpec.describe Gitlab::Gpg::Commit do valid_signature: false ) end + + it 'returns the cached signature on second call' do + gpg_commit = described_class.new(commit) + + expect(gpg_commit).to receive(:verified_signature).and_call_original + gpg_commit.signature + + # consecutive call + expect(gpg_commit).not_to receive(:verified_signature).and_call_original + gpg_commit.signature + end end context 'unknown public key' do - it 'returns an invalid signature', :gpg do + let!(:commit) do raw_commit = double(:raw_commit, signature: [ GpgHelpers::User1.signed_commit_signature, GpgHelpers::User1.signed_commit_base_data ], sha: '0beec7b5ea3f0fdbc95d0dd47f3c5bc275da8a33') allow(raw_commit).to receive :save! - commit = create :commit, + create :commit, git_commit: raw_commit, project: project + end + it 'returns an invalid signature' do expect(described_class.new(commit).signature).to have_attributes( commit_sha: '0beec7b5ea3f0fdbc95d0dd47f3c5bc275da8a33', project: project, @@ -78,6 +104,17 @@ RSpec.describe Gitlab::Gpg::Commit do valid_signature: false ) end + + it 'returns the cached signature on second call' do + gpg_commit = described_class.new(commit) + + expect(gpg_commit).to receive(:verified_signature).and_call_original + gpg_commit.signature + + # consecutive call + expect(gpg_commit).not_to receive(:verified_signature).and_call_original + gpg_commit.signature + end end end end |