3 class Arvados::V1::ApiClientAuthorizationsControllerTest < ActionController::TestCase
4 test "should get index" do
5 authorize_with :active_trustedclient
7 assert_response :success
10 test "should not get index with expired auth" do
11 authorize_with :expired
12 get :index, format: :json
16 test "should not get index from untrusted client" do
17 authorize_with :active
22 test "create system auth" do
23 authorize_with :admin_trustedclient
24 post :create_system_auth, scopes: '["test"]'
25 assert_response :success
26 assert_not_nil JSON.parse(@response.body)['uuid']
29 test "prohibit create system auth with token from non-trusted client" do
31 post :create_system_auth, scopes: '["test"]'
35 test "prohibit create system auth by non-admin" do
36 authorize_with :active
37 post :create_system_auth, scopes: '["test"]'
41 def assert_found_tokens(auth, search_params, *expected_tokens)
43 expected_tokens.map! { |name| api_client_authorizations(name).api_token }
44 get :index, search_params
45 assert_response :success
46 got_tokens = JSON.parse(@response.body)['items']
47 .map { |auth| auth['api_token'] }
48 assert_equal(expected_tokens.sort, got_tokens.sort,
49 "wrong results for #{search_params.inspect}")
52 # Three-tuples with auth to use, scopes to find, and expected tokens.
53 # Make two tests for each tuple, one searching with where and the other
55 [[:admin_trustedclient, [], :admin_noscope],
56 [:active_trustedclient, ["GET /arvados/v1/users"], :active_userlist],
57 [:active_trustedclient,
58 ["POST /arvados/v1/api_client_authorizations",
59 "GET /arvados/v1/api_client_authorizations"],
61 ].each do |auth, scopes, *expected|
62 test "#{auth.to_s} can find auths where scopes=#{scopes.inspect}" do
63 assert_found_tokens(auth, {where: {scopes: scopes}}, *expected)
66 test "#{auth.to_s} can find auths filtered with scopes=#{scopes.inspect}" do
67 assert_found_tokens(auth, {filters: [['scopes', '=', scopes]]}, *expected)
72 [:admin, :admin, 200],
73 [:admin, :active, 403],
74 [:admin, :admin_vm, 403], # this belongs to the user of current session, but we can't get it by uuid
75 [:admin_trustedclient, :active, 200],
76 ].each do |user, token, status|
77 test "as user #{user} get #{token} token and expect #{status}" do
79 get :show, {id: api_client_authorizations(token).uuid}
80 assert_response status
85 [:admin, :admin, 200],
86 [:admin, :active, 403],
87 [:admin, :admin_vm, 403], # this belongs to the user of current session, but we can't list it by uuid
88 [:admin_trustedclient, :active, 200],
89 ].each do |user, token, status|
90 test "as user #{user} list #{token} token using uuid and expect #{status}" do
93 filters: [['uuid','=',api_client_authorizations(token).uuid]]
95 assert_response status
100 [:admin, :admin, 200],
101 [:admin, :active, 403],
102 [:admin, :admin_vm, 200], # this belongs to the user of current session, and can be listed by token
103 [:admin_trustedclient, :active, 200],
104 ].each do |user, token, status|
105 test "as user #{user} list #{token} token using token and expect #{status}" do
108 filters: [['api_token','=',api_client_authorizations(token).api_token]]
110 assert_response status