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", {:format => :json, :scopes => ['test'].to_json}, {'HTTP_AUTHORIZATION' => "OAuth2 #{api_client_authorizations(:admin_trustedclient).api_token}"}
12 assert_response :success
15 test "create token for different user" do
16 post "/arvados/v1/api_client_authorizations", {
18 :api_client_authorization => {
19 :owner_uuid => users(:spectator).uuid
21 }, {'HTTP_AUTHORIZATION' => "OAuth2 #{api_client_authorizations(:admin_trustedclient).api_token}"}
22 assert_response :success
24 get "/arvados/v1/users/current", {
26 }, {'HTTP_AUTHORIZATION' => "OAuth2 #{json_response['api_token']}"}
28 assert_equal users(:spectator).uuid, json_response['uuid']
31 test "refuse to create token for different user if not trusted client" do
32 post "/arvados/v1/api_client_authorizations", {
34 :api_client_authorization => {
35 :owner_uuid => users(:spectator).uuid
37 }, {'HTTP_AUTHORIZATION' => "OAuth2 #{api_client_authorizations(:admin).api_token}"}
41 test "refuse to create token for different user if not admin" do
42 post "/arvados/v1/api_client_authorizations", {
44 :api_client_authorization => {
45 :owner_uuid => users(:spectator).uuid
47 }, {'HTTP_AUTHORIZATION' => "OAuth2 #{api_client_authorizations(:active_trustedclient).api_token}"}