1 # Copyright (C) The Arvados Authors. All rights reserved.
3 # SPDX-License-Identifier: AGPL-3.0
7 class ApiClientAuthorizationsApiTest < ActionDispatch::IntegrationTest
10 test "create system auth" do
11 post "/arvados/v1/api_client_authorizations/create_system_auth",
12 params: {:format => :json, :scopes => ['test'].to_json},
13 headers: {'HTTP_AUTHORIZATION' => "OAuth2 #{api_client_authorizations(:admin_trustedclient).api_token}"}
14 assert_response :success
17 [:admin_trustedclient, :SystemRootToken].each do |tk|
18 test "create token for different user using #{tk}" do
19 if tk == :SystemRootToken
20 token = "xyzzy-SystemRootToken"
21 Rails.configuration.SystemRootToken = token
23 token = api_client_authorizations(tk).api_token
26 post "/arvados/v1/api_client_authorizations",
29 :api_client_authorization => {
30 :owner_uuid => users(:spectator).uuid
33 headers: {'HTTP_AUTHORIZATION' => "OAuth2 #{token}"}
34 assert_response :success
36 get "/arvados/v1/users/current",
37 params: {:format => :json},
38 headers: {'HTTP_AUTHORIZATION' => "OAuth2 #{json_response['api_token']}"}
40 assert_equal json_response['uuid'], users(:spectator).uuid
44 test "System root token is system user" do
45 token = "xyzzy-SystemRootToken"
46 Rails.configuration.SystemRootToken = token
47 get "/arvados/v1/users/current",
48 params: {:format => :json},
49 headers: {'HTTP_AUTHORIZATION' => "OAuth2 #{token}"}
50 assert_equal json_response['uuid'], system_user_uuid
53 test "refuse to create token for different user if not trusted client" do
54 post "/arvados/v1/api_client_authorizations",
57 :api_client_authorization => {
58 :owner_uuid => users(:spectator).uuid
61 headers: {'HTTP_AUTHORIZATION' => "OAuth2 #{api_client_authorizations(:admin).api_token}"}
65 test "refuse to create token for different user if not admin" do
66 post "/arvados/v1/api_client_authorizations",
69 :api_client_authorization => {
70 :owner_uuid => users(:spectator).uuid
73 headers: {'HTTP_AUTHORIZATION' => "OAuth2 #{api_client_authorizations(:active_trustedclient).api_token}"}