X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/ddb83a220cd6f3b62171c3c374c58e553d82a5d6..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 13644e00bd..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']}) @@ -514,4 +513,123 @@ class CollectionsControllerTest < ActionController::TestCase get :show, {id: api_fixture('collections')['user_agreement']['uuid']}, session_for(:active) assert_not_includes @response.body, '