1 # Copyright (C) The Arvados Authors. All rights reserved.
3 # SPDX-License-Identifier: AGPL-3.0
7 class ContainerAuthTest < ActionDispatch::IntegrationTest
10 test "container token validate, Running, regular auth" do
11 get "/arvados/v1/containers/current",
12 params: {:format => :json},
13 headers: {'HTTP_AUTHORIZATION' => "Bearer #{api_client_authorizations(:running_container_auth).token}/#{containers(:running).uuid}"}
14 # Container is Running, token can be used
15 assert_response :success
16 assert_equal containers(:running).uuid, json_response['uuid']
19 test "container token validate, Locked, runtime_token" do
20 get "/arvados/v1/containers/current",
21 params: {:format => :json},
22 headers: {'HTTP_AUTHORIZATION' => "Bearer #{api_client_authorizations(:container_runtime_token).token}/#{containers(:runtime_token).uuid}"}
23 # Container is Running, token can be used
24 assert_response :success
25 assert_equal containers(:runtime_token).uuid, json_response['uuid']
28 test "container token validate, Cancelled, runtime_token" do
29 put "/arvados/v1/containers/#{containers(:runtime_token).uuid}",
32 :container => {:state => "Cancelled"}
34 headers: {'HTTP_AUTHORIZATION' => "Bearer #{api_client_authorizations(:dispatch1).token}"}
35 assert_response :success
36 get "/arvados/v1/containers/current",
37 params: {:format => :json},
38 headers: {'HTTP_AUTHORIZATION' => "Bearer #{api_client_authorizations(:container_runtime_token).token}/#{containers(:runtime_token).uuid}"}
39 # Container is Queued, token cannot be used
43 test "container token validate, Running, without optional portion" do
44 get "/arvados/v1/containers/current",
45 params: {:format => :json},
46 headers: {'HTTP_AUTHORIZATION' => "Bearer #{api_client_authorizations(:running_container_auth).token}"}
47 # Container is Running, token can be used
48 assert_response :success
49 assert_equal containers(:running).uuid, json_response['uuid']
52 test "container token validate, Locked, runtime_token, without optional portion" do
53 get "/arvados/v1/containers/current",
54 params: {:format => :json},
55 headers: {'HTTP_AUTHORIZATION' => "Bearer #{api_client_authorizations(:container_runtime_token).token}"}
56 # runtime_token without container uuid won't return 'current'
60 test "container token validate, wrong container uuid" do
61 get "/arvados/v1/containers/current",
62 params: {:format => :json},
63 headers: {'HTTP_AUTHORIZATION' => "Bearer #{api_client_authorizations(:container_runtime_token).token}/#{containers(:running).uuid}"}
64 # Container uuid mismatch, token can't be used