X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/6951a378515a726fa178e0d1554c72044a7f5f88..e768a05df9fd75cee3724e6b68cb65beeebaaa38:/services/api/test/functional/arvados/v1/collections_controller_test.rb 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 4b87ebd41f..e6ecea219b 100644 --- a/services/api/test/functional/arvados/v1/collections_controller_test.rb +++ b/services/api/test/functional/arvados/v1/collections_controller_test.rb @@ -1,3 +1,7 @@ +# Copyright (C) The Arvados Authors. All rights reserved. +# +# SPDX-License-Identifier: AGPL-3.0 + require 'test_helper' class Arvados::V1::CollectionsControllerTest < ActionController::TestCase @@ -283,12 +287,12 @@ EOS assert_response :success assert_not_nil assigns(:object) resp = assigns(:object) - assert_equal foo_collection[:portable_data_hash], resp['portable_data_hash'] - assert_signed_manifest resp['manifest_text'] + assert_equal foo_collection[:portable_data_hash], resp[:portable_data_hash] + assert_signed_manifest resp[:manifest_text] # The manifest in the response will have had permission hints added. # Remove any permission hints in the response before comparing it to the source. - stripped_manifest = resp['manifest_text'].gsub(/\+A[A-Za-z0-9@_-]+/, '') + stripped_manifest = resp[:manifest_text].gsub(/\+A[A-Za-z0-9@_-]+/, '') assert_equal foo_collection[:manifest_text], stripped_manifest end end @@ -345,7 +349,7 @@ EOS ensure_unique_name: true } assert_response :success - assert_equal 'owned_by_active (2)', json_response['name'] + assert_match /^owned_by_active \(\d{4}-\d\d-\d\d.*?Z\)$/, json_response['name'] end end @@ -987,7 +991,7 @@ EOS id: uuid, } assert_response 200 - c = Collection.unscoped.find_by_uuid(uuid) + c = Collection.find_by_uuid(uuid) assert_operator c.trash_at, :<, db_current_time assert_equal c.delete_at, c.trash_at + Rails.configuration.blob_signature_ttl end @@ -999,7 +1003,7 @@ EOS id: uuid, } assert_response 200 - c = Collection.unscoped.find_by_uuid(uuid) + c = Collection.find_by_uuid(uuid) assert_operator c.trash_at, :<, db_current_time assert_operator c.delete_at, :<, db_current_time end @@ -1019,9 +1023,124 @@ EOS id: uuid, } assert_response 200 - c = Collection.unscoped.find_by_uuid(uuid) + c = Collection.find_by_uuid(uuid) assert_operator c.trash_at, :<, db_current_time assert_operator c.delete_at, :>=, time_before_trashing + Rails.configuration.default_trash_lifetime end end + + test 'untrash a trashed collection' do + authorize_with :active + post :untrash, { + id: collections(:expired_collection).uuid, + } + assert_response 200 + assert_equal false, json_response['is_trashed'] + assert_nil json_response['trash_at'] + end + + test 'untrash error on not trashed collection' do + authorize_with :active + post :untrash, { + id: collections(:collection_owned_by_active).uuid, + } + assert_response 422 + end + + [:active, :admin].each do |user| + test "get trashed collections as #{user}" do + authorize_with user + get :index, { + filters: [["is_trashed", "=", true]], + include_trash: true, + } + assert_response :success + + items = [] + json_response["items"].each do |coll| + items << coll['uuid'] + end + + assert_includes(items, collections('unique_expired_collection')['uuid']) + if user == :admin + assert_includes(items, collections('unique_expired_collection2')['uuid']) + else + assert_not_includes(items, collections('unique_expired_collection2')['uuid']) + end + end + end + + test 'untrash collection with same name as another with no ensure unique name' do + authorize_with :active + post :untrash, { + id: collections(:trashed_collection_to_test_name_conflict_on_untrash).uuid, + } + assert_response 422 + end + + test 'untrash collection with same name as another with ensure unique name' do + authorize_with :active + post :untrash, { + id: collections(:trashed_collection_to_test_name_conflict_on_untrash).uuid, + ensure_unique_name: true + } + assert_response 200 + assert_equal false, json_response['is_trashed'] + assert_nil json_response['trash_at'] + 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, { limit: 1000 } + 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, { limit: 1000 } + 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 + + test 'can index trashed subproject collection with include_trash' do + authorize_with :active + get :index, { + include_trash: true, + limit: 1000 + } + 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