1 # Copyright (C) The Arvados Authors. All rights reserved.
3 # SPDX-License-Identifier: AGPL-3.0
7 class Arvados::V1::VirtualMachinesControllerTest < ActionController::TestCase
8 def get_logins_for(vm_sym)
10 get(:logins, params: {id: virtual_machines(vm_sym).uuid})
13 def find_login(sshkey_sym)
14 assert_response :success
15 want_key = authorized_keys(sshkey_sym).public_key
16 logins = json_response["items"].select do |login|
17 login["public_key"] == want_key
19 assert_equal(1, logins.size, "failed to find #{sshkey_sym} login")
23 test "username propagated from permission" do
24 get_logins_for(:testvm2)
25 admin_login = find_login(:admin)
26 perm = links(:admin_can_login_to_testvm2)
27 assert_equal(perm.properties["username"], admin_login["username"])
30 test "groups propagated from permission" do
31 get_logins_for(:testvm2)
32 admin_login = find_login(:admin)
33 perm = links(:admin_can_login_to_testvm2)
34 assert_equal(perm.properties["groups"], admin_login["groups"])
37 test "groups is an empty list by default" do
38 get_logins_for(:testvm2)
39 active_login = find_login(:active)
40 assert_equal([], active_login["groups"])
43 test "logins without usernames not listed" do
44 get_logins_for(:testvm2)
45 assert_response :success
46 spectator_uuid = users(:spectator).uuid
47 assert_empty(json_response.
48 select { |login| login["user_uuid"] == spectator_uuid })
51 test "logins without ssh keys are listed" do
54 u = create :active_user, first_name: 'Bob', last_name: 'Blogin'
55 vm = VirtualMachine.create! hostname: 'foo.shell'
56 Link.create!(tail_uuid: u.uuid,
58 link_class: 'permission',
60 properties: {'username' => 'bobblogin'})
63 get :logins, params: {id: vm.uuid}
64 assert_response :success
65 assert_equal 1, json_response['items'].length
66 assert_nil json_response['items'][0]['public_key']
67 assert_nil json_response['items'][0]['authorized_key_uuid']
68 assert_equal u.uuid, json_response['items'][0]['user_uuid']
69 assert_equal 'bobblogin', json_response['items'][0]['username']
72 test 'get all logins' do