1 # Copyright (C) The Arvados Authors. All rights reserved.
3 # SPDX-License-Identifier: AGPL-3.0
7 class Arvados::V1::ContainersControllerTest < ActionController::TestCase
9 authorize_with :system_user
12 command: ['echo', 'hello'],
13 container_image: 'test',
17 assert_response :success
20 [Container::Queued, Container::Complete].each do |state|
21 test "cannot get auth in #{state} state" do
22 authorize_with :dispatch1
23 get :auth, id: containers(:queued).uuid
28 test 'cannot get auth with wrong token' do
29 authorize_with :dispatch1
30 c = containers(:queued)
31 assert c.lock, show_errors(c)
33 authorize_with :system_user
39 authorize_with :dispatch1
40 c = containers(:queued)
41 assert c.lock, show_errors(c)
43 assert_response :success
44 assert_operator 32, :<, json_response['api_token'].length
45 assert_equal 'arvados#apiClientAuthorization', json_response['kind']
48 test 'no auth in container response' do
49 authorize_with :dispatch1
50 c = containers(:queued)
51 assert c.lock, show_errors(c)
53 assert_response :success
54 assert_nil json_response['auth']
57 test "lock container" do
58 authorize_with :dispatch1
59 uuid = containers(:queued).uuid
60 post :lock, {id: uuid}
61 assert_response :success
62 assert_nil json_response['mounts']
63 assert_nil json_response['command']
64 assert_not_nil json_response['auth_uuid']
65 assert_not_nil json_response['locked_by_uuid']
66 assert_equal containers(:queued).uuid, json_response['uuid']
67 assert_equal 'Locked', json_response['state']
68 assert_equal containers(:queued).priority, json_response['priority']
70 container = Container.where(uuid: uuid).first
71 assert_equal 'Locked', container.state
72 assert_not_nil container.locked_by_uuid
73 assert_not_nil container.auth_uuid
76 test "unlock container" do
77 authorize_with :dispatch1
78 uuid = containers(:locked).uuid
79 post :unlock, {id: uuid}
80 assert_response :success
81 assert_nil json_response['mounts']
82 assert_nil json_response['command']
83 assert_nil json_response['auth_uuid']
84 assert_nil json_response['locked_by_uuid']
85 assert_equal containers(:locked).uuid, json_response['uuid']
86 assert_equal 'Queued', json_response['state']
87 assert_equal containers(:locked).priority, json_response['priority']
89 container = Container.where(uuid: uuid).first
90 assert_equal 'Queued', container.state
91 assert_nil container.locked_by_uuid
92 assert_nil container.auth_uuid
95 test "unlock container locked by different dispatcher" do
96 authorize_with :dispatch2
97 uuid = containers(:locked).uuid
98 post :unlock, {id: uuid}
103 [:queued, :lock, :success, 'Locked'],
104 [:queued, :unlock, 422, 'Queued'],
105 [:locked, :lock, 422, 'Locked'],
106 [:running, :lock, 422, 'Running'],
107 [:running, :unlock, 422, 'Running'],
108 ].each do |fixture, action, response, state|
109 test "state transitions from #{fixture } to #{action}" do
110 authorize_with :dispatch1
111 uuid = containers(fixture).uuid
112 post action, {id: uuid}
113 assert_response response
114 assert_equal state, Container.where(uuid: uuid).first.state
118 test 'get current container for token' do
119 authorize_with :running_container_auth
121 assert_response :success
122 assert_equal containers(:running).uuid, json_response['uuid']
125 test 'no container associated with token' do
126 authorize_with :dispatch1
131 test 'try get current container, no token' do