2872: Fix bookmark bar causing spurious window width.
[arvados.git] / apps / workbench / test / integration / users_test.rb
1 require 'integration_helper'
2 require 'selenium-webdriver'
3 require 'headless'
4
5 class UsersTest < ActionDispatch::IntegrationTest
6
7   test "login as active user but not admin" do
8     Capybara.current_driver = Capybara.javascript_driver
9     visit page_with_token('active_trustedclient')
10
11     assert page.has_no_link? 'Users' 'Found Users link for non-admin user'
12   end
13
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')
17
18     # go to Users list page
19     find('#system-menu').click
20     click_link 'Users'
21
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'
25     end
26
27     find('tr', text: 'zzzzz-tpzed-xurymjxw79nv3jz').
28       find('a', text: 'Show').
29       click
30     assert page.has_text? 'Attributes'
31     assert page.has_text? 'Advanced'
32     assert page.has_text? 'Admin'
33
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"
39     end
40     page.within(:xpath, '//span[@data-name="is_admin"]') do
41       assert_equal "false", text, "Expected user's is_admin to be false"
42     end
43
44   end
45
46   test "create a new user" do
47     headless = Headless.new
48     headless.start
49
50     Capybara.current_driver = :selenium
51
52     visit page_with_token('admin_trustedclient')
53
54     find('#system-menu').click
55     click_link 'Users'
56
57     assert page.has_text? 'zzzzz-tpzed-d9tiejq69daie8f'
58
59     click_link 'Add a new user'
60
61     sleep(0.1)
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"
67       click_button "Submit"
68       wait_for_ajax
69     end
70
71     visit '/users'
72
73     # verify that the new user showed up in the users page and find
74     # the new user's UUID
75     new_user_uuid = 
76       find('tr[data-object-uuid]', text: 'foo@example.com')['data-object-uuid']
77     assert new_user_uuid, "Expected new user uuid not found"
78
79     # go to the new user's page
80     find('tr', text: new_user_uuid).
81       find('a', text: 'Show').
82       click
83
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"
87     end
88
89     click_link 'Advanced'
90     click_link 'Metadata'
91     assert page.has_text? 'Repository: test_repo'
92     assert !(page.has_text? 'VirtualMachine:')
93
94     headless.stop
95   end
96
97   test "setup the active user" do
98     headless = Headless.new
99     headless.start
100
101     Capybara.current_driver = :selenium
102     visit page_with_token('admin_trustedclient')
103
104     find('#system-menu').click
105     click_link 'Users'
106
107     # click on active user
108     find('tr', text: 'zzzzz-tpzed-xurymjxw79nv3jz').
109       find('a', text: 'Show').
110       click
111
112     # Setup user
113     click_link 'Admin'
114     assert page.has_text? 'As an admin, you can setup'
115
116     click_link 'Setup Active User'
117
118     sleep(0.1)
119
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"
125       wait_for_ajax
126     end
127
128     assert page.has_text? 'modified_by_client_uuid'
129
130     click_link 'Advanced'
131     click_link 'Metadata'
132     assert page.has_text? 'Repository: test_repo'
133     assert !(page.has_text? 'VirtualMachine:')
134
135     # Click on Setup button again and this time also choose a VM
136     click_link 'Admin'
137     click_link 'Setup Active User'
138
139     sleep(0.1)
140     popup = page.driver.browser.window_handles.last
141     page.within_window popup do
142       fill_in "repo_name", :with => "second_test_repo"
143       select("testvm.shell", :from => 'vm_uuid')
144       click_button "Submit"
145       wait_for_ajax
146     end
147
148     assert page.has_text? 'modified_by_client_uuid'
149
150     click_link 'Advanced'
151     click_link 'Metadata'
152     assert page.has_text? 'Repository: second_test_repo'
153     assert page.has_text? 'VirtualMachine: testvm.shell'
154
155     headless.stop
156   end
157
158   test "unsetup active user" do
159     headless = Headless.new
160     headless.start
161
162     Capybara.current_driver = :selenium
163
164     visit page_with_token('admin_trustedclient')
165
166     find('#system-menu').click
167     click_link 'Users'
168
169     # click on active user
170     find('tr', text: 'zzzzz-tpzed-xurymjxw79nv3jz').
171       find('a', text: 'Show').
172       click
173
174     # Verify that is_active is set
175     find('a,button', text: 'Attributes').click
176     assert page.has_text? 'modified_by_user_uuid'
177     page.within(:xpath, '//span[@data-name="is_active"]') do
178       assert_equal "true", text, "Expected user's is_active to be true"
179     end
180
181     # go to Admin tab
182     click_link 'Admin'
183     assert page.has_text? 'As an admin, you can deactivate and reset this user'
184
185     # unsetup user and verify all the above links are deleted
186     click_link 'Admin'
187     click_button 'Deactivate Active User'
188     sleep(0.1)
189
190     # Should now be back in the Attributes tab for the user
191     page.driver.browser.switch_to.alert.accept
192     assert page.has_text? 'modified_by_user_uuid'
193     page.within(:xpath, '//span[@data-name="is_active"]') do
194       assert_equal "false", text, "Expected user's is_active to be false after unsetup"
195     end
196
197     click_link 'Advanced'
198     click_link 'Metadata'
199     assert !(page.has_text? 'Repository: test_repo')
200     assert !(page.has_text? 'Repository: second_test_repo')
201     assert !(page.has_text? 'VirtualMachine: testvm.shell')
202
203     # setup user again and verify links present
204     click_link 'Admin'
205     click_link 'Setup Active User'
206
207     sleep(0.1)
208     popup = page.driver.browser.window_handles.last
209     page.within_window popup do
210       fill_in "repo_name", :with => "second_test_repo"
211       select("testvm.shell", :from => 'vm_uuid')
212       click_button "Submit"
213       wait_for_ajax
214     end
215
216     assert page.has_text? 'modified_by_client_uuid'
217
218     click_link 'Advanced'
219     click_link 'Metadata'
220     assert page.has_text? 'Repository: second_test_repo'
221     assert page.has_text? 'VirtualMachine: testvm.shell'
222
223     headless.stop
224   end
225
226 end