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