diff --git a/lib/noosfero/api/helpers.rb b/lib/noosfero/api/helpers.rb index d7bb8e6..0347dfe 100644 --- a/lib/noosfero/api/helpers.rb +++ b/lib/noosfero/api/helpers.rb @@ -262,8 +262,7 @@ # captcha_helpers # ########################################## - def test_captcha(remote_ip, params, _environment = nil) - environment ||= _environment + def test_captcha(remote_ip, params, environment) d = environment.api_captcha_settings return true unless d[:enabled] == true diff --git a/lib/noosfero/api/session.rb b/lib/noosfero/api/session.rb index 1698f67..149af79 100644 --- a/lib/noosfero/api/session.rb +++ b/lib/noosfero/api/session.rb @@ -41,7 +41,7 @@ module Noosfero attrs = attributes_for_keys [:email, :login, :password, :password_confirmation] + environment.signup_person_fields remote_ip = (request.respond_to?(:remote_ip) && request.remote_ip) || (env && env['REMOTE_ADDR']) - if not test_captcha(remote_ip, params, environment) == true + unless test_captcha(remote_ip, params, environment) == true render_api_error!(_('Please solve the test in order to register.'), 401) return end diff --git a/test/unit/api/helpers_test.rb b/test/unit/api/helpers_test.rb index f947309..1a8e99f 100644 --- a/test/unit/api/helpers_test.rb +++ b/test/unit/api/helpers_test.rb @@ -164,8 +164,7 @@ class APIHelpersTest < ActiveSupport::TestCase should 'do not test captcha when there are no settings' do environment = Environment.new - stubs(:environment).returns(environment) - assert test_captcha("127.0.0.1", {}) + assert test_captcha("127.0.0.1", {}, environment) end should 'do not test captcha when captcha is disabled on settings' do @@ -173,8 +172,7 @@ class APIHelpersTest < ActiveSupport::TestCase environment.api_captcha_settings = { enabled: false, } - stubs(:environment).returns(environment) - assert test_captcha("127.0.0.1", {}) + assert test_captcha("127.0.0.1", {}, environment) end should 'fail display recaptcha v1' do @@ -187,8 +185,7 @@ class APIHelpersTest < ActiveSupport::TestCase public_key: '6LdsWAcTAAAAAChTUUD6yu9fCDhdIZzNd7F53zf-', verify_uri: 'https://www.google.com/recaptcha/api/verify', } - stubs(:environment).returns(environment) - assert_equal test_captcha("127.0.0.1", {}), "Missing captcha data" + assert_equal test_captcha("127.0.0.1", {}, environment), "Missing captcha data" end should 'fail display recaptcha v2' do @@ -201,8 +198,7 @@ class APIHelpersTest < ActiveSupport::TestCase public_key: '6LdsWAcTAAAAAChTUUD6yu9fCDhdIZzNd7F53zf-', verify_uri: 'https://www.google.com/recaptcha/api/siteverify', } - stubs(:environment).returns(environment) - assert_equal test_captcha("127.0.0.1", {}), "Missing captcha data" + assert_equal test_captcha("127.0.0.1", {}, environment), "Missing captcha data" end should 'fail display Serpro captcha' do @@ -212,8 +208,7 @@ class APIHelpersTest < ActiveSupport::TestCase provider: 'serpro', serpro_client_id: '0000000000000000', } - stubs(:environment).returns(environment) - assert_equal test_captcha("127.0.0.1", {}), "Missing captcha data" + assert_equal test_captcha("127.0.0.1", {}, environment), "Missing captcha data" end should 'render not_found if endpoint is unavailable' do -- libgit2 0.21.2