2019-07-25 01:24:42 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2019-08-29 03:56:52 -04:00
|
|
|
require 'spec_helper'
|
2017-01-27 11:25:39 -05:00
|
|
|
|
2020-06-16 14:09:01 -04:00
|
|
|
RSpec.describe 'New issue', :js do
|
2017-01-27 11:25:39 -05:00
|
|
|
include StubENV
|
|
|
|
|
2017-08-02 15:55:11 -04:00
|
|
|
let(:project) { create(:project, :public) }
|
2017-01-27 11:25:39 -05:00
|
|
|
let(:user) { create(:user)}
|
|
|
|
|
|
|
|
before do
|
|
|
|
stub_env('IN_MEMORY_APPLICATION_SETTINGS', 'false')
|
|
|
|
|
2018-02-02 13:39:55 -05:00
|
|
|
Gitlab::CurrentSettings.update!(
|
2017-01-27 11:25:39 -05:00
|
|
|
akismet_enabled: true,
|
|
|
|
akismet_api_key: 'testkey',
|
|
|
|
recaptcha_enabled: true,
|
|
|
|
recaptcha_site_key: 'test site key',
|
|
|
|
recaptcha_private_key: 'test private key'
|
|
|
|
)
|
|
|
|
|
2018-07-11 10:36:08 -04:00
|
|
|
project.add_maintainer(user)
|
2017-06-21 19:44:10 -04:00
|
|
|
sign_in(user)
|
2017-01-27 11:25:39 -05:00
|
|
|
end
|
|
|
|
|
2020-04-21 11:21:10 -04:00
|
|
|
context 'when SpamVerdictService disallows' do
|
|
|
|
include_context 'includes Spam constants'
|
|
|
|
|
2017-01-27 11:25:39 -05:00
|
|
|
before do
|
2020-04-21 11:21:10 -04:00
|
|
|
allow_next_instance_of(Spam::SpamVerdictService) do |verdict_service|
|
|
|
|
allow(verdict_service).to receive(:execute).and_return(DISALLOW)
|
|
|
|
end
|
2017-01-27 11:25:39 -05:00
|
|
|
|
2017-07-06 12:20:50 -04:00
|
|
|
visit new_project_issue_path(project)
|
2017-01-27 11:25:39 -05:00
|
|
|
end
|
|
|
|
|
2019-09-24 23:06:21 -04:00
|
|
|
context 'when allow_possible_spam feature flag is false' do
|
|
|
|
before do
|
|
|
|
stub_feature_flags(allow_possible_spam: false)
|
2017-01-27 11:25:39 -05:00
|
|
|
|
2019-09-24 23:06:21 -04:00
|
|
|
fill_in 'issue_title', with: 'issue title'
|
|
|
|
fill_in 'issue_description', with: 'issue description'
|
2020-04-21 11:21:10 -04:00
|
|
|
end
|
2017-01-27 11:25:39 -05:00
|
|
|
|
2020-04-21 11:21:10 -04:00
|
|
|
it 'rejects issue creation' do
|
2019-09-24 23:06:21 -04:00
|
|
|
click_button 'Submit issue'
|
2017-01-27 11:25:39 -05:00
|
|
|
|
2020-04-21 11:21:10 -04:00
|
|
|
expect(page).to have_content('discarded')
|
|
|
|
expect(page).not_to have_content('potential spam')
|
2019-09-24 23:06:21 -04:00
|
|
|
expect(page).not_to have_content('issue title')
|
2020-04-21 11:21:10 -04:00
|
|
|
end
|
2019-09-24 23:06:21 -04:00
|
|
|
|
2020-04-21 11:21:10 -04:00
|
|
|
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')
|
2019-09-24 23:06:21 -04:00
|
|
|
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
|
|
|
|
|
2020-04-21 11:21:10 -04:00
|
|
|
it 'allows issue creation' do
|
2019-09-24 23:06:21 -04:00
|
|
|
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
|
|
|
|
|
|
|
|
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-01-27 11:25:39 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-04-21 11:21:10 -04:00
|
|
|
context 'when SpamVerdictService requires recaptcha' do
|
|
|
|
include_context 'includes Spam constants'
|
|
|
|
|
2017-01-27 11:25:39 -05:00
|
|
|
before do
|
2020-04-21 11:21:10 -04:00
|
|
|
allow_next_instance_of(Spam::SpamVerdictService) do |verdict_service|
|
2020-05-25 23:08:02 -04:00
|
|
|
allow(verdict_service).to receive(:execute).and_return(CONDITIONAL_ALLOW)
|
2020-04-21 11:21:10 -04:00
|
|
|
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'
|
|
|
|
|
2020-04-21 14:09:31 -04:00
|
|
|
# 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
|
2020-04-21 11:21:10 -04:00
|
|
|
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
|
2020-05-20 20:08:06 -04:00
|
|
|
include_context 'includes Spam constants'
|
|
|
|
|
2020-04-21 11:21:10 -04:00
|
|
|
before do
|
|
|
|
allow_next_instance_of(Spam::SpamVerdictService) do |verdict_service|
|
|
|
|
allow(verdict_service).to receive(:execute).and_return(ALLOW)
|
|
|
|
end
|
2017-01-27 11:25:39 -05:00
|
|
|
|
2017-07-06 12:20:50 -04:00
|
|
|
visit new_project_issue_path(project)
|
2017-01-27 11:25:39 -05:00
|
|
|
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
|