1 require 'integration_helper'
2 require 'selenium-webdriver'
5 class UsersTest < ActionDispatch::IntegrationTest
7 test "login as active user but not admin" do
8 Capybara.current_driver = Capybara.javascript_driver
9 visit page_with_token('active_trustedclient')
11 assert page.has_no_link? 'Users' 'Found Users link for non-admin user'
14 test "login as admin user and verify active user data" do
15 Capybara.current_driver = Capybara.javascript_driver
16 visit page_with_token('admin_trustedclient')
18 # go to Users list page
21 # check active user attributes in the list page
22 page.within(:xpath, '//tr[@data-object-uuid="zzzzz-tpzed-xurymjxw79nv3jz"]') do
23 assert (text.include? 'true false'), 'Expected is_active'
26 find('tr', text: 'zzzzz-tpzed-xurymjxw79nv3jz').
27 find('a,button', text: 'Show').
29 assert page.has_text? 'Attributes'
30 assert page.has_text? 'Metadata'
31 assert page.has_text? 'Admin'
33 # go to the Attributes tab
34 click_link 'Attributes'
35 assert page.has_text? 'modified_by_user_uuid'
36 page.within(:xpath, '//span[@data-name="is_active"]') do
37 assert_equal "true", text, "Expected user's is_active to be true"
39 page.within(:xpath, '//span[@data-name="is_admin"]') do
40 assert_equal "false", text, "Expected user's is_admin to be false"
45 test "create a new user" do
46 headless = Headless.new
49 Capybara.current_driver = :selenium
51 visit page_with_token('admin_trustedclient')
55 assert page.has_text? 'zzzzz-tpzed-d9tiejq69daie8f'
57 click_link 'Add a new user'
60 popup = page.driver.browser.window_handles.last
61 page.within_window popup do
62 assert has_text? 'Virtual Machine'
63 fill_in "email", :with => "foo@example.com"
64 fill_in "repo_name", :with => "test_repo"
70 # verify that the new user showed up in the users page and find
73 find('tr[data-object-uuid]', text: 'foo@example.com').
74 find('td', text: '-tpzed-').
76 assert new_user_uuid, "Expected new user uuid not found"
78 # go to the new user's page
79 find('tr', text: new_user_uuid).
80 find('a,button', text: 'Show').
83 assert page.has_text? 'modified_by_user_uuid'
84 page.within(:xpath, '//span[@data-name="is_active"]') do
85 assert_equal "false", text, "Expected new user's is_active to be false"
89 assert page.has_text? '(Repository: test_repo)'
90 assert !(page.has_text? '(VirtualMachine:)')
95 test "setup the active user" do
96 headless = Headless.new
99 Capybara.current_driver = :selenium
100 visit page_with_token('admin_trustedclient')
104 # click on active user
105 find('tr', text: 'zzzzz-tpzed-xurymjxw79nv3jz').
106 find('a,button', text: 'Show').
111 assert page.has_text? 'As an admin, you can setup'
113 click_link 'Setup Active User'
117 popup = page.driver.browser.window_handles.last
118 page.within_window popup do
119 assert has_text? 'Virtual Machine'
120 fill_in "repo_name", :with => "test_repo"
121 click_button "Submit"
125 assert page.has_text? 'modified_by_client_uuid'
127 click_link 'Metadata'
128 assert page.has_text? '(Repository: test_repo)'
129 assert !(page.has_text? '(VirtualMachine:)')
131 # Click on Setup button again and this time also choose a VM
133 click_link 'Setup Active User'
136 popup = page.driver.browser.window_handles.last
137 page.within_window popup do
138 fill_in "repo_name", :with => "second_test_repo"
139 select("testvm.shell", :from => 'vm_uuid')
140 click_button "Submit"
144 assert page.has_text? 'modified_by_client_uuid'
146 click_link 'Metadata'
147 assert page.has_text? '(Repository: second_test_repo)'
148 assert page.has_text? '(VirtualMachine: testvm.shell)'
153 test "unsetup active user" do
154 headless = Headless.new
157 Capybara.current_driver = :selenium
159 visit page_with_token('admin_trustedclient')
163 # click on active user
164 find('tr', text: 'zzzzz-tpzed-xurymjxw79nv3jz').
165 find('a,button', text: 'Show').
168 # Verify that is_active is set
169 click_link 'Attributes'
170 assert page.has_text? 'modified_by_user_uuid'
171 page.within(:xpath, '//span[@data-name="is_active"]') do
172 assert_equal "true", text, "Expected user's is_active to be true"
177 assert page.has_text? 'As an admin, you can deactivate and reset this user'
179 # unsetup user and verify all the above links are deleted
181 click_button 'Deactivate Active User'
184 # Should now be back in the Attributes tab for the user
185 page.driver.browser.switch_to.alert.accept
186 assert page.has_text? 'modified_by_user_uuid'
187 page.within(:xpath, '//span[@data-name="is_active"]') do
188 assert_equal "false", text, "Expected user's is_active to be false after unsetup"
191 click_link 'Metadata'
192 assert !(page.has_text? '(Repository: test_repo)')
193 assert !(page.has_text? '(Repository: second_test_repo)')
194 assert !(page.has_text? '(VirtualMachine: testvm.shell)')
196 # setup user again and verify links present
198 click_link 'Setup Active User'
201 popup = page.driver.browser.window_handles.last
202 page.within_window popup do
203 fill_in "repo_name", :with => "second_test_repo"
204 select("testvm.shell", :from => 'vm_uuid')
205 click_button "Submit"
209 assert page.has_text? 'modified_by_client_uuid'
211 click_link 'Metadata'
212 assert page.has_text? '(Repository: second_test_repo)'
213 assert page.has_text? '(VirtualMachine: testvm.shell)'