diff options
Diffstat (limited to 'spec/features/snippets/spam_snippets_spec.rb')
-rw-r--r-- | spec/features/snippets/spam_snippets_spec.rb | 76 |
1 files changed, 53 insertions, 23 deletions
diff --git a/spec/features/snippets/spam_snippets_spec.rb b/spec/features/snippets/spam_snippets_spec.rb index 69e3f190725..d7b181dc678 100644 --- a/spec/features/snippets/spam_snippets_spec.rb +++ b/spec/features/snippets/spam_snippets_spec.rb @@ -3,6 +3,8 @@ require 'spec_helper' shared_examples_for 'snippet editor' do + include_context 'includes Spam constants' + def description_field find('.js-description-input').find('input,textarea') end @@ -11,7 +13,6 @@ shared_examples_for 'snippet editor' do stub_feature_flags(allow_possible_spam: false) stub_feature_flags(snippets_vue: false) stub_feature_flags(snippets_edit_vue: false) - stub_feature_flags(monaco_snippets: flag) stub_env('IN_MEMORY_APPLICATION_SETTINGS', 'false') Gitlab::CurrentSettings.update!( @@ -33,18 +34,18 @@ shared_examples_for 'snippet editor' do find('#personal_snippet_visibility_level_20').set(true) page.within('.file-editor') do - el = flag == true ? find('.inputarea') : find('.ace_text-input', visible: false) + el = find('.inputarea') el.send_keys 'Hello World!' end end - shared_examples 'solve recaptcha' do - it 'creates a snippet after solving reCaptcha' do + shared_examples 'solve reCAPTCHA' do + it 'creates a snippet after solving reCAPTCHA' do click_button('Create snippet') wait_for_requests - # 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 + # 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('My Snippet Title') expect(page).to have_css('.recaptcha') click_button('Submit personal snippet') @@ -53,23 +54,62 @@ shared_examples_for 'snippet editor' do end end - context 'when identified as spam' do + shared_examples 'does not allow creation' do + it 'rejects creation of the snippet' do + click_button('Create snippet') + wait_for_requests + + expect(page).to have_content('discarded') + expect(page).not_to have_content('My Snippet Title') + expect(page).not_to have_css('.recaptcha') + end + end + + context 'when SpamVerdictService requires recaptcha' do + before do + expect_next_instance_of(Spam::SpamVerdictService) do |verdict_service| + expect(verdict_service).to receive(:execute).and_return(REQUIRE_RECAPTCHA) + end + end + + context 'when allow_possible_spam feature flag is false' do + before do + stub_application_setting(recaptcha_enabled: false) + end + + it_behaves_like 'does not allow creation' + end + + context 'when allow_possible_spam feature flag is true' do + it_behaves_like 'solve reCAPTCHA' + end + end + + context 'when SpamVerdictService disallows' do before do - WebMock.stub_request(:any, /.*akismet.com.*/).to_return(body: "true", status: 200) + expect_next_instance_of(Spam::SpamVerdictService) do |verdict_service| + expect(verdict_service).to receive(:execute).and_return(DISALLOW) + end end context 'when allow_possible_spam feature flag is false' do - it_behaves_like 'solve recaptcha' + before do + stub_application_setting(recaptcha_enabled: false) + end + + it_behaves_like 'does not allow creation' end context 'when allow_possible_spam feature flag is true' do - it_behaves_like 'solve recaptcha' + it_behaves_like 'does not allow creation' end end - context 'when not identified as spam' do + context 'when SpamVerdictService allows' do before do - WebMock.stub_request(:any, /.*akismet.com.*/).to_return(body: "false", status: 200) + expect_next_instance_of(Spam::SpamVerdictService) do |verdict_service| + expect(verdict_service).to receive(:execute).and_return(ALLOW) + end end it 'creates a snippet' do @@ -85,15 +125,5 @@ end describe 'User creates snippet', :js do let_it_be(:user) { create(:user) } - context 'when using Monaco' do - it_behaves_like "snippet editor" do - let(:flag) { true } - end - end - - context 'when using ACE' do - it_behaves_like "snippet editor" do - let(:flag) { false } - end - end + it_behaves_like "snippet editor" end |