1 require 'integration_helper'
3 class UsersTest < ActionDispatch::IntegrationTest
5 test "login as active user but not admin" do
7 visit page_with_token('active_trustedclient')
9 assert page.has_no_link? 'Users' 'Found Users link for non-admin user'
12 test "login as admin user and verify active user data" do
14 visit page_with_token('admin_trustedclient')
16 # go to Users list page
17 find('#system-menu').click
20 # check active user attributes in the list page
21 page.within(:xpath, '//tr[@data-object-uuid="zzzzz-tpzed-xurymjxw79nv3jz"]') do
22 assert (text.include? 'true false'), 'Expected is_active'
25 find('tr', text: 'zzzzz-tpzed-xurymjxw79nv3jz').
26 find('a', text: 'Show').
28 assert page.has_text? 'Attributes'
29 assert page.has_text? 'Advanced'
30 assert page.has_text? 'Admin'
32 # go to the Attributes tab
33 click_link 'Attributes'
34 assert page.has_text? 'modified_by_user_uuid'
35 page.within(:xpath, '//span[@data-name="is_active"]') do
36 assert_equal "true", text, "Expected user's is_active to be true"
38 page.within(:xpath, '//span[@data-name="is_admin"]') do
39 assert_equal "false", text, "Expected user's is_admin to be false"
44 test "create a new user" do
47 visit page_with_token('admin_trustedclient')
49 find('#system-menu').click
52 assert page.has_text? 'zzzzz-tpzed-d9tiejq69daie8f'
54 click_link 'Add a new user'
56 within '.modal-content' do
57 find 'label', text: 'Virtual Machine'
58 fill_in "email", :with => "foo@example.com"
65 # verify that the new user showed up in the users page and find
68 find('tr[data-object-uuid]', text: 'foo@example.com')['data-object-uuid']
69 assert new_user_uuid, "Expected new user uuid not found"
71 # go to the new user's page
72 find('tr', text: new_user_uuid).
73 find('a', text: 'Show').
76 assert page.has_text? 'modified_by_user_uuid'
77 page.within(:xpath, '//span[@data-name="is_active"]') do
78 assert_equal "false", text, "Expected new user's is_active to be false"
83 assert !(page.has_text? 'VirtualMachine:')
86 test "setup the active user" do
88 visit page_with_token('admin_trustedclient')
90 find('#system-menu').click
93 # click on active user
94 find('tr', text: 'zzzzz-tpzed-xurymjxw79nv3jz').
95 find('a', text: 'Show').
97 user_url = page.current_url
101 assert page.has_text? 'As an admin, you can setup'
103 click_link 'Setup shell account for Active User'
105 within '.modal-content' do
106 find 'label', text: 'Virtual Machine'
107 click_button "Submit"
111 assert page.has_text? 'modified_by_client_uuid'
113 click_link 'Advanced'
114 click_link 'Metadata'
115 vm_links = all("a", text: "VirtualMachine:")
116 assert_equal(1, vm_links.size)
117 assert_equal("VirtualMachine: testvm2.shell", vm_links.first.text)
119 # Click on Setup button again and this time also choose a VM
121 click_link 'Setup shell account for Active User'
123 within '.modal-content' do
124 select("testvm.shell", :from => 'vm_uuid')
125 fill_in "groups", :with => "test group one, test-group-two"
126 click_button "Submit"
130 find '#Attributes', text: 'modified_by_client_uuid'
132 click_link 'Advanced'
133 click_link 'Metadata'
134 assert page.has_text? 'VirtualMachine: testvm.shell'
135 assert page.has_text? '["test group one", "test-group-two"]'
138 test "unsetup active user" do
141 visit page_with_token('admin_trustedclient')
143 find('#system-menu').click
146 # click on active user
147 find('tr', text: 'zzzzz-tpzed-xurymjxw79nv3jz').
148 find('a', text: 'Show').
150 user_url = page.current_url
152 # Verify that is_active is set
153 find('a,button', text: 'Attributes').click
154 assert page.has_text? 'modified_by_user_uuid'
155 page.within(:xpath, '//span[@data-name="is_active"]') do
156 assert_equal "true", text, "Expected user's is_active to be true"
161 assert page.has_text? 'As an admin, you can deactivate and reset this user'
163 # unsetup user and verify all the above links are deleted
165 click_button 'Deactivate Active User'
167 if Capybara.current_driver == :selenium
169 page.driver.browser.switch_to.alert.accept
171 # poltergeist returns true for confirm(), so we don't need to accept.
174 # Should now be back in the Attributes tab for the user
175 assert page.has_text? 'modified_by_user_uuid'
176 page.within(:xpath, '//span[@data-name="is_active"]') do
177 assert_equal "false", text, "Expected user's is_active to be false after unsetup"
180 click_link 'Advanced'
181 click_link 'Metadata'
182 assert page.has_no_text? 'VirtualMachine: testvm.shell'
184 # setup user again and verify links present
186 click_link 'Setup shell account for Active User'
188 within '.modal-content' do
189 select("testvm.shell", :from => 'vm_uuid')
190 click_button "Submit"
194 assert page.has_text? 'modified_by_client_uuid'
196 click_link 'Advanced'
197 click_link 'Metadata'
198 assert page.has_text? 'VirtualMachine: testvm.shell'
201 test "test add group button" do
204 user_url = "/users/#{api_fixture('users')['active']['uuid']}"
205 visit page_with_token('admin_trustedclient', user_url)
209 assert page.has_text? 'As an admin, you can setup'
211 click_link 'Add new group'
213 within '.modal-content' do
214 fill_in "group_name_input", :with => "test-group-added-in-modal"
215 click_button "Create"
219 # Back in the user "Admin" tab
220 assert page.has_text? 'test-group-added-in-modal'