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: "#{user['email']}"
26 find('a', text: "#{user['email']}").click
27 within('.dropdown-menu') do
28 assert_selector 'a', text: 'Log out'
32 assert_text 'Unrestricted public data'
33 within('.navbar-fixed-top') do
34 assert_selector 'a', text: 'Log in'
40 [nil, nil, false, false],
41 ['inactive', api_fixture('users')['inactive'], false, false],
42 ['active', api_fixture('users')['active'], true, true],
43 ].each do |token, user, is_active|
44 test "visit public project as user #{token.inspect} when anonymous browsing is enabled" do
48 visit page_with_token(token, PUBLIC_PROJECT)
51 verify_site_navigation_anonymous_enabled user, is_active
55 test "selection actions when anonymous user accesses shared project" do
58 assert_selector 'a', text: 'Data collections'
59 assert_selector 'a', text: 'Jobs and pipelines'
60 assert_selector 'a', text: 'Pipeline templates'
61 assert_selector 'a', text: 'Advanced'
62 assert_no_selector 'a', text: 'Subprojects'
63 assert_no_selector 'a', text: 'Other objects'
64 assert_no_selector 'button', text: 'Add data'
66 click_button 'Selection'
67 within('.selection-action-container') do
68 assert_selector 'li', text: 'Compare selected'
69 assert_no_selector 'li', text: 'Create new collection with selected collections'
70 assert_no_selector 'li', text: 'Copy selected'
71 assert_no_selector 'li', text: 'Move selected'
72 assert_no_selector 'li', text: 'Remove selected'
76 test "anonymous user accesses data collections tab in shared project" do
78 collection = api_fixture('collections')['user_agreement_in_anonymously_accessible_project']
79 assert_text 'GNU General Public License'
81 assert_selector 'a', text: 'Data collections'
83 # click on show collection
84 within "tr[data-object-uuid=\"#{collection['uuid']}\"]" do
89 assert_no_selector 'input', text: 'Create sharing link'
90 assert_no_text 'Sharing and permissions'
91 assert_no_selector 'a', text: 'Upload'
92 assert_no_selector 'button', 'Selection'
94 within '#collection_files tr,li', text: 'GNU_General_Public_License,_version_3.pdf' do
96 find 'a[title~=Download]'
101 magic = rand(2**512).to_s 36
102 CollectionsController.any_instance.stubs(:file_enumerator).returns([magic])
103 collection = api_fixture('collections')['public_text_file']
104 visit '/collections/' + collection['uuid']
105 find('tr,li', text: 'Hello world.txt').
106 find('a[title~=View]').click
115 test "anonymous user accesses jobs and pipelines tab in shared project and clicks on #{type}" do
117 assert_text 'GNU General Public License'
119 click_link 'Jobs and pipelines'
120 assert_text 'Pipeline in publicly accessible project'
122 # click on the specified job
123 if type.include? 'job'
126 verify_pipeline_instance_row
131 def verify_job_row look_for
132 within first('tr', text: look_for) do
135 assert_text 'script_version'
137 assert_text 'zzzzz-tpzed-xurymjxw79nv3jz' # modified by user
138 assert_no_selector 'a', text: 'zzzzz-tpzed-xurymjxw79nv3jz'
139 assert_no_selector 'a', text: 'Move job'
140 assert_no_selector 'button', text: 'Cancel'
141 assert_no_selector 'button', text: 'Re-run job'
144 def verify_pipeline_instance_row
145 within first('tr[data-kind="arvados#pipelineInstance"]') do
146 assert_text 'Pipeline in publicly accessible project'
150 # in pipeline instance page
151 assert_text 'This pipeline is complete'
152 assert_no_selector 'a', text: 'Re-run with latest'
153 assert_no_selector 'a', text: 'Re-run options'
156 test "anonymous user accesses pipeline templates tab in shared project" do
158 assert_text 'GNU General Public License'
160 assert_selector 'a', text: 'Pipeline templates'
162 click_link 'Pipeline templates'
163 assert_text 'Pipeline template in publicly accessible project'
165 within first('tr[data-kind="arvados#pipelineTemplate"]') do
170 assert_text 'script version'
171 assert_no_selector 'a', text: 'Run this pipeline'