X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/a57f8602e4a89e526464587c78e91c2086aae8d8..aa12c56d26cb72824ddd2399e17e846cd9d9b483:/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 c0d63e0f30..055af9e67c 100644 --- a/services/api/test/functional/arvados/v1/collections_controller_test.rb +++ b/services/api/test/functional/arvados/v1/collections_controller_test.rb @@ -1,6 +1,7 @@ require 'test_helper' class Arvados::V1::CollectionsControllerTest < ActionController::TestCase + include DbCurrentTime PERM_TOKEN_RE = /\+A[[:xdigit:]]+@[[:xdigit:]]{8}\b/ @@ -75,6 +76,49 @@ class Arvados::V1::CollectionsControllerTest < ActionController::TestCase assert_operator locs, :>, 0, "no locators found in any manifests" end + test 'index without select returns everything except manifest' do + authorize_with :active + get :index + assert_response :success + assert json_response['items'].any? + json_response['items'].each do |coll| + assert_includes(coll.keys, 'uuid') + assert_includes(coll.keys, 'name') + assert_includes(coll.keys, 'created_at') + refute_includes(coll.keys, 'manifest_text') + end + end + + ['', nil, false, 'null'].each do |select| + test "index with select=#{select.inspect} returns everything except manifest" do + authorize_with :active + get :index, select: select + assert_response :success + assert json_response['items'].any? + json_response['items'].each do |coll| + assert_includes(coll.keys, 'uuid') + assert_includes(coll.keys, 'name') + assert_includes(coll.keys, 'created_at') + refute_includes(coll.keys, 'manifest_text') + end + end + end + + [["uuid"], + ["uuid", "manifest_text"], + '["uuid"]', + '["uuid", "manifest_text"]'].each do |select| + test "index with select=#{select.inspect} returns no name" do + authorize_with :active + get :index, select: select + assert_response :success + assert json_response['items'].any? + json_response['items'].each do |coll| + refute_includes(coll.keys, 'name') + end + end + end + [0,1,2].each do |limit| test "get index with limit=#{limit}" do authorize_with :active @@ -239,12 +283,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 @@ -301,7 +345,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 @@ -780,11 +824,11 @@ EOS [2**8, :success], [2**18, 422], ].each do |description_size, expected_response| - test "create collection with description size #{description_size} + # Descriptions are not part of search indexes. Skip until + # full-text search is implemented, at which point replace with a + # search in description. + skip "create collection with description size #{description_size} and expect response #{expected_response}" do - skip "(Descriptions are not part of search indexes. Skip until full-text search - is implemented, at which point replace with a search in description.)" - authorize_with :active description = 'here is a collection with a very large description' @@ -916,4 +960,109 @@ EOS assert_response 200 end end + + test 'get trashed collection with include_trash' do + uuid = 'zzzzz-4zz18-mto52zx1s7sn3ih' # expired_collection + authorize_with :active + get :show, { + id: uuid, + include_trash: true, + } + assert_response 200 + end + + test 'get trashed collection without include_trash' do + uuid = 'zzzzz-4zz18-mto52zx1s7sn3ih' # expired_collection + authorize_with :active + get :show, { + id: uuid, + } + assert_response 404 + end + + test 'trash collection using http DELETE verb' do + uuid = collections(:collection_owned_by_active).uuid + authorize_with :active + delete :destroy, { + id: uuid, + } + assert_response 200 + c = Collection.unscoped.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 + + test 'delete long-trashed collection immediately using http DELETE verb' do + uuid = 'zzzzz-4zz18-mto52zx1s7sn3ih' # expired_collection + authorize_with :active + delete :destroy, { + id: uuid, + } + assert_response 200 + c = Collection.unscoped.find_by_uuid(uuid) + assert_operator c.trash_at, :<, db_current_time + assert_operator c.delete_at, :<, db_current_time + end + + ['zzzzz-4zz18-mto52zx1s7sn3ih', # expired_collection + :empty_collection_name_in_active_user_home_project, + ].each do |fixture| + test "trash collection #{fixture} via trash action with grace period" do + if fixture.is_a? String + uuid = fixture + else + uuid = collections(fixture).uuid + end + authorize_with :active + time_before_trashing = db_current_time + post :trash, { + id: uuid, + } + assert_response 200 + c = Collection.unscoped.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 :active + 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 end