4458: breadcrumbs now visible in small window sizes; also, use user icon instead...
[arvados.git] / apps / workbench / test / integration / anonymous_access_test.rb
1 require 'integration_helper'
2
3 class AnonymousAccessTest < ActionDispatch::IntegrationTest
4   # These tests don't do state-changing API calls. Save some time by
5   # skipping the database reset.
6   reset_api_fixtures :after_each_test, false
7   reset_api_fixtures :after_suite, true
8
9   setup do
10     need_javascript
11     Rails.configuration.anonymous_user_token = api_fixture('api_client_authorizations')['anonymous']['api_token']
12   end
13
14   PUBLIC_PROJECT = "/projects/#{api_fixture('groups')['anonymously_accessible_project']['uuid']}"
15
16   def verify_site_navigation_anonymous_enabled user, is_active
17     if user
18       if user['is_active']
19         assert_text 'Unrestricted public data'
20         assert_selector 'a', text: 'Projects'
21       else
22         assert_text 'indicate that you have read and accepted the user agreement'
23       end
24       within('.navbar-fixed-top') do
25         assert_selector 'a', text: Rails.configuration.site_name.downcase
26         assert(page.has_link?("notifications-menu"), 'no user menu')
27         page.find("#notifications-menu").click
28         within('.dropdown-menu') do
29           assert_selector 'a', text: 'Log out'
30         end
31       end
32     else  # anonymous
33       assert_text 'Unrestricted public data'
34       within('.navbar-fixed-top') do
35         assert_text Rails.configuration.site_name.downcase
36         assert_no_selector 'a', text: Rails.configuration.site_name.downcase
37         assert_selector 'a', text: 'Log in'
38       end
39     end
40   end
41
42   [
43     [nil, nil, false, false],
44     ['inactive', api_fixture('users')['inactive'], false, false],
45     ['active', api_fixture('users')['active'], true, true],
46   ].each do |token, user, is_active|
47     test "visit public project as user #{token.inspect} when anonymous browsing is enabled" do
48       if !token
49         visit PUBLIC_PROJECT
50       else
51         visit page_with_token(token, PUBLIC_PROJECT)
52       end
53
54       verify_site_navigation_anonymous_enabled user, is_active
55     end
56   end
57
58   test "selection actions when anonymous user accesses shared project" do
59     visit PUBLIC_PROJECT
60
61     assert_selector 'a', text: 'Description'
62     assert_selector 'a', text: 'Data collections'
63     assert_selector 'a', text: 'Jobs and pipelines'
64     assert_selector 'a', text: 'Pipeline templates'
65     assert_selector 'a', text: 'Subprojects'
66     assert_selector 'a', text: 'Advanced'
67     assert_no_selector 'a', text: 'Other objects'
68     assert_no_selector 'button', text: 'Add data'
69
70     click_link 'Data collections'
71     click_button 'Selection'
72     within('.selection-action-container') do
73       assert_selector 'li', text: 'Compare selected'
74       assert_no_selector 'li', text: 'Create new collection with selected collections'
75       assert_no_selector 'li', text: 'Copy selected'
76       assert_no_selector 'li', text: 'Move selected'
77       assert_no_selector 'li', text: 'Remove selected'
78     end
79   end
80
81   test "anonymous user accesses data collections tab in shared project" do
82     visit PUBLIC_PROJECT
83     click_link 'Data collections'
84     collection = api_fixture('collections')['user_agreement_in_anonymously_accessible_project']
85     assert_text 'GNU General Public License'
86
87     assert_selector 'a', text: 'Data collections'
88
89     # click on show collection
90     within "tr[data-object-uuid=\"#{collection['uuid']}\"]" do
91       click_link 'Show'
92     end
93
94     # in collection page
95     assert_no_selector 'input', text: 'Create sharing link'
96     assert_no_text 'Sharing and permissions'
97     assert_no_selector 'a', text: 'Upload'
98     assert_no_selector 'button', 'Selection'
99
100     within '#collection_files tr,li', text: 'GNU_General_Public_License,_version_3.pdf' do
101       assert page.has_no_selector?('[value*="GNU_General_Public_License"]')
102       find 'a[title~=View]'
103       find 'a[title~=Download]'
104     end
105   end
106
107   test 'view file' do
108     magic = rand(2**512).to_s 36
109     CollectionsController.any_instance.stubs(:file_enumerator).returns([magic])
110     collection = api_fixture('collections')['public_text_file']
111     visit '/collections/' + collection['uuid']
112     find('tr,li', text: 'Hello world.txt').
113       find('a[title~=View]').click
114     assert_text magic
115   end
116
117   [
118     'running_job',
119     'completed_job',
120     'pipelineInstance'
121   ].each do |type|
122     test "anonymous user accesses jobs and pipelines tab in shared project and clicks on #{type}" do
123       visit PUBLIC_PROJECT
124       click_link 'Data collections'
125       assert_text 'GNU General Public License'
126
127       click_link 'Jobs and pipelines'
128       assert_text 'Pipeline in publicly accessible project'
129
130       # click on the specified job
131       if type.include? 'job'
132         verify_job_row type
133       else
134         verify_pipeline_instance_row
135       end
136     end
137   end
138
139   def verify_job_row look_for
140     within first('tr', text: look_for) do
141       click_link 'Show'
142     end
143     assert_text 'Public Projects Unrestricted public data'
144     assert_text 'script_version'
145
146     assert_text 'zzzzz-tpzed-xurymjxw79nv3jz' # modified by user
147     assert_no_selector 'a', text: 'zzzzz-tpzed-xurymjxw79nv3jz'
148     assert_no_selector 'a', text: 'Move job'
149     assert_no_selector 'button', text: 'Cancel'
150     assert_no_selector 'button', text: 'Re-run job'
151   end
152
153   def verify_pipeline_instance_row
154     within first('tr[data-kind="arvados#pipelineInstance"]') do
155       assert_text 'Pipeline in publicly accessible project'
156       click_link 'Show'
157     end
158
159     # in pipeline instance page
160     assert_text 'Public Projects Unrestricted public data'
161     assert_text 'This pipeline is complete'
162     assert_no_selector 'a', text: 'Re-run with latest'
163     assert_no_selector 'a', text: 'Re-run options'
164   end
165
166   test "anonymous user accesses pipeline templates tab in shared project" do
167     visit PUBLIC_PROJECT
168     click_link 'Data collections'
169     assert_text 'GNU General Public License'
170
171     assert_selector 'a', text: 'Pipeline templates'
172
173     click_link 'Pipeline templates'
174     assert_text 'Pipeline template in publicly accessible project'
175
176     within first('tr[data-kind="arvados#pipelineTemplate"]') do
177       click_link 'Show'
178     end
179
180     # in template page
181     assert_text 'Public Projects Unrestricted public data'
182     assert_text 'script version'
183     assert_no_selector 'a', text: 'Run this pipeline'
184   end
185
186   test "anonymous user accesses subprojects tab in shared project" do
187     visit PUBLIC_PROJECT + '#Subprojects'
188
189     assert_text 'Subproject in anonymous accessible project'
190
191     within first('tr[data-kind="arvados#group"]') do
192       click_link 'Show'
193     end
194
195     # in subproject
196     assert_text 'Description for subproject in anonymous accessible project'
197   end
198
199   [
200     ['pipeline_in_publicly_accessible_project', true],
201     ['pipeline_in_publicly_accessible_project_but_other_objects_elsewhere', false],
202     ['pipeline_in_publicly_accessible_project_but_other_objects_elsewhere', false, 'spectator'],
203     ['pipeline_in_publicly_accessible_project_but_other_objects_elsewhere', true, 'admin'],
204
205     ['completed_job_in_publicly_accessible_project', true],
206     ['job_in_publicly_accessible_project_but_other_objects_elsewhere', false],
207   ].each do |fixture, objects_readable, user=nil|
208     test "access #{fixture} in public project with objects readable=#{objects_readable} with user #{user}" do
209       pipeline_page = true if fixture.include?('pipeline')
210
211       if pipeline_page
212         object = api_fixture('pipeline_instances')[fixture]
213         page = "/pipeline_instances/#{object['uuid']}"
214         expect_log_text = "Log for foo"
215       else      # job
216         object = api_fixture('jobs')[fixture]
217         page = "/jobs/#{object['uuid']}"
218         expect_log_text = "stderr crunchstat"
219       end
220
221       if user
222         visit page_with_token user, page
223       else
224         visit page
225       end
226
227       # click job link, if in pipeline page
228       click_link 'foo' if pipeline_page
229
230       if objects_readable
231         assert_selector 'a[href="#Log"]', text: 'Log'
232         assert_no_selector 'a[data-toggle="disabled"]', text: 'Log'
233         assert_no_text 'Output data not available'
234         if pipeline_page
235           assert_text 'This pipeline was created from'
236           assert_selector 'a', text: object['components']['foo']['job']['uuid']
237           # We'd like to test the Log tab on job pages too, but we can't right
238           # now because Poltergeist 1.x doesn't support JavaScript's
239           # Function.prototype.bind, which is used by job_log_graph.js.
240           click_link "Log"
241           assert_text expect_log_text
242         end
243       else
244         assert_selector 'a[data-toggle="disabled"]', text: 'Log'
245         assert_text 'Output data not available'
246         assert_text object['job']
247         if pipeline_page
248           assert_no_text 'This pipeline was created from'  # template is not readable
249           assert_no_selector 'a', text: object['components']['foo']['job']['uuid']
250         end
251         click_link "Log"
252         assert_text 'Output data not available'
253         assert_no_text expect_log_text
254       end
255     end
256   end
257
258   [
259     ['new_pipeline_in_publicly_accessible_project', true],
260     ['new_pipeline_in_publicly_accessible_project', true, 'spectator'],
261     ['new_pipeline_in_publicly_accessible_project_but_other_objects_elsewhere', false],
262     ['new_pipeline_in_publicly_accessible_project_but_other_objects_elsewhere', false, 'spectator'],
263     ['new_pipeline_in_publicly_accessible_project_but_other_objects_elsewhere', true, 'admin'],
264     ['new_pipeline_in_publicly_accessible_project_with_dataclass_file_and_other_objects_elsewhere', false],
265     ['new_pipeline_in_publicly_accessible_project_with_dataclass_file_and_other_objects_elsewhere', false, 'spectator'],
266     ['new_pipeline_in_publicly_accessible_project_with_dataclass_file_and_other_objects_elsewhere', true, 'admin'],
267   ].each do |fixture, objects_readable, user=nil|
268     test "access #{fixture} in public project with objects readable=#{objects_readable} with user #{user}" do
269       object = api_fixture('pipeline_instances')[fixture]
270       page = "/pipeline_instances/#{object['uuid']}"
271       if user
272         visit page_with_token user, page
273       else
274         visit page
275       end
276
277       # click Components tab
278       click_link 'Components'
279
280       if objects_readable
281         assert_text 'This pipeline was created from'
282         if user == 'admin'
283           assert_text 'input'
284           assert_selector 'a', text: 'Choose'
285           assert_selector 'a', text: 'Run'
286           assert_no_selector 'a.disabled', text: 'Run'
287         else
288           assert_selector 'a', text: object['components']['foo']['script_parameters']['input']['value']
289           user ? (assert_selector 'a', text: 'Run') : (assert_no_selector 'a', text: 'Run')
290         end
291       else
292         assert_no_text 'This pipeline was created from'  # template is not readable
293         input = object['components']['foo']['script_parameters']['input']['value']
294         assert_no_selector 'a', text: input
295         if user
296           input = input.gsub('/', '\\/')
297           assert_text "One or more inputs provided are not readable"
298           assert_selector "input[type=text][value=#{input}]"
299           assert_selector 'a.disabled', text: 'Run'
300         else
301           assert_no_text "One or more inputs provided are not readable"
302           assert_text input
303           assert_no_selector 'a', text: 'Run'
304         end
305       end
306     end
307   end
308
309   test "anonymous user accesses collection in shared project" do
310     visit "/collections/#{api_fixture('collections')['public_text_file']['uuid']}"
311
312     # in collection page
313     assert_text 'Public Projects Unrestricted public data'
314     assert_text 'Hello world'
315     assert_text 'Content address'
316     assert_selector 'a', text: 'Provenance graph'
317   end
318 end