diff options
author | Alexis Reigel <mail@koffeinfrei.org> | 2017-08-24 14:21:42 +0200 |
---|---|---|
committer | Alexis Reigel <mail@koffeinfrei.org> | 2017-09-05 12:18:32 +0200 |
commit | 00392d929b4553a9ed8e1938cb11f091b79566c9 (patch) | |
tree | a5b61a15f1283bec4bc6b0e471186d09c3893f65 /spec | |
parent | 2a89037b63967aac0725cf4e122cecbe0c3c5596 (diff) | |
download | gitlab-ce-00392d929b4553a9ed8e1938cb11f091b79566c9.tar.gz |
add verification_status: same_user_different_email
this is used to make a difference between a committer email that belongs
to user, where the user used a different email for the gpg key. this
means that the user is the same, but a different, unverified email is
used for the signature.
Diffstat (limited to 'spec')
-rw-r--r-- | spec/lib/gitlab/gpg/commit_spec.rb | 44 |
1 files changed, 42 insertions, 2 deletions
diff --git a/spec/lib/gitlab/gpg/commit_spec.rb b/spec/lib/gitlab/gpg/commit_spec.rb index 843418aef6d..40113429d23 100644 --- a/spec/lib/gitlab/gpg/commit_spec.rb +++ b/spec/lib/gitlab/gpg/commit_spec.rb @@ -28,7 +28,7 @@ describe Gitlab::Gpg::Commit do context 'known key' do context 'user matches the key uid' do - context 'user matches the committer' do + context 'user email matches the email committer' do let!(:commit) { create :commit, project: project, sha: commit_sha, committer_email: GpgHelpers::User1.emails.first } let!(:user) { create(:user, email: GpgHelpers::User1.emails.first) } @@ -64,7 +64,47 @@ describe Gitlab::Gpg::Commit do it_behaves_like 'returns the cached signature on second call' end - context 'user does not match the committer' do + context 'user email does not match the committer email, but is the same user' do + let!(:commit) { create :commit, project: project, sha: commit_sha, committer_email: GpgHelpers::User2.emails.first } + + let(:user) do + create(:user, email: GpgHelpers::User1.emails.first).tap do |user| + create :email, user: user, email: GpgHelpers::User2.emails.first + end + end + + let!(:gpg_key) do + create :gpg_key, key: GpgHelpers::User1.public_key, user: user + end + + before do + allow(Rugged::Commit).to receive(:extract_signature) + .with(Rugged::Repository, commit_sha) + .and_return( + [ + GpgHelpers::User1.signed_commit_signature, + GpgHelpers::User1.signed_commit_base_data + ] + ) + end + + it 'returns an invalid signature' do + expect(described_class.new(commit).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, + valid_signature: false, + verification_status: 'same_user_different_email' + ) + end + + it_behaves_like 'returns the cached signature on second call' + end + + context 'user email does not match the committer email' do let!(:commit) { create :commit, project: project, sha: commit_sha, committer_email: GpgHelpers::User2.emails.first } let(:user) { create(:user, email: GpgHelpers::User1.emails.first) } |