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
|
|
|
|
2020-06-23 00:09:42 +05:30
|
|
|
RSpec.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-05-24 23:13:21 +05:30
|
|
|
context 'when SpamVerdictService disallows' do
|
|
|
|
include_context 'includes Spam constants'
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
before do
|
2020-05-24 23:13:21 +05:30
|
|
|
allow_next_instance_of(Spam::SpamVerdictService) do |verdict_service|
|
|
|
|
allow(verdict_service).to receive(:execute).and_return(DISALLOW)
|
|
|
|
end
|
2017-08-17 22:00:37 +05:30
|
|
|
|
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)
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2019-12-21 20:55:43 +05:30
|
|
|
fill_in 'issue_title', with: 'issue title'
|
|
|
|
fill_in 'issue_description', with: 'issue description'
|
2020-05-24 23:13:21 +05:30
|
|
|
end
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2020-05-24 23:13:21 +05:30
|
|
|
it 'rejects issue creation' do
|
2019-12-21 20:55:43 +05:30
|
|
|
click_button 'Submit issue'
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2020-05-24 23:13:21 +05:30
|
|
|
expect(page).to have_content('discarded')
|
|
|
|
expect(page).not_to have_content('potential spam')
|
2019-12-21 20:55:43 +05:30
|
|
|
expect(page).not_to have_content('issue title')
|
2020-05-24 23:13:21 +05:30
|
|
|
end
|
2019-12-21 20:55:43 +05:30
|
|
|
|
2020-05-24 23:13:21 +05:30
|
|
|
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-12-21 20:55:43 +05:30
|
|
|
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-05-24 23:13:21 +05:30
|
|
|
it 'allows issue creation' do
|
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
|
|
|
|
|
|
|
|
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-05-24 23:13:21 +05:30
|
|
|
context 'when SpamVerdictService requires recaptcha' do
|
|
|
|
include_context 'includes Spam constants'
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
before do
|
2020-05-24 23:13:21 +05:30
|
|
|
allow_next_instance_of(Spam::SpamVerdictService) do |verdict_service|
|
2020-06-23 00:09:42 +05:30
|
|
|
allow(verdict_service).to receive(:execute).and_return(CONDITIONAL_ALLOW)
|
2020-05-24 23:13:21 +05:30
|
|
|
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'
|
|
|
|
|
|
|
|
# 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')
|
|
|
|
|
|
|
|
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-06-23 00:09:42 +05:30
|
|
|
include_context 'includes Spam constants'
|
|
|
|
|
2020-05-24 23:13:21 +05:30
|
|
|
before do
|
|
|
|
allow_next_instance_of(Spam::SpamVerdictService) do |verdict_service|
|
|
|
|
allow(verdict_service).to receive(:execute).and_return(ALLOW)
|
|
|
|
end
|
2017-08-17 22:00:37 +05:30
|
|
|
|
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
|