X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/90e9b3c5ef43242afc42770d03c61489d69c1de5..40b15b9523c1a89769c8df5bafa250075af0c567:/services/api/test/functional/arvados/v1/users_controller_test.rb diff --git a/services/api/test/functional/arvados/v1/users_controller_test.rb b/services/api/test/functional/arvados/v1/users_controller_test.rb index 531f8e26eb..2d26370b74 100644 --- a/services/api/test/functional/arvados/v1/users_controller_test.rb +++ b/services/api/test/functional/arvados/v1/users_controller_test.rb @@ -1,7 +1,9 @@ require 'test_helper' +require 'helpers/users_test_helper' class Arvados::V1::UsersControllerTest < ActionController::TestCase include CurrentApiClient + include UsersTestHelper setup do @all_links_at_start = Link.all @@ -34,18 +36,20 @@ class Arvados::V1::UsersControllerTest < ActionController::TestCase name: 'click', tail_uuid: users(:inactive).uuid, head_uuid: required_uuids). - collect(&:head_uuid) + collect(&:head_uuid) assert_equal 0, signed_uuids.length end authorize_with :inactive + assert_equal false, users(:inactive).is_active post :activate, id: users(:inactive).uuid assert_response 403 - response_body = JSON.parse(@response.body) - assert response_body['errors'].first.include? 'Cannot activate without user agreements' + resp = json_response + assert resp['errors'].first.include? 'Cannot activate without user agreements' + assert_nil resp['is_active'] end test "activate an already-active user" do @@ -360,7 +364,7 @@ class Arvados::V1::UsersControllerTest < ActionController::TestCase verify_num_links @all_links_at_start, 5 end - test "setup user with an exising user email and check different object is created" do + test "setup user with an existing user email and check different object is created" do authorize_with :admin inactive_user = users(:inactive) @@ -775,6 +779,16 @@ class Arvados::V1::UsersControllerTest < ActionController::TestCase assert_equal false, found_email, 'Expected no email after updating profile' end + test "user API response includes writable_by" do + authorize_with :active + get :current + assert_response :success + assert_includes(json_response["writable_by"], users(:active).uuid, + "user's writable_by should include self") + assert_includes(json_response["writable_by"], users(:active).owner_uuid, + "user's writable_by should include its owner_uuid") + end + NON_ADMIN_USER_DATA = ["uuid", "kind", "is_active", "email", "first_name", "last_name"].sort @@ -853,103 +867,4 @@ class Arvados::V1::UsersControllerTest < ActionController::TestCase } return return_obj end - - def verify_link(response_items, link_object_name, expect_link, link_class, - link_name, head_uuid, tail_uuid, head_kind, fetch_object, class_name) - - link = find_obj_in_resp response_items, 'Link', link_object_name - - if !expect_link - assert_nil link, "Expected no link for #{link_object_name}" - return - end - - assert_not_nil link, "Expected link for #{link_object_name}" - - if fetch_object - object = Object.const_get(class_name).where(name: head_uuid) - assert [] != object, "expected #{class_name} with name #{head_uuid}" - head_uuid = object.first[:uuid] - end - assert_equal link_class, link['link_class'], - "did not find expected link_class for #{link_object_name}" - - assert_equal link_name, link['name'], - "did not find expected link_name for #{link_object_name}" - - assert_equal tail_uuid, link['tail_uuid'], - "did not find expected tail_uuid for #{link_object_name}" - - assert_equal head_kind, link['head_kind'], - "did not find expected head_kind for #{link_object_name}" - - assert_equal head_uuid, link['head_uuid'], - "did not find expected head_uuid for #{link_object_name}" - end - - def verify_link_existence uuid, email, expect_oid_login_perms, - expect_repo_perms, expect_vm_perms, expect_group_perms, expect_signatures - # verify that all links are deleted for the user - oid_login_perms = Link.where(tail_uuid: email, - link_class: 'permission', - name: 'can_login').where("head_uuid like ?", User.uuid_like_pattern) - if expect_oid_login_perms - assert oid_login_perms.any?, "expected oid_login_perms" - else - assert !oid_login_perms.any?, "expected all oid_login_perms deleted" - end - - repo_perms = Link.where(tail_uuid: uuid, - link_class: 'permission', - name: 'can_manage').where("head_uuid like ?", Repository.uuid_like_pattern) - if expect_repo_perms - assert repo_perms.any?, "expected repo_perms" - else - assert !repo_perms.any?, "expected all repo_perms deleted" - end - - vm_login_perms = Link. - where(tail_uuid: uuid, - link_class: 'permission', - name: 'can_login'). - where("head_uuid like ?", - VirtualMachine.uuid_like_pattern). - where('uuid <> ?', - links(:auto_setup_vm_login_username_can_login_to_test_vm).uuid) - if expect_vm_perms - assert vm_login_perms.any?, "expected vm_login_perms" - else - assert !vm_login_perms.any?, "expected all vm_login_perms deleted" - end - - group = Group.where(name: 'All users').select do |g| - g[:uuid].match /-f+$/ - end.first - group_read_perms = Link.where(tail_uuid: uuid, - head_uuid: group[:uuid], - link_class: 'permission', - name: 'can_read') - if expect_group_perms - assert group_read_perms.any?, "expected all users group read perms" - else - assert !group_read_perms.any?, "expected all users group perm deleted" - end - - signed_uuids = Link.where(link_class: 'signature', - tail_uuid: uuid) - - if expect_signatures - assert signed_uuids.any?, "expected signatures" - else - assert !signed_uuids.any?, "expected all signatures deleted" - end - - end - - def verify_system_group_permission_link_for user_uuid - assert_equal 1, Link.where(link_class: 'permission', - name: 'can_manage', - tail_uuid: system_group_uuid, - head_uuid: user_uuid).count - end end