8784: Fix test for latest firefox.
[arvados.git] / apps / workbench / test / integration / users_test.rb
1 require 'integration_helper'
2
3 class UsersTest < ActionDispatch::IntegrationTest
4
5   test "login as active user but not admin" do
6     need_javascript
7     visit page_with_token('active_trustedclient')
8
9     assert page.has_no_link? 'Users' 'Found Users link for non-admin user'
10   end
11
12   test "login as admin user and verify active user data" do
13     need_javascript
14     visit page_with_token('admin_trustedclient')
15
16     # go to Users list page
17     find('#system-menu').click
18     click_link 'Users'
19
20     # check active user attributes in the list page
21     page.within(:xpath, '//tr[@data-object-uuid="zzzzz-tpzed-xurymjxw79nv3jz"]') do
22       assert (text.include? 'true false'), 'Expected is_active'
23     end
24
25     find('tr', text: 'zzzzz-tpzed-xurymjxw79nv3jz').
26       find('a', text: 'Show').
27       click
28     assert page.has_text? 'Attributes'
29     assert page.has_text? 'Advanced'
30     assert page.has_text? 'Admin'
31
32     # go to the Attributes tab
33     click_link 'Attributes'
34     assert page.has_text? 'modified_by_user_uuid'
35     page.within(:xpath, '//span[@data-name="is_active"]') do
36       assert_equal "true", text, "Expected user's is_active to be true"
37     end
38     page.within(:xpath, '//span[@data-name="is_admin"]') do
39       assert_equal "false", text, "Expected user's is_admin to be false"
40     end
41
42   end
43
44   test "create a new user" do
45     need_javascript
46
47     visit page_with_token('admin_trustedclient')
48
49     find('#system-menu').click
50     click_link 'Users'
51
52     assert page.has_text? 'zzzzz-tpzed-d9tiejq69daie8f'
53
54     click_link 'Add a new user'
55
56     within '.modal-content' do
57       find 'label', text: 'Virtual Machine'
58       fill_in "email", :with => "foo@example.com"
59       click_button "Submit"
60       wait_for_ajax
61     end
62
63     visit '/users'
64
65     # verify that the new user showed up in the users page and find
66     # the new user's UUID
67     new_user_uuid =
68       find('tr[data-object-uuid]', text: 'foo@example.com')['data-object-uuid']
69     assert new_user_uuid, "Expected new user uuid not found"
70
71     # go to the new user's page
72     find('tr', text: new_user_uuid).
73       find('a', text: 'Show').
74       click
75
76     assert page.has_text? 'modified_by_user_uuid'
77     page.within(:xpath, '//span[@data-name="is_active"]') do
78       assert_equal "false", text, "Expected new user's is_active to be false"
79     end
80
81     click_link 'Advanced'
82     click_link 'Metadata'
83     assert page.has_text? 'can_login' # make sure page is rendered / ready
84     assert page.has_no_text? 'VirtualMachine:'
85   end
86
87   test "setup the active user" do
88     need_javascript
89     visit page_with_token('admin_trustedclient')
90
91     find('#system-menu').click
92     click_link 'Users'
93
94     # click on active user
95     find('tr', text: 'zzzzz-tpzed-xurymjxw79nv3jz').
96       find('a', text: 'Show').
97       click
98     user_url = page.current_url
99
100     # Setup user
101     click_link 'Admin'
102     assert page.has_text? 'As an admin, you can setup'
103
104     click_link 'Setup shell account for Active User'
105
106     within '.modal-content' do
107       find 'label', text: 'Virtual Machine'
108       click_button "Submit"
109     end
110
111     visit user_url
112     assert page.has_text? 'modified_by_client_uuid'
113
114     click_link 'Advanced'
115     click_link 'Metadata'
116     vm_links = all("a", text: "VirtualMachine:")
117     assert_equal(1, vm_links.size)
118     assert_equal("VirtualMachine: testvm2.shell", vm_links.first.text)
119
120     # Click on Setup button again and this time also choose a VM
121     click_link 'Admin'
122     click_link 'Setup shell account for Active User'
123
124     within '.modal-content' do
125       select("testvm.shell", :from => 'vm_uuid')
126       fill_in "groups", :with => "test group one, test-group-two"
127       click_button "Submit"
128     end
129
130     visit user_url
131     find '#Attributes', text: 'modified_by_client_uuid'
132
133     click_link 'Advanced'
134     click_link 'Metadata'
135     assert page.has_text? 'VirtualMachine: testvm.shell'
136     assert page.has_text? '["test group one", "test-group-two"]'
137   end
138
139   test "unsetup active user" do
140     need_javascript
141
142     visit page_with_token('admin_trustedclient')
143
144     find('#system-menu').click
145     click_link 'Users'
146
147     # click on active user
148     find('tr', text: 'zzzzz-tpzed-xurymjxw79nv3jz').
149       find('a', text: 'Show').
150       click
151     user_url = page.current_url
152
153     # Verify that is_active is set
154     find('a,button', text: 'Attributes').click
155     assert page.has_text? 'modified_by_user_uuid'
156     page.within(:xpath, '//span[@data-name="is_active"]') do
157       assert_equal "true", text, "Expected user's is_active to be true"
158     end
159
160     # go to Admin tab
161     click_link 'Admin'
162     assert page.has_text? 'As an admin, you can deactivate and reset this user'
163
164     # unsetup user and verify all the above links are deleted
165     click_link 'Admin'
166     click_button 'Deactivate Active User'
167
168     if Capybara.current_driver == :selenium
169       sleep(0.1)
170       page.driver.browser.switch_to.alert.accept
171     else
172       # poltergeist returns true for confirm(), so we don't need to accept.
173     end
174
175     # Should now be back in the Attributes tab for the user
176     assert page.has_text? 'modified_by_user_uuid'
177     page.within(:xpath, '//span[@data-name="is_active"]') do
178       assert_equal "false", text, "Expected user's is_active to be false after unsetup"
179     end
180
181     click_link 'Advanced'
182     click_link 'Metadata'
183     assert page.has_no_text? 'VirtualMachine: testvm.shell'
184
185     # setup user again and verify links present
186     click_link 'Admin'
187     click_link 'Setup shell account for Active User'
188
189     within '.modal-content' do
190       select("testvm.shell", :from => 'vm_uuid')
191       click_button "Submit"
192     end
193
194     visit user_url
195     assert page.has_text? 'modified_by_client_uuid'
196
197     click_link 'Advanced'
198     click_link 'Metadata'
199     assert page.has_text? 'VirtualMachine: testvm.shell'
200   end
201
202   test "test add group button" do
203     need_javascript
204
205     user_url = "/users/#{api_fixture('users')['active']['uuid']}"
206     visit page_with_token('admin_trustedclient', user_url)
207
208     # Setup user
209     click_link 'Admin'
210     assert page.has_text? 'As an admin, you can setup'
211
212     click_link 'Add new group'
213
214     within '.modal-content' do
215       fill_in "group_name_input", :with => "test-group-added-in-modal"
216       click_button "Create"
217     end
218     wait_for_ajax
219
220     # Back in the user "Admin" tab
221     assert page.has_text? 'test-group-added-in-modal'
222   end
223 end