A platform for community discussion. Free, open, simple.
FIX: Hcaptcha plugin was incompatible with login-required sites (#34181)
Penar Musarajeec7ecac7e0d
diff --git a/plugins/discourse-hcaptcha/app/controllers/discourse_hcaptcha/hcaptcha_controller.rb b/plugins/discourse-hcaptcha/app/controllers/discourse_hcaptcha/hcaptcha_controller.rbindex 1f64f969b4e..eda834ec03e 100644--- a/plugins/discourse-hcaptcha/app/controllers/discourse_hcaptcha/hcaptcha_controller.rb+++ b/plugins/discourse-hcaptcha/app/controllers/discourse_hcaptcha/hcaptcha_controller.rb@@ -5,6 +5,8 @@ module ::DiscourseHcaptcharequires_plugin DiscourseHcaptcha::PLUGIN_NAMEbefore_action :ensure_config+ skip_before_action :redirect_to_login_if_required+TOKEN_TTL = 2.minutesprotect_from_forgery except: [:create]diff --git a/plugins/discourse-hcaptcha/spec/lib/discourse_h_captcha/create_users_controller_patch_spec.rb b/plugins/discourse-hcaptcha/spec/lib/discourse_h_captcha/create_users_controller_patch_spec.rbindex 991416fe089..e211494d73d 100644--- a/plugins/discourse-hcaptcha/spec/lib/discourse_h_captcha/create_users_controller_patch_spec.rb+++ b/plugins/discourse-hcaptcha/spec/lib/discourse_h_captcha/create_users_controller_patch_spec.rb@@ -56,6 +56,16 @@ RSpec.describe "Users", type: :request dopost "/u.json", params: user_paramsexpect(JSON.parse(response.body)["success"]).to be(true)end++ context "when site is login-required" do+ before { SiteSetting.login_required = true }++ it "succeeds in registration" do+ post "/hcaptcha/create.json", params: { token: "token-from-hCaptcha" }+ post "/u.json", params: user_params+ expect(JSON.parse(response.body)["success"]).to be(true)+ end+ endendcontext "when h_captcha is disabled" do