1 # Copyright (C) The Arvados Authors. All rights reserved.
3 # SPDX-License-Identifier: AGPL-3.0
5 require 'integration_helper'
7 class UsersTest < ActionDispatch::IntegrationTest
9 test "login as active user but not admin" do
11 visit page_with_token('active_trustedclient')
13 assert page.has_no_link? 'Users' 'Found Users link for non-admin user'
16 test "login as admin user and verify active user data" do
18 visit page_with_token('admin_trustedclient')
20 # go to Users list page
21 find('#system-menu').click
24 # check active user attributes in the list page
25 page.within(:xpath, '//tr[@data-object-uuid="zzzzz-tpzed-xurymjxw79nv3jz"]') do
26 assert (text.include? 'true false'), 'Expected is_active'
29 find('tr', text: 'zzzzz-tpzed-xurymjxw79nv3jz').
30 find('a', text: 'Show').
32 assert page.has_text? 'Attributes'
33 assert page.has_text? 'Advanced'
34 assert page.has_text? 'Admin'
36 # go to the Attributes tab
37 click_link 'Attributes'
38 assert page.has_text? 'modified_by_user_uuid'
39 page.within(:xpath, '//span[@data-name="is_active"]') do
40 assert_equal "true", text, "Expected user's is_active to be true"
42 page.within(:xpath, '//span[@data-name="is_admin"]') do
43 assert_equal "false", text, "Expected user's is_admin to be false"
48 test "create a new user" do
51 visit page_with_token('admin_trustedclient')
53 find('#system-menu').click
56 assert page.has_text? 'zzzzz-tpzed-d9tiejq69daie8f'
58 click_link 'Add a new user'
60 within '.modal-content' do
61 find 'label', text: 'Virtual Machine'
62 fill_in "email", :with => "foo@example.com"
69 # verify that the new user showed up in the users page and find
72 find('tr[data-object-uuid]', text: 'foo@example.com')['data-object-uuid']
73 assert new_user_uuid, "Expected new user uuid not found"
75 # go to the new user's page
76 find('tr', text: new_user_uuid).
77 find('a', text: 'Show').
80 assert page.has_text? 'modified_by_user_uuid'
81 page.within(:xpath, '//span[@data-name="is_active"]') do
82 assert_equal "false", text, "Expected new user's is_active to be false"
87 assert page.has_text? 'can_login' # make sure page is rendered / ready
88 assert page.has_no_text? 'VirtualMachine:'
91 test "setup the active user" do
93 visit page_with_token('admin_trustedclient')
95 find('#system-menu').click
98 # click on active user
99 find('tr', text: 'zzzzz-tpzed-xurymjxw79nv3jz').
100 find('a', text: 'Show').
102 user_url = page.current_url
106 assert page.has_text? 'As an admin, you can setup'
108 click_link 'Setup shell account for Active User'
110 within '.modal-content' do
111 find 'label', text: 'Virtual Machine'
112 click_button "Submit"
116 assert page.has_text? 'modified_by_client_uuid'
118 click_link 'Advanced'
119 click_link 'Metadata'
120 vm_links = all("a", text: "VirtualMachine:")
121 assert_equal(1, vm_links.size)
122 assert_equal("VirtualMachine: testvm2.shell", vm_links.first.text)
124 # Click on Setup button again and this time also choose a VM
126 click_link 'Setup shell account for Active User'
128 within '.modal-content' do
129 select("testvm.shell", :from => 'vm_uuid')
130 fill_in "groups", :with => "test group one, test-group-two"
131 click_button "Submit"
135 find '#Attributes', text: 'modified_by_client_uuid'
137 click_link 'Advanced'
138 click_link 'Metadata'
139 assert page.has_text? 'VirtualMachine: testvm.shell'
140 assert page.has_text? '["test group one", "test-group-two"]'
143 test "unsetup active user" do
146 visit page_with_token('admin_trustedclient')
148 find('#system-menu').click
151 # click on active user
152 find('tr', text: 'zzzzz-tpzed-xurymjxw79nv3jz').
153 find('a', text: 'Show').
155 user_url = page.current_url
157 # Verify that is_active is set
158 find('a,button', text: 'Attributes').click
159 assert page.has_text? 'modified_by_user_uuid'
160 page.within(:xpath, '//span[@data-name="is_active"]') do
161 assert_equal "true", text, "Expected user's is_active to be true"
166 assert page.has_text? 'As an admin, you can deactivate and reset this user'
168 # unsetup user and verify all the above links are deleted
170 click_button 'Deactivate Active User'
172 if Capybara.current_driver == :selenium
174 page.driver.browser.switch_to.alert.accept
176 # poltergeist returns true for confirm(), so we don't need to accept.
179 # Should now be back in the Attributes tab for the user
180 assert page.has_text? 'modified_by_user_uuid'
181 page.within(:xpath, '//span[@data-name="is_active"]') do
182 assert_equal "false", text, "Expected user's is_active to be false after unsetup"
185 click_link 'Advanced'
186 click_link 'Metadata'
187 assert page.has_no_text? 'VirtualMachine: testvm.shell'
189 # setup user again and verify links present
191 click_link 'Setup shell account for Active User'
193 within '.modal-content' do
194 select("testvm.shell", :from => 'vm_uuid')
195 click_button "Submit"
199 assert page.has_text? 'modified_by_client_uuid'
201 click_link 'Advanced'
202 click_link 'Metadata'
203 assert page.has_text? 'VirtualMachine: testvm.shell'
206 test "test add group button" do
209 user_url = "/users/#{api_fixture('users')['active']['uuid']}"
210 visit page_with_token('admin_trustedclient', user_url)
214 assert page.has_text? 'As an admin, you can setup'
216 click_link 'Add new group'
218 within '.modal-content' do
219 fill_in "group_name_input", :with => "test-group-added-in-modal"
220 click_button "Create"
224 # Back in the user "Admin" tab
225 assert page.has_text? 'test-group-added-in-modal'