Merge branch 'master' into 2272-setup-user-in-workbench
[arvados.git] / apps / workbench / test / integration / users_test.rb
1 require 'integration_helper'
2
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')
7
8     assert page.has_no_link? 'Users' 'Found Users link for non-admin user'
9   end
10
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')
14
15     # go to Users list page
16     click_link 'Users'
17
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'
21     end
22
23     click_link 'zzzzz-tpzed-xurymjxw79nv3jz'
24     assert page.has_text? 'Attributes'
25     assert page.has_text? 'Metadata'
26     assert page.has_text? 'Admin'
27
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"
33     end
34     page.within(:xpath, '//a[@data-name="is_admin"]') do
35       assert_equal "false", text, "Expected user's is_admin to be false"
36     end
37
38   end
39
40   test "create a new user" do
41     Capybara.current_driver = :webkit
42     visit page_with_token('admin_trustedclient')
43
44     click_link 'Users'
45
46     assert page.has_text? 'zzzzz-tpzed-d9tiejq69daie8f'
47
48     click_link 'Add a new user'
49     
50     sleep(0.1)
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"
56       click_button "Submit"
57     end
58
59     sleep(0.1)
60     
61     # verify that the new user showed up in the users page
62     assert page.has_text? 'foo@example.com'
63
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]
67
68       # go to the new user's page
69       click_link new_user_uuid
70     end
71
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"
75     end
76
77     click_link 'Metadata'
78     assert page.has_text? '(Repository: test_repo)'
79     assert !(page.has_text? '(VirtualMachine:)')
80   end
81
82   test "setup the active user" do
83     Capybara.current_driver = :webkit
84     visit page_with_token('admin_trustedclient')
85
86     click_link 'Users'
87
88     assert page.has_link? 'zzzzz-tpzed-xurymjxw79nv3jz'
89
90     # click on active user
91     click_link 'zzzzz-tpzed-xurymjxw79nv3jz'
92
93     # Setup user
94     click_link 'Admin'
95     assert page.has_text? 'As an admin, you can setup'
96
97     click_link 'Setup Active User'
98
99     sleep(0.1)
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"
105     end
106
107     sleep(0.1)
108     assert page.has_text? 'modified_by_client_uuid'
109
110     click_link 'Metadata'
111     assert page.has_text? '(Repository: test_repo)'
112     assert !(page.has_text? '(VirtualMachine:)')
113
114     # Click on Setup button again and this time also choose a VM
115     click_link 'Admin'
116     click_link 'Setup Active User'
117
118     sleep(0.1)
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"
124     end
125
126     sleep(0.1)
127     assert page.has_text? 'modified_by_client_uuid'
128
129     click_link 'Metadata'
130     assert page.has_text? '(Repository: second_test_repo)'
131     assert page.has_text? '(VirtualMachine: testvm.shell)'
132   end
133
134   test "unsetup active user" do
135     Capybara.current_driver = :webkit
136
137     visit page_with_token('admin_trustedclient')
138
139     click_link 'Users'
140
141     assert page.has_link? 'zzzzz-tpzed-xurymjxw79nv3jz'
142
143     # click on active user
144     click_link 'zzzzz-tpzed-xurymjxw79nv3jz'
145
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"
151     end
152
153     # go to Admin tab
154     click_link 'Admin'
155     assert page.has_text? 'As an admin, you can deactivate and reset this user'
156
157     # unsetup user and verify all the above links are deleted
158     click_link 'Admin'
159     click_button 'Deactivate Active User'
160     sleep(0.1)
161
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"
166     end
167
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)')
172
173     # setup user again and verify links present
174     click_link 'Admin'
175     click_link 'Setup Active User'
176
177     sleep(0.1)
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"
183     end
184
185     sleep(0.1)
186     assert page.has_text? 'modified_by_client_uuid'
187
188     click_link 'Metadata'
189     assert page.has_text? '(Repository: second_test_repo)'
190     assert page.has_text? '(VirtualMachine: testvm.shell)'
191   end
192
193 end