1 require 'integration_helper'
3 class UsersTest < ActionDispatch::IntegrationTest
4 test "login as active user but not admin" do
5 Capybara.current_driver = Capybara.javascript_driver
6 visit page_with_token('active_trustedclient')
8 assert page.has_no_link? 'Users' 'Found Users link for non-admin user'
11 test "login as admin user and verify active user data" do
12 Capybara.current_driver = Capybara.javascript_driver
13 visit page_with_token('admin_trustedclient')
15 # go to Users list page
18 # check active user attributes in the list page
19 page.within(:xpath, '//tr[@data-object-uuid="zzzzz-tpzed-xurymjxw79nv3jz"]') do
20 assert (text.include? 'true false'), 'Expected is_active'
23 click_link 'zzzzz-tpzed-xurymjxw79nv3jz'
24 assert page.has_text? 'Attributes'
25 assert page.has_text? 'Metadata'
26 assert page.has_text? 'Admin'
28 # go to the Attributes tab
29 click_link 'Attributes'
30 assert page.has_text? 'modified_by_user_uuid'
31 page.within(:xpath, '//a[@data-name="is_active"]') do
32 assert_equal "true", text, "Expected user's is_active to be true"
34 page.within(:xpath, '//a[@data-name="is_admin"]') do
35 assert_equal "false", text, "Expected user's is_admin to be false"
40 test "create a new user" do
41 Capybara.current_driver = :webkit
42 visit page_with_token('admin_trustedclient')
46 assert page.has_text? 'zzzzz-tpzed-d9tiejq69daie8f'
48 click_link 'Add a new user'
51 popup = page.driver.browser.window_handles.last
52 page.within_window popup do
53 assert has_text? 'Virtual Machine'
54 fill_in "email", :with => "foo@example.com"
55 fill_in "repo_name", :with => "test_repo"
61 # verify that the new user showed up in the users page
62 assert page.has_text? 'foo@example.com'
64 page.within(:xpath, '//tr[@data-object-uuid][1]') do
65 assert (text.include? 'foo@example.com false'), 'Expected email'
66 new_user_uuid = text.split[0]
68 # go to the new user's page
69 click_link new_user_uuid
72 assert page.has_text? 'modified_by_user_uuid'
73 page.within(:xpath, '//a[@data-name="is_active"]') do
74 assert_equal "false", text, "Expected new user's is_active to be false"
78 assert page.has_text? '(Repository: test_repo)'
79 assert !(page.has_text? '(VirtualMachine:)')
82 test "setup the active user" do
83 Capybara.current_driver = :webkit
84 visit page_with_token('admin_trustedclient')
88 assert page.has_link? 'zzzzz-tpzed-xurymjxw79nv3jz'
90 # click on active user
91 click_link 'zzzzz-tpzed-xurymjxw79nv3jz'
95 assert page.has_text? 'As an admin, you can setup'
97 click_link 'Setup Active User'
100 popup = page.driver.browser.window_handles.last
101 page.within_window popup do
102 assert has_text? 'Virtual Machine'
103 fill_in "repo_name", :with => "test_repo"
104 click_button "Submit"
108 assert page.has_text? 'modified_by_client_uuid'
110 click_link 'Metadata'
111 assert page.has_text? '(Repository: test_repo)'
112 assert !(page.has_text? '(VirtualMachine:)')
114 # Click on Setup button again and this time also choose a VM
116 click_link 'Setup Active User'
119 popup = page.driver.browser.window_handles.last
120 page.within_window popup do
121 fill_in "repo_name", :with => "second_test_repo"
122 select("testvm.shell", :from => 'vm_uuid')
123 click_button "Submit"
127 assert page.has_text? 'modified_by_client_uuid'
129 click_link 'Metadata'
130 assert page.has_text? '(Repository: second_test_repo)'
131 assert page.has_text? '(VirtualMachine: testvm.shell)'
134 test "unsetup active user" do
135 Capybara.current_driver = :webkit
137 visit page_with_token('admin_trustedclient')
141 assert page.has_link? 'zzzzz-tpzed-xurymjxw79nv3jz'
143 # click on active user
144 click_link 'zzzzz-tpzed-xurymjxw79nv3jz'
146 # Verify that is_active is set
147 click_link 'Attributes'
148 assert page.has_text? 'modified_by_user_uuid'
149 page.within(:xpath, '//a[@data-name="is_active"]') do
150 assert_equal "true", text, "Expected user's is_active to be true"
155 assert page.has_text? 'As an admin, you can deactivate and reset this user'
157 # unsetup user and verify all the above links are deleted
159 click_button 'Deactivate Active User'
162 # Should now be back in the Attributes tab for the user
163 assert page.has_text? 'modified_by_user_uuid'
164 page.within(:xpath, '//a[@data-name="is_active"]') do
165 assert_equal "false", text, "Expected user's is_active to be false after unsetup"
168 click_link 'Metadata'
169 assert !(page.has_text? '(Repository: test_repo)')
170 assert !(page.has_text? '(Repository: second_test_repo)')
171 assert !(page.has_text? '(VirtualMachine: testvm.shell)')
173 # setup user again and verify links present
175 click_link 'Setup Active User'
178 popup = page.driver.browser.window_handles.last
179 page.within_window popup do
180 fill_in "repo_name", :with => "second_test_repo"
181 select("testvm.shell", :from => 'vm_uuid')
182 click_button "Submit"
186 assert page.has_text? 'modified_by_client_uuid'
188 click_link 'Metadata'
189 assert page.has_text? '(Repository: second_test_repo)'
190 assert page.has_text? '(VirtualMachine: testvm.shell)'