summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStan Hu <stanhu@gmail.com>2017-06-10 03:28:30 -0700
committerStan Hu <stanhu@gmail.com>2017-06-10 03:43:02 -0700
commita7e82cbd61c613ebd2d6a8efe464400d2da13faf (patch)
tree5e78784b42cc2e870d45ae32470d39bf0329ad75
parentb134f950d70bdb73bc76e9a9091c0a50a6b8b8cd (diff)
downloadgitlab-ce-a7e82cbd61c613ebd2d6a8efe464400d2da13faf.tar.gz
Make sure reCAPTCHA configuration is loaded when spam checks are initiatedsh-recaptcha-fix-try2
Previously it was possible when an issue was updated and Akismet flagged it as spam that the reCAPTCHA configuration was not loaded. Closes #33532
-rw-r--r--app/controllers/concerns/spammable_actions.rb10
-rw-r--r--changelogs/unreleased/sh-recaptcha-fix-try2.yml4
-rw-r--r--spec/controllers/projects/issues_controller_spec.rb1
3 files changed, 14 insertions, 1 deletions
diff --git a/app/controllers/concerns/spammable_actions.rb b/app/controllers/concerns/spammable_actions.rb
index d0a692070d9..b68d76aeff0 100644
--- a/app/controllers/concerns/spammable_actions.rb
+++ b/app/controllers/concerns/spammable_actions.rb
@@ -17,10 +17,18 @@ module SpammableActions
private
+ def ensure_spam_config_loaded!
+ return @spam_config_loaded if defined?(@spam_config_loaded)
+
+ @spam_config_loaded = Gitlab::Recaptcha.load_configurations!
+ end
+
def recaptcha_check_with_fallback(&fallback)
if spammable.valid?
redirect_to spammable
elsif render_recaptcha?
+ ensure_spam_config_loaded!
+
if params[:recaptcha_verification]
flash[:alert] = 'There was an error with the reCAPTCHA. Please solve the reCAPTCHA again.'
end
@@ -35,7 +43,7 @@ module SpammableActions
default_params = { request: request }
recaptcha_check = params[:recaptcha_verification] &&
- Gitlab::Recaptcha.load_configurations! &&
+ ensure_spam_config_loaded! &&
verify_recaptcha
return default_params unless recaptcha_check
diff --git a/changelogs/unreleased/sh-recaptcha-fix-try2.yml b/changelogs/unreleased/sh-recaptcha-fix-try2.yml
new file mode 100644
index 00000000000..94729252c6f
--- /dev/null
+++ b/changelogs/unreleased/sh-recaptcha-fix-try2.yml
@@ -0,0 +1,4 @@
+---
+title: Make sure reCAPTCHA configuration is loaded when spam checks are initiated
+merge_request:
+author:
diff --git a/spec/controllers/projects/issues_controller_spec.rb b/spec/controllers/projects/issues_controller_spec.rb
index a38ae2eb990..b65e9e0dfc0 100644
--- a/spec/controllers/projects/issues_controller_spec.rb
+++ b/spec/controllers/projects/issues_controller_spec.rb
@@ -260,6 +260,7 @@ describe Projects::IssuesController do
before { allow_any_instance_of(described_class).to receive(:verify_recaptcha).and_return(false) }
it 'rejects an issue recognized as a spam' do
+ expect(Gitlab::Recaptcha).to receive(:load_configurations!).and_return(true)
expect { update_spam_issue }.not_to change{ issue.reload.title }
end