3 class Arvados::V1::VirtualMachinesControllerTest < ActionController::TestCase
4 def get_logins_for(vm_sym)
6 get(:logins, id: virtual_machines(vm_sym).uuid)
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
15 assert_equal(1, logins.size, "failed to find #{sshkey_sym} login")
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"])
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"])
33 test "groups is an empty list by default" do
34 get_logins_for(:testvm2)
35 active_login = find_login(:active)
36 perm = links(:active_can_login_to_testvm2)
37 assert_equal([], active_login["groups"])
40 test "logins without usernames not listed" do
41 get_logins_for(:testvm2)
42 assert_response :success
43 spectator_uuid = users(:spectator).uuid
44 assert_empty(json_response.
45 select { |login| login["user_uuid"] == spectator_uuid })
48 test "logins without ssh keys are listed" do
51 u = create :active_user, first_name: 'Bob', last_name: 'Blogin'
52 vm = VirtualMachine.create! hostname: 'foo.shell'
53 Link.create!(tail_uuid: u.uuid,
55 link_class: 'permission',
57 properties: {'username' => 'bobblogin'})
60 get :logins, id: vm.uuid
61 assert_response :success
62 assert_equal 1, json_response['items'].length
63 assert_equal nil, json_response['items'][0]['public_key']
64 assert_equal nil, json_response['items'][0]['authorized_key_uuid']
65 assert_equal u.uuid, json_response['items'][0]['user_uuid']
66 assert_equal 'bobblogin', json_response['items'][0]['username']