From 568f53d1517bd43e4e4285cb19336ebbcca75389 Mon Sep 17 00:00:00 2001 From: Peter Amstutz Date: Mon, 28 Aug 2017 09:57:05 -0400 Subject: [PATCH] 12032: Adding controller tests Arvados-DCO-1.1-Signed-off-by: Peter Amstutz --- services/api/test/fixtures/groups.yml | 2 +- .../arvados/v1/collections_controller_test.rb | 40 +++++++ .../arvados/v1/groups_controller_test.rb | 111 ++++++++++++++++++ 3 files changed, 152 insertions(+), 1 deletion(-) diff --git a/services/api/test/fixtures/groups.yml b/services/api/test/fixtures/groups.yml index c9783d024d..1cb5817b0a 100644 --- a/services/api/test/fixtures/groups.yml +++ b/services/api/test/fixtures/groups.yml @@ -310,7 +310,7 @@ trashed_project: trashed_subproject: uuid: zzzzz-j7d0g-trashedproject2 - owner_uuid: + owner_uuid: zzzzz-j7d0g-trashedproject1 name: trashed subproject group_class: project trash_at: 2001-01-01T00:00:00Z diff --git a/services/api/test/functional/arvados/v1/collections_controller_test.rb b/services/api/test/functional/arvados/v1/collections_controller_test.rb index 56b0790a0a..4cf8778e6a 100644 --- a/services/api/test/functional/arvados/v1/collections_controller_test.rb +++ b/services/api/test/functional/arvados/v1/collections_controller_test.rb @@ -1090,4 +1090,44 @@ EOS assert_nil json_response['delete_at'] assert_match /^same name for trashed and persisted collections \(\d{4}-\d\d-\d\d.*?Z\)$/, json_response['name'] end + + test 'cannot show collection in trashed subproject' do + authorize_with :active + get :show, { + id: collections(:collection_in_trashed_subproject).uuid, + format: :json + } + assert_response 404 + end + + test 'can show collection in untrashed subproject' do + authorize_with :active + Group.find_by_uuid(groups(:trashed_project).uuid).update! is_trashed: false + get :show, { + id: collections(:collection_in_trashed_subproject).uuid, + format: :json, + } + assert_response :success + end + + test 'cannot index collection in trashed subproject' do + authorize_with :active + get :index + assert_response :success + item_uuids = json_response['items'].map do |item| + item['uuid'] + end + assert_not_includes(item_uuids, collections(:collection_in_trashed_subproject).uuid) + end + + test 'can index collection in untrashed subproject' do + authorize_with :active + Group.find_by_uuid(groups(:trashed_project).uuid).update! is_trashed: false + get :index + assert_response :success + item_uuids = json_response['items'].map do |item| + item['uuid'] + end + assert_includes(item_uuids, collections(:collection_in_trashed_subproject).uuid) + end end 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 5ae1e9a9e2..043d66506d 100644 --- a/services/api/test/functional/arvados/v1/groups_controller_test.rb +++ b/services/api/test/functional/arvados/v1/groups_controller_test.rb @@ -529,4 +529,115 @@ class Arvados::V1::GroupsControllerTest < ActionController::TestCase assert_includes(owners, groups(:aproject).uuid) assert_includes(owners, groups(:asubproject).uuid) end + + ### trashed project tests ### + + [:active, :admin].each do |auth| + test "trashed project is hidden in contents (#{auth})" do + authorize_with auth + get :contents, { + id: users(:active).uuid, + format: :json, + } + item_uuids = json_response['items'].map do |item| + item['uuid'] + end + assert_not_includes(item_uuids, groups(:trashed_project).uuid) + end + + test "untrashed project is visible in contents (#{auth})" do + authorize_with auth + Group.find_by_uuid(groups(:trashed_project).uuid).update! is_trashed: false + get :contents, { + id: users(:active).uuid, + format: :json, + } + item_uuids = json_response['items'].map do |item| + item['uuid'] + end + assert_includes(item_uuids, groups(:trashed_project).uuid) + end + + test "trashed project is hidden in index (#{auth})" do + authorize_with :active + get :index, { + format: :json, + } + item_uuids = json_response['items'].map do |item| + item['uuid'] + end + assert_not_includes(item_uuids, groups(:trashed_project).uuid) + assert_not_includes(item_uuids, groups(:trashed_subproject).uuid) + end + + test "untrashed project is visible in index (#{auth})" do + authorize_with :active + Group.find_by_uuid(groups(:trashed_project).uuid).update! is_trashed: false + get :index, { + format: :json, + } + item_uuids = json_response['items'].map do |item| + item['uuid'] + end + assert_includes(item_uuids, groups(:trashed_project).uuid) + assert_includes(item_uuids, groups(:trashed_subproject).uuid) + end + + test "cannot get contents of trashed project (#{auth})" do + authorize_with :active + get :contents, { + id: groups(:trashed_project).uuid, + format: :json, + } + assert_response 404 + end + + test "cannot get contents of trashed subproject (#{auth})" do + authorize_with :active + get :contents, { + id: groups(:trashed_subproject).uuid, + format: :json, + } + assert_response 404 + end + + test "can get contents of untrashed project (#{auth})" do + authorize_with :active + Group.find_by_uuid(groups(:trashed_project).uuid).update! is_trashed: false + get :contents, { + id: groups(:trashed_project).uuid, + format: :json, + } + assert_response 200 + end + + test "can get contents of untrashed subproject (#{auth})" do + authorize_with :active + Group.find_by_uuid(groups(:trashed_project).uuid).update! is_trashed: false + get :contents, { + id: groups(:trashed_subproject).uuid, + format: :json, + } + assert_response 200 + end + + test "cannot show trashed project (#{auth})" do + authorize_with :active + get :show, { + id: groups(:trashed_project).uuid, + format: :json, + } + assert_response 404 + end + + test "cannot show trashed subproject (#{auth})" do + authorize_with :active + get :show, { + id: groups(:trashed_subproject).uuid, + format: :json, + } + assert_response 404 + end + end + end -- 2.30.2