2659: do not include "You are viewing public data" in topnav when anonymous user...
[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 visit_publicly_accessible_project token=nil, path=nil
14     Rails.configuration.anonymous_user_token = api_fixture('api_client_authorizations')['anonymous']['api_token']
15
16     path = "/projects/#{api_fixture('groups')['anonymously_accessible_project']['uuid']}" if !path
17
18     if token
19       visit page_with_token(token, path)
20     else
21       visit path
22       assert_text 'Unrestricted public data' if path.include? 'anonymously_accessible_project'
23     end
24   end
25
26   def verify_site_navigation_anonymous_enabled user, is_active
27     if user
28       if user['is_active']
29         assert_text 'Unrestricted public data'
30         assert_selector 'a', text: 'Projects'
31       else
32         assert_text 'indicate that you have read and accepted the user agreement'
33       end
34       within('.navbar-fixed-top') do
35         assert_selector 'a', text: "#{user['email']}"
36         find('a', text: "#{user['email']}").click
37         within('.dropdown-menu') do
38           assert_selector 'a', text: 'Log out'
39         end
40       end
41     else  # anonymous
42       assert_text 'Unrestricted public data'
43       within('.navbar-fixed-top') do
44         assert_selector 'a', text: 'Log in'
45       end
46     end
47   end
48
49   [
50     [nil, nil, false, false],
51     ['inactive', api_fixture('users')['inactive'], false, false],
52     ['active', api_fixture('users')['active'], true, true],
53   ].each do |token, user, is_active|
54     test "visit public project as user #{token.inspect} when anonymous browsing is enabled" do
55       visit_publicly_accessible_project token
56       verify_site_navigation_anonymous_enabled user, is_active
57     end
58   end
59
60   test "visit non-public project as anonymous when anonymous browsing is enabled and expect page not found" do
61     visit_publicly_accessible_project nil,
62         "/projects/#{api_fixture('groups')['aproject']['uuid']}"
63     assert_text 'Not Found'
64   end
65
66   test "anonymous user clicking on topnav sees login page" do
67     visit_publicly_accessible_project
68
69     # click on topnav
70     click_link 'workbench:test'
71     assert_text 'Please log in'
72   end
73
74   test "selection actions when anonymous user accesses shared project" do
75     visit_publicly_accessible_project
76
77     assert_selector 'a', text: 'Data collections'
78     assert_selector 'a', text: 'Jobs and pipelines'
79     assert_selector 'a', text: 'Pipeline templates'
80     assert_selector 'a', text: 'Advanced'
81     assert_no_selector 'a', text: 'Subprojects'
82     assert_no_selector 'a', text: 'Other objects'
83     assert_no_selector 'button', text: 'Add data'
84
85     click_button 'Selection'
86     within('.selection-action-container') do
87       assert_selector 'li', text: 'Compare selected'
88       assert_no_selector 'li', text: 'Create new collection with selected collections'
89       assert_no_selector 'li', text: 'Copy selected'
90       assert_no_selector 'li', text: 'Move selected'
91       assert_no_selector 'li', text: 'Remove selected'
92     end
93   end
94
95   test "anonymous user accesses data collections tab in shared project" do
96     visit_publicly_accessible_project
97     assert_text 'GNU General Public License'
98
99     assert_selector 'a', text: 'Data collections'
100
101     # click on show collection
102     within first('tr[data-kind="arvados#collection"]') do
103       click_link 'Show'
104     end
105
106     # in collection page
107     assert_no_selector 'input', text: 'Create sharing link'
108     assert_no_selector 'a', text: 'Upload'
109     assert_no_selector 'button', 'Selection'
110
111     within ('#collection_files') do
112       assert_text 'GNU_General_Public_License,_version_3.pdf'
113       # how do i assert the view and download link existence?
114     end
115   end
116
117   [
118     'running_job',
119     'completed_job',
120     'pipelineInstance'
121   ].each do |type|
122     test "anonymous user accesses jobs and pipelines tab in shared project and clicks on #{type}" do
123       visit_publicly_accessible_project
124       assert_text 'GNU General Public License'
125
126       click_link 'Jobs and pipelines'
127       assert_text 'Pipeline in publicly accessible project'
128
129       # click on type specified collection
130       if type.include? 'job'
131         verify_job_row type
132       else
133         verify_pipeline_instance_row
134       end
135     end
136   end
137
138   def verify_job_row look_for
139     within first('tr', text: look_for) do
140       click_link 'Show'
141     end
142     assert_text 'script_version'
143
144     assert_text 'zzzzz-tpzed-xurymjxw79nv3jz' # modified by user
145     assert_no_selector 'a', text: 'zzzzz-tpzed-xurymjxw79nv3jz'
146     #assert_no_selector 'a', text: 'Log'  # this is finding 'Log in'
147     assert_no_selector 'a', text: 'Move job'
148     assert_no_selector 'button', text: 'Cancel'
149     assert_no_selector 'button', text: 'Re-run job'
150   end
151
152   def verify_pipeline_instance_row
153     within first('tr[data-kind="arvados#pipelineInstance"]') do
154       assert_text 'Pipeline in publicly accessible project'
155       click_link 'Show'
156     end
157
158     # in pipeline instance page
159     assert_text 'This pipeline is complete'
160     assert_no_selector 'a', text: 'Re-run with latest'
161     assert_no_selector 'a', text: 'Re-run options'
162   end
163
164   test "anonymous user accesses pipeline templates tab in shared project" do
165     visit_publicly_accessible_project
166     assert_text 'GNU General Public License'
167
168     assert_selector 'a', text: 'Pipeline templates'
169
170     click_link 'Pipeline templates'
171     assert_text 'Pipeline template in publicly accessible project'
172
173     within first('tr[data-kind="arvados#pipelineTemplate"]') do
174       click_link 'Show'
175     end
176
177     # in template page
178     assert_text 'script version'
179     assert_no_selector 'a', text: 'Run this pipeline'
180   end
181
182   [
183     '/users',
184     '/groups',
185   ].each do |page|
186     test "anonymous user accesses publicly accessible project and then traverses to #{page}" do
187       # when anonymous, first visit publicly accessible project
188       visit_publicly_accessible_project
189       visit page
190
191       if page == '/users'
192       assert_no_selector 'a', text: 'Add a new user'
193       elsif page == '/groups'
194         assert_no_selector 'button', text: 'Add a new group'
195       end
196     end
197   end
198 end