1 # Copyright (C) The Arvados Authors. All rights reserved.
3 # SPDX-License-Identifier: AGPL-3.0
7 class ReaderTokensTest < ActionDispatch::IntegrationTest
11 collections(:collection_owned_by_foo).uuid
14 def get_collections(main_auth, read_auth, formatter=:to_a)
16 params[:reader_tokens] = [api_token(read_auth)].send(formatter) if read_auth
18 headers.merge!(auth(main_auth)) if main_auth
19 get('/arvados/v1/collections', params: params, headers: headers)
22 def get_collection_uuids(main_auth, read_auth, formatter=:to_a)
23 get_collections(main_auth, read_auth, formatter)
24 assert_response :success
25 json_response['items'].map { |spec| spec['uuid'] }
28 def assert_post_denied(main_auth, read_auth, formatter=:to_a)
30 headers = auth(main_auth)
36 post('/arvados/v1/collections.json',
37 params: {collection: {}, reader_tokens: [api_token(read_auth)].send(formatter)},
39 assert_response expected
42 test "active user can't see foo-owned collection" do
43 # Other tests in this suite assume that the active user doesn't
44 # have read permission to the owned_by_foo collection.
45 # This test checks that this assumption still holds.
46 refute_includes(get_collection_uuids(:active, nil), owned_by_foo,
47 ["active user can read the owned_by_foo collection",
48 "other tests will return false positives"].join(" - "))
51 [nil, :active_noscope].each do |main_auth|
52 [:foo, :foo_collections].each do |read_auth|
53 [:to_a, :to_json].each do |formatter|
54 test "#{main_auth.inspect} auth with #{formatter} reader token #{read_auth} can#{"'t" if main_auth} read" do
55 get_collections(main_auth, read_auth)
56 assert_response(if main_auth then 403 else 200 end)
59 test "#{main_auth.inspect} auth with #{formatter} reader token #{read_auth} can't write" do
60 assert_post_denied(main_auth, read_auth, formatter)
66 test "scopes are still limited with reader tokens" do
67 get('/arvados/v1/collections',
68 params: {reader_tokens: [api_token(:foo_collections)]},
69 headers: auth(:active_noscope))
73 test "reader tokens grant no permissions when expired" do
74 get_collections(:active_noscope, :expired)
78 test "reader tokens grant no permissions outside their scope" do
79 refute_includes(get_collection_uuids(:active, :admin_vm), owned_by_foo,
80 "scoped reader token granted permissions out of scope")