8784: Fix test for latest firefox.
[arvados.git] / services / api / test / functional / arvados / v1 / virtual_machines_controller_test.rb
1 require 'test_helper'
2
3 class Arvados::V1::VirtualMachinesControllerTest < ActionController::TestCase
4   def get_logins_for(vm_sym)
5     authorize_with :admin
6     get(:logins, id: virtual_machines(vm_sym).uuid)
7   end
8
9   def find_login(sshkey_sym)
10     assert_response :success
11     want_key = authorized_keys(sshkey_sym).public_key
12     logins = json_response["items"].select do |login|
13       login["public_key"] == want_key
14     end
15     assert_equal(1, logins.size, "failed to find #{sshkey_sym} login")
16     logins.first
17   end
18
19   test "username propagated from permission" do
20     get_logins_for(:testvm2)
21     admin_login = find_login(:admin)
22     perm = links(:admin_can_login_to_testvm2)
23     assert_equal(perm.properties["username"], admin_login["username"])
24   end
25
26   test "groups propagated from permission" do
27     get_logins_for(:testvm2)
28     admin_login = find_login(:admin)
29     perm = links(:admin_can_login_to_testvm2)
30     assert_equal(perm.properties["groups"], admin_login["groups"])
31   end
32
33   test "groups is an empty list by default" do
34     get_logins_for(:testvm2)
35     active_login = find_login(:active)
36     assert_equal([], active_login["groups"])
37   end
38
39   test "logins without usernames not listed" do
40     get_logins_for(:testvm2)
41     assert_response :success
42     spectator_uuid = users(:spectator).uuid
43     assert_empty(json_response.
44                  select { |login| login["user_uuid"] == spectator_uuid })
45   end
46
47   test "logins without ssh keys are listed" do
48     u, vm = nil
49     act_as_system_user do
50       u = create :active_user, first_name: 'Bob', last_name: 'Blogin'
51       vm = VirtualMachine.create! hostname: 'foo.shell'
52       Link.create!(tail_uuid: u.uuid,
53                    head_uuid: vm.uuid,
54                    link_class: 'permission',
55                    name: 'can_login',
56                    properties: {'username' => 'bobblogin'})
57     end
58     authorize_with :admin
59     get :logins, id: vm.uuid
60     assert_response :success
61     assert_equal 1, json_response['items'].length
62     assert_nil json_response['items'][0]['public_key']
63     assert_nil json_response['items'][0]['authorized_key_uuid']
64     assert_equal u.uuid, json_response['items'][0]['user_uuid']
65     assert_equal 'bobblogin', json_response['items'][0]['username']
66   end
67
68   test 'get all logins' do
69     authorize_with :admin
70     get :get_all_logins
71     find_login :admin
72     find_login :active
73   end
74 end