From 9250de6aba0d9d1f0c0a0651c9d87d47570ac103 Mon Sep 17 00:00:00 2001 From: Robert Speicher Date: Wed, 21 Nov 2018 19:00:04 +0100 Subject: Speed up "show GPG badge" feature specs Previously, this group of specs would create a new user, add them as a maintainer, sign them in, load the project's commit list, click a specific GPG key badge, and then verify the content in the popover. Now, we make the project public in order to skip the user setup and login, and load a specific commit page because it loads faster than the commit list while still showing the GPG badge. --- spec/features/signed_commits_spec.rb | 52 ++++++++++++++---------------------- 1 file changed, 20 insertions(+), 32 deletions(-) diff --git a/spec/features/signed_commits_spec.rb b/spec/features/signed_commits_spec.rb index ef0e55a1468..22b47a9cb49 100644 --- a/spec/features/signed_commits_spec.rb +++ b/spec/features/signed_commits_spec.rb @@ -1,8 +1,8 @@ require 'spec_helper' describe 'GPG signed commits', :js do - set(:ref) { :'2d1096e3a0ecf1d2baf6dee036cc80775d4940ba' } - let(:project) { create(:project, :repository) } + let(:ref) { '2d1096e3a0ecf1d2baf6dee036cc80775d4940ba' } + let(:project) { create(:project, :public, :repository) } 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' @@ -62,6 +62,7 @@ describe 'GPG signed commits', :js do end context 'shows popover badges' do + let(:ref) { GpgHelpers::SIGNED_COMMIT_SHA } let(:user_1) do create :user, email: GpgHelpers::User1.emails.first, username: 'nannie.bernhard', name: 'Nannie Bernhard' end @@ -85,19 +86,10 @@ describe 'GPG signed commits', :js do end end - before do - user = create :user - project.add_maintainer(user) - - sign_in(user) - end - it 'unverified signature' do - visit project_commits_path(project, ref) + visit project_commit_path(project, ref) - within(find('.commit', text: 'signed commit by bette cartwright')) do - click_on 'Unverified' - end + click_on 'Unverified' within '.popover' do expect(page).to have_content 'This commit was signed with an unverified signature.' @@ -106,13 +98,13 @@ describe 'GPG signed commits', :js do end it 'unverified signature: user email does not match the committer email, but is the same user' do + ref = 'a17a9f66543673edf0a3d1c6b93bdda3fe600f32' + user_2_key - visit project_commits_path(project, ref) + visit project_commit_path(project, ref) - within(find('.commit', text: 'signed and authored commit by bette cartwright, different email')) do - click_on 'Unverified' - end + click_on 'Unverified' 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.' @@ -125,11 +117,9 @@ describe 'GPG signed commits', :js do it 'unverified signature: user email does not match the committer email' do user_2_key - visit project_commits_path(project, ref) + visit project_commit_path(project, ref) - within(find('.commit', text: 'signed commit by bette cartwright')) do - click_on 'Unverified' - end + click_on 'Unverified' within '.popover' do expect(page).to have_content "This commit was signed with a different user's verified signature." @@ -140,13 +130,13 @@ describe 'GPG signed commits', :js do end it 'verified and the gpg user has a gitlab profile' do + ref = '3c1d9a0266cb0c62d926f4a6c649beed561846f5' + user_1_key - visit project_commits_path(project, ref) + visit project_commit_path(project, ref) - within(find('.commit', text: 'signed and authored commit by nannie bernhard')) do - click_on 'Verified' - end + click_on 'Verified' 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.' @@ -157,22 +147,20 @@ describe 'GPG signed commits', :js do end it "verified and the gpg user's profile doesn't exist anymore" do + ref = '3c1d9a0266cb0c62d926f4a6c649beed561846f5' + user_1_key - visit project_commits_path(project, ref) + visit project_commit_path(project, ref) # wait for the signature to get generated - within(find('.commit', text: 'signed and authored commit by nannie bernhard')) do - expect(page).to have_content 'Verified' - end + expect(page).to have_content 'Verified' user_1.destroy! refresh - within(find('.commit', text: 'signed and authored commit by nannie bernhard')) do - click_on 'Verified' - end + click_on 'Verified' 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.' -- cgit v1.2.3 From 8afd0381229978faa5d3111e37656f7ebf63ab89 Mon Sep 17 00:00:00 2001 From: Robert Speicher Date: Wed, 21 Nov 2018 19:32:04 +0100 Subject: Remove magic SHAs from GPG badge feature spec We're trying to give the arbitrary SHAs required by each spec a meaningful name. This also adds an explicit `ref` definition to each spec so we're not dealing with a mystery guest. --- spec/features/signed_commits_spec.rb | 21 ++++++++------------- spec/support/helpers/gpg_helpers.rb | 6 +++++- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/spec/features/signed_commits_spec.rb b/spec/features/signed_commits_spec.rb index 22b47a9cb49..1efe94e727e 100644 --- a/spec/features/signed_commits_spec.rb +++ b/spec/features/signed_commits_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'GPG signed commits', :js do @@ -61,8 +63,7 @@ describe 'GPG signed commits', :js do end end - context 'shows popover badges' do - let(:ref) { GpgHelpers::SIGNED_COMMIT_SHA } + context 'shows popover badges', :js do let(:user_1) do create :user, email: GpgHelpers::User1.emails.first, username: 'nannie.bernhard', name: 'Nannie Bernhard' end @@ -87,7 +88,7 @@ describe 'GPG signed commits', :js do end it 'unverified signature' do - visit project_commit_path(project, ref) + visit project_commit_path(project, GpgHelpers::SIGNED_COMMIT_SHA) click_on 'Unverified' @@ -98,11 +99,9 @@ describe 'GPG signed commits', :js do end it 'unverified signature: user email does not match the committer email, but is the same user' do - ref = 'a17a9f66543673edf0a3d1c6b93bdda3fe600f32' - user_2_key - visit project_commit_path(project, ref) + visit project_commit_path(project, GpgHelpers::DIFFERING_EMAIL_SHA) click_on 'Unverified' @@ -117,7 +116,7 @@ describe 'GPG signed commits', :js do it 'unverified signature: user email does not match the committer email' do user_2_key - visit project_commit_path(project, ref) + visit project_commit_path(project, GpgHelpers::SIGNED_COMMIT_SHA) click_on 'Unverified' @@ -130,11 +129,9 @@ describe 'GPG signed commits', :js do end it 'verified and the gpg user has a gitlab profile' do - ref = '3c1d9a0266cb0c62d926f4a6c649beed561846f5' - user_1_key - visit project_commit_path(project, ref) + visit project_commit_path(project, GpgHelpers::SIGNED_AND_AUTHORED_SHA) click_on 'Verified' @@ -147,11 +144,9 @@ describe 'GPG signed commits', :js do end it "verified and the gpg user's profile doesn't exist anymore" do - ref = '3c1d9a0266cb0c62d926f4a6c649beed561846f5' - user_1_key - visit project_commit_path(project, ref) + visit project_commit_path(project, GpgHelpers::SIGNED_AND_AUTHORED_SHA) # wait for the signature to get generated expect(page).to have_content 'Verified' diff --git a/spec/support/helpers/gpg_helpers.rb b/spec/support/helpers/gpg_helpers.rb index 3f7279a50e0..8d1637228d0 100644 --- a/spec/support/helpers/gpg_helpers.rb +++ b/spec/support/helpers/gpg_helpers.rb @@ -1,5 +1,9 @@ +# frozen_string_literal: true + module GpgHelpers - SIGNED_COMMIT_SHA = '8a852d50dda17cc8fd1408d2fd0c5b0f24c76ca4'.freeze + SIGNED_COMMIT_SHA = '8a852d50dda17cc8fd1408d2fd0c5b0f24c76ca4' + SIGNED_AND_AUTHORED_SHA = '3c1d9a0266cb0c62d926f4a6c649beed561846f5' + DIFFERING_EMAIL_SHA = 'a17a9f66543673edf0a3d1c6b93bdda3fe600f32' module User1 extend self -- cgit v1.2.3 From ee17268690eba03a3f5e7086f0a679f815a84888 Mon Sep 17 00:00:00 2001 From: Robert Speicher Date: Wed, 21 Nov 2018 19:33:36 +0100 Subject: Simplify "changes to verified" GPG feature specs Previously, we wasted time creating a maintainer and signing them in, then loaded the entire commit list just to verify the GPG status of a single commit. Now, we rely on the project being public so no user needs to be authenticated, and load just the page for the commit we care about. --- spec/features/signed_commits_spec.rb | 47 +++++++++++++----------------------- 1 file changed, 17 insertions(+), 30 deletions(-) diff --git a/spec/features/signed_commits_spec.rb b/spec/features/signed_commits_spec.rb index 1efe94e727e..10b6900799f 100644 --- a/spec/features/signed_commits_spec.rb +++ b/spec/features/signed_commits_spec.rb @@ -2,26 +2,21 @@ require 'spec_helper' -describe 'GPG signed commits', :js do - let(:ref) { '2d1096e3a0ecf1d2baf6dee036cc80775d4940ba' } +describe 'GPG signed commits' do let(:project) { create(:project, :public, :repository) } 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' - project.add_maintainer(user) + ref = GpgHelpers::SIGNED_AND_AUTHORED_SHA + user = create(:user, email: 'unrelated.user@example.org') perform_enqueued_jobs do create :gpg_key, key: GpgHelpers::User1.public_key, user: user end - sign_in(user) + visit project_commit_path(project, ref) - visit project_commits_path(project, ref) - - within '#commits-list' do - expect(page).to have_content 'Unverified' - expect(page).not_to have_content 'Verified' - end + expect(page).to have_content 'Unverified' + expect(page).not_to have_content 'Verified' # user changes his email which makes the gpg key verified perform_enqueued_jobs do @@ -29,38 +24,30 @@ describe 'GPG signed commits', :js do user.update!(email: GpgHelpers::User1.emails.first) end - visit project_commits_path(project, ref) + visit project_commit_path(project, ref) - within '#commits-list' do - expect(page).to have_content 'Unverified' - expect(page).to have_content 'Verified' - end + expect(page).not_to have_content 'Unverified' + expect(page).to have_content 'Verified' end it 'changes from unverified to verified when the user adds the missing gpg key' do - user = create :user, email: GpgHelpers::User1.emails.first - project.add_maintainer(user) + ref = GpgHelpers::SIGNED_AND_AUTHORED_SHA + user = create(:user, email: GpgHelpers::User1.emails.first) - sign_in(user) + visit project_commit_path(project, ref) - visit project_commits_path(project, ref) - - within '#commits-list' do - expect(page).to have_content 'Unverified' - expect(page).not_to have_content 'Verified' - end + expect(page).to have_content 'Unverified' + expect(page).not_to have_content 'Verified' # user adds the gpg key which makes the signature valid perform_enqueued_jobs do create :gpg_key, key: GpgHelpers::User1.public_key, user: user end - visit project_commits_path(project, ref) + visit project_commit_path(project, ref) - within '#commits-list' do - expect(page).to have_content 'Unverified' - expect(page).to have_content 'Verified' - end + expect(page).not_to have_content 'Unverified' + expect(page).to have_content 'Verified' end context 'shows popover badges', :js do -- cgit v1.2.3 From 87d1e865f57fbaa73f44ac196ec712ce2224e7e7 Mon Sep 17 00:00:00 2001 From: Robert Speicher Date: Wed, 21 Nov 2018 19:41:52 +0100 Subject: Use have_link over have_content for GPG feature It's more semantically accurate for what we're verifying. --- spec/features/signed_commits_spec.rb | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/spec/features/signed_commits_spec.rb b/spec/features/signed_commits_spec.rb index 10b6900799f..e2b3444272e 100644 --- a/spec/features/signed_commits_spec.rb +++ b/spec/features/signed_commits_spec.rb @@ -15,8 +15,8 @@ describe 'GPG signed commits' do visit project_commit_path(project, ref) - expect(page).to have_content 'Unverified' - expect(page).not_to have_content 'Verified' + expect(page).to have_link 'Unverified' + expect(page).not_to have_link 'Verified' # user changes his email which makes the gpg key verified perform_enqueued_jobs do @@ -26,8 +26,8 @@ describe 'GPG signed commits' do visit project_commit_path(project, ref) - expect(page).not_to have_content 'Unverified' - expect(page).to have_content 'Verified' + expect(page).not_to have_link 'Unverified' + expect(page).to have_link 'Verified' end it 'changes from unverified to verified when the user adds the missing gpg key' do @@ -36,8 +36,8 @@ describe 'GPG signed commits' do visit project_commit_path(project, ref) - expect(page).to have_content 'Unverified' - expect(page).not_to have_content 'Verified' + expect(page).to have_link 'Unverified' + expect(page).not_to have_link 'Verified' # user adds the gpg key which makes the signature valid perform_enqueued_jobs do @@ -46,8 +46,8 @@ describe 'GPG signed commits' do visit project_commit_path(project, ref) - expect(page).not_to have_content 'Unverified' - expect(page).to have_content 'Verified' + expect(page).not_to have_link 'Unverified' + expect(page).to have_link 'Verified' end context 'shows popover badges', :js do @@ -136,7 +136,7 @@ describe 'GPG signed commits' do visit project_commit_path(project, GpgHelpers::SIGNED_AND_AUTHORED_SHA) # wait for the signature to get generated - expect(page).to have_content 'Verified' + expect(page).to have_link 'Verified' user_1.destroy! -- cgit v1.2.3