Commit 59122560 authored by Dylan Griffith's avatar Dylan Griffith

Merge branch 'cablett-conditional-allow-spam' into 'master'

Decouple reCAPTCHA from conditional allow

See merge request gitlab-org/gitlab!32805
parents fd40e9ec 7bf9acb8
...@@ -49,7 +49,8 @@ module Spam ...@@ -49,7 +49,8 @@ module Spam
# ask the SpamVerdictService what to do with the target. # ask the SpamVerdictService what to do with the target.
spam_verdict_service.execute.tap do |result| spam_verdict_service.execute.tap do |result|
case result case result
when REQUIRE_RECAPTCHA when CONDITIONAL_ALLOW
# at the moment, this means "ask for reCAPTCHA"
create_spam_log(api) create_spam_log(api)
break if target.allow_possible_spam? break if target.allow_possible_spam?
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
module Spam module Spam
module SpamConstants module SpamConstants
REQUIRE_RECAPTCHA = "recaptcha" CONDITIONAL_ALLOW = "conditional_allow"
DISALLOW = "disallow" DISALLOW = "disallow"
ALLOW = "allow" ALLOW = "allow"
BLOCK_USER = "block" BLOCK_USER = "block"
...@@ -14,7 +14,7 @@ module Spam ...@@ -14,7 +14,7 @@ module Spam
DISALLOW => { DISALLOW => {
priority: 2 priority: 2
}, },
REQUIRE_RECAPTCHA => { CONDITIONAL_ALLOW => {
priority: 3 priority: 3
}, },
ALLOW => { ALLOW => {
......
...@@ -31,7 +31,7 @@ module Spam ...@@ -31,7 +31,7 @@ module Spam
def akismet_verdict def akismet_verdict
if akismet.spam? if akismet.spam?
Gitlab::Recaptcha.enabled? ? REQUIRE_RECAPTCHA : DISALLOW Gitlab::Recaptcha.enabled? ? CONDITIONAL_ALLOW : DISALLOW
else else
ALLOW ALLOW
end end
......
...@@ -536,7 +536,7 @@ describe Projects::IssuesController do ...@@ -536,7 +536,7 @@ describe Projects::IssuesController do
before do before do
stub_application_setting(recaptcha_enabled: true) stub_application_setting(recaptcha_enabled: true)
expect_next_instance_of(Spam::SpamVerdictService) do |verdict_service| expect_next_instance_of(Spam::SpamVerdictService) do |verdict_service|
expect(verdict_service).to receive(:execute).and_return(REQUIRE_RECAPTCHA) expect(verdict_service).to receive(:execute).and_return(CONDITIONAL_ALLOW)
end end
end end
...@@ -851,7 +851,7 @@ describe Projects::IssuesController do ...@@ -851,7 +851,7 @@ describe Projects::IssuesController do
context 'when recaptcha is not verified' do context 'when recaptcha is not verified' do
before do before do
expect_next_instance_of(Spam::SpamVerdictService) do |verdict_service| expect_next_instance_of(Spam::SpamVerdictService) do |verdict_service|
expect(verdict_service).to receive(:execute).and_return(REQUIRE_RECAPTCHA) expect(verdict_service).to receive(:execute).and_return(CONDITIONAL_ALLOW)
end end
end end
...@@ -1103,7 +1103,7 @@ describe Projects::IssuesController do ...@@ -1103,7 +1103,7 @@ describe Projects::IssuesController do
context 'when captcha is not verified' do context 'when captcha is not verified' do
before do before do
expect_next_instance_of(Spam::SpamVerdictService) do |verdict_service| expect_next_instance_of(Spam::SpamVerdictService) do |verdict_service|
expect(verdict_service).to receive(:execute).and_return(REQUIRE_RECAPTCHA) expect(verdict_service).to receive(:execute).and_return(CONDITIONAL_ALLOW)
end end
end end
......
...@@ -81,7 +81,7 @@ describe 'New issue', :js do ...@@ -81,7 +81,7 @@ describe 'New issue', :js do
before do before do
allow_next_instance_of(Spam::SpamVerdictService) do |verdict_service| allow_next_instance_of(Spam::SpamVerdictService) do |verdict_service|
allow(verdict_service).to receive(:execute).and_return(REQUIRE_RECAPTCHA) allow(verdict_service).to receive(:execute).and_return(CONDITIONAL_ALLOW)
end end
visit new_project_issue_path(project) visit new_project_issue_path(project)
......
...@@ -68,7 +68,7 @@ shared_examples_for 'snippet editor' do ...@@ -68,7 +68,7 @@ shared_examples_for 'snippet editor' do
context 'when SpamVerdictService requires recaptcha' do context 'when SpamVerdictService requires recaptcha' do
before do before do
expect_next_instance_of(Spam::SpamVerdictService) do |verdict_service| expect_next_instance_of(Spam::SpamVerdictService) do |verdict_service|
expect(verdict_service).to receive(:execute).and_return(REQUIRE_RECAPTCHA) expect(verdict_service).to receive(:execute).and_return(CONDITIONAL_ALLOW)
end end
end end
......
...@@ -458,7 +458,7 @@ describe Issues::CreateService do ...@@ -458,7 +458,7 @@ describe Issues::CreateService do
context 'when SpamVerdictService requires reCAPTCHA' do context 'when SpamVerdictService requires reCAPTCHA' do
before do before do
expect_next_instance_of(Spam::SpamVerdictService) do |verdict_service| expect_next_instance_of(Spam::SpamVerdictService) do |verdict_service|
expect(verdict_service).to receive(:execute).and_return(REQUIRE_RECAPTCHA) expect(verdict_service).to receive(:execute).and_return(CONDITIONAL_ALLOW)
end end
end end
......
...@@ -163,9 +163,9 @@ describe Spam::SpamActionService do ...@@ -163,9 +163,9 @@ describe Spam::SpamActionService do
end end
end end
context 'when spam verdict service requires reCAPTCHA' do context 'when spam verdict service conditionally allows' do
before do before do
allow(fake_verdict_service).to receive(:execute).and_return(REQUIRE_RECAPTCHA) allow(fake_verdict_service).to receive(:execute).and_return(CONDITIONAL_ALLOW)
end end
context 'when allow_possible_spam feature flag is false' do context 'when allow_possible_spam feature flag is false' do
......
...@@ -123,8 +123,8 @@ describe Spam::SpamVerdictService do ...@@ -123,8 +123,8 @@ describe Spam::SpamVerdictService do
stub_application_setting(recaptcha_enabled: true) stub_application_setting(recaptcha_enabled: true)
end end
it 'returns require reCAPTCHA verdict' do it 'returns conditionally allow verdict' do
expect(subject).to eq REQUIRE_RECAPTCHA expect(subject).to eq CONDITIONAL_ALLOW
end end
end end
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
shared_context 'includes Spam constants' do shared_context 'includes Spam constants' do
before do before do
stub_const('REQUIRE_RECAPTCHA', Spam::SpamConstants::REQUIRE_RECAPTCHA) stub_const('CONDITIONAL_ALLOW', Spam::SpamConstants::CONDITIONAL_ALLOW)
stub_const('DISALLOW', Spam::SpamConstants::DISALLOW) stub_const('DISALLOW', Spam::SpamConstants::DISALLOW)
stub_const('ALLOW', Spam::SpamConstants::ALLOW) stub_const('ALLOW', Spam::SpamConstants::ALLOW)
stub_const('BLOCK_USER', Spam::SpamConstants::BLOCK_USER) stub_const('BLOCK_USER', Spam::SpamConstants::BLOCK_USER)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment