Commit aed123ef13d1ae26e70faa50b69ad3b1871f8b20

Authored by Evandro Junior
1 parent 49b8a45b

Made environment parameter for captcha mandatory

lib/noosfero/api/helpers.rb
@@ -262,8 +262,7 @@ @@ -262,8 +262,7 @@
262 # captcha_helpers # 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 d = environment.api_captcha_settings 266 d = environment.api_captcha_settings
268 return true unless d[:enabled] == true 267 return true unless d[:enabled] == true
269 268
lib/noosfero/api/session.rb
@@ -41,7 +41,7 @@ module Noosfero @@ -41,7 +41,7 @@ module Noosfero
41 attrs = attributes_for_keys [:email, :login, :password, :password_confirmation] + environment.signup_person_fields 41 attrs = attributes_for_keys [:email, :login, :password, :password_confirmation] + environment.signup_person_fields
42 remote_ip = (request.respond_to?(:remote_ip) && request.remote_ip) || (env && env['REMOTE_ADDR']) 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 render_api_error!(_('Please solve the test in order to register.'), 401) 45 render_api_error!(_('Please solve the test in order to register.'), 401)
46 return 46 return
47 end 47 end
test/unit/api/helpers_test.rb
@@ -164,8 +164,7 @@ class APIHelpersTest < ActiveSupport::TestCase @@ -164,8 +164,7 @@ class APIHelpersTest < ActiveSupport::TestCase
164 164
165 should 'do not test captcha when there are no settings' do 165 should 'do not test captcha when there are no settings' do
166 environment = Environment.new 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 end 168 end
170 169
171 should 'do not test captcha when captcha is disabled on settings' do 170 should 'do not test captcha when captcha is disabled on settings' do
@@ -173,8 +172,7 @@ class APIHelpersTest < ActiveSupport::TestCase @@ -173,8 +172,7 @@ class APIHelpersTest < ActiveSupport::TestCase
173 environment.api_captcha_settings = { 172 environment.api_captcha_settings = {
174 enabled: false, 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 end 176 end
179 177
180 should 'fail display recaptcha v1' do 178 should 'fail display recaptcha v1' do
@@ -187,8 +185,7 @@ class APIHelpersTest < ActiveSupport::TestCase @@ -187,8 +185,7 @@ class APIHelpersTest < ActiveSupport::TestCase
187 public_key: '6LdsWAcTAAAAAChTUUD6yu9fCDhdIZzNd7F53zf-', 185 public_key: '6LdsWAcTAAAAAChTUUD6yu9fCDhdIZzNd7F53zf-',
188 verify_uri: 'https://www.google.com/recaptcha/api/verify', 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 end 189 end
193 190
194 should 'fail display recaptcha v2' do 191 should 'fail display recaptcha v2' do
@@ -201,8 +198,7 @@ class APIHelpersTest < ActiveSupport::TestCase @@ -201,8 +198,7 @@ class APIHelpersTest < ActiveSupport::TestCase
201 public_key: '6LdsWAcTAAAAAChTUUD6yu9fCDhdIZzNd7F53zf-', 198 public_key: '6LdsWAcTAAAAAChTUUD6yu9fCDhdIZzNd7F53zf-',
202 verify_uri: 'https://www.google.com/recaptcha/api/siteverify', 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 end 202 end
207 203
208 should 'fail display Serpro captcha' do 204 should 'fail display Serpro captcha' do
@@ -212,8 +208,7 @@ class APIHelpersTest < ActiveSupport::TestCase @@ -212,8 +208,7 @@ class APIHelpersTest < ActiveSupport::TestCase
212 provider: 'serpro', 208 provider: 'serpro',
213 serpro_client_id: '0000000000000000', 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 end 212 end
218 213
219 should 'render not_found if endpoint is unavailable' do 214 should 'render not_found if endpoint is unavailable' do