Merge branch 'master' into 1971-show-image-thumbnails
[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     click_link 'Users'
20
21     # check active user attributes in the list page
22     page.within(:xpath, '//tr[@data-object-uuid="zzzzz-tpzed-xurymjxw79nv3jz"]') do
23       assert (text.include? 'true false'), 'Expected is_active'
24     end
25
26     click_link 'zzzzz-tpzed-xurymjxw79nv3jz'
27     assert page.has_text? 'Attributes'
28     assert page.has_text? 'Metadata'
29     assert page.has_text? 'Admin'
30
31     # go to the Attributes tab
32     click_link 'Attributes'
33     assert page.has_text? 'modified_by_user_uuid'
34     page.within(:xpath, '//a[@data-name="is_active"]') do
35       assert_equal "true", text, "Expected user's is_active to be true"
36     end
37     page.within(:xpath, '//a[@data-name="is_admin"]') do
38       assert_equal "false", text, "Expected user's is_admin to be false"
39     end
40
41   end
42
43   test "create a new user" do
44     headless = Headless.new
45     headless.start
46
47     Capybara.current_driver = :selenium
48
49     visit page_with_token('admin_trustedclient')
50
51     click_link 'Users'
52
53     assert page.has_text? 'zzzzz-tpzed-d9tiejq69daie8f'
54
55     click_link 'Add a new user'
56
57     sleep(0.1)
58     popup = page.driver.browser.window_handles.last
59     page.within_window popup do
60       assert has_text? 'Virtual Machine'
61       fill_in "email", :with => "foo@example.com"
62       fill_in "repo_name", :with => "test_repo"
63       click_button "Submit"
64     end
65
66     sleep(0.1)
67
68     # verify that the new user showed up in the users page
69     assert page.has_text? 'foo@example.com'
70
71     new_user_uuid = nil
72     all("tr").each do |elem|
73       if elem.text.include? 'foo@example.com'
74         new_user_uuid = elem.text.split[0]
75         break
76       end
77     end
78
79     assert new_user_uuid, "Expected new user uuid not found"
80
81     # go to the new user's page
82     click_link new_user_uuid
83
84     assert page.has_text? 'modified_by_user_uuid'
85     page.within(:xpath, '//a[@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 'Metadata'
90     assert page.has_text? '(Repository: test_repo)'
91     assert !(page.has_text? '(VirtualMachine:)')
92
93     headless.stop
94   end
95
96   test "setup the active user" do
97     headless = Headless.new
98     headless.start
99
100     Capybara.current_driver = :selenium
101     visit page_with_token('admin_trustedclient')
102
103     click_link 'Users'
104
105     assert page.has_link? 'zzzzz-tpzed-xurymjxw79nv3jz'
106
107     # click on active user
108     click_link 'zzzzz-tpzed-xurymjxw79nv3jz'
109
110     # Setup user
111     click_link 'Admin'
112     assert page.has_text? 'As an admin, you can setup'
113
114     click_link 'Setup Active User'
115
116     sleep(0.1)
117
118     popup = page.driver.browser.window_handles.last
119     page.within_window popup do
120       assert has_text? 'Virtual Machine'
121       fill_in "repo_name", :with => "test_repo"
122       click_button "Submit"
123     end
124
125     sleep(0.1)
126     assert page.has_text? 'modified_by_client_uuid'
127
128     click_link 'Metadata'
129     assert page.has_text? '(Repository: test_repo)'
130     assert !(page.has_text? '(VirtualMachine:)')
131
132     # Click on Setup button again and this time also choose a VM
133     click_link 'Admin'
134     click_link 'Setup Active User'
135
136     sleep(0.1)
137     popup = page.driver.browser.window_handles.last
138     page.within_window popup do
139       fill_in "repo_name", :with => "second_test_repo"
140       select("testvm.shell", :from => 'vm_uuid')
141       click_button "Submit"
142     end
143
144     sleep(0.1)
145     assert page.has_text? 'modified_by_client_uuid'
146
147     click_link 'Metadata'
148     assert page.has_text? '(Repository: second_test_repo)'
149     assert page.has_text? '(VirtualMachine: testvm.shell)'
150
151     headless.stop
152   end
153
154   test "unsetup active user" do
155     headless = Headless.new
156     headless.start
157
158     Capybara.current_driver = :selenium
159
160     visit page_with_token('admin_trustedclient')
161
162     click_link 'Users'
163
164     assert page.has_link? 'zzzzz-tpzed-xurymjxw79nv3jz'
165
166     # click on active user
167     click_link 'zzzzz-tpzed-xurymjxw79nv3jz'
168
169     # Verify that is_active is set
170     click_link 'Attributes'
171     assert page.has_text? 'modified_by_user_uuid'
172     page.within(:xpath, '//a[@data-name="is_active"]') do
173       assert_equal "true", text, "Expected user's is_active to be true"
174     end
175
176     # go to Admin tab
177     click_link 'Admin'
178     assert page.has_text? 'As an admin, you can deactivate and reset this user'
179
180     # unsetup user and verify all the above links are deleted
181     click_link 'Admin'
182     click_button 'Deactivate Active User'
183     sleep(0.1)
184
185     # Should now be back in the Attributes tab for the user
186     page.driver.browser.switch_to.alert.accept
187     assert page.has_text? 'modified_by_user_uuid'
188     page.within(:xpath, '//a[@data-name="is_active"]') do
189       assert_equal "false", text, "Expected user's is_active to be false after unsetup"
190     end
191
192     click_link 'Metadata'
193     assert !(page.has_text? '(Repository: test_repo)')
194     assert !(page.has_text? '(Repository: second_test_repo)')
195     assert !(page.has_text? '(VirtualMachine: testvm.shell)')
196
197     # setup user again and verify links present
198     click_link 'Admin'
199     click_link 'Setup Active User'
200
201     sleep(0.1)
202     popup = page.driver.browser.window_handles.last
203     page.within_window popup do
204       fill_in "repo_name", :with => "second_test_repo"
205       select("testvm.shell", :from => 'vm_uuid')
206       click_button "Submit"
207     end
208
209     sleep(0.1)
210     assert page.has_text? 'modified_by_client_uuid'
211
212     click_link 'Metadata'
213     assert page.has_text? '(Repository: second_test_repo)'
214     assert page.has_text? '(VirtualMachine: testvm.shell)'
215
216     headless.stop
217   end
218
219 end