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
19 find('#system-menu').click
22 # check active user attributes in the list page
23 page.within(:xpath, '//tr[@data-object-uuid="zzzzz-tpzed-xurymjxw79nv3jz"]') do
24 assert (text.include? 'true false'), 'Expected is_active'
27 find('tr', text: 'zzzzz-tpzed-xurymjxw79nv3jz').
28 find('a', text: 'Show').
30 assert page.has_text? 'Attributes'
31 assert page.has_text? 'Advanced'
32 assert page.has_text? 'Admin'
34 # go to the Attributes tab
35 click_link 'Attributes'
36 assert page.has_text? 'modified_by_user_uuid'
37 page.within(:xpath, '//span[@data-name="is_active"]') do
38 assert_equal "true", text, "Expected user's is_active to be true"
40 page.within(:xpath, '//span[@data-name="is_admin"]') do
41 assert_equal "false", text, "Expected user's is_admin to be false"
46 test "create a new user" do
47 headless = Headless.new
50 Capybara.current_driver = :selenium
52 visit page_with_token('admin_trustedclient')
54 find('#system-menu').click
57 assert page.has_text? 'zzzzz-tpzed-d9tiejq69daie8f'
59 click_link 'Add a new user'
62 popup = page.driver.browser.window_handles.last
63 page.within_window popup do
64 assert has_text? 'Virtual Machine'
65 fill_in "email", :with => "foo@example.com"
66 fill_in "repo_name", :with => "test_repo"
73 # verify that the new user showed up in the users page and find
76 find('tr[data-object-uuid]', text: 'foo@example.com')['data-object-uuid']
77 assert new_user_uuid, "Expected new user uuid not found"
79 # go to the new user's page
80 find('tr', text: new_user_uuid).
81 find('a', text: 'Show').
84 assert page.has_text? 'modified_by_user_uuid'
85 page.within(:xpath, '//span[@data-name="is_active"]') do
86 assert_equal "false", text, "Expected new user's is_active to be false"
91 assert page.has_text? 'Repository: test_repo'
92 assert !(page.has_text? 'VirtualMachine:')
97 test "setup the active user" do
98 headless = Headless.new
101 Capybara.current_driver = :selenium
102 visit page_with_token('admin_trustedclient')
104 find('#system-menu').click
107 # click on active user
108 find('tr', text: 'zzzzz-tpzed-xurymjxw79nv3jz').
109 find('a', text: 'Show').
114 assert page.has_text? 'As an admin, you can setup'
116 click_link 'Setup Active User'
120 popup = page.driver.browser.window_handles.last
121 page.within_window popup do
122 assert has_text? 'Virtual Machine'
123 fill_in "repo_name", :with => "test_repo"
124 click_button "Submit"
127 assert page.has_text? 'modified_by_client_uuid'
129 click_link 'Advanced'
130 click_link 'Metadata'
131 assert page.has_text? 'Repository: test_repo'
132 assert !(page.has_text? 'VirtualMachine:')
134 # Click on Setup button again and this time also choose a VM
136 click_link 'Setup Active User'
139 popup = page.driver.browser.window_handles.last
140 page.within_window popup do
141 fill_in "repo_name", :with => "second_test_repo"
142 select("testvm.shell", :from => 'vm_uuid')
143 click_button "Submit"
146 assert page.has_text? 'modified_by_client_uuid'
148 click_link 'Advanced'
149 click_link 'Metadata'
150 assert page.has_text? 'Repository: second_test_repo'
151 assert page.has_text? 'VirtualMachine: testvm.shell'
156 test "unsetup active user" do
157 headless = Headless.new
160 Capybara.current_driver = :selenium
162 visit page_with_token('admin_trustedclient')
164 find('#system-menu').click
167 # click on active user
168 find('tr', text: 'zzzzz-tpzed-xurymjxw79nv3jz').
169 find('a', text: 'Show').
172 # Verify that is_active is set
173 find('a,button', text: 'Attributes').click
174 assert page.has_text? 'modified_by_user_uuid'
175 page.within(:xpath, '//span[@data-name="is_active"]') do
176 assert_equal "true", text, "Expected user's is_active to be true"
181 assert page.has_text? 'As an admin, you can deactivate and reset this user'
183 # unsetup user and verify all the above links are deleted
185 click_button 'Deactivate Active User'
188 # Should now be back in the Attributes tab for the user
189 page.driver.browser.switch_to.alert.accept
190 assert page.has_text? 'modified_by_user_uuid'
191 page.within(:xpath, '//span[@data-name="is_active"]') do
192 assert_equal "false", text, "Expected user's is_active to be false after unsetup"
195 click_link 'Advanced'
196 click_link 'Metadata'
197 assert !(page.has_text? 'Repository: test_repo')
198 assert !(page.has_text? 'Repository: second_test_repo')
199 assert !(page.has_text? 'VirtualMachine: testvm.shell')
201 # setup user again and verify links present
203 click_link 'Setup Active User'
206 popup = page.driver.browser.window_handles.last
207 page.within_window popup do
208 fill_in "repo_name", :with => "second_test_repo"
209 select("testvm.shell", :from => 'vm_uuid')
210 click_button "Submit"
213 assert page.has_text? 'modified_by_client_uuid'
215 click_link 'Advanced'
216 click_link 'Metadata'
217 assert page.has_text? 'Repository: second_test_repo'
218 assert page.has_text? 'VirtualMachine: testvm.shell'