Bump loofah from 2.2.3 to 2.3.1 in /apps/workbench
[arvados.git] / services / api / test / functional / arvados / v1 / container_requests_controller_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 Arvados::V1::ContainerRequestsControllerTest < ActionController::TestCase
8   def minimal_cr
9     {
10       command: ['echo', 'hello'],
11       container_image: 'test',
12       output_path: 'test',
13     }
14   end
15
16   test 'create with scheduling parameters' do
17     authorize_with :active
18
19     sp = {'partitions' => ['test1', 'test2']}
20     post :create, params: {
21            container_request: minimal_cr.merge(scheduling_parameters: sp.dup)
22          }
23     assert_response :success
24
25     cr = JSON.parse(@response.body)
26     assert_not_nil cr, 'Expected container request'
27     assert_equal sp, cr['scheduling_parameters']
28   end
29
30   test "secret_mounts not in #create responses" do
31     authorize_with :active
32
33     post :create, params: {
34            container_request: minimal_cr.merge(
35              secret_mounts: {'/foo' => {'kind' => 'json', 'content' => 'bar'}}),
36          }
37     assert_response :success
38
39     resp = JSON.parse(@response.body)
40     refute resp.has_key?('secret_mounts')
41
42     req = ContainerRequest.where(uuid: resp['uuid']).first
43     assert_equal 'bar', req.secret_mounts['/foo']['content']
44   end
45
46   test "update with secret_mounts" do
47     authorize_with :active
48     req = container_requests(:uncommitted)
49
50     patch :update, params: {
51             id: req.uuid,
52             container_request: {
53               secret_mounts: {'/foo' => {'kind' => 'json', 'content' => 'bar'}},
54             },
55           }
56     assert_response :success
57
58     resp = JSON.parse(@response.body)
59     refute resp.has_key?('secret_mounts')
60
61     req.reload
62     assert_equal 'bar', req.secret_mounts['/foo']['content']
63   end
64
65   test "update without deleting secret_mounts" do
66     authorize_with :active
67     req = container_requests(:uncommitted)
68     req.update_attributes!(secret_mounts: {'/foo' => {'kind' => 'json', 'content' => 'bar'}})
69
70     patch :update, params: {
71             id: req.uuid,
72             container_request: {
73               command: ['echo', 'test'],
74             },
75           }
76     assert_response :success
77
78     resp = JSON.parse(@response.body)
79     refute resp.has_key?('secret_mounts')
80
81     req.reload
82     assert_equal 'bar', req.secret_mounts['/foo']['content']
83   end
84
85   test "runtime_token not in #create responses" do
86     authorize_with :active
87
88     post :create, params: {
89            container_request: minimal_cr.merge(
90              runtime_token: api_client_authorizations(:spectator).token)
91          }
92     assert_response :success
93
94     resp = JSON.parse(@response.body)
95     refute resp.has_key?('runtime_token')
96
97     req = ContainerRequest.where(uuid: resp['uuid']).first
98     assert_equal api_client_authorizations(:spectator).token, req.runtime_token
99   end
100
101 end