Skip to content

Commit

Permalink
Merge pull request #464 from ambethia/grosser/fix
Browse files Browse the repository at this point in the history
fix ci
  • Loading branch information
grosser authored Jan 14, 2025
2 parents eff11da + 47fad7a commit f86f4d7
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
6 changes: 4 additions & 2 deletions lib/recaptcha/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,10 @@ class Configuration
'enterprise_verify_url' => 'https://recaptchaenterprise.googleapis.com/v1/projects'
}.freeze

attr_accessor :default_env, :skip_verify_env, :proxy, :secret_key, :site_key, :handle_timeouts_gracefully,
:hostname, :enterprise, :enterprise_api_key, :enterprise_project_id, :response_limit, :response_minimum
attr_accessor(
:default_env, :skip_verify_env, :proxy, :secret_key, :site_key, :handle_timeouts_gracefully,
:hostname, :enterprise, :enterprise_api_key, :enterprise_project_id, :response_limit, :response_minimum
)
attr_writer :api_server_url, :verify_url

def initialize # :nodoc:
Expand Down
8 changes: 4 additions & 4 deletions test/verify_enterprise_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def initialize

@controller = EnterpriseTestController.new
@controller.request = stub(remote_ip: "1.1.1.1", format: :html)
@controller.params = {:recaptcha_response_field => "response", 'g-recaptcha-response-data' => 'string'}
@controller.params = {:recaptcha_response_field => "response", 'g-recaptcha-response-data' => "a" * 200}
end

after do
Expand Down Expand Up @@ -184,17 +184,17 @@ def initialize
# this returns a 400 or 413 instead of a 200 response with error code
# typical response length is less than 400 characters
str = "a" * 4001
@controller.params = { 'g-recaptcha-response' => "#{str}"}
@controller.params = { 'g-recaptcha-response' => str}
assert_not_requested :get, %r{\.google\.com}
assert_equal false, @controller.verify_recaptcha
assert_equal "reCAPTCHA verification failed, please try again.", @controller.flash[:recaptcha_error]
end

it "does not verify via http call when response length below limit" do
# this returns a 400 or 413 instead of a 200 response with error code
# typical response length is less than 100 characters
# typical response length is more than 100 characters
str = "a" * 99
@controller.params = { 'g-recaptcha-response' => "#{str}"}
@controller.params = { 'g-recaptcha-response' => str}
assert_not_requested :get, %r{\.google\.com}
assert_equal false, @controller.verify_recaptcha
assert_equal "reCAPTCHA verification failed, please try again.", @controller.flash[:recaptcha_error]
Expand Down
9 changes: 4 additions & 5 deletions test/verify_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def initialize
before do
@controller = TestController.new
@controller.request = stub(remote_ip: "1.1.1.1", format: :html)
@controller.params = {:recaptcha_response_field => "response", 'g-recaptcha-response-data' => 'string'}
@controller.params = {:recaptcha_response_field => "response", 'g-recaptcha-response-data' => "a" * 200}
end

describe "#verify_recaptcha!" do
Expand Down Expand Up @@ -106,7 +106,7 @@ def initialize
secret_key = Recaptcha.configuration.secret_key
stub_request(
:get,
"https://www.recaptcha.net/recaptcha/api/siteverify?response=string&secret=#{secret_key}"
"https://www.recaptcha.net/recaptcha/api/siteverify?response=#{"a" * 200}&secret=#{secret_key}"
).to_return(body: '{"success":true}')

assert @controller.verify_recaptcha(skip_remote_ip: true)
Expand Down Expand Up @@ -453,8 +453,7 @@ def initialize
end

it "returns the g-recaptcha-response when response is valid and no action is provided" do
@controller.params = { "g-recaptcha-response" => "recaptcha-response" }
assert_equal @controller.recaptcha_response_token, "recaptcha-response"
assert_equal @controller.recaptcha_response_token, "a" * 200
end

it "returns an empty string when params are empty and an action is provided" do
Expand Down Expand Up @@ -503,7 +502,7 @@ def initialize
def expect_http_post(secret_key: Recaptcha.configuration.secret_key)
stub_request(
:get,
"https://www.recaptcha.net/recaptcha/api/siteverify?remoteip=1.1.1.1&response=string&secret=#{secret_key}"
"https://www.recaptcha.net/recaptcha/api/siteverify?remoteip=1.1.1.1&response=#{"a" * 200}&secret=#{secret_key}"
)
end

Expand Down

0 comments on commit f86f4d7

Please sign in to comment.