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 verify_homepage_anonymous_enabled user, is_active, has_profile
17 assert_text 'Unrestricted public data'
18 assert_selector 'a', text: 'Projects'
20 assert_text 'All required fields must be completed before you can proceed'
23 assert_text 'indicate that you have read and accepted the user agreement'
25 within('.navbar-fixed-top') do
26 assert_no_text 'You are viewing public data'
27 assert_selector 'a', text: "#{user['email']}"
28 find('a', text: "#{user['email']}").click
29 within('.dropdown-menu') do
30 assert_selector 'a', text: 'Log out'
34 assert_text 'Unrestricted public data'
35 within('.navbar-fixed-top') do
36 assert_text 'You are viewing public data'
37 anonymous_user = api_fixture('users')['anonymous']
38 assert_selector 'a', "#{anonymous_user['email']}"
39 find('a', text: "#{anonymous_user['email']}").click
40 within('.dropdown-menu') do
41 assert_selector 'a', text: 'Log in'
42 assert_no_selector 'a', text: 'Log out'
49 [nil, nil, false, false],
50 ['inactive', api_fixture('users')['inactive'], false, false],
51 ['active', api_fixture('users')['active'], true, true],
52 ['active_no_prefs_profile', api_fixture('users')['active_no_prefs_profile'], true, false],
53 ['admin', api_fixture('users')['admin'], true, true],
54 ].each do |token, user, is_active, has_profile|
55 test "visit public project as user #{token} when anonymous browsing is enabled" do
56 Rails.configuration.anonymous_user_token = api_fixture('api_client_authorizations')['anonymous']['api_token']
58 path = "/projects/#{api_fixture('groups')['anonymously_accessible_project']['uuid']}/?public_data=true"
63 visit page_with_token(token, path)
65 verify_homepage_anonymous_enabled user, is_active, has_profile
71 ['active', api_fixture('users')['active']],
72 ].each do |token, user, is_active|
73 test "visit public project as user #{token} when anonymous browsing is not enabled" do
74 Rails.configuration.anonymous_user_token = false
76 path = "/projects/#{api_fixture('groups')['anonymously_accessible_project']['uuid']}/?public_data=true"
80 visit page_with_token(token, path)
84 assert_text 'Unrestricted public data'
86 assert_text 'Please log in'
91 test "visit non-public project as anonymous when anonymous browsing is enabled and expect page not found" do
92 Rails.configuration.anonymous_user_token = api_fixture('api_client_authorizations')['anonymous']['api_token']
93 visit "/projects/#{api_fixture('groups')['aproject']['uuid']}/?public_data=true"
94 assert_text 'Not Found'
97 test "selection actions when anonymous user accesses shared project" do
98 Rails.configuration.anonymous_user_token = api_fixture('api_client_authorizations')['anonymous']['api_token']
99 visit "/projects/#{api_fixture('groups')['anonymously_accessible_project']['uuid']}/?public_data=true"
101 assert_selector 'a', text: 'Data collections'
102 assert_selector 'a', text: 'Jobs and pipelines'
103 assert_selector 'a', text: 'Pipeline templates'
104 assert_selector 'a', text: 'Advanced'
105 assert_no_selector 'a', text: 'Subprojects'
106 assert_no_selector 'a', text: 'Other objects'
107 assert_no_selector 'button', text: 'Add data'
109 click_button 'Selection'
110 within('.selection-action-container') do
111 assert_selector 'li', text: 'Compare selected'
112 assert_no_selector 'li', text: 'Create new collection with selected collections'
113 assert_no_selector 'li', text: 'Copy selected'
114 assert_no_selector 'li', text: 'Move selected'
115 assert_no_selector 'li', text: 'Remove selected'
119 def visit_publicly_accessible_project
120 Rails.configuration.anonymous_user_token = api_fixture('api_client_authorizations')['anonymous']['api_token']
121 visit "/projects/#{api_fixture('groups')['anonymously_accessible_project']['uuid']}/?public_data=true"
124 test "anonymous user accesses data collections tab in shared project" do
125 visit_publicly_accessible_project
127 assert_selector 'a', text: 'Data collections (1)'
129 # click on show collection
130 within first('tr[data-kind="arvados#collection"]') do
135 assert_no_selector 'input', text: 'Create sharing link'
136 assert_no_selector 'a', text: 'Upload'
138 within ('#collection_files') do
139 assert_text 'GNU_General_Public_License,_version_3.pdf'
140 # how do i assert the view and download links?
144 [ 'job', 'pipelineInstance' ].each do |type|
145 test "anonymous user accesses jobs and pipelines tab in shared project and clicks on #{type}" do
146 visit_publicly_accessible_project
148 assert_selector 'a', 'Jobs and pipelines (2)'
150 click_link 'Jobs and pipelines'
151 assert_text 'hash job'
153 # click on type specified collection
157 verify_pipeline_instance_row
163 within first('tr[data-kind="arvados#job"]') do
164 assert_text 'hash job using'
169 assert_no_selector 'button', text: 'Re-run job'
170 assert_text 'script_version'
173 def verify_pipeline_instance_row
174 within first('tr[data-kind="arvados#pipelineInstance"]') do
175 assert_text 'Pipeline in publicly accessible project'
179 # in pipeline instance page
180 assert_no_selector 'a', text: 'Re-run with latest'
181 assert_no_selector 'a', text: 'Re-run options'
182 assert_text 'This pipeline is complete'
185 test "anonymous user accesses pipeline templates tab in shared project" do
186 visit_publicly_accessible_project
188 assert_selector 'a', 'Pipeline templates (1)'
190 click_link 'Pipeline templates'
191 assert_text 'Pipeline template in publicly accessible project'
193 within first('tr[data-kind="arvados#pipelineTemplate"]') do
198 assert_text 'script version'
199 assert_no_selector 'a', text: 'Run this pipeline'