X-Git-Url: https://git.openstreetmap.org./rails.git/blobdiff_plain/2d5acd199b059ec5d508ca967080f128dcd712f3..6cc31259e4e96784e4937c8c0ae561f8291ecaa2:/test/integration/oauth2_test.rb diff --git a/test/integration/oauth2_test.rb b/test/integration/oauth2_test.rb index 35893e4ab..3c532ca74 100644 --- a/test/integration/oauth2_test.rb +++ b/test/integration/oauth2_test.rb @@ -91,7 +91,7 @@ class OAuth2Test < ActionDispatch::IntegrationTest id_token = token["id_token"] assert_not_nil id_token - data, _headers = JWT.decode id_token, Doorkeeper::OpenidConnect.signing_key.public_key, true, { + data, _headers = JWT.decode id_token, nil, true, { :algorithm => [Doorkeeper::OpenidConnect.signing_algorithm.to_s], :verify_iss => true, :iss => "#{Settings.server_protocol}://#{Settings.server_url}", @@ -99,7 +99,13 @@ class OAuth2Test < ActionDispatch::IntegrationTest :sub => user.id, :verify_aud => true, :aud => client.uid - } + } do |headers, _payload| + kid = headers["kid"] + get oauth_discovery_keys_path + keys = response.parsed_body["keys"] + jwk = keys&.detect { |e| e["kid"] == kid } + jwk && JWT::JWK::RSA.import(jwk).public_key + end assert_equal user.id.to_s, data["sub"] assert_not data.key?("preferred_username") @@ -151,7 +157,6 @@ class OAuth2Test < ActionDispatch::IntegrationTest }.merge(options) get oauth_authorization_path(options) - assert_response :redirect assert_redirected_to login_path(:referer => request.fullpath) post login_path(:username => user.email, :password => "test") @@ -217,18 +222,18 @@ class OAuth2Test < ActionDispatch::IntegrationTest end def test_token(token, user, client) - get user_preferences_path + get api_user_preferences_path assert_response :unauthorized auth_header = bearer_authorization_header(token) - get user_preferences_path, :headers => auth_header + get api_user_preferences_path, :headers => auth_header assert_response :success - get user_preferences_path(:access_token => token) + get api_user_preferences_path(:access_token => token) assert_response :unauthorized - get user_preferences_path(:bearer_token => token) + get api_user_preferences_path(:bearer_token => token) assert_response :unauthorized get api_trace_path(:id => 2), :headers => auth_header @@ -236,17 +241,17 @@ class OAuth2Test < ActionDispatch::IntegrationTest user.suspend! - get user_preferences_path, :headers => auth_header + get api_user_preferences_path, :headers => auth_header assert_response :forbidden user.hide! - get user_preferences_path, :headers => auth_header + get api_user_preferences_path, :headers => auth_header assert_response :forbidden user.unhide! - get user_preferences_path, :headers => auth_header + get api_user_preferences_path, :headers => auth_header assert_response :success post oauth_revoke_path(:token => token) @@ -257,7 +262,7 @@ class OAuth2Test < ActionDispatch::IntegrationTest :client_secret => client.plaintext_secret) assert_response :success - get user_preferences_path, :headers => auth_header + get api_user_preferences_path, :headers => auth_header assert_response :unauthorized end end