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