Merge branch 'master' into wtsi-hgi-8087-arv-cli-request-body-from-file
[arvados.git] / services / api / test / functional / arvados / v1 / containers_controller_test.rb
1 require 'test_helper'
2
3 class Arvados::V1::ContainersControllerTest < ActionController::TestCase
4   test 'create' do
5     authorize_with :system_user
6     post :create, {
7       container: {
8         command: ['echo', 'hello'],
9         container_image: 'test',
10         output_path: 'test',
11       },
12     }
13     assert_response :success
14   end
15
16   [Container::Queued, Container::Complete].each do |state|
17     test "cannot get auth in #{state} state" do
18       authorize_with :dispatch1
19       get :auth, id: containers(:queued).uuid
20       assert_response 403
21     end
22   end
23
24   test 'cannot get auth with wrong token' do
25     authorize_with :dispatch1
26     c = containers(:queued)
27     assert c.update_attributes(state: Container::Locked), show_errors(c)
28
29     authorize_with :system_user
30     get :auth, id: c.uuid
31     assert_response 403
32   end
33
34   test 'get auth' do
35     authorize_with :dispatch1
36     c = containers(:queued)
37     assert c.update_attributes(state: Container::Locked), show_errors(c)
38     get :auth, id: c.uuid
39     assert_response :success
40     assert_operator 32, :<, json_response['api_token'].length
41     assert_equal 'arvados#apiClientAuthorization', json_response['kind']
42   end
43
44   test 'no auth in container response' do
45     authorize_with :dispatch1
46     c = containers(:queued)
47     assert c.update_attributes(state: Container::Locked), show_errors(c)
48     get :show, id: c.uuid
49     assert_response :success
50     assert_nil json_response['auth']
51   end
52 end