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,7 +116,7 @@ module Noosfero | ||
| 116 | expose :permissions do |user, options| | 116 | expose :permissions do |user, options| |
| 117 | output = {} | 117 | output = {} |
| 118 | user.person.role_assignments.map do |role_assigment| | 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 | output[role_assigment.resource.identifier] = role_assigment.role.permissions | 120 | output[role_assigment.resource.identifier] = role_assigment.role.permissions |
| 121 | end | 121 | end |
| 122 | end | 122 | end |
lib/noosfero/api/helpers.rb
| @@ -275,8 +275,7 @@ | @@ -275,8 +275,7 @@ | ||
| 275 | # captcha_helpers # | 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 | d = environment.api_captcha_settings | 279 | d = environment.api_captcha_settings |
| 281 | return true unless d[:enabled] == true | 280 | return true unless d[:enabled] == true |
| 282 | 281 | ||
| @@ -293,7 +292,7 @@ | @@ -293,7 +292,7 @@ | ||
| 293 | end | 292 | end |
| 294 | end | 293 | end |
| 295 | if d[:provider] == 'serpro' | 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 | return verify_serpro_captcha(d[:serpro_client_id], params[:txtToken_captcha_serpro_gov_br], params[:captcha_text], d[:verify_uri]) | 296 | return verify_serpro_captcha(d[:serpro_client_id], params[:txtToken_captcha_serpro_gov_br], params[:captcha_text], d[:verify_uri]) |
| 298 | end | 297 | end |
| 299 | raise ArgumentError, "Environment api_captcha_settings provider not defined" | 298 | raise ArgumentError, "Environment api_captcha_settings provider not defined" |
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 |
| @@ -211,9 +207,9 @@ class APIHelpersTest < ActiveSupport::TestCase | @@ -211,9 +207,9 @@ class APIHelpersTest < ActiveSupport::TestCase | ||
| 211 | enabled: true, | 207 | enabled: true, |
| 212 | provider: 'serpro', | 208 | provider: 'serpro', |
| 213 | serpro_client_id: '0000000000000000', | 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 | end | 213 | end |
| 218 | 214 | ||
| 219 | should 'render not_found if endpoint is unavailable' do | 215 | should 'render not_found if endpoint is unavailable' do |