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').
109 user_url = page.current_url
113 assert page.has_text? 'As an admin, you can setup'
115 click_link 'Setup Active User'
117 within '.modal-content' do
118 find 'label', text: 'Virtual Machine'
119 fill_in "repo_name", :with => "test_repo"
120 click_button "Submit"
124 assert page.has_text? 'modified_by_client_uuid'
126 click_link 'Advanced'
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'
135 within '.modal-content' do
136 fill_in "repo_name", :with => "second_test_repo"
137 select("testvm.shell", :from => 'vm_uuid')
138 click_button "Submit"
142 find '#Attributes', text: 'modified_by_client_uuid'
144 click_link 'Advanced'
145 click_link 'Metadata'
146 assert page.has_text? 'Repository: second_test_repo'
147 assert page.has_text? 'VirtualMachine: testvm.shell'
152 test "unsetup active user" do
153 headless = Headless.new
156 Capybara.current_driver = :selenium
158 visit page_with_token('admin_trustedclient')
160 find('#system-menu').click
163 # click on active user
164 find('tr', text: 'zzzzz-tpzed-xurymjxw79nv3jz').
165 find('a', text: 'Show').
167 user_url = page.current_url
169 # Verify that is_active is set
170 find('a,button', text: 'Attributes').click
171 assert page.has_text? 'modified_by_user_uuid'
172 page.within(:xpath, '//span[@data-name="is_active"]') do
173 assert_equal "true", text, "Expected user's is_active to be true"
178 assert page.has_text? 'As an admin, you can deactivate and reset this user'
180 # unsetup user and verify all the above links are deleted
182 click_button 'Deactivate Active User'
185 # Should now be back in the Attributes tab for the user
186 page.driver.browser.switch_to.alert.accept
188 assert page.has_text? 'modified_by_user_uuid'
189 page.within(:xpath, '//span[@data-name="is_active"]') do
190 assert_equal "false", text, "Expected user's is_active to be false after unsetup"
193 click_link 'Advanced'
194 click_link 'Metadata'
195 assert !(page.has_text? 'Repository: test_repo')
196 assert !(page.has_text? 'Repository: second_test_repo')
197 assert !(page.has_text? 'VirtualMachine: testvm.shell')
199 # setup user again and verify links present
201 click_link 'Setup Active User'
203 within '.modal-content' do
204 fill_in "repo_name", :with => "second_test_repo"
205 select("testvm.shell", :from => 'vm_uuid')
206 click_button "Submit"
210 assert page.has_text? 'modified_by_client_uuid'
212 click_link 'Advanced'
213 click_link 'Metadata'
214 assert page.has_text? 'Repository: second_test_repo'
215 assert page.has_text? 'VirtualMachine: testvm.shell'