Merge branch 'master' into 2257-inequality-conditions
[arvados.git] / services / api / test / integration / api_client_authorizations_api_test.rb
1 require 'test_helper'
2
3 class ApiClientAuthorizationsApiTest < ActionDispatch::IntegrationTest
4   fixtures :all
5
6   test "create system auth" do
7     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}"}
8     assert_response :success
9   end
10
11   test "create token for different user" do
12     post "/arvados/v1/api_client_authorizations", {
13       :format => :json,
14       :api_client_authorization => {
15         :owner_uuid => users(:spectator).uuid
16       }
17     }, {'HTTP_AUTHORIZATION' => "OAuth2 #{api_client_authorizations(:admin_trustedclient).api_token}"}
18     assert_response :success
19
20     get "/arvados/v1/users/current", {
21       :format => :json
22     }, {'HTTP_AUTHORIZATION' => "OAuth2 #{jresponse['api_token']}"}
23     @jresponse = nil
24     assert_equal users(:spectator).uuid, jresponse['uuid']
25   end
26
27   test "refuse to create token for different user if not trusted client" do
28     post "/arvados/v1/api_client_authorizations", {
29       :format => :json,
30       :api_client_authorization => {
31         :owner_uuid => users(:spectator).uuid
32       }
33     }, {'HTTP_AUTHORIZATION' => "OAuth2 #{api_client_authorizations(:admin).api_token}"}
34     assert_response 403
35   end
36
37   test "refuse to create token for different user if not admin" do
38     post "/arvados/v1/api_client_authorizations", {
39       :format => :json,
40       :api_client_authorization => {
41         :owner_uuid => users(:spectator).uuid
42       }
43     }, {'HTTP_AUTHORIZATION' => "OAuth2 #{api_client_authorizations(:active_trustedclient).api_token}"}
44     assert_response 403
45   end
46
47 end