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'
61 within '.modal-content' do
62 find 'label', text: 'Virtual Machine'
63 fill_in "email", :with => "foo@example.com"
64 fill_in "repo_name", :with => "test_repo"
71 # verify that the new user showed up in the users page and find
74 find('tr[data-object-uuid]', text: 'foo@example.com')['data-object-uuid']
75 assert new_user_uuid, "Expected new user uuid not found"
77 # go to the new user's page
78 find('tr', text: new_user_uuid).
79 find('a', text: 'Show').
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? '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')
102 find('#system-menu').click
105 # click on active user
106 find('tr', text: 'zzzzz-tpzed-xurymjxw79nv3jz').
107 find('a', text: 'Show').
112 assert page.has_text? 'As an admin, you can setup'
114 click_link 'Setup Active User'
116 within '.modal-content' do
117 find 'label', text: 'Virtual Machine'
118 fill_in "repo_name", :with => "test_repo"
119 click_button "Submit"
122 assert page.has_text? 'modified_by_client_uuid'
124 click_link 'Advanced'
125 click_link 'Metadata'
126 assert page.has_text? 'Repository: test_repo'
127 assert !(page.has_text? 'VirtualMachine:')
129 # Click on Setup button again and this time also choose a VM
131 click_link 'Setup Active User'
133 within '.modal-content' do
134 fill_in "repo_name", :with => "second_test_repo"
135 select("testvm.shell", :from => 'vm_uuid')
136 click_button "Submit"
139 find '#Attributes', text: 'modified_by_client_uuid'
141 click_link 'Advanced'
142 click_link 'Metadata'
143 assert page.has_text? 'Repository: second_test_repo'
144 assert page.has_text? 'VirtualMachine: testvm.shell'
149 test "unsetup active user" do
150 headless = Headless.new
153 Capybara.current_driver = :selenium
155 visit page_with_token('admin_trustedclient')
157 find('#system-menu').click
160 # click on active user
161 find('tr', text: 'zzzzz-tpzed-xurymjxw79nv3jz').
162 find('a', text: 'Show').
165 # Verify that is_active is set
166 find('a,button', text: 'Attributes').click
167 assert page.has_text? 'modified_by_user_uuid'
168 page.within(:xpath, '//span[@data-name="is_active"]') do
169 assert_equal "true", text, "Expected user's is_active to be true"
174 assert page.has_text? 'As an admin, you can deactivate and reset this user'
176 # unsetup user and verify all the above links are deleted
178 click_button 'Deactivate Active User'
181 # Should now be back in the Attributes tab for the user
182 page.driver.browser.switch_to.alert.accept
184 assert page.has_text? 'modified_by_user_uuid'
185 page.within(:xpath, '//span[@data-name="is_active"]') do
186 assert_equal "false", text, "Expected user's is_active to be false after unsetup"
189 click_link 'Advanced'
190 click_link 'Metadata'
191 assert !(page.has_text? 'Repository: test_repo')
192 assert !(page.has_text? 'Repository: second_test_repo')
193 assert !(page.has_text? 'VirtualMachine: testvm.shell')
195 # setup user again and verify links present
197 click_link 'Setup Active User'
199 within '.modal-content' do
200 fill_in "repo_name", :with => "second_test_repo"
201 select("testvm.shell", :from => 'vm_uuid')
202 click_button "Submit"
205 assert page.has_text? 'modified_by_client_uuid'
207 click_link 'Advanced'
208 click_link 'Metadata'
209 assert page.has_text? 'Repository: second_test_repo'
210 assert page.has_text? 'VirtualMachine: testvm.shell'