Commit efe4067e authored by Rémy Coutable's avatar Rémy Coutable

Merge branch 'rs-signed-commits-spec' into 'master'

Speed up "show GPG badge" feature specs

See merge request gitlab-org/gitlab-ce!23359
parents 7f477f7b 87d1e865
# frozen_string_literal: true
require 'spec_helper' require 'spec_helper'
describe 'GPG signed commits', :js do describe 'GPG signed commits' do
set(:ref) { :'2d1096e3a0ecf1d2baf6dee036cc80775d4940ba' } let(:project) { create(:project, :public, :repository) }
let(:project) { create(:project, :repository) }
it 'changes from unverified to verified when the user changes his email to match the gpg key' do it 'changes from unverified to verified when the user changes his email to match the gpg key' do
user = create :user, email: 'unrelated.user@example.org' ref = GpgHelpers::SIGNED_AND_AUTHORED_SHA
project.add_maintainer(user) user = create(:user, email: 'unrelated.user@example.org')
perform_enqueued_jobs do perform_enqueued_jobs do
create :gpg_key, key: GpgHelpers::User1.public_key, user: user create :gpg_key, key: GpgHelpers::User1.public_key, user: user
end end
sign_in(user) visit project_commit_path(project, ref)
visit project_commits_path(project, ref)
within '#commits-list' do expect(page).to have_link 'Unverified'
expect(page).to have_content 'Unverified' expect(page).not_to have_link 'Verified'
expect(page).not_to have_content 'Verified'
end
# user changes his email which makes the gpg key verified # user changes his email which makes the gpg key verified
perform_enqueued_jobs do perform_enqueued_jobs do
...@@ -27,41 +24,33 @@ describe 'GPG signed commits', :js do ...@@ -27,41 +24,33 @@ describe 'GPG signed commits', :js do
user.update!(email: GpgHelpers::User1.emails.first) user.update!(email: GpgHelpers::User1.emails.first)
end end
visit project_commits_path(project, ref) visit project_commit_path(project, ref)
within '#commits-list' do expect(page).not_to have_link 'Unverified'
expect(page).to have_content 'Unverified' expect(page).to have_link 'Verified'
expect(page).to have_content 'Verified'
end
end end
it 'changes from unverified to verified when the user adds the missing gpg key' do it 'changes from unverified to verified when the user adds the missing gpg key' do
user = create :user, email: GpgHelpers::User1.emails.first ref = GpgHelpers::SIGNED_AND_AUTHORED_SHA
project.add_maintainer(user) user = create(:user, email: GpgHelpers::User1.emails.first)
sign_in(user) visit project_commit_path(project, ref)
visit project_commits_path(project, ref) expect(page).to have_link 'Unverified'
expect(page).not_to have_link 'Verified'
within '#commits-list' do
expect(page).to have_content 'Unverified'
expect(page).not_to have_content 'Verified'
end
# user adds the gpg key which makes the signature valid # user adds the gpg key which makes the signature valid
perform_enqueued_jobs do perform_enqueued_jobs do
create :gpg_key, key: GpgHelpers::User1.public_key, user: user create :gpg_key, key: GpgHelpers::User1.public_key, user: user
end end
visit project_commits_path(project, ref) visit project_commit_path(project, ref)
within '#commits-list' do expect(page).not_to have_link 'Unverified'
expect(page).to have_content 'Unverified' expect(page).to have_link 'Verified'
expect(page).to have_content 'Verified'
end
end end
context 'shows popover badges' do context 'shows popover badges', :js do
let(:user_1) do let(:user_1) do
create :user, email: GpgHelpers::User1.emails.first, username: 'nannie.bernhard', name: 'Nannie Bernhard' create :user, email: GpgHelpers::User1.emails.first, username: 'nannie.bernhard', name: 'Nannie Bernhard'
end end
...@@ -85,19 +74,10 @@ describe 'GPG signed commits', :js do ...@@ -85,19 +74,10 @@ describe 'GPG signed commits', :js do
end end
end end
before do
user = create :user
project.add_maintainer(user)
sign_in(user)
end
it 'unverified signature' do it 'unverified signature' do
visit project_commits_path(project, ref) visit project_commit_path(project, GpgHelpers::SIGNED_COMMIT_SHA)
within(find('.commit', text: 'signed commit by bette cartwright')) do
click_on 'Unverified' click_on 'Unverified'
end
within '.popover' do within '.popover' do
expect(page).to have_content 'This commit was signed with an unverified signature.' expect(page).to have_content 'This commit was signed with an unverified signature.'
...@@ -108,11 +88,9 @@ describe 'GPG signed commits', :js do ...@@ -108,11 +88,9 @@ describe 'GPG signed commits', :js do
it 'unverified signature: user email does not match the committer email, but is the same user' do it 'unverified signature: user email does not match the committer email, but is the same user' do
user_2_key user_2_key
visit project_commits_path(project, ref) visit project_commit_path(project, GpgHelpers::DIFFERING_EMAIL_SHA)
within(find('.commit', text: 'signed and authored commit by bette cartwright, different email')) do
click_on 'Unverified' click_on 'Unverified'
end
within '.popover' do within '.popover' do
expect(page).to have_content 'This commit was signed with a verified signature, but the committer email is not verified to belong to the same user.' expect(page).to have_content 'This commit was signed with a verified signature, but the committer email is not verified to belong to the same user.'
...@@ -125,11 +103,9 @@ describe 'GPG signed commits', :js do ...@@ -125,11 +103,9 @@ describe 'GPG signed commits', :js do
it 'unverified signature: user email does not match the committer email' do it 'unverified signature: user email does not match the committer email' do
user_2_key user_2_key
visit project_commits_path(project, ref) visit project_commit_path(project, GpgHelpers::SIGNED_COMMIT_SHA)
within(find('.commit', text: 'signed commit by bette cartwright')) do
click_on 'Unverified' click_on 'Unverified'
end
within '.popover' do within '.popover' do
expect(page).to have_content "This commit was signed with a different user's verified signature." expect(page).to have_content "This commit was signed with a different user's verified signature."
...@@ -142,11 +118,9 @@ describe 'GPG signed commits', :js do ...@@ -142,11 +118,9 @@ describe 'GPG signed commits', :js do
it 'verified and the gpg user has a gitlab profile' do it 'verified and the gpg user has a gitlab profile' do
user_1_key user_1_key
visit project_commits_path(project, ref) visit project_commit_path(project, GpgHelpers::SIGNED_AND_AUTHORED_SHA)
within(find('.commit', text: 'signed and authored commit by nannie bernhard')) do
click_on 'Verified' click_on 'Verified'
end
within '.popover' do within '.popover' do
expect(page).to have_content 'This commit was signed with a verified signature and the committer email is verified to belong to the same user.' expect(page).to have_content 'This commit was signed with a verified signature and the committer email is verified to belong to the same user.'
...@@ -159,20 +133,16 @@ describe 'GPG signed commits', :js do ...@@ -159,20 +133,16 @@ describe 'GPG signed commits', :js do
it "verified and the gpg user's profile doesn't exist anymore" do it "verified and the gpg user's profile doesn't exist anymore" do
user_1_key user_1_key
visit project_commits_path(project, ref) visit project_commit_path(project, GpgHelpers::SIGNED_AND_AUTHORED_SHA)
# wait for the signature to get generated # wait for the signature to get generated
within(find('.commit', text: 'signed and authored commit by nannie bernhard')) do expect(page).to have_link 'Verified'
expect(page).to have_content 'Verified'
end
user_1.destroy! user_1.destroy!
refresh refresh
within(find('.commit', text: 'signed and authored commit by nannie bernhard')) do
click_on 'Verified' click_on 'Verified'
end
within '.popover' do within '.popover' do
expect(page).to have_content 'This commit was signed with a verified signature and the committer email is verified to belong to the same user.' expect(page).to have_content 'This commit was signed with a verified signature and the committer email is verified to belong to the same user.'
......
# frozen_string_literal: true
module GpgHelpers module GpgHelpers
SIGNED_COMMIT_SHA = '8a852d50dda17cc8fd1408d2fd0c5b0f24c76ca4'.freeze SIGNED_COMMIT_SHA = '8a852d50dda17cc8fd1408d2fd0c5b0f24c76ca4'
SIGNED_AND_AUTHORED_SHA = '3c1d9a0266cb0c62d926f4a6c649beed561846f5'
DIFFERING_EMAIL_SHA = 'a17a9f66543673edf0a3d1c6b93bdda3fe600f32'
module User1 module User1
extend self extend self
......
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