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 click_link 'Attributes'
82 assert page.has_text? 'modified_by_user_uuid'
83 page.within(:xpath, '//span[@data-name="is_active"]') do
84 assert_equal "false", text, "Expected new user's is_active to be false"
89 assert page.has_text? 'can_read' # make sure page is rendered / ready
90 assert page.has_no_text? 'VirtualMachine:'
93 test "setup the active user" do
95 visit page_with_token('admin_trustedclient')
97 find('#system-menu').click
100 # click on active user
101 find('tr', text: 'zzzzz-tpzed-xurymjxw79nv3jz').
102 find('a', text: 'Show').
104 user_url = page.current_url
108 assert page.has_text? 'This button sets up a user'
110 click_link 'Setup account for Active User'
112 within '.modal-content' do
113 find 'label', text: 'Virtual Machine'
114 click_button "Submit"
118 click_link 'Attributes'
119 assert page.has_text? 'modified_by_client_uuid'
121 click_link 'Advanced'
122 click_link 'Metadata'
123 vm_links = all("a", text: "VirtualMachine:")
124 assert_equal(1, vm_links.size)
125 assert_equal("VirtualMachine: testvm2.shell", vm_links.first.text)
127 # Click on Setup button again and this time also choose a VM
129 click_link 'Setup account for Active User'
131 within '.modal-content' do
132 select("testvm.shell", :from => 'vm_uuid')
133 fill_in "groups", :with => "test group one, test-group-two"
134 click_button "Submit"
138 click_link 'Attributes'
139 find '#Attributes', text: 'modified_by_client_uuid'
141 click_link 'Advanced'
142 click_link 'Metadata'
143 assert page.has_text? 'VirtualMachine: testvm.shell'
144 assert page.has_text? '["test group one", "test-group-two"]'
145 vm_links = all("a", text: "VirtualMachine:")
146 assert_equal(2, vm_links.size)
149 test "unsetup active user" do
152 visit page_with_token('admin_trustedclient')
154 find('#system-menu').click
157 # click on active user
158 find('tr', text: 'zzzzz-tpzed-xurymjxw79nv3jz').
159 find('a', text: 'Show').
161 user_url = page.current_url
163 # Verify that is_active is set
164 click_link 'Attributes'
165 assert page.has_text? 'modified_by_user_uuid'
166 page.within(:xpath, '//span[@data-name="is_active"]') do
167 assert_equal "true", text, "Expected user's is_active to be true"
172 assert page.has_text? 'As an admin, you can deactivate and reset this user'
174 # unsetup user and verify all the above links are deleted
176 click_button 'Deactivate Active User'
178 if Capybara.current_driver == :selenium
180 page.driver.browser.switch_to.alert.accept
182 # poltergeist returns true for confirm(), so we don't need to accept.
185 click_link 'Attributes'
187 # Should now be back in the Attributes tab for the user
188 assert page.has_text? 'modified_by_user_uuid'
189 page.within(:xpath, '//span[@data-name="is_active"]') do
190 assert_equal "false", text, "Expected user's is_active to be false after unsetup"
193 click_link 'Advanced'
194 click_link 'Metadata'
195 assert page.has_no_text? 'VirtualMachine: testvm.shell'
197 # setup user again and verify links present
199 click_link 'Setup account for Active User'
201 within '.modal-content' do
202 select("testvm.shell", :from => 'vm_uuid')
203 click_button "Submit"
207 click_link 'Attributes'
208 assert page.has_text? 'modified_by_client_uuid'
210 click_link 'Advanced'
211 click_link 'Metadata'
212 assert page.has_text? 'VirtualMachine: testvm.shell'
215 test "test add group button" do
218 user_url = "/users/#{api_fixture('users')['active']['uuid']}"
219 visit page_with_token('admin_trustedclient', user_url)
223 assert page.has_text? 'This button sets up a user'
225 click_link 'Add new group'
227 within '.modal-content' do
228 fill_in "group_name_input", :with => "test-group-added-in-modal"
229 click_button "Create"
233 # Back in the user "Admin" tab
234 assert page.has_text? 'test-group-added-in-modal'