From 7bb7a8d529fd1155a35a2e9e9cdddd7953f3776d Mon Sep 17 00:00:00 2001 From: GitLab Bot Date: Wed, 25 Sep 2019 03:06:21 +0000 Subject: Add latest changes from gitlab-org/gitlab@master --- spec/features/snippets/spam_snippets_spec.rb | 73 ++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 spec/features/snippets/spam_snippets_spec.rb (limited to 'spec/features/snippets') diff --git a/spec/features/snippets/spam_snippets_spec.rb b/spec/features/snippets/spam_snippets_spec.rb new file mode 100644 index 00000000000..3e71a4e7879 --- /dev/null +++ b/spec/features/snippets/spam_snippets_spec.rb @@ -0,0 +1,73 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe 'User creates snippet', :js do + let(:user) { create(:user) } + + before do + stub_feature_flags(allow_possible_spam: false) + stub_env('IN_MEMORY_APPLICATION_SETTINGS', 'false') + + Gitlab::CurrentSettings.update!( + akismet_enabled: true, + akismet_api_key: 'testkey', + recaptcha_enabled: true, + recaptcha_site_key: 'test site key', + recaptcha_private_key: 'test private key' + ) + + sign_in(user) + visit new_snippet_path + + fill_in 'personal_snippet_title', with: 'My Snippet Title' + fill_in 'personal_snippet_description', with: 'My Snippet **Description**' + find('#personal_snippet_visibility_level_20').set(true) + page.within('.file-editor') do + find('.ace_text-input', visible: false).send_keys 'Hello World!' + end + end + + 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 + expect(page).not_to have_content('My Snippet Title') + expect(page).to have_css('.recaptcha') + click_button('Submit personal snippet') + + expect(page).to have_content('My Snippet Title') + end + end + + context 'when identified as a spam' do + before do + WebMock.stub_request(:any, /.*akismet.com.*/).to_return(body: "true", status: 200) + end + + context 'when allow_possible_spam feature flag is false' do + it_behaves_like 'solve recaptcha' + end + + context 'when allow_possible_spam feature flag is true' do + it_behaves_like 'solve recaptcha' + end + end + + context 'when not identified as a spam' do + before do + WebMock.stub_request(:any, /.*akismet.com.*/).to_return(body: "false", status: 200) + end + + it 'creates a snippet' do + click_button('Create snippet') + wait_for_requests + + expect(page).not_to have_css('.recaptcha') + expect(page).to have_content('My Snippet Title') + end + end +end -- cgit v1.2.1