X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/c435ef61a97a115797c3075a6e5870b9a9587348..1df6b1005acfdc098f6f42a384924f6879543c7b:/services/api/test/functional/arvados/v1/groups_controller_test.rb diff --git a/services/api/test/functional/arvados/v1/groups_controller_test.rb b/services/api/test/functional/arvados/v1/groups_controller_test.rb index d2b2ad7de8..55493046ed 100644 --- a/services/api/test/functional/arvados/v1/groups_controller_test.rb +++ b/services/api/test/functional/arvados/v1/groups_controller_test.rb @@ -116,6 +116,25 @@ class Arvados::V1::GroupsControllerTest < ActionController::TestCase end end + test "list trashed collections and projects" do + authorize_with :active + get(:contents, { + format: :json, + include_trash: true, + filters: [ + ['uuid', 'is_a', ['arvados#collection', 'arvados#group']], + ['is_trashed', '=', true], + ], + limit: 10000, + }) + assert_response :success + found_uuids = json_response['items'].collect { |i| i['uuid'] } + assert_includes found_uuids, groups(:trashed_project).uuid + refute_includes found_uuids, groups(:aproject).uuid + assert_includes found_uuids, collections(:expired_collection).uuid + refute_includes found_uuids, collections(:w_a_z_file).uuid + end + test "list objects in home project" do authorize_with :active get :contents, { @@ -194,25 +213,6 @@ class Arvados::V1::GroupsControllerTest < ActionController::TestCase assert actually_checked_anything, "Didn't even find two items to compare." end - test 'list objects across multiple projects' do - authorize_with :project_viewer - get :contents, { - format: :json, - filters: [['uuid', 'is_a', 'arvados#specimen']] - } - assert_response :success - found_uuids = json_response['items'].collect { |i| i['uuid'] } - [[:in_aproject, true], - [:in_asubproject, true], - [:owned_by_private_group, false]].each do |specimen_fixture, should_find| - if should_find - assert_includes found_uuids, specimens(specimen_fixture).uuid, "did not find specimen fixture '#{specimen_fixture}'" - else - refute_includes found_uuids, specimens(specimen_fixture).uuid, "found specimen fixture '#{specimen_fixture}'" - end - end - end - # Even though the project_viewer tests go through other controllers, # I'm putting them here so they're easy to find alongside the other # project tests. @@ -719,4 +719,134 @@ class Arvados::V1::GroupsControllerTest < ActionController::TestCase assert_not_nil Group.readable_by(users(auth)).where(uuid: groups(:trashed_subproject).uuid).first end end + + test 'get shared owned by another user' do + authorize_with :user_bar_in_sharing_group + + act_as_system_user do + Link.create!( + tail_uuid: users(:user_bar_in_sharing_group).uuid, + link_class: 'permission', + name: 'can_read', + head_uuid: groups(:project_owned_by_foo).uuid) + end + + get :shared, {:filters => [["group_class", "=", "project"]], :include => "owner_uuid"} + + assert_equal 1, json_response['items'].length + assert_equal json_response['items'][0]["uuid"], groups(:project_owned_by_foo).uuid + + assert_equal 1, json_response['included'].length + assert_equal json_response['included'][0]["uuid"], users(:user_foo_in_sharing_group).uuid + end + + test 'get shared, owned by unreadable project' do + authorize_with :user_bar_in_sharing_group + + act_as_system_user do + Group.find_by_uuid(groups(:project_owned_by_foo).uuid).update!(owner_uuid: groups(:aproject).uuid) + Link.create!( + tail_uuid: users(:user_bar_in_sharing_group).uuid, + link_class: 'permission', + name: 'can_read', + head_uuid: groups(:project_owned_by_foo).uuid) + end + + get :shared, {:filters => [["group_class", "=", "project"]], :include => "owner_uuid"} + + assert_equal 1, json_response['items'].length + assert_equal json_response['items'][0]["uuid"], groups(:project_owned_by_foo).uuid + + assert_equal 0, json_response['included'].length + end + + test 'get shared, owned by non-project' do + authorize_with :user_bar_in_sharing_group + + act_as_system_user do + Group.find_by_uuid(groups(:project_owned_by_foo).uuid).update!(owner_uuid: groups(:group_for_sharing_tests).uuid) + end + + get :shared, {:filters => [["group_class", "=", "project"]], :include => "owner_uuid"} + + assert_equal 1, json_response['items'].length + assert_equal json_response['items'][0]["uuid"], groups(:project_owned_by_foo).uuid + + assert_equal 1, json_response['included'].length + assert_equal json_response['included'][0]["uuid"], groups(:group_for_sharing_tests).uuid + end + + ### contents with exclude_home_project + + test 'contents, exclude home owned by another user' do + authorize_with :user_bar_in_sharing_group + + act_as_system_user do + Link.create!( + tail_uuid: users(:user_bar_in_sharing_group).uuid, + link_class: 'permission', + name: 'can_read', + head_uuid: groups(:project_owned_by_foo).uuid) + Link.create!( + tail_uuid: users(:user_bar_in_sharing_group).uuid, + link_class: 'permission', + name: 'can_read', + head_uuid: collections(:collection_owned_by_foo).uuid) + end + + get :contents, {:include => "owner_uuid", :exclude_home_project => true} + + assert_equal 2, json_response['items'].length + assert_equal json_response['items'][0]["uuid"], groups(:project_owned_by_foo).uuid + assert_equal json_response['items'][1]["uuid"], collections(:collection_owned_by_foo).uuid + + assert_equal 1, json_response['included'].length + assert_equal json_response['included'][0]["uuid"], users(:user_foo_in_sharing_group).uuid + end + + test 'contents, exclude home, owned by unreadable project' do + authorize_with :user_bar_in_sharing_group + + act_as_system_user do + Group.find_by_uuid(groups(:project_owned_by_foo).uuid).update!(owner_uuid: groups(:aproject).uuid) + Link.create!( + tail_uuid: users(:user_bar_in_sharing_group).uuid, + link_class: 'permission', + name: 'can_read', + head_uuid: groups(:project_owned_by_foo).uuid) + end + + get :contents, {:include => "owner_uuid", :exclude_home_project => true} + + assert_equal 1, json_response['items'].length + assert_equal json_response['items'][0]["uuid"], groups(:project_owned_by_foo).uuid + + assert_equal 0, json_response['included'].length + end + + test 'contents, exclude home, owned by non-project' do + authorize_with :user_bar_in_sharing_group + + act_as_system_user do + Group.find_by_uuid(groups(:project_owned_by_foo).uuid).update!(owner_uuid: groups(:group_for_sharing_tests).uuid) + end + + get :contents, {:include => "owner_uuid", :exclude_home_project => true} + + assert_equal 1, json_response['items'].length + assert_equal json_response['items'][0]["uuid"], groups(:project_owned_by_foo).uuid + + assert_equal 1, json_response['included'].length + assert_equal json_response['included'][0]["uuid"], groups(:group_for_sharing_tests).uuid + end + + + test 'contents, exclude home, with parent specified' do + authorize_with :active + + get :contents, {id: groups(:aproject).uuid, :include => "owner_uuid", :exclude_home_project => true} + + assert_response 422 + end + end