1 require 'integration_helper'
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
11 Rails.configuration.anonymous_user_token = api_fixture('api_client_authorizations')['anonymous']['api_token']
14 PUBLIC_PROJECT = "/projects/#{api_fixture('groups')['anonymously_accessible_project']['uuid']}"
16 def verify_site_navigation_anonymous_enabled user, is_active
19 assert_text 'Unrestricted public data'
20 assert_selector 'a', text: 'Projects'
21 page.find("#projects-menu").click
22 within('.dropdown-menu') do
23 assert_selector 'a', text: 'Search all projects'
24 assert_selector "a[href=\"/projects/public\"]", text: 'Browse public projects'
25 assert_selector 'a', text: 'Add a new project'
26 assert_selector 'li[class="dropdown-header"]', text: 'My projects'
29 assert_text 'indicate that you have read and accepted the user agreement'
31 within('.navbar-fixed-top') do
32 assert_selector 'a', text: Rails.configuration.site_name.downcase
33 assert(page.has_link?("notifications-menu"), 'no user menu')
34 page.find("#notifications-menu").click
35 within('.dropdown-menu') do
36 assert_selector 'a', text: 'Log out'
40 assert_text 'Unrestricted public data'
41 within('.navbar-fixed-top') do
42 assert_text Rails.configuration.site_name.downcase
43 assert_no_selector 'a', text: Rails.configuration.site_name.downcase
44 assert_selector 'a', text: 'Log in'
45 assert_selector 'a', text: 'Browse public projects'
51 [nil, nil, false, false],
52 ['inactive', api_fixture('users')['inactive'], false, false],
53 ['active', api_fixture('users')['active'], true, true],
54 ].each do |token, user, is_active|
55 test "visit public project as user #{token.inspect} when anonymous browsing is enabled" do
59 visit page_with_token(token, PUBLIC_PROJECT)
62 verify_site_navigation_anonymous_enabled user, is_active
66 test "selection actions when anonymous user accesses shared project" do
69 assert_selector 'a', text: 'Description'
70 assert_selector 'a', text: 'Data collections'
71 assert_selector 'a', text: 'Pipelines and processes'
72 assert_selector 'a', text: 'Pipeline templates'
73 assert_selector 'a', text: 'Subprojects'
74 assert_selector 'a', text: 'Advanced'
75 assert_no_selector 'a', text: 'Other objects'
76 assert_no_selector 'button', text: 'Add data'
78 click_link 'Data collections'
79 click_button 'Selection'
80 within('.selection-action-container') do
81 assert_selector 'li', text: 'Compare selected'
82 assert_no_selector 'li', text: 'Create new collection with selected collections'
83 assert_no_selector 'li', text: 'Copy selected'
84 assert_no_selector 'li', text: 'Move selected'
85 assert_no_selector 'li', text: 'Remove selected'
89 test "anonymous user accesses data collections tab in shared project" do
91 click_link 'Data collections'
92 collection = api_fixture('collections')['user_agreement_in_anonymously_accessible_project']
93 assert_text 'GNU General Public License'
95 assert_selector 'a', text: 'Data collections'
97 # click on show collection
98 within "tr[data-object-uuid=\"#{collection['uuid']}\"]" do
103 assert_no_selector 'input', text: 'Create sharing link'
104 assert_no_text 'Sharing and permissions'
105 assert_no_selector 'a', text: 'Upload'
106 assert_no_selector 'button', 'Selection'
108 within '#collection_files tr,li', text: 'GNU_General_Public_License,_version_3.pdf' do
109 assert page.has_no_selector?('[value*="GNU_General_Public_License"]')
110 find 'a[title~=View]'
111 find 'a[title~=Download]'
116 magic = rand(2**512).to_s 36
117 CollectionsController.any_instance.stubs(:file_enumerator).returns([magic])
118 collection = api_fixture('collections')['public_text_file']
119 visit '/collections/' + collection['uuid']
120 find('tr,li', text: 'Hello world.txt').
121 find('a[title~=View]').click
126 'running anonymously accessible cr',
129 test "anonymous user accesses pipelines and processes tab in shared project and clicks on '#{proc}'" do
131 click_link 'Data collections'
132 assert_text 'GNU General Public License'
134 click_link 'Pipelines and processes'
135 assert_text 'Pipeline in publicly accessible project'
137 if proc.include? 'pipeline'
138 verify_pipeline_instance_row
140 verify_container_request_row proc
145 def verify_container_request_row look_for
146 within first('tr', text: look_for) do
149 assert_text 'Public Projects Unrestricted public data'
150 assert_text 'command'
152 assert_text 'zzzzz-tpzed-xurymjxw79nv3jz' # modified by user
153 assert_no_selector 'a', text: 'zzzzz-tpzed-xurymjxw79nv3jz'
154 assert_no_selector 'button', text: 'Cancel'
157 def verify_pipeline_instance_row
158 within first('tr[data-kind="arvados#pipelineInstance"]') do
159 assert_text 'Pipeline in publicly accessible project'
163 # in pipeline instance page
164 assert_text 'Public Projects Unrestricted public data'
165 assert_text 'This pipeline is complete'
166 assert_no_selector 'a', text: 'Re-run with latest'
167 assert_no_selector 'a', text: 'Re-run options'
174 test "anonymous user accesses pipeline templates tab in shared project and click on #{type}" do
176 click_link 'Data collections'
177 assert_text 'GNU General Public License'
179 assert_selector 'a', text: 'Pipeline templates'
181 click_link 'Pipeline templates'
182 assert_text 'Pipeline template in publicly accessible project'
183 assert_text 'Workflow with input specifications'
185 if type == 'pipelineTemplate'
186 within first('tr[data-kind="arvados#pipelineTemplate"]') do
191 assert_text 'Public Projects Unrestricted public data'
192 assert_text 'script version'
193 assert_no_selector 'a', text: 'Run this pipeline'
195 within first('tr[data-kind="arvados#workflow"]') do
200 assert_text 'Public Projects Unrestricted public data'
201 assert_text 'this workflow has inputs specified'
206 test "anonymous user accesses subprojects tab in shared project" do
207 visit PUBLIC_PROJECT + '#Subprojects'
209 assert_text 'Subproject in anonymous accessible project'
211 within first('tr[data-kind="arvados#group"]') do
216 assert_text 'Description for subproject in anonymous accessible project'
220 ['pipeline_in_publicly_accessible_project', true],
221 ['pipeline_in_publicly_accessible_project_but_other_objects_elsewhere', false],
222 ['pipeline_in_publicly_accessible_project_but_other_objects_elsewhere', false, 'spectator'],
223 ['pipeline_in_publicly_accessible_project_but_other_objects_elsewhere', true, 'admin'],
225 ['completed_job_in_publicly_accessible_project', true],
226 ['running_job_in_publicly_accessible_project', true],
227 ['job_in_publicly_accessible_project_but_other_objects_elsewhere', false],
228 ].each do |fixture, objects_readable, user=nil|
229 test "access #{fixture} in public project with objects readable=#{objects_readable} with user #{user}" do
230 pipeline_page = true if fixture.include?('pipeline')
233 object = api_fixture('pipeline_instances')[fixture]
234 page_link = "/pipeline_instances/#{object['uuid']}"
235 expect_log_text = "Log for foo"
237 object = api_fixture('jobs')[fixture]
238 page_link = "/jobs/#{object['uuid']}"
239 expect_log_text = "stderr crunchstat"
243 visit page_with_token user, page_link
248 # click job link, if in pipeline page
249 click_link 'foo' if pipeline_page
252 assert_selector 'a[href="#Log"]', text: 'Log'
253 assert_no_selector 'a[data-toggle="disabled"]', text: 'Log'
254 assert_no_text 'Output data not available'
256 assert_text 'This pipeline was created from'
257 job_id = object['components']['foo']['job']['uuid']
258 assert_selector 'a', text: job_id
259 assert_selector "a[href=\"/jobs/#{job_id}#Log\"]", text: 'Log'
261 # We'd like to test the Log tab on job pages too, but we can't right
262 # now because Poltergeist 1.x doesn't support JavaScript's
263 # Function.prototype.bind, which is used by job_log_graph.js.
264 find(:xpath, "//a[@href='#Log']").click
265 assert_text expect_log_text
268 assert_selector 'a[data-toggle="disabled"]', text: 'Log'
269 assert_text 'Output data not available'
270 assert_text object['job']
272 assert_no_text 'This pipeline was created from' # template is not readable
273 assert_no_selector 'a', text: object['components']['foo']['job']['uuid']
274 assert_text 'Log unavailable'
276 find(:xpath, "//a[@href='#Log']").click
277 assert_text 'Output data not available'
278 assert_no_text expect_log_text
284 ['new_pipeline_in_publicly_accessible_project', true],
285 ['new_pipeline_in_publicly_accessible_project', true, 'spectator'],
286 ['new_pipeline_in_publicly_accessible_project_but_other_objects_elsewhere', false],
287 ['new_pipeline_in_publicly_accessible_project_but_other_objects_elsewhere', false, 'spectator'],
288 ['new_pipeline_in_publicly_accessible_project_but_other_objects_elsewhere', true, 'admin'],
289 ['new_pipeline_in_publicly_accessible_project_with_dataclass_file_and_other_objects_elsewhere', false],
290 ['new_pipeline_in_publicly_accessible_project_with_dataclass_file_and_other_objects_elsewhere', false, 'spectator'],
291 ['new_pipeline_in_publicly_accessible_project_with_dataclass_file_and_other_objects_elsewhere', true, 'admin'],
292 ].each do |fixture, objects_readable, user=nil|
293 test "access #{fixture} in public project with objects readable=#{objects_readable} with user #{user}" do
294 object = api_fixture('pipeline_instances')[fixture]
295 page = "/pipeline_instances/#{object['uuid']}"
297 visit page_with_token user, page
302 # click Components tab
303 click_link 'Components'
306 assert_text 'This pipeline was created from'
309 assert_selector 'a', text: 'Choose'
310 assert_selector 'a', text: 'Run'
311 assert_no_selector 'a.disabled', text: 'Run'
313 assert_selector 'a', text: object['components']['foo']['script_parameters']['input']['value']
314 user ? (assert_selector 'a', text: 'Run') : (assert_no_selector 'a', text: 'Run')
317 assert_no_text 'This pipeline was created from' # template is not readable
318 input = object['components']['foo']['script_parameters']['input']['value']
319 assert_no_selector 'a', text: input
321 input = input.gsub('/', '\\/')
322 assert_text "One or more inputs provided are not readable"
323 assert_selector "input[type=text][value=#{input}]"
324 assert_selector 'a.disabled', text: 'Run'
326 assert_no_text "One or more inputs provided are not readable"
328 assert_no_selector 'a', text: 'Run'