3 class Arvados::V1::ReaderTokensTest < ActionController::IntegrationTest
7 specimens(:owned_by_spectator).uuid
10 def get_specimens(main_auth, read_auth, formatter=:to_a)
12 params[:reader_tokens] = [api_token(read_auth)].send(formatter) if read_auth
14 headers.merge!(auth(main_auth)) if main_auth
15 get('/arvados/v1/specimens', params, headers)
18 def get_specimen_uuids(main_auth, read_auth, formatter=:to_a)
19 get_specimens(main_auth, read_auth, formatter)
20 assert_response :success
21 json_response['items'].map { |spec| spec['uuid'] }
24 def assert_post_denied(main_auth, read_auth, formatter=:to_a)
26 headers = auth(main_auth)
32 post('/arvados/v1/specimens.json',
33 {specimen: {}, reader_tokens: [api_token(read_auth)].send(formatter)},
35 assert_response expected
38 test "active user can't see spectator specimen" do
39 # Other tests in this suite assume that the active user doesn't
40 # have read permission to the owned_by_spectator specimen.
41 # This test checks that this assumption still holds.
42 refute_includes(get_specimen_uuids(:active, nil), spectator_specimen,
43 ["active user can read the owned_by_spectator specimen",
44 "other tests will return false positives"].join(" - "))
47 [nil, :active_noscope].each do |main_auth|
48 [:spectator, :spectator_specimens].each do |read_auth|
49 test "#{main_auth} auth with reader token #{read_auth} can read" do
50 assert_includes(get_specimen_uuids(main_auth, read_auth),
51 spectator_specimen, "did not find spectator specimen")
54 test "#{main_auth} auth with JSON read token #{read_auth} can read" do
55 assert_includes(get_specimen_uuids(main_auth, read_auth, :to_json),
56 spectator_specimen, "did not find spectator specimen")
59 test "#{main_auth} auth with reader token #{read_auth} can't write" do
60 assert_post_denied(main_auth, read_auth)
63 test "#{main_auth} auth with JSON read token #{read_auth} can't write" do
64 assert_post_denied(main_auth, read_auth, :to_json)
69 test "scopes are still limited with reader tokens" do
70 get('/arvados/v1/collections',
71 {reader_tokens: [api_token(:spectator_specimens)]},
72 auth(:active_noscope))
76 test "reader tokens grant no permissions when expired" do
77 get_specimens(:active_noscope, :expired)
81 test "reader tokens grant no permissions outside their scope" do
82 refute_includes(get_specimen_uuids(:active, :admin_vm), spectator_specimen,
83 "scoped reader token granted permissions out of scope")