X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/bdc87ddb113a2e05dd859a7f68f5fe1135bbc650..4077a9af0985d3c85f2f2de2bb7a0f6be581e71e:/services/api/test/integration/permissions_test.rb diff --git a/services/api/test/integration/permissions_test.rb b/services/api/test/integration/permissions_test.rb index 40a77e72c5..44b5e6e377 100644 --- a/services/api/test/integration/permissions_test.rb +++ b/services/api/test/integration/permissions_test.rb @@ -1,12 +1,9 @@ require 'test_helper' class PermissionsTest < ActionDispatch::IntegrationTest + include CurrentApiClient # for empty_collection fixtures :users, :groups, :api_client_authorizations, :collections - def auth auth_fixture - {'HTTP_AUTHORIZATION' => "OAuth2 #{api_client_authorizations(auth_fixture).api_token}"} - end - test "adding and removing direct can_read links" do # try to read collection as spectator get "/arvados/v1/collections/#{collections(:foo_file).uuid}", {:format => :json}, auth(:spectator) @@ -16,11 +13,9 @@ class PermissionsTest < ActionDispatch::IntegrationTest post "/arvados/v1/links", { :format => :json, :link => { - tail_kind: 'arvados#user', tail_uuid: users(:spectator).uuid, link_class: 'permission', name: 'can_read', - head_kind: 'arvados#collection', head_uuid: collections(:foo_file).uuid, properties: {} } @@ -31,16 +26,14 @@ class PermissionsTest < ActionDispatch::IntegrationTest post "/arvados/v1/links", { :format => :json, :link => { - tail_kind: 'arvados#user', tail_uuid: users(:spectator).uuid, link_class: 'permission', name: 'can_read', - head_kind: 'arvados#collection', head_uuid: collections(:foo_file).uuid, properties: {} } }, auth(:admin) - u = jresponse['uuid'] + u = json_response['uuid'] assert_response :success # read collection as spectator @@ -70,11 +63,9 @@ class PermissionsTest < ActionDispatch::IntegrationTest post "/arvados/v1/links", { :format => :json, :link => { - tail_kind: 'arvados#user', tail_uuid: users(:spectator).uuid, link_class: 'permission', name: 'can_read', - head_kind: 'arvados#group', head_uuid: groups(:private).uuid, properties: {} } @@ -89,16 +80,14 @@ class PermissionsTest < ActionDispatch::IntegrationTest post "/arvados/v1/links", { :format => :json, :link => { - tail_kind: 'arvados#group', tail_uuid: groups(:private).uuid, link_class: 'permission', name: 'can_read', - head_kind: 'arvados#collection', head_uuid: collections(:foo_file).uuid, properties: {} } }, auth(:admin) - u = jresponse['uuid'] + u = json_response['uuid'] assert_response :success # try to read collection as spectator @@ -112,7 +101,7 @@ class PermissionsTest < ActionDispatch::IntegrationTest # try to read collection as spectator get "/arvados/v1/collections/#{collections(:foo_file).uuid}", {:format => :json}, auth(:spectator) assert_response 404 - + end @@ -125,11 +114,9 @@ class PermissionsTest < ActionDispatch::IntegrationTest post "/arvados/v1/links", { :format => :json, :link => { - tail_kind: 'arvados#group', tail_uuid: groups(:private).uuid, link_class: 'permission', name: 'can_read', - head_kind: 'arvados#collection', head_uuid: collections(:foo_file).uuid, properties: {} } @@ -144,16 +131,14 @@ class PermissionsTest < ActionDispatch::IntegrationTest post "/arvados/v1/links", { :format => :json, :link => { - tail_kind: 'arvados#user', tail_uuid: users(:spectator).uuid, link_class: 'permission', name: 'can_read', - head_kind: 'arvados#group', head_uuid: groups(:private).uuid, properties: {} } }, auth(:admin) - u = jresponse['uuid'] + u = json_response['uuid'] assert_response :success # try to read collection as spectator @@ -167,7 +152,7 @@ class PermissionsTest < ActionDispatch::IntegrationTest # try to read collection as spectator get "/arvados/v1/collections/#{collections(:foo_file).uuid}", {:format => :json}, auth(:spectator) assert_response 404 - + end test "adding can_read links from user to group, group to group, group to collection" do @@ -179,11 +164,9 @@ class PermissionsTest < ActionDispatch::IntegrationTest post "/arvados/v1/links", { :format => :json, :link => { - tail_kind: 'arvados#user', tail_uuid: users(:spectator).uuid, link_class: 'permission', name: 'can_read', - head_kind: 'arvados#group', head_uuid: groups(:private).uuid, properties: {} } @@ -194,11 +177,9 @@ class PermissionsTest < ActionDispatch::IntegrationTest post "/arvados/v1/links", { :format => :json, :link => { - tail_kind: 'arvados#group', tail_uuid: groups(:private).uuid, link_class: 'permission', name: 'can_read', - head_kind: 'arvados#group', head_uuid: groups(:empty_lonely_group).uuid, properties: {} } @@ -209,16 +190,14 @@ class PermissionsTest < ActionDispatch::IntegrationTest post "/arvados/v1/links", { :format => :json, :link => { - tail_kind: 'arvados#group', tail_uuid: groups(:empty_lonely_group).uuid, link_class: 'permission', name: 'can_read', - head_kind: 'arvados#collection', head_uuid: collections(:foo_file).uuid, properties: {} } }, auth(:admin) - u = jresponse['uuid'] + u = json_response['uuid'] assert_response :success # try to read collection as spectator @@ -234,18 +213,6 @@ class PermissionsTest < ActionDispatch::IntegrationTest assert_response 404 end - test "read-only group-admin sees correct subset of user list" do - get "/arvados/v1/users", {:format => :json}, auth(:rominiadmin) - assert_response :success - resp_uuids = jresponse['items'].collect { |i| i['uuid'] } - [[true, users(:rominiadmin).uuid], - [true, users(:active).uuid], - [false, users(:miniadmin).uuid], - [false, users(:spectator).uuid]].each do |should_find, uuid| - assert_equal should_find, !resp_uuids.index(uuid).nil?, "rominiadmin should #{'not ' if !should_find}see #{uuid} in user list" - end - end - test "read-only group-admin cannot modify administered user" do put "/arvados/v1/users/#{users(:active).uuid}", { :user => { @@ -276,7 +243,7 @@ class PermissionsTest < ActionDispatch::IntegrationTest [:miniadmin, true]].each do |which_user, update_should_succeed| get "/arvados/v1/specimens", {:format => :json}, auth(which_user) assert_response :success - resp_uuids = jresponse['items'].collect { |i| i['uuid'] } + resp_uuids = json_response['items'].collect { |i| i['uuid'] } [[true, specimens(:owned_by_active_user).uuid], [true, specimens(:owned_by_private_group).uuid], [false, specimens(:owned_by_spectator).uuid], @@ -305,4 +272,103 @@ class PermissionsTest < ActionDispatch::IntegrationTest end end + test "get_permissions returns list" do + # First confirm that user :active cannot get permissions on group :public + get "/arvados/v1/permissions/#{groups(:public).uuid}", nil, auth(:active) + assert_response 404 + + # add some permissions, including can_manage + # permission for user :active + post "/arvados/v1/links", { + :format => :json, + :link => { + tail_uuid: users(:spectator).uuid, + link_class: 'permission', + name: 'can_read', + head_uuid: groups(:public).uuid, + properties: {} + } + }, auth(:admin) + assert_response :success + can_read_uuid = json_response['uuid'] + + post "/arvados/v1/links", { + :format => :json, + :link => { + tail_uuid: users(:inactive).uuid, + link_class: 'permission', + name: 'can_write', + head_uuid: groups(:public).uuid, + properties: {} + } + }, auth(:admin) + assert_response :success + can_write_uuid = json_response['uuid'] + + post "/arvados/v1/links", { + :format => :json, + :link => { + tail_uuid: users(:active).uuid, + link_class: 'permission', + name: 'can_manage', + head_uuid: groups(:public).uuid, + properties: {} + } + }, auth(:admin) + assert_response :success + can_manage_uuid = json_response['uuid'] + + # Now user :active should be able to retrieve permissions + # on group :public. + get("/arvados/v1/permissions/#{groups(:public).uuid}", + { :format => :json }, + auth(:active)) + assert_response :success + + perm_uuids = json_response['items'].map { |item| item['uuid'] } + assert_includes perm_uuids, can_read_uuid, "can_read_uuid not found" + assert_includes perm_uuids, can_write_uuid, "can_write_uuid not found" + assert_includes perm_uuids, can_manage_uuid, "can_manage_uuid not found" + end + + test "get_permissions returns 404 for nonexistent uuid" do + nonexistent = Group.generate_uuid + # make sure it really doesn't exist + get "/arvados/v1/groups/#{nonexistent}", nil, auth(:admin) + assert_response 404 + + get "/arvados/v1/permissions/#{nonexistent}", nil, auth(:active) + assert_response 404 + end + + test "get_permissions returns 404 for unreadable uuid" do + get "/arvados/v1/permissions/#{groups(:public).uuid}", nil, auth(:active) + assert_response 404 + end + + test "get_permissions returns 403 if user can read but not manage" do + post "/arvados/v1/links", { + :link => { + tail_uuid: users(:active).uuid, + link_class: 'permission', + name: 'can_read', + head_uuid: groups(:public).uuid, + properties: {} + } + }, auth(:admin) + assert_response :success + + get "/arvados/v1/permissions/#{groups(:public).uuid}", nil, auth(:active) + assert_response 403 + end + + test "active user can read the empty collection" do + # The active user should be able to read the empty collection. + + get("/arvados/v1/collections/#{empty_collection_uuid}", + { :format => :json }, + auth(:active)) + assert_response :success + assert_empty json_response['manifest_text'], "empty collection manifest_text is not empty" + end end