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? 'can_login' # make sure page is rendered / ready
84 assert page.has_no_text? 'VirtualMachine:'
87 test "setup the active user" do
89 visit page_with_token('admin_trustedclient')
91 find('#system-menu').click
94 # click on active user
95 find('tr', text: 'zzzzz-tpzed-xurymjxw79nv3jz').
96 find('a', text: 'Show').
98 user_url = page.current_url
102 assert page.has_text? 'As an admin, you can setup'
104 click_link 'Setup shell account for Active User'
106 within '.modal-content' do
107 find 'label', text: 'Virtual Machine'
108 click_button "Submit"
112 assert page.has_text? 'modified_by_client_uuid'
114 click_link 'Advanced'
115 click_link 'Metadata'
116 vm_links = all("a", text: "VirtualMachine:")
117 assert_equal(1, vm_links.size)
118 assert_equal("VirtualMachine: testvm2.shell", vm_links.first.text)
120 # Click on Setup button again and this time also choose a VM
122 click_link 'Setup shell account for Active User'
124 within '.modal-content' do
125 select("testvm.shell", :from => 'vm_uuid')
126 fill_in "groups", :with => "test group one, test-group-two"
127 click_button "Submit"
131 find '#Attributes', text: 'modified_by_client_uuid'
133 click_link 'Advanced'
134 click_link 'Metadata'
135 assert page.has_text? 'VirtualMachine: testvm.shell'
136 assert page.has_text? '["test group one", "test-group-two"]'
139 test "unsetup active user" do
142 visit page_with_token('admin_trustedclient')
144 find('#system-menu').click
147 # click on active user
148 find('tr', text: 'zzzzz-tpzed-xurymjxw79nv3jz').
149 find('a', text: 'Show').
151 user_url = page.current_url
153 # Verify that is_active is set
154 find('a,button', text: 'Attributes').click
155 assert page.has_text? 'modified_by_user_uuid'
156 page.within(:xpath, '//span[@data-name="is_active"]') do
157 assert_equal "true", text, "Expected user's is_active to be true"
162 assert page.has_text? 'As an admin, you can deactivate and reset this user'
164 # unsetup user and verify all the above links are deleted
166 click_button 'Deactivate Active User'
168 if Capybara.current_driver == :selenium
170 page.driver.browser.switch_to.alert.accept
172 # poltergeist returns true for confirm(), so we don't need to accept.
175 # Should now be back in the Attributes tab for the user
176 assert page.has_text? 'modified_by_user_uuid'
177 page.within(:xpath, '//span[@data-name="is_active"]') do
178 assert_equal "false", text, "Expected user's is_active to be false after unsetup"
181 click_link 'Advanced'
182 click_link 'Metadata'
183 assert page.has_no_text? 'VirtualMachine: testvm.shell'
185 # setup user again and verify links present
187 click_link 'Setup shell account for Active User'
189 within '.modal-content' do
190 select("testvm.shell", :from => 'vm_uuid')
191 click_button "Submit"
195 assert page.has_text? 'modified_by_client_uuid'
197 click_link 'Advanced'
198 click_link 'Metadata'
199 assert page.has_text? 'VirtualMachine: testvm.shell'
202 test "test add group button" do
205 user_url = "/users/#{api_fixture('users')['active']['uuid']}"
206 visit page_with_token('admin_trustedclient', user_url)
210 assert page.has_text? 'As an admin, you can setup'
212 click_link 'Add new group'
214 within '.modal-content' do
215 fill_in "group_name_input", :with => "test-group-added-in-modal"
216 click_button "Create"
220 # Back in the user "Admin" tab
221 assert page.has_text? 'test-group-added-in-modal'