Skip to content

Commit 6876bcd

Browse files
committed
Fix recaptcha feature flag gating for Primo articles
1 parent b76ea6c commit 6876bcd

File tree

3 files changed

+32
-6
lines changed

3 files changed

+32
-6
lines changed

app/controllers/primo_central_controller.rb

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,8 @@ class PrimoCentralController < CatalogController
1111
helper_method :tags_strip
1212
helper_method :solr_range_queries_to_a
1313

14-
def self.recaptcha_on?
15-
Proc.new { |context| ::FeatureFlags.recaptcha_on?(context.params) }
16-
end
17-
1814
def recaptcha
19-
::FeatureFlags.recaptcha?(params)
15+
return unless ::FeatureFlags.recaptcha?(params)
2016
# Do not enable for logged in users.
2117
return if current_user
2218

app/lib/feature_flags.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,6 @@ def self.recaptcha?(params = nil)
2727
if !params.nil? && params.has_key?("recaptcha")
2828
return (params["recaptcha"] == "false") ? false : true
2929
end
30-
!!Rails.configuration.features.fetch(:recaptcha, false)
30+
!!Rails.configuration.features.fetch(:recaptcha_on, false)
3131
end
3232
end

spec/controllers/primo_central_controller_spec.rb

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,14 @@
5353
end
5454

5555
describe "recaptcha enabled" do
56+
around do |example|
57+
original = Rails.configuration.features[:recaptcha_on]
58+
Rails.configuration.features[:recaptcha_on] = true
59+
example.run
60+
ensure
61+
Rails.configuration.features[:recaptcha_on] = original
62+
end
63+
5664
before do
5765
stub_const("ENV", ENV.to_h.merge("RECAPTCHA_SITE_KEY" => "foo"))
5866
allow(controller).to receive(:verify_recaptcha).and_return(false)
@@ -70,4 +78,26 @@
7078
end
7179
end
7280
end
81+
82+
describe "recaptcha disabled" do
83+
around do |example|
84+
original = Rails.configuration.features[:recaptcha_on]
85+
Rails.configuration.features[:recaptcha_on] = false
86+
example.run
87+
ensure
88+
Rails.configuration.features[:recaptcha_on] = original
89+
end
90+
91+
before do
92+
stub_const("ENV", ENV.to_h.merge("RECAPTCHA_SITE_KEY" => "foo"))
93+
end
94+
95+
it "skips recaptcha checks" do
96+
expect(controller).not_to receive(:verify_recaptcha)
97+
98+
get :index, params: { q: "foo" }
99+
100+
expect(response).to have_http_status(:ok)
101+
end
102+
end
73103
end

0 commit comments

Comments
 (0)