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
13 def visit_publicly_accessible_project token=nil, use_config=true, path=nil
15 Rails.configuration.anonymous_user_token = api_fixture('api_client_authorizations')['anonymous']['api_token']
17 Rails.configuration.anonymous_user_token = false
20 path = "/projects/#{api_fixture('groups')['anonymously_accessible_project']['uuid']}/?public_data=true" if !path
23 visit page_with_token(token, path)
29 def verify_site_navigation_anonymous_enabled user, is_active
32 assert_text 'Unrestricted public data'
33 assert_selector 'a', text: 'Projects'
35 assert_text 'indicate that you have read and accepted the user agreement'
37 within('.navbar-fixed-top') do
38 assert_no_text 'You are viewing public data'
39 assert_selector 'a', text: "#{user['email']}"
40 find('a', text: "#{user['email']}").click
41 within('.dropdown-menu') do
42 assert_selector 'a', text: 'Log out'
46 assert_text 'Unrestricted public data'
47 within('.navbar-fixed-top') do
48 assert_text 'You are viewing public data'
49 anonymous_user = api_fixture('users')['anonymous']
50 assert_selector 'a', "#{anonymous_user['email']}"
51 find('a', text: "#{anonymous_user['email']}").click
52 within('.dropdown-menu') do
53 assert_selector 'a', text: 'Log in'
54 assert_no_selector 'a', text: 'Log out'
61 [nil, nil, false, false],
62 ['inactive', api_fixture('users')['inactive'], false, false],
63 ['active', api_fixture('users')['active'], true, true],
64 ].each do |token, user, is_active|
65 test "visit public project as user #{token.inspect} when anonymous browsing is enabled" do
66 visit_publicly_accessible_project token
67 verify_site_navigation_anonymous_enabled user, is_active
71 test "anonymous user visit public project when anonymous browsing not enabled and expect to see login page" do
72 visit_publicly_accessible_project nil, false
73 assert_text 'Please log in'
76 test "visit non-public project as anonymous when anonymous browsing is enabled and expect page not found" do
77 visit_publicly_accessible_project nil, true,
78 "/projects/#{api_fixture('groups')['aproject']['uuid']}/?public_data=true"
79 assert_text 'Not Found'
82 test "selection actions when anonymous user accesses shared project" do
83 visit_publicly_accessible_project
85 assert_selector 'a', text: 'Data collections'
86 assert_selector 'a', text: 'Jobs and pipelines'
87 assert_selector 'a', text: 'Pipeline templates'
88 assert_selector 'a', text: 'Advanced'
89 assert_no_selector 'a', text: 'Subprojects'
90 assert_no_selector 'a', text: 'Other objects'
91 assert_no_selector 'button', text: 'Add data'
93 click_button 'Selection'
94 within('.selection-action-container') do
95 assert_selector 'li', text: 'Compare selected'
96 assert_no_selector 'li', text: 'Create new collection with selected collections'
97 assert_no_selector 'li', text: 'Copy selected'
98 assert_no_selector 'li', text: 'Move selected'
99 assert_no_selector 'li', text: 'Remove selected'
104 ['All pipelines', 'Pipeline in publicly accessible project'],
105 ['All jobs', 'job submitted'],
106 ['All collections', 'GNU_General_Public_License,_version_3.pdf'],
107 ].each do |selector, expectation|
108 test "verify dashboard when anonymous user accesses shared project and click #{selector}" do
109 visit_publicly_accessible_project
112 click_link 'You are viewing public data'
114 assert_no_selector 'a', text: 'Run a pipeline'
115 assert_selector 'a', text: selector
117 assert_text expectation
121 test "anonymous user accesses data collections tab in shared project" do
122 visit_publicly_accessible_project
124 assert_selector 'a', text: 'Data collections (1)'
126 # click on show collection
127 within first('tr[data-kind="arvados#collection"]') do
132 assert_no_selector 'input', text: 'Create sharing link'
133 assert_no_selector 'a', text: 'Upload'
134 assert_no_selector 'button', 'Selection'
136 within ('#collection_files') do
137 assert_text 'GNU_General_Public_License,_version_3.pdf'
138 # how do i assert the view and download link existence?
147 test "anonymous user accesses jobs and pipelines tab in shared project and clicks on #{type}" do
148 visit_publicly_accessible_project
149 click_link 'Jobs and pipelines'
150 assert_text 'Pipeline in publicly accessible project'
152 # click on type specified collection
153 if type.include? 'job'
156 verify_pipeline_instance_row
161 def verify_job_row look_for
162 within first('tr', text: look_for) do
165 assert_text 'script_version'
167 assert_text 'zzzzz-tpzed-xurymjxw79nv3jz' # modified by user
168 assert_no_selector 'a', text: 'zzzzz-tpzed-xurymjxw79nv3jz'
169 assert_no_selector 'a', text: 'Log'
170 assert_no_selector 'a', text: 'Move job'
171 assert_no_selector 'button', text: 'Cancel'
172 assert_no_selector 'button', text: 'Re-run job'
175 def verify_pipeline_instance_row
176 within first('tr[data-kind="arvados#pipelineInstance"]') do
177 assert_text 'Pipeline in publicly accessible project'
181 # in pipeline instance page
182 assert_text 'This pipeline is complete'
183 assert_no_selector 'a', text: 'Re-run with latest'
184 assert_no_selector 'a', text: 'Re-run options'
187 test "anonymous user accesses pipeline templates tab in shared project" do
188 visit_publicly_accessible_project
190 assert_selector 'a', 'Pipeline templates (1)'
192 click_link 'Pipeline templates'
193 assert_text 'Pipeline template in publicly accessible project'
195 within first('tr[data-kind="arvados#pipelineTemplate"]') do
200 assert_text 'script version'
201 assert_no_selector 'a', text: 'Run this pipeline'
208 test "anonymous user accesses publicly accessible project and then traverses to #{page}" do
209 # when anonymous, first visit publicly accessible project
210 visit_publicly_accessible_project
214 assert_no_selector 'a', text: 'Add a new user'
215 elsif page == '/groups'
216 assert_no_selector 'button', text: 'Add a new group'