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