diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-05-20 17:34:42 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-05-20 17:34:42 +0300 |
commit | 9f46488805e86b1bc341ea1620b866016c2ce5ed (patch) | |
tree | f9748c7e287041e37d6da49e0a29c9511dc34768 /spec/features/issues/spam_issues_spec.rb | |
parent | dfc92d081ea0332d69c8aca2f0e745cb48ae5e6d (diff) |
Add latest changes from gitlab-org/gitlab@13-0-stable-ee
Diffstat (limited to 'spec/features/issues/spam_issues_spec.rb')
-rw-r--r-- | spec/features/issues/spam_issues_spec.rb | 121 |
1 files changed, 106 insertions, 15 deletions
diff --git a/spec/features/issues/spam_issues_spec.rb b/spec/features/issues/spam_issues_spec.rb index b59cd2d632a..47e7022011d 100644 --- a/spec/features/issues/spam_issues_spec.rb +++ b/spec/features/issues/spam_issues_spec.rb @@ -23,9 +23,13 @@ describe 'New issue', :js do sign_in(user) end - context 'when identified as spam' do + context 'when SpamVerdictService disallows' do + include_context 'includes Spam constants' + before do - WebMock.stub_request(:any, /.*akismet.com.*/).to_return(body: "true", status: 200) + allow_next_instance_of(Spam::SpamVerdictService) do |verdict_service| + allow(verdict_service).to receive(:execute).and_return(DISALLOW) + end visit new_project_issue_path(project) end @@ -33,23 +37,22 @@ describe 'New issue', :js do context 'when allow_possible_spam feature flag is false' do before do stub_feature_flags(allow_possible_spam: false) - end - it 'creates an issue after solving reCaptcha' do fill_in 'issue_title', with: 'issue title' fill_in 'issue_description', with: 'issue description' + end + it 'rejects issue creation' do click_button 'Submit issue' - # it is impossible to test recaptcha automatically and there is no possibility to fill in recaptcha - # recaptcha verification is skipped in test environment and it always returns true + expect(page).to have_content('discarded') + expect(page).not_to have_content('potential spam') expect(page).not_to have_content('issue title') - expect(page).to have_css('.recaptcha') - - click_button 'Submit issue' + end - expect(page.find('.issue-details h2.title')).to have_content('issue title') - expect(page.find('.issue-details .description')).to have_content('issue description') + it 'creates a spam log record' do + expect { click_button 'Submit issue' } + .to log_spam(title: 'issue title', description: 'issue description', user_id: user.id, noteable_type: 'Issue') end end @@ -59,10 +62,9 @@ describe 'New issue', :js do fill_in 'issue_description', with: 'issue description' end - it 'creates an issue without a need to solve reCaptcha' do + it 'allows issue creation' do click_button 'Submit issue' - expect(page).not_to have_css('.recaptcha') expect(page.find('.issue-details h2.title')).to have_content('issue title') expect(page.find('.issue-details .description')).to have_content('issue description') end @@ -74,9 +76,98 @@ describe 'New issue', :js do end end - context 'when not identified as spam' do + context 'when SpamVerdictService requires recaptcha' do + include_context 'includes Spam constants' + before do - WebMock.stub_request(:any, /.*akismet.com.*/).to_return(body: 'false', status: 200) + allow_next_instance_of(Spam::SpamVerdictService) do |verdict_service| + allow(verdict_service).to receive(:execute).and_return(REQUIRE_RECAPTCHA) + end + + visit new_project_issue_path(project) + end + + context 'when recaptcha is enabled' do + before do + stub_application_setting(recaptcha_enabled: true) + end + + context 'when allow_possible_spam feature flag is false' do + before do + stub_feature_flags(allow_possible_spam: false) + end + + it 'creates an issue after solving reCaptcha' do + fill_in 'issue_title', with: 'issue title' + fill_in 'issue_description', with: 'issue description' + + click_button 'Submit issue' + + # it is impossible to test reCAPTCHA automatically and there is no possibility to fill in recaptcha + # reCAPTCHA verification is skipped in test environment and it always returns true + expect(page).not_to have_content('issue title') + expect(page).to have_css('.recaptcha') + + click_button 'Submit issue' + + expect(page.find('.issue-details h2.title')).to have_content('issue title') + expect(page.find('.issue-details .description')).to have_content('issue description') + end + end + + context 'when allow_possible_spam feature flag is true' do + before do + fill_in 'issue_title', with: 'issue title' + fill_in 'issue_description', with: 'issue description' + end + + it 'creates an issue without a need to solve reCAPTCHA' do + click_button 'Submit issue' + + expect(page).not_to have_css('.recaptcha') + expect(page.find('.issue-details h2.title')).to have_content('issue title') + expect(page.find('.issue-details .description')).to have_content('issue description') + end + + it 'creates a spam log record' do + expect { click_button 'Submit issue' } + .to log_spam(title: 'issue title', description: 'issue description', user_id: user.id, noteable_type: 'Issue') + end + end + end + + context 'when reCAPTCHA is not enabled' do + before do + stub_application_setting(recaptcha_enabled: false) + end + + context 'when allow_possible_spam feature flag is true' do + before do + fill_in 'issue_title', with: 'issue title' + fill_in 'issue_description', with: 'issue description' + end + + it 'creates an issue without a need to solve reCaptcha' do + click_button 'Submit issue' + + expect(page).not_to have_css('.recaptcha') + expect(page.find('.issue-details h2.title')).to have_content('issue title') + expect(page.find('.issue-details .description')).to have_content('issue description') + end + + it 'creates a spam log record' do + expect { click_button 'Submit issue' } + .to log_spam(title: 'issue title', description: 'issue description', user_id: user.id, noteable_type: 'Issue') + end + end + end + end + + context 'when the SpamVerdictService allows' do + before do + allow_next_instance_of(Spam::SpamVerdictService) do |verdict_service| + allow(verdict_service).to receive(:execute).and_return(ALLOW) + end visit new_project_issue_path(project) end |