Commit e618194cd599a1acc8dc88e60036c434d3fa9d9f
Committed by
Carlos Purificação
1 parent
c7c60371
Exists in
staging
and in
4 other branches
Made environment parameter for captcha mandatory
Showing
3 changed files
with
7 additions
and
13 deletions
Show diff stats
lib/noosfero/api/helpers.rb
| ... | ... | @@ -262,8 +262,7 @@ |
| 262 | 262 | # captcha_helpers # |
| 263 | 263 | ########################################## |
| 264 | 264 | |
| 265 | - def test_captcha(remote_ip, params, _environment = nil) | |
| 266 | - environment ||= _environment | |
| 265 | + def test_captcha(remote_ip, params, environment) | |
| 267 | 266 | d = environment.api_captcha_settings |
| 268 | 267 | return true unless d[:enabled] == true |
| 269 | 268 | ... | ... |
lib/noosfero/api/session.rb
| ... | ... | @@ -41,7 +41,7 @@ module Noosfero |
| 41 | 41 | attrs = attributes_for_keys [:email, :login, :password, :password_confirmation] + environment.signup_person_fields |
| 42 | 42 | remote_ip = (request.respond_to?(:remote_ip) && request.remote_ip) || (env && env['REMOTE_ADDR']) |
| 43 | 43 | |
| 44 | - if not test_captcha(remote_ip, params, environment) == true | |
| 44 | + unless test_captcha(remote_ip, params, environment) == true | |
| 45 | 45 | render_api_error!(_('Please solve the test in order to register.'), 401) |
| 46 | 46 | return |
| 47 | 47 | end | ... | ... |
test/unit/api/helpers_test.rb
| ... | ... | @@ -164,8 +164,7 @@ class APIHelpersTest < ActiveSupport::TestCase |
| 164 | 164 | |
| 165 | 165 | should 'do not test captcha when there are no settings' do |
| 166 | 166 | environment = Environment.new |
| 167 | - stubs(:environment).returns(environment) | |
| 168 | - assert test_captcha("127.0.0.1", {}) | |
| 167 | + assert test_captcha("127.0.0.1", {}, environment) | |
| 169 | 168 | end |
| 170 | 169 | |
| 171 | 170 | should 'do not test captcha when captcha is disabled on settings' do |
| ... | ... | @@ -173,8 +172,7 @@ class APIHelpersTest < ActiveSupport::TestCase |
| 173 | 172 | environment.api_captcha_settings = { |
| 174 | 173 | enabled: false, |
| 175 | 174 | } |
| 176 | - stubs(:environment).returns(environment) | |
| 177 | - assert test_captcha("127.0.0.1", {}) | |
| 175 | + assert test_captcha("127.0.0.1", {}, environment) | |
| 178 | 176 | end |
| 179 | 177 | |
| 180 | 178 | should 'fail display recaptcha v1' do |
| ... | ... | @@ -187,8 +185,7 @@ class APIHelpersTest < ActiveSupport::TestCase |
| 187 | 185 | public_key: '6LdsWAcTAAAAAChTUUD6yu9fCDhdIZzNd7F53zf-', |
| 188 | 186 | verify_uri: 'https://www.google.com/recaptcha/api/verify', |
| 189 | 187 | } |
| 190 | - stubs(:environment).returns(environment) | |
| 191 | - assert_equal test_captcha("127.0.0.1", {}), "Missing captcha data" | |
| 188 | + assert_equal test_captcha("127.0.0.1", {}, environment), "Missing captcha data" | |
| 192 | 189 | end |
| 193 | 190 | |
| 194 | 191 | should 'fail display recaptcha v2' do |
| ... | ... | @@ -201,8 +198,7 @@ class APIHelpersTest < ActiveSupport::TestCase |
| 201 | 198 | public_key: '6LdsWAcTAAAAAChTUUD6yu9fCDhdIZzNd7F53zf-', |
| 202 | 199 | verify_uri: 'https://www.google.com/recaptcha/api/siteverify', |
| 203 | 200 | } |
| 204 | - stubs(:environment).returns(environment) | |
| 205 | - assert_equal test_captcha("127.0.0.1", {}), "Missing captcha data" | |
| 201 | + assert_equal test_captcha("127.0.0.1", {}, environment), "Missing captcha data" | |
| 206 | 202 | end |
| 207 | 203 | |
| 208 | 204 | should 'fail display Serpro captcha' do |
| ... | ... | @@ -212,8 +208,7 @@ class APIHelpersTest < ActiveSupport::TestCase |
| 212 | 208 | provider: 'serpro', |
| 213 | 209 | serpro_client_id: '0000000000000000', |
| 214 | 210 | } |
| 215 | - stubs(:environment).returns(environment) | |
| 216 | - assert_equal test_captcha("127.0.0.1", {}), "Missing captcha data" | |
| 211 | + assert_equal test_captcha("127.0.0.1", {}, environment), "Missing captcha data" | |
| 217 | 212 | end |
| 218 | 213 | |
| 219 | 214 | should 'render not_found if endpoint is unavailable' do | ... | ... |