Merge branch '4759-timestamp-precision-TC' closes #4759
[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     collection = api_fixture('collections')['user_agreement_in_anonymously_accessible_project']
79     assert_text 'GNU General Public License'
80
81     assert_selector 'a', text: 'Data collections'
82
83     # click on show collection
84     within "tr[data-object-uuid=\"#{collection['uuid']}\"]" do
85       click_link 'Show'
86     end
87
88     # in collection page
89     assert_no_selector 'input', text: 'Create sharing link'
90     assert_no_text 'Sharing and permissions'
91     assert_no_selector 'a', text: 'Upload'
92     assert_no_selector 'button', 'Selection'
93
94     within '#collection_files tr,li', text: 'GNU_General_Public_License,_version_3.pdf' do
95       find 'a[title~=View]'
96       find 'a[title~=Download]'
97     end
98   end
99
100   test 'view file' do
101     magic = rand(2**512).to_s 36
102     CollectionsController.any_instance.stubs(:file_enumerator).returns([magic])
103     collection = api_fixture('collections')['public_text_file']
104     visit '/collections/' + collection['uuid']
105     find('tr,li', text: 'Hello world.txt').
106       find('a[title~=View]').click
107     assert_text magic
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