X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/cfcfa1c48d95a07bb961baeef8d7658ddecce41e..3678eda6ea138d948919944d1b54e680ba20ea81:/apps/workbench/test/controllers/collections_controller_test.rb diff --git a/apps/workbench/test/controllers/collections_controller_test.rb b/apps/workbench/test/controllers/collections_controller_test.rb index d046d882f4..1bf967ccfd 100644 --- a/apps/workbench/test/controllers/collections_controller_test.rb +++ b/apps/workbench/test/controllers/collections_controller_test.rb @@ -10,6 +10,15 @@ class CollectionsControllerTest < ActionController::TestCase NONEXISTENT_COLLECTION = "ffffffffffffffffffffffffffffffff+0" + def config_anonymous enable + Rails.configuration.anonymous_user_token = + if enable + api_fixture('api_client_authorizations')['anonymous']['api_token'] + else + false + end + end + def stub_file_content # For the duration of the current test case, stub file download # content with a randomized (but recognizable) string. Return the @@ -103,13 +112,6 @@ class CollectionsControllerTest < ActionController::TestCase "controller did not find logger job") end - test "viewing a collection fetches logs about it" do - show_collection(:foo_file, :active) - assert_includes(assigns(:logs).map(&:uuid), - api_fixture('logs')['system_adds_foo_file']['uuid'], - "controller did not find related log") - end - test "sharing auths available to admin" do show_collection("collection_owned_by_active", "admin_trustedclient") assert_not_nil assigns(:search_sharing) @@ -167,8 +169,7 @@ class CollectionsControllerTest < ActionController::TestCase end test 'anonymous download' do - Rails.configuration.anonymous_user_token = - api_fixture('api_client_authorizations')['anonymous']['api_token'] + config_anonymous true expect_content = stub_file_content get :show_file, { uuid: api_fixture('collections')['user_agreement_in_anonymously_accessible_project']['uuid'], @@ -205,15 +206,14 @@ class CollectionsControllerTest < ActionController::TestCase "using a reader token set the session's API token") end - [false, api_fixture('api_client_authorizations')['anonymous']['api_token']]. - each do |anon_conf| - test "download a file using a reader token with insufficient scope (anon_conf=#{!!anon_conf})" do - Rails.configuration.anonymous_user_token = anon_conf + [false, true].each do |anon| + test "download a file using a reader token with insufficient scope, anon #{anon}" do + config_anonymous anon params = collection_params(:foo_file, 'foo') params[:reader_token] = api_fixture('api_client_authorizations')['active_noscope']['api_token'] get(:show_file, params) - if anon_conf + if anon # Some files can be shown without a valid token, but not this one. assert_response 404 else @@ -463,8 +463,7 @@ class CollectionsControllerTest < ActionController::TestCase end test "anonymous user accesses collection in shared project" do - Rails.configuration.anonymous_user_token = - api_fixture('api_client_authorizations')['anonymous']['api_token'] + config_anonymous true collection = api_fixture('collections')['public_text_file'] get(:show, {id: collection['uuid']}) @@ -475,4 +474,162 @@ class CollectionsControllerTest < ActionController::TestCase assert_includes @response.body, 'Content address' refute_nil css_select('[href="#Advanced"]') end + + test "can view empty collection" do + get :show, {id: 'd41d8cd98f00b204e9800998ecf8427e+0'}, session_for(:active) + assert_includes @response.body, 'The following collections have this content' + end + + test "collection portable data hash redirect" do + di = api_fixture('collections')['docker_image'] + get :show, {id: di['portable_data_hash']}, session_for(:active) + assert_match /\/collections\/#{di['uuid']}/, @response.redirect_url + end + + test "collection portable data hash with multiple matches" do + pdh = api_fixture('collections')['foo_file']['portable_data_hash'] + get :show, {id: pdh}, session_for(:admin) + matches = api_fixture('collections').select {|k,v| v["portable_data_hash"] == pdh} + assert matches.size > 1 + + matches.each do |k,v| + assert_match /href="\/collections\/#{v['uuid']}">.*#{v['name']}<\/a>/, @response.body + end + + assert_includes @response.body, 'The following collections have this content:' + assert_not_includes @response.body, 'more results are not shown' + assert_not_includes @response.body, 'Activity' + assert_not_includes @response.body, 'Sharing and permissions' + end + + test "collection page renders name" do + collection = api_fixture('collections')['foo_file'] + get :show, {id: collection['uuid']}, session_for(:active) + assert_includes @response.body, collection['name'] + assert_match /href="#{collection['uuid']}\/foo" ><\/i> foo