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 assert_equal([], active_login["groups"])
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 })
47 test "logins without ssh keys are listed" 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,
54 link_class: 'permission',
56 properties: {'username' => 'bobblogin'})
59 get :logins, id: vm.uuid
60 assert_response :success
61 assert_equal 1, json_response['items'].length
62 assert_equal nil, json_response['items'][0]['public_key']
63 assert_equal 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']
68 test 'get all logins' do