Commit 197f5da4a0093232c7da654f66d300e566f2f2d2
Exists in
staging
and in
4 other branches
Merge branch 'api' of gitlab.com:participa/noosfero into api
Showing
4 changed files
with
10 additions
and
15 deletions
Show diff stats
lib/noosfero/api/entities.rb
| ... | ... | @@ -116,7 +116,7 @@ module Noosfero |
| 116 | 116 | expose :permissions do |user, options| |
| 117 | 117 | output = {} |
| 118 | 118 | user.person.role_assignments.map do |role_assigment| |
| 119 | - if role_assigment.resource.respond_to?(:identifier) | |
| 119 | + if role_assigment.resource.respond_to?(:identifier) && !role_assigment.role.nil? | |
| 120 | 120 | output[role_assigment.resource.identifier] = role_assigment.role.permissions |
| 121 | 121 | end |
| 122 | 122 | end | ... | ... |
lib/noosfero/api/helpers.rb
| ... | ... | @@ -275,8 +275,7 @@ |
| 275 | 275 | # captcha_helpers # |
| 276 | 276 | ########################################## |
| 277 | 277 | |
| 278 | - def test_captcha(remote_ip, params, _environment = nil) | |
| 279 | - environment ||= _environment | |
| 278 | + def test_captcha(remote_ip, params, environment) | |
| 280 | 279 | d = environment.api_captcha_settings |
| 281 | 280 | return true unless d[:enabled] == true |
| 282 | 281 | |
| ... | ... | @@ -293,7 +292,7 @@ |
| 293 | 292 | end |
| 294 | 293 | end |
| 295 | 294 | if d[:provider] == 'serpro' |
| 296 | - d[:verify_uri] ||= 'http://captcha2.servicoscorporativos.serpro.gov.br/captchavalidar/1.0.0/validar' | |
| 295 | + raise ArgumentError, "Environment api_captcha_settings verify_uri not defined" if d[:verify_uri].nil? | |
| 297 | 296 | return verify_serpro_captcha(d[:serpro_client_id], params[:txtToken_captcha_serpro_gov_br], params[:captcha_text], d[:verify_uri]) |
| 298 | 297 | end |
| 299 | 298 | raise ArgumentError, "Environment api_captcha_settings provider not defined" | ... | ... |
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 |
| ... | ... | @@ -211,9 +207,9 @@ class APIHelpersTest < ActiveSupport::TestCase |
| 211 | 207 | enabled: true, |
| 212 | 208 | provider: 'serpro', |
| 213 | 209 | serpro_client_id: '0000000000000000', |
| 210 | + verify_uri: 'http://localhost/api/verify', | |
| 214 | 211 | } |
| 215 | - stubs(:environment).returns(environment) | |
| 216 | - assert_equal test_captcha("127.0.0.1", {}), "Missing captcha data" | |
| 212 | + assert_equal test_captcha("127.0.0.1", {}, environment), "Missing captcha data" | |
| 217 | 213 | end |
| 218 | 214 | |
| 219 | 215 | should 'render not_found if endpoint is unavailable' do | ... | ... |