X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/42fff42165a0fa1602758a078746f8697f265f83..8ce476b7864f1a2d1f05cd0a770ae159eeb845eb:/services/api/test/integration/api_client_authorizations_api_test.rb?ds=sidebyside diff --git a/services/api/test/integration/api_client_authorizations_api_test.rb b/services/api/test/integration/api_client_authorizations_api_test.rb index ce79fc5579..405e4bf687 100644 --- a/services/api/test/integration/api_client_authorizations_api_test.rb +++ b/services/api/test/integration/api_client_authorizations_api_test.rb @@ -124,7 +124,7 @@ class ApiClientAuthorizationsApiTest < ActionDispatch::IntegrationTest end end - test "expires_at can be set to #{desired_expiration.nil? ? 'nil' : 'exceed the limit'} by admins when API.MaxTokenLifetime is set" do + test "behavior when expires_at is set to #{desired_expiration.nil? ? 'nil' : 'exceed the limit'} by admins when API.MaxTokenLifetime is set" do Rails.configuration.API.MaxTokenLifetime = 1.hour # Test token creation @@ -139,32 +139,44 @@ class ApiClientAuthorizationsApiTest < ActionDispatch::IntegrationTest headers: {'HTTP_AUTHORIZATION' => "OAuth2 #{api_client_authorizations(:admin_trustedclient).api_token}"} assert_response 200 if desired_expiration.nil? - assert json_response['expires_at'].nil? + # When expires_at is nil, default to MaxTokenLifetime + assert_operator (json_response['expires_at'].to_time.to_i - (db_current_time + Rails.configuration.API.MaxTokenLifetime).to_i).abs, :<, 2 else assert_equal json_response['expires_at'].to_time.to_i, desired_expiration.to_i end # Test token update (reverse the above behavior) - previous_expiration = json_response['expires_at'] token_uuid = json_response['uuid'] - if previous_expiration.nil? - desired_updated_expiration = db_current_time + Rails.configuration.API.MaxTokenLifetime + 1.hour + if desired_expiration.nil? + submitted_updated_expiration = db_current_time + Rails.configuration.API.MaxTokenLifetime + 1.hour else - desired_updated_expiration = nil + submitted_updated_expiration = nil end put "/arvados/v1/api_client_authorizations/#{token_uuid}", params: { :api_client_authorization => { - :expires_at => desired_updated_expiration, + :expires_at => submitted_updated_expiration, } }, headers: {'HTTP_AUTHORIZATION' => "OAuth2 #{api_client_authorizations(:admin_trustedclient).api_token}"} assert_response 200 - if desired_updated_expiration.nil? - assert json_response['expires_at'].nil? + if submitted_updated_expiration.nil? + assert_operator (json_response['expires_at'].to_time.to_i - (db_current_time + Rails.configuration.API.MaxTokenLifetime).to_i).abs, :<, 2 else - assert_equal json_response['expires_at'].to_time.to_i, desired_updated_expiration.to_i + assert_equal json_response['expires_at'].to_time.to_i, submitted_updated_expiration.to_i end end end + + test "get current token using salted token" do + salted = salt_token(fixture: :active, remote: 'abcde') + get('/arvados/v1/api_client_authorizations/current', + params: {remote: 'abcde'}, + headers: {'HTTP_AUTHORIZATION' => "Bearer #{salted}"}) + assert_response :success + assert_equal(json_response['uuid'], api_client_authorizations(:active).uuid) + assert_equal(json_response['scopes'], ['all']) + assert_not_nil(json_response['expires_at']) + assert_nil(json_response['api_token']) + end end