debian-mirror-gitlab/spec/features/snippets/spam_snippets_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

129 lines
3.7 KiB
Ruby
Raw Permalink Normal View History

2019-12-21 20:55:43 +05:30
# frozen_string_literal: true
require 'spec_helper'
2023-03-04 22:38:38 +05:30
RSpec.describe 'snippet editor with spam', skip: "Will be handled in https://gitlab.com/gitlab-org/gitlab/-/issues/217722",
feature_category: :source_code_management do
2020-05-24 23:13:21 +05:30
include_context 'includes Spam constants'
2021-01-03 14:25:43 +05:30
let_it_be(:user) { create(:user) }
2020-03-13 15:44:24 +05:30
def description_field
2020-04-08 14:13:33 +05:30
find('.js-description-input').find('input,textarea')
2020-03-13 15:44:24 +05:30
end
2019-12-21 20:55:43 +05:30
before do
stub_env('IN_MEMORY_APPLICATION_SETTINGS', 'false')
Gitlab::CurrentSettings.update!(
akismet_enabled: true,
akismet_api_key: 'testkey',
2021-06-08 01:23:25 +05:30
spam_check_api_key: 'testkey',
2019-12-21 20:55:43 +05:30
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'
2020-03-13 15:44:24 +05:30
# Click placeholder first to expand full description field
description_field.click
2019-12-21 20:55:43 +05:30
fill_in 'personal_snippet_description', with: 'My Snippet **Description**'
2020-03-13 15:44:24 +05:30
2019-12-21 20:55:43 +05:30
find('#personal_snippet_visibility_level_20').set(true)
page.within('.file-editor') do
2020-05-24 23:13:21 +05:30
el = find('.inputarea')
2020-04-08 14:13:33 +05:30
el.send_keys 'Hello World!'
2019-12-21 20:55:43 +05:30
end
end
2020-05-24 23:13:21 +05:30
shared_examples 'solve reCAPTCHA' do
it 'creates a snippet after solving reCAPTCHA' do
2019-12-21 20:55:43 +05:30
click_button('Create snippet')
wait_for_requests
2020-05-24 23:13:21 +05:30
# 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
2019-12-21 20:55:43 +05:30
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
2020-05-24 23:13:21 +05:30
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|
2020-06-23 00:09:42 +05:30
expect(verdict_service).to receive(:execute).and_return(CONDITIONAL_ALLOW)
2020-05-24 23:13:21 +05:30
end
end
2023-04-23 21:23:45 +05:30
context 'when allow_possible_spam application setting is false' do
2020-05-24 23:13:21 +05:30
it_behaves_like 'does not allow creation'
end
2023-04-23 21:23:45 +05:30
context 'when allow_possible_spam application setting is true' do
before do
stub_application_setting(allow_possible_spam: true)
end
2020-05-24 23:13:21 +05:30
it_behaves_like 'solve reCAPTCHA'
end
end
context 'when SpamVerdictService disallows' do
2019-12-21 20:55:43 +05:30
before do
2020-05-24 23:13:21 +05:30
expect_next_instance_of(Spam::SpamVerdictService) do |verdict_service|
expect(verdict_service).to receive(:execute).and_return(DISALLOW)
end
2019-12-21 20:55:43 +05:30
end
2023-04-23 21:23:45 +05:30
context 'when allow_possible_spam application setting is false' do
2020-05-24 23:13:21 +05:30
before do
stub_application_setting(recaptcha_enabled: false)
end
it_behaves_like 'does not allow creation'
2019-12-21 20:55:43 +05:30
end
2023-04-23 21:23:45 +05:30
context 'when allow_possible_spam application setting is true' do
before do
stub_application_setting(allow_possible_spam: true)
end
2020-05-24 23:13:21 +05:30
it_behaves_like 'does not allow creation'
2019-12-21 20:55:43 +05:30
end
end
2020-05-24 23:13:21 +05:30
context 'when SpamVerdictService allows' do
2019-12-21 20:55:43 +05:30
before do
2020-05-24 23:13:21 +05:30
expect_next_instance_of(Spam::SpamVerdictService) do |verdict_service|
expect(verdict_service).to receive(:execute).and_return(ALLOW)
end
2019-12-21 20:55:43 +05:30
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