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'
22 assert_text 'indicate that you have read and accepted the user agreement'
24 within('.navbar-fixed-top') do
25 assert_selector 'a', text: Rails.configuration.site_name.downcase
26 assert_selector 'a', text: "#{user['email']}"
27 find('a', text: "#{user['email']}").click
28 within('.dropdown-menu') do
29 assert_selector 'a', text: 'Log out'
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'
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
51 visit page_with_token(token, PUBLIC_PROJECT)
54 verify_site_navigation_anonymous_enabled user, is_active
58 test "selection actions when anonymous user accesses shared project" do
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: 'Advanced'
66 assert_no_selector 'a', text: 'Subprojects'
67 assert_no_selector 'a', text: 'Other objects'
68 assert_no_selector 'button', text: 'Add data'
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'
81 test "anonymous user accesses data collections tab in shared project" do
83 click_link 'Data collections'
84 collection = api_fixture('collections')['user_agreement_in_anonymously_accessible_project']
85 assert_text 'GNU General Public License'
87 assert_selector 'a', text: 'Data collections'
89 # click on show collection
90 within "tr[data-object-uuid=\"#{collection['uuid']}\"]" do
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'
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]'
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
122 test "anonymous user accesses jobs and pipelines tab in shared project and clicks on #{type}" do
124 click_link 'Data collections'
125 assert_text 'GNU General Public License'
127 click_link 'Jobs and pipelines'
128 assert_text 'Pipeline in publicly accessible project'
130 # click on the specified job
131 if type.include? 'job'
134 verify_pipeline_instance_row
139 def verify_job_row look_for
140 within first('tr', text: look_for) do
143 assert_text 'script_version'
145 assert_text 'zzzzz-tpzed-xurymjxw79nv3jz' # modified by user
146 assert_no_selector 'a', text: 'zzzzz-tpzed-xurymjxw79nv3jz'
147 assert_no_selector 'a', text: 'Move job'
148 assert_no_selector 'button', text: 'Cancel'
149 assert_no_selector 'button', text: 'Re-run job'
152 def verify_pipeline_instance_row
153 within first('tr[data-kind="arvados#pipelineInstance"]') do
154 assert_text 'Pipeline in publicly accessible project'
158 # in pipeline instance page
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'
164 test "anonymous user accesses pipeline templates tab in shared project" do
166 click_link 'Data collections'
167 assert_text 'GNU General Public License'
169 assert_selector 'a', text: 'Pipeline templates'
171 click_link 'Pipeline templates'
172 assert_text 'Pipeline template in publicly accessible project'
174 within first('tr[data-kind="arvados#pipelineTemplate"]') do
179 assert_text 'script version'
180 assert_no_selector 'a', text: 'Run this pipeline'