2659: hide job re-run button when user is inactive and add fixtures and tests for...
[arvados.git] / apps / workbench / test / integration / anonymous_access_test.rb
1 require 'integration_helper'
2
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
8
9   setup do
10     need_javascript
11   end
12
13   def verify_homepage_anonymous_enabled user, is_active, has_profile
14     if user
15       if user['is_active']
16         if has_profile
17           assert_text 'Unrestricted public data'
18           assert_selector 'a', text: 'Projects'
19         else
20           assert_text 'All required fields must be completed before you can proceed'
21         end
22       else
23         assert_text 'indicate that you have read and accepted the user agreement'
24       end
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'
31         end
32       end
33     else
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'
43         end
44       end
45     end
46   end
47
48   [
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']
57
58       path = "/projects/#{api_fixture('groups')['anonymously_accessible_project']['uuid']}/?public_data=true"
59
60       if !token
61         visit path
62       else
63         visit page_with_token(token, path)
64       end
65       verify_homepage_anonymous_enabled user, is_active, has_profile
66     end
67   end
68
69   [
70     [nil, nil],
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
75
76       path = "/projects/#{api_fixture('groups')['anonymously_accessible_project']['uuid']}/?public_data=true"
77       if !token
78         visit path
79       else
80         visit page_with_token(token, path)
81       end
82
83       if user
84         assert_text 'Unrestricted public data'
85       else
86         assert_text 'Please log in'
87       end
88     end
89   end
90
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'
95   end
96
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"
100
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'
108
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'
116     end
117   end
118
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"
122   end
123
124   test "anonymous user accesses data collections tab in shared project" do
125     visit_publicly_accessible_project
126
127     assert_selector 'a', text: 'Data collections (1)'
128
129     # click on show collection
130     within first('tr[data-kind="arvados#collection"]') do
131       click_link 'Show'
132     end
133
134     # in collection page
135     assert_no_selector 'input', text: 'Create sharing link'
136     assert_no_selector 'a', text: 'Upload'
137
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?
141     end
142   end
143
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
147
148       assert_selector 'a', 'Jobs and pipelines (2)'
149
150       click_link 'Jobs and pipelines'
151       assert_text 'hash job'
152
153       # click on type specified collection
154       if type == 'job'
155         verify_job_row
156       else
157         verify_pipeline_instance_row
158       end
159     end
160   end
161
162   def verify_job_row
163     within first('tr[data-kind="arvados#job"]') do
164       assert_text 'hash job using'
165       click_link 'Show'
166     end
167
168     # in job page
169     assert_no_selector 'button', text: 'Re-run job'
170     assert_text 'script_version'
171   end
172
173   def verify_pipeline_instance_row
174     within first('tr[data-kind="arvados#pipelineInstance"]') do
175       assert_text 'Pipeline in publicly accessible project'
176       click_link 'Show'
177     end
178
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'
183   end
184
185   test "anonymous user accesses pipeline templates tab in shared project" do
186     visit_publicly_accessible_project
187
188     assert_selector 'a', 'Pipeline templates (1)'
189
190     click_link 'Pipeline templates'
191     assert_text 'Pipeline template in publicly accessible project'
192
193     within first('tr[data-kind="arvados#pipelineTemplate"]') do
194       click_link 'Show'
195     end
196
197     # in template page
198     assert_text 'script version'
199     assert_no_selector 'a', text: 'Run this pipeline'
200   end
201 end