5565: show trimmed down version of breadcrumbs in anonymous view.
[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: Rails.configuration.site_name.downcase
26         assert_selector 'a', text: "#{user['email']}"
27         find('a', text: "#{user['email']}").click
28         within('.dropdown-menu') do
29           assert_selector 'a', text: 'Log out'
30         end
31       end
32     else  # anonymous
33       assert_text 'Unrestricted public data'
34       within('.navbar-fixed-top') do
35         assert_text Rails.configuration.site_name.downcase
36         assert_no_selector 'a', text: Rails.configuration.site_name.downcase
37         assert_selector 'a', text: 'Log in'
38       end
39     end
40   end
41
42   [
43     [nil, nil, false, false],
44     ['inactive', api_fixture('users')['inactive'], false, false],
45     ['active', api_fixture('users')['active'], true, true],
46   ].each do |token, user, is_active|
47     test "visit public project as user #{token.inspect} when anonymous browsing is enabled" do
48       if !token
49         visit PUBLIC_PROJECT
50       else
51         visit page_with_token(token, PUBLIC_PROJECT)
52       end
53
54       verify_site_navigation_anonymous_enabled user, is_active
55     end
56   end
57
58   test "selection actions when anonymous user accesses shared project" do
59     visit PUBLIC_PROJECT
60
61     assert_selector 'a', text: 'Description'
62     assert_selector 'a', text: 'Data collections'
63     assert_selector 'a', text: 'Jobs and pipelines'
64     assert_selector 'a', text: 'Pipeline templates'
65     assert_selector 'a', text: 'Advanced'
66     assert_no_selector 'a', text: 'Subprojects'
67     assert_no_selector 'a', text: 'Other objects'
68     assert_no_selector 'button', text: 'Add data'
69
70     click_link 'Data collections'
71     click_button 'Selection'
72     within('.selection-action-container') do
73       assert_selector 'li', text: 'Compare selected'
74       assert_no_selector 'li', text: 'Create new collection with selected collections'
75       assert_no_selector 'li', text: 'Copy selected'
76       assert_no_selector 'li', text: 'Move selected'
77       assert_no_selector 'li', text: 'Remove selected'
78     end
79   end
80
81   test "anonymous user accesses data collections tab in shared project" do
82     visit PUBLIC_PROJECT
83     click_link 'Data collections'
84     collection = api_fixture('collections')['user_agreement_in_anonymously_accessible_project']
85     assert_text 'GNU General Public License'
86
87     assert_selector 'a', text: 'Data collections'
88
89     # click on show collection
90     within "tr[data-object-uuid=\"#{collection['uuid']}\"]" do
91       click_link 'Show'
92     end
93
94     # in collection page
95     assert_no_selector 'input', text: 'Create sharing link'
96     assert_no_text 'Sharing and permissions'
97     assert_no_selector 'a', text: 'Upload'
98     assert_no_selector 'button', 'Selection'
99
100     within '#collection_files tr,li', text: 'GNU_General_Public_License,_version_3.pdf' do
101       assert page.has_no_selector?('[value*="GNU_General_Public_License"]')
102       find 'a[title~=View]'
103       find 'a[title~=Download]'
104     end
105   end
106
107   test 'view file' do
108     magic = rand(2**512).to_s 36
109     CollectionsController.any_instance.stubs(:file_enumerator).returns([magic])
110     collection = api_fixture('collections')['public_text_file']
111     visit '/collections/' + collection['uuid']
112     find('tr,li', text: 'Hello world.txt').
113       find('a[title~=View]').click
114     assert_text magic
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 PUBLIC_PROJECT
124       click_link 'Data collections'
125       assert_text 'GNU General Public License'
126
127       click_link 'Jobs and pipelines'
128       assert_text 'Pipeline in publicly accessible project'
129
130       # click on the specified job
131       if type.include? 'job'
132         verify_job_row type
133       else
134         verify_pipeline_instance_row
135       end
136     end
137   end
138
139   def verify_job_row look_for
140     within first('tr', text: look_for) do
141       click_link 'Show'
142     end
143     assert_text 'Public Projects Unrestricted public data'
144     assert_text 'script_version'
145
146     assert_text 'zzzzz-tpzed-xurymjxw79nv3jz' # modified by user
147     assert_no_selector 'a', text: 'zzzzz-tpzed-xurymjxw79nv3jz'
148     assert_no_selector 'a', text: 'Move job'
149     assert_no_selector 'button', text: 'Cancel'
150     assert_no_selector 'button', text: 'Re-run job'
151   end
152
153   def verify_pipeline_instance_row
154     within first('tr[data-kind="arvados#pipelineInstance"]') do
155       assert_text 'Pipeline in publicly accessible project'
156       click_link 'Show'
157     end
158
159     # in pipeline instance page
160     assert_text 'Public Projects Unrestricted public data'
161     assert_text 'This pipeline is complete'
162     assert_no_selector 'a', text: 'Re-run with latest'
163     assert_no_selector 'a', text: 'Re-run options'
164   end
165
166   test "anonymous user accesses pipeline templates tab in shared project" do
167     visit PUBLIC_PROJECT
168     click_link 'Data collections'
169     assert_text 'GNU General Public License'
170
171     assert_selector 'a', text: 'Pipeline templates'
172
173     click_link 'Pipeline templates'
174     assert_text 'Pipeline template in publicly accessible project'
175
176     within first('tr[data-kind="arvados#pipelineTemplate"]') do
177       click_link 'Show'
178     end
179
180     # in template page
181     assert_text 'Public Projects Unrestricted public data'
182     assert_text 'script version'
183     assert_no_selector 'a', text: 'Run this pipeline'
184   end
185
186   test "anonymous user accesses collection in shared project" do
187     visit "/collections/#{api_fixture('collections')['public_text_file']['uuid']}"
188
189     # in collection page
190     assert_text 'Public Projects Unrestricted public data'
191     assert_text 'Hello world'
192     assert_text 'Content address'
193     assert_selector 'a', text: 'Provenance graph'
194   end
195 end