debian-mirror-gitlab/spec/features/issues/spam_issues_spec.rb

95 lines
2.9 KiB
Ruby
Raw Normal View History

2019-10-12 21:52:04 +05:30
# frozen_string_literal: true
2019-12-04 20:38:33 +05:30
require 'spec_helper'
2017-08-17 22:00:37 +05:30
2018-03-17 18:26:18 +05:30
describe 'New issue', :js do
2017-08-17 22:00:37 +05:30
include StubENV
let(:project) { create(:project, :public) }
let(:user) { create(:user)}
before do
stub_env('IN_MEMORY_APPLICATION_SETTINGS', 'false')
2018-03-17 18:26:18 +05:30
Gitlab::CurrentSettings.update!(
2017-08-17 22:00:37 +05:30
akismet_enabled: true,
akismet_api_key: 'testkey',
recaptcha_enabled: true,
recaptcha_site_key: 'test site key',
recaptcha_private_key: 'test private key'
)
2018-11-18 11:00:15 +05:30
project.add_maintainer(user)
2017-09-10 17:25:29 +05:30
sign_in(user)
2017-08-17 22:00:37 +05:30
end
2020-04-22 19:07:51 +05:30
context 'when identified as spam' do
2017-08-17 22:00:37 +05:30
before do
WebMock.stub_request(:any, /.*akismet.com.*/).to_return(body: "true", status: 200)
2017-09-10 17:25:29 +05:30
visit new_project_issue_path(project)
2017-08-17 22:00:37 +05:30
end
2019-12-21 20:55:43 +05:30
context 'when allow_possible_spam feature flag is false' do
before do
stub_feature_flags(allow_possible_spam: false)
end
2017-08-17 22:00:37 +05:30
2019-12-21 20:55:43 +05:30
it 'creates an issue after solving reCaptcha' do
fill_in 'issue_title', with: 'issue title'
fill_in 'issue_description', with: 'issue description'
2017-08-17 22:00:37 +05:30
2019-12-21 20:55:43 +05:30
click_button 'Submit issue'
2017-08-17 22:00:37 +05:30
2019-12-21 20:55:43 +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
expect(page).not_to have_content('issue title')
expect(page).to have_css('.recaptcha')
2017-08-17 22:00:37 +05:30
2019-12-21 20:55:43 +05:30
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
2017-08-17 22:00:37 +05:30
end
end
2020-04-22 19:07:51 +05:30
context 'when not identified as spam' do
2017-08-17 22:00:37 +05:30
before do
WebMock.stub_request(:any, /.*akismet.com.*/).to_return(body: 'false', status: 200)
2017-09-10 17:25:29 +05:30
visit new_project_issue_path(project)
2017-08-17 22:00:37 +05:30
end
it 'creates an issue' do
fill_in 'issue_title', with: 'issue title'
fill_in 'issue_description', with: 'issue description'
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
end