1 # Copyright (C) The Arvados Authors. All rights reserved.
3 # SPDX-License-Identifier: AGPL-3.0
5 require 'integration_helper'
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
15 Rails.configuration.Users.AnonymousUserToken = api_fixture('api_client_authorizations')['anonymous']['api_token']
18 PUBLIC_PROJECT = "/projects/#{api_fixture('groups')['anonymously_accessible_project']['uuid']}"
20 def verify_site_navigation_anonymous_enabled 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'
33 assert_text 'indicate that you have read and accepted the user agreement'
35 within('.navbar-fixed-top') do
36 assert_selector 'a', text: Rails.configuration.Workbench.SiteName.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'
44 assert_text 'Unrestricted public data'
45 within('.navbar-fixed-top') do
46 assert_text Rails.configuration.Workbench.SiteName.downcase
47 assert_no_selector 'a', text: Rails.configuration.Workbench.SiteName.downcase
48 assert_selector 'a', text: 'Log in'
49 assert_selector 'a', text: 'Browse public projects'
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
63 visit page_with_token(token, PUBLIC_PROJECT)
66 verify_site_navigation_anonymous_enabled user, is_active
70 test "selection actions when anonymous user accesses shared project" do
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'
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'
93 test "anonymous user accesses data collections tab in shared project" do
95 click_link 'Data collections'
96 collection = api_fixture('collections')['user_agreement_in_anonymously_accessible_project']
97 assert_text 'GNU General Public License'
99 assert_selector 'a', text: 'Data collections'
101 # click on show collection
102 within "tr[data-object-uuid=\"#{collection['uuid']}\"]" do
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'
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]'
122 magic = rand(2**512).to_s 36
123 owner = api_fixture('groups')['anonymously_accessible_project']['uuid']
124 col = upload_data_and_get_collection(magic, 'admin', "Hello\\040world.txt", owner)
125 visit '/collections/' + col.uuid
126 find('tr,li', text: 'Hello world.txt').
127 find('a[title~=View]').click
132 'running anonymously accessible cr',
135 test "anonymous user accesses pipelines and processes tab in shared project and clicks on '#{proc}'" do
137 click_link 'Data collections'
138 assert_text 'GNU General Public License'
140 click_link 'Pipelines and processes'
141 assert_text 'Pipeline in publicly accessible project'
143 if proc.include? 'pipeline'
144 verify_pipeline_instance_row
146 verify_container_request_row proc
151 def verify_container_request_row look_for
152 within first('tr', text: look_for) do
155 assert_text 'Public Projects Unrestricted public data'
156 assert_text 'command'
158 assert_text 'zzzzz-tpzed-xurymjxw79nv3jz' # modified by user
159 assert_no_selector 'a', text: 'zzzzz-tpzed-xurymjxw79nv3jz'
160 assert_no_selector 'button', text: 'Cancel'
163 def verify_pipeline_instance_row
164 within first('tr[data-kind="arvados#pipelineInstance"]') do
165 assert_text 'Pipeline in publicly accessible project'
169 # in pipeline instance page
170 assert_text 'Public Projects Unrestricted public data'
171 assert_text 'This pipeline is complete'
172 assert_no_selector 'a', text: 'Re-run with latest'
173 assert_no_selector 'a', text: 'Re-run options'
180 test "anonymous user accesses pipeline templates tab in shared project and click on #{type}" do
182 click_link 'Data collections'
183 assert_text 'GNU General Public License'
185 assert_selector 'a', text: 'Pipeline templates'
187 click_link 'Pipeline templates'
188 assert_text 'Pipeline template in publicly accessible project'
189 assert_text 'Workflow with input specifications'
191 if type == 'pipelineTemplate'
192 within first('tr[data-kind="arvados#pipelineTemplate"]') do
197 assert_text 'Public Projects Unrestricted public data'
198 assert_text 'script version'
199 assert_no_selector 'a', text: 'Run this pipeline'
201 within first('tr[data-kind="arvados#workflow"]') do
206 assert_text 'Public Projects Unrestricted public data'
207 assert_text 'this workflow has inputs specified'
212 test "anonymous user accesses subprojects tab in shared project" do
213 visit PUBLIC_PROJECT + '#Subprojects'
215 assert_text 'Subproject in anonymous accessible project'
217 within first('tr[data-kind="arvados#group"]') do
222 assert_text 'Description for subproject in anonymous accessible project'
226 ['pipeline_in_publicly_accessible_project', true],
227 ['pipeline_in_publicly_accessible_project_but_other_objects_elsewhere', false],
228 ['pipeline_in_publicly_accessible_project_but_other_objects_elsewhere', false, 'spectator'],
229 ['pipeline_in_publicly_accessible_project_but_other_objects_elsewhere', true, 'admin'],
231 ['completed_job_in_publicly_accessible_project', true],
232 ['running_job_in_publicly_accessible_project', true],
233 ['job_in_publicly_accessible_project_but_other_objects_elsewhere', false],
234 ].each do |fixture, objects_readable, user=nil|
235 test "access #{fixture} in public project with objects readable=#{objects_readable} with user #{user}" do
236 pipeline_page = true if fixture.include?('pipeline')
239 object = api_fixture('pipeline_instances')[fixture]
240 page_link = "/pipeline_instances/#{object['uuid']}"
241 expect_log_text = "Log for foo"
243 object = api_fixture('jobs')[fixture]
244 page_link = "/jobs/#{object['uuid']}"
245 expect_log_text = "stderr crunchstat"
249 visit page_with_token user, page_link
254 # click job link, if in pipeline page
255 click_link 'foo' if pipeline_page
258 assert_selector 'a[href="#Log"]', text: 'Log'
259 assert_no_selector 'a[data-toggle="disabled"]', text: 'Log'
260 assert_no_text 'zzzzz-4zz18-bv31uwvy3neko21 (Unavailable)'
262 assert_text 'This pipeline was created from'
263 job_id = object['components']['foo']['job']['uuid']
264 assert_selector 'a', text: job_id
265 assert_selector "a[href=\"/jobs/#{job_id}#Log\"]", text: 'Log'
267 # We'd like to test the Log tab on job pages too, but we can't right
268 # now because Poltergeist 1.x doesn't support JavaScript's
269 # Function.prototype.bind, which is used by job_log_graph.js.
270 find(:xpath, "//a[@href='#Log']").click
271 assert_text expect_log_text
274 assert_selector 'a[data-toggle="disabled"]', text: 'Log'
275 assert_text 'zzzzz-4zz18-bv31uwvy3neko21 (Unavailable)'
276 assert_text object['job']
278 assert_no_text 'This pipeline was created from' # template is not readable
279 assert_no_selector 'a', text: object['components']['foo']['job']['uuid']
280 assert_text 'Log unavailable'
282 find(:xpath, "//a[@href='#Log']").click
283 assert_text 'zzzzz-4zz18-bv31uwvy3neko21 (Unavailable)'
284 assert_no_text expect_log_text
290 ['new_pipeline_in_publicly_accessible_project', true],
291 ['new_pipeline_in_publicly_accessible_project', true, 'spectator'],
292 ['new_pipeline_in_publicly_accessible_project_but_other_objects_elsewhere', false],
293 ['new_pipeline_in_publicly_accessible_project_but_other_objects_elsewhere', false, 'spectator'],
294 ['new_pipeline_in_publicly_accessible_project_but_other_objects_elsewhere', true, 'admin'],
295 ['new_pipeline_in_publicly_accessible_project_with_dataclass_file_and_other_objects_elsewhere', false],
296 ['new_pipeline_in_publicly_accessible_project_with_dataclass_file_and_other_objects_elsewhere', false, 'spectator'],
297 ['new_pipeline_in_publicly_accessible_project_with_dataclass_file_and_other_objects_elsewhere', true, 'admin'],
298 ].each do |fixture, objects_readable, user=nil|
299 test "access #{fixture} in public project with objects readable=#{objects_readable} with user #{user}" do
300 object = api_fixture('pipeline_instances')[fixture]
301 page = "/pipeline_instances/#{object['uuid']}"
303 visit page_with_token user, page
308 # click Components tab
309 click_link 'Components'
312 assert_text 'This pipeline was created from'
315 assert_selector 'a', text: 'Choose'
316 assert_selector 'a', text: 'Run'
317 assert_no_selector 'a.disabled', text: 'Run'
319 assert_selector 'a', text: object['components']['foo']['script_parameters']['input']['value']
320 user ? (assert_selector 'a', text: 'Run') : (assert_no_selector 'a', text: 'Run')
323 assert_no_text 'This pipeline was created from' # template is not readable
324 input = object['components']['foo']['script_parameters']['input']['value']
325 assert_no_selector 'a', text: input
327 input = input.gsub('/', '\\/')
328 assert_text "One or more inputs provided are not readable"
329 assert_selector "input[type=text][value=#{input}]"
330 assert_selector 'a.disabled', text: 'Run'
332 assert_no_text "One or more inputs provided are not readable"
334 assert_no_selector 'a', text: 'Run'