X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/476f6188d78a8d7c60043b0dd5d22bfba045484c..2f66d4cc05e9442a9bb69969744d0750a02a1ed4:/services/api/test/integration/remote_user_test.rb diff --git a/services/api/test/integration/remote_user_test.rb b/services/api/test/integration/remote_user_test.rb index 81ea9623e8..04a45420fd 100644 --- a/services/api/test/integration/remote_user_test.rb +++ b/services/api/test/integration/remote_user_test.rb @@ -143,6 +143,30 @@ class RemoteUsersTest < ActionDispatch::IntegrationTest assert_equal 'blarney@example.com', json_response['email'] end + test 'remote user is deactivated' do + Rails.configuration.RemoteClusters['zbbbb'].ActivateUsers = true + get '/arvados/v1/users/current', + params: {format: 'json'}, + headers: auth(remote: 'zbbbb') + assert_response :success + assert_equal true, json_response['is_active'] + + # revoke original token + @stub_content[:is_active] = false + + # simulate cache expiry + ApiClientAuthorization.where( + uuid: salted_active_token(remote: 'zbbbb').split('/')[1]). + update_all(expires_at: db_current_time - 1.minute) + + # re-authorize after cache expires + get '/arvados/v1/users/current', + params: {format: 'json'}, + headers: auth(remote: 'zbbbb') + assert_equal false, json_response['is_active'] + + end + test 'authenticate with remote token, remote username conflicts with local' do @stub_content[:username] = 'active' get '/arvados/v1/users/current', @@ -255,6 +279,24 @@ class RemoteUsersTest < ActionDispatch::IntegrationTest refute_includes(group_uuids, groups(:testusergroup_admins).uuid) end + test 'do not auto-activate user from untrusted cluster' do + Rails.configuration.RemoteClusters['zbbbb'].AutoSetupNewUsers = false + Rails.configuration.RemoteClusters['zbbbb'].ActivateUsers = false + get '/arvados/v1/users/current', + params: {format: 'json'}, + headers: auth(remote: 'zbbbb') + assert_response :success + assert_equal 'zbbbb-tpzed-000000000000000', json_response['uuid'] + assert_equal false, json_response['is_admin'] + assert_equal false, json_response['is_active'] + assert_equal 'foo@example.com', json_response['email'] + assert_equal 'barney', json_response['username'] + post '/arvados/v1/users/zbbbb-tpzed-000000000000000/activate', + params: {format: 'json'}, + headers: auth(remote: 'zbbbb') + assert_response 422 + end + test 'auto-activate user from trusted cluster' do Rails.configuration.RemoteClusters['zbbbb'].ActivateUsers = true get '/arvados/v1/users/current', @@ -268,6 +310,19 @@ class RemoteUsersTest < ActionDispatch::IntegrationTest assert_equal 'barney', json_response['username'] end + test 'get user from Login cluster' do + Rails.configuration.Login.LoginCluster = 'zbbbb' + get '/arvados/v1/users/current', + params: {format: 'json'}, + headers: auth(remote: 'zbbbb') + assert_response :success + assert_equal 'zbbbb-tpzed-000000000000000', json_response['uuid'] + assert_equal true, json_response['is_admin'] + assert_equal true, json_response['is_active'] + assert_equal 'foo@example.com', json_response['email'] + assert_equal 'barney', json_response['username'] + end + test 'pre-activate remote user' do @stub_content = { uuid: 'zbbbb-tpzed-000000000001234', @@ -294,7 +349,6 @@ class RemoteUsersTest < ActionDispatch::IntegrationTest params: {format: 'json'}, headers: auth(remote: 'zbbbb') assert_response :success - puts json_response assert_equal 'zbbbb-tpzed-000000000001234', json_response['uuid'] assert_equal false, json_response['is_admin'] assert_equal true, json_response['is_active']