1 require 'integration_helper'
3 class UsersTest < ActionDispatch::IntegrationTest
5 test "login as active user but not admin" do
7 visit page_with_token('active_trustedclient')
9 assert page.has_no_link? 'Users' 'Found Users link for non-admin user'
12 test "login as admin user and verify active user data" do
14 visit page_with_token('admin_trustedclient')
16 # go to Users list page
17 find('#system-menu').click
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'
25 find('tr', text: 'zzzzz-tpzed-xurymjxw79nv3jz').
26 find('a', text: 'Show').
28 assert page.has_text? 'Attributes'
29 assert page.has_text? 'Advanced'
30 assert page.has_text? 'Admin'
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"
38 page.within(:xpath, '//span[@data-name="is_admin"]') do
39 assert_equal "false", text, "Expected user's is_admin to be false"
44 test "create a new user" do
47 visit page_with_token('admin_trustedclient')
49 find('#system-menu').click
52 assert page.has_text? 'zzzzz-tpzed-d9tiejq69daie8f'
54 click_link 'Add a new user'
56 within '.modal-content' do
57 find 'label', text: 'Virtual Machine'
58 fill_in "email", :with => "foo@example.com"
59 fill_in "repo_name", :with => "newtestrepo"
66 # verify that the new user showed up in the users page and find
69 find('tr[data-object-uuid]', text: 'foo@example.com')['data-object-uuid']
70 assert new_user_uuid, "Expected new user uuid not found"
72 # go to the new user's page
73 find('tr', text: new_user_uuid).
74 find('a', text: 'Show').
77 assert page.has_text? 'modified_by_user_uuid'
78 page.within(:xpath, '//span[@data-name="is_active"]') do
79 assert_equal "false", text, "Expected new user's is_active to be false"
84 assert page.has_text? 'Repository: foo/newtestrepo'
85 assert !(page.has_text? 'VirtualMachine:')
88 test "setup the active user" do
90 visit page_with_token('admin_trustedclient')
92 find('#system-menu').click
95 # click on active user
96 find('tr', text: 'zzzzz-tpzed-xurymjxw79nv3jz').
97 find('a', text: 'Show').
99 user_url = page.current_url
103 assert page.has_text? 'As an admin, you can setup'
105 click_link 'Setup Active User'
107 within '.modal-content' do
108 find 'label', text: 'Virtual Machine'
109 fill_in "repo_name", :with => "activetestrepo"
110 click_button "Submit"
114 assert page.has_text? 'modified_by_client_uuid'
116 click_link 'Advanced'
117 click_link 'Metadata'
118 assert page.has_text? 'Repository: active/activetestrepo'
119 assert !(page.has_text? 'VirtualMachine:')
121 # Click on Setup button again and this time also choose a VM
123 click_link 'Setup Active User'
125 within '.modal-content' do
126 fill_in "repo_name", :with => "activetestrepo2"
127 select("testvm.shell", :from => 'vm_uuid')
128 fill_in "groups", :with => "test group one, test-group-two"
129 click_button "Submit"
133 find '#Attributes', text: 'modified_by_client_uuid'
135 click_link 'Advanced'
136 click_link 'Metadata'
137 assert page.has_text? 'Repository: active/activetestrepo2'
138 assert page.has_text? 'VirtualMachine: testvm.shell'
139 assert page.has_text? '["test group one", "test-group-two"]'
142 test "unsetup active user" do
145 visit page_with_token('admin_trustedclient')
147 find('#system-menu').click
150 # click on active user
151 find('tr', text: 'zzzzz-tpzed-xurymjxw79nv3jz').
152 find('a', text: 'Show').
154 user_url = page.current_url
156 # Verify that is_active is set
157 find('a,button', text: 'Attributes').click
158 assert page.has_text? 'modified_by_user_uuid'
159 page.within(:xpath, '//span[@data-name="is_active"]') do
160 assert_equal "true", text, "Expected user's is_active to be true"
165 assert page.has_text? 'As an admin, you can deactivate and reset this user'
167 # unsetup user and verify all the above links are deleted
169 click_button 'Deactivate Active User'
171 if Capybara.current_driver == :selenium
173 page.driver.browser.switch_to.alert.accept
175 # poltergeist returns true for confirm(), so we don't need to accept.
178 # Should now be back in the Attributes tab for the user
179 assert page.has_text? 'modified_by_user_uuid'
180 page.within(:xpath, '//span[@data-name="is_active"]') do
181 assert_equal "false", text, "Expected user's is_active to be false after unsetup"
184 click_link 'Advanced'
185 click_link 'Metadata'
186 assert page.has_no_text? 'Repository: active/'
187 assert page.has_no_text? 'VirtualMachine: testvm.shell'
189 # setup user again and verify links present
191 click_link 'Setup Active User'
193 within '.modal-content' do
194 fill_in "repo_name", :with => "activetestrepo"
195 select("testvm.shell", :from => 'vm_uuid')
196 click_button "Submit"
200 assert page.has_text? 'modified_by_client_uuid'
202 click_link 'Advanced'
203 click_link 'Metadata'
204 assert page.has_text? 'Repository: active/activetestrepo'
205 assert page.has_text? 'VirtualMachine: testvm.shell'
211 ].each do |username, expect_show_button|
212 test "login as #{username} and access show button #{expect_show_button}" do
215 user = api_fixture('users', username)
217 visit page_with_token(username, '/users')
219 if expect_show_button
220 within('tr', text: user['uuid']) do
221 assert_text user['email']
222 assert_selector 'a', text: 'Show'
223 find('a', text: 'Show').click
225 assert_selector 'a', 'Data collections'
227 # no 'Show' button in the admin user's own row
228 within('tr', text: user['uuid']) do
229 assert_text user['email']
230 assert_no_selector 'a', text: 'Show'
233 # but the admin user can access 'Show' button for other users
234 active_user = api_fixture('users', 'active')
235 within('tr', text: active_user['uuid']) do
236 assert_text active_user['email']
237 assert_selector 'a', text: 'Show'
238 find('a', text: 'Show').click
239 assert_selector 'a', 'Attributes'