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 ].each do |token, user, is_active, has_profile|
54 test "visit public project as user #{token} when anonymous browsing is enabled" do
55 Rails.configuration.anonymous_user_token = api_fixture('api_client_authorizations')['anonymous']['api_token']
57 path = "/projects/#{api_fixture('groups')['anonymously_accessible_project']['uuid']}/?public_data=true"
62 visit page_with_token(token, path)
64 verify_homepage_anonymous_enabled user, is_active, has_profile
68 test "anonymous user visit public project when anonymous browsing not enabled and expect to see login page" do
69 Rails.configuration.anonymous_user_token = false
70 visit "/projects/#{api_fixture('groups')['anonymously_accessible_project']['uuid']}/?public_data=true"
71 assert_text 'Please log in'
74 test "visit non-public project as anonymous when anonymous browsing is enabled and expect page not found" do
75 Rails.configuration.anonymous_user_token = api_fixture('api_client_authorizations')['anonymous']['api_token']
76 visit "/projects/#{api_fixture('groups')['aproject']['uuid']}/?public_data=true"
77 assert_text 'Not Found'
80 test "selection actions when anonymous user accesses shared project" do
81 Rails.configuration.anonymous_user_token = api_fixture('api_client_authorizations')['anonymous']['api_token']
82 visit "/projects/#{api_fixture('groups')['anonymously_accessible_project']['uuid']}/?public_data=true"
84 assert_selector 'a', text: 'Data collections'
85 assert_selector 'a', text: 'Jobs and pipelines'
86 assert_selector 'a', text: 'Pipeline templates'
87 assert_selector 'a', text: 'Advanced'
88 assert_no_selector 'a', text: 'Subprojects'
89 assert_no_selector 'a', text: 'Other objects'
90 assert_no_selector 'button', text: 'Add data'
92 click_button 'Selection'
93 within('.selection-action-container') do
94 assert_selector 'li', text: 'Compare selected'
95 assert_no_selector 'li', text: 'Create new collection with selected collections'
96 assert_no_selector 'li', text: 'Copy selected'
97 assert_no_selector 'li', text: 'Move selected'
98 assert_no_selector 'li', text: 'Remove selected'
102 def visit_publicly_accessible_project
103 Rails.configuration.anonymous_user_token = api_fixture('api_client_authorizations')['anonymous']['api_token']
104 visit "/projects/#{api_fixture('groups')['anonymously_accessible_project']['uuid']}/?public_data=true"
108 ['All pipelines', 'Pipeline in publicly accessible project'],
109 ['All jobs', 'job submitted'],
110 ['All collections', 'GNU_General_Public_License,_version_3.pdf'],
111 ].each do |selector, expectation|
112 test "verify dashboard when anonymous user accesses shared project and click #{selector}" do
113 visit_publicly_accessible_project
116 click_link 'You are viewing public data'
118 assert_no_selector 'a', text: 'Run a pipeline'
119 assert_selector 'a', text: selector
121 assert_text expectation
125 test "anonymous user accesses data collections tab in shared project" do
126 visit_publicly_accessible_project
128 assert_selector 'a', text: 'Data collections (1)'
130 # click on show collection
131 within first('tr[data-kind="arvados#collection"]') do
136 assert_no_selector 'input', text: 'Create sharing link'
137 assert_no_selector 'a', text: 'Upload'
138 assert_no_selector 'button', 'Selection'
140 within ('#collection_files') do
141 assert_text 'GNU_General_Public_License,_version_3.pdf'
142 # how do i assert the view and download links?
146 [ 'job', 'pipelineInstance' ].each do |type|
147 test "anonymous user accesses jobs and pipelines tab in shared project and clicks on #{type}" do
148 visit_publicly_accessible_project
150 assert_selector 'a', 'Jobs and pipelines (2)'
152 click_link 'Jobs and pipelines'
153 assert_text 'hash job'
155 # click on type specified collection
159 verify_pipeline_instance_row
165 within first('tr[data-kind="arvados#job"]') do
166 assert_text 'hash job using'
171 assert_no_selector 'button', text: 'Re-run job'
172 assert_text 'script_version'
173 assert_no_selector 'button', text: 'Cancel'
176 def verify_pipeline_instance_row
177 within first('tr[data-kind="arvados#pipelineInstance"]') do
178 assert_text 'Pipeline in publicly accessible project'
182 # in pipeline instance page
183 assert_no_selector 'a', text: 'Re-run with latest'
184 assert_no_selector 'a', text: 'Re-run options'
185 assert_text 'This pipeline is complete'
188 test "anonymous user accesses pipeline templates tab in shared project" do
189 visit_publicly_accessible_project
191 assert_selector 'a', 'Pipeline templates (1)'
193 click_link 'Pipeline templates'
194 assert_text 'Pipeline template in publicly accessible project'
196 within first('tr[data-kind="arvados#pipelineTemplate"]') do
201 assert_text 'script version'
202 assert_no_selector 'a', text: 'Run this pipeline'