X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/de98daba898ad2dfa58c9e810d98dadf4d208b95..8c4542afc387211a36cc90f8085f229ff314854e:/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..45aab3c857 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 @@ -167,8 +176,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 +213,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 +470,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 +481,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