16306: Move nginx temp dirs into a subdir.
[arvados.git] / services / api / test / integration / api_client_authorizations_api_test.rb
1 # Copyright (C) The Arvados Authors. All rights reserved.
2 #
3 # SPDX-License-Identifier: AGPL-3.0
4
5 require 'test_helper'
6
7 class ApiClientAuthorizationsApiTest < ActionDispatch::IntegrationTest
8   fixtures :all
9
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
15   end
16
17   test "create token for different user" do
18     post "/arvados/v1/api_client_authorizations",
19       params: {
20         :format => :json,
21         :api_client_authorization => {
22           :owner_uuid => users(:spectator).uuid
23         }
24       },
25       headers: {'HTTP_AUTHORIZATION' => "OAuth2 #{api_client_authorizations(:admin_trustedclient).api_token}"}
26     assert_response :success
27
28     get "/arvados/v1/users/current",
29       params: {:format => :json},
30       headers: {'HTTP_AUTHORIZATION' => "OAuth2 #{json_response['api_token']}"}
31     @json_response = nil
32     assert_equal users(:spectator).uuid, json_response['uuid']
33   end
34
35   test "refuse to create token for different user if not trusted client" do
36     post "/arvados/v1/api_client_authorizations",
37       params: {
38         :format => :json,
39         :api_client_authorization => {
40           :owner_uuid => users(:spectator).uuid
41         }
42       },
43       headers: {'HTTP_AUTHORIZATION' => "OAuth2 #{api_client_authorizations(:admin).api_token}"}
44     assert_response 403
45   end
46
47   test "refuse to create token for different user if not admin" do
48     post "/arvados/v1/api_client_authorizations",
49       params: {
50         :format => :json,
51         :api_client_authorization => {
52           :owner_uuid => users(:spectator).uuid
53         }
54       },
55       headers: {'HTTP_AUTHORIZATION' => "OAuth2 #{api_client_authorizations(:active_trustedclient).api_token}"}
56     assert_response 403
57   end
58
59 end