8784: Fix test for latest firefox.
[arvados.git] / apps / workbench / test / controllers / actions_controller_test.rb
1 require 'test_helper'
2
3 class ActionsControllerTest < ActionController::TestCase
4
5   test "send report" do
6     post :report_issue, {format: 'js'}, session_for(:admin)
7     assert_response :success
8
9     found_email = false
10     ActionMailer::Base.deliveries.andand.each do |email|
11       if email.subject.include? "Issue reported by admin"
12         found_email = true
13         break
14       end
15     end
16     assert_equal true, found_email, 'Expected email after issue reported'
17   end
18
19   test "combine files into new collection" do
20     post(:combine_selected_files_into_collection, {
21            selection: ['zzzzz-4zz18-znfnqtbbv4spc3w/foo',
22                        'zzzzz-4zz18-ehbhgtheo8909or/bar',
23                        'zzzzz-4zz18-y9vne9npefyxh8g/baz',
24                        '7a6ef4c162a5c6413070a8bd0bffc818+150'],
25            format: "json"},
26          session_for(:active))
27
28     assert_response 302   # collection created and redirected to new collection page
29
30     assert_includes(response.headers['Location'], '/collections/')
31     new_collection_uuid = response.headers['Location'].split('/')[-1]
32
33     use_token :active
34     collection = Collection.select([:uuid, :manifest_text]).where(uuid: new_collection_uuid).first
35     manifest_text = collection['manifest_text']
36     assert_includes(manifest_text, "foo")
37     assert_includes(manifest_text, "bar")
38     assert_includes(manifest_text, "baz")
39     assert_includes(manifest_text, "0:0:file1 0:0:file2 0:0:file3")
40     assert_includes(manifest_text, "dir1/subdir")
41     assert_includes(manifest_text, "dir2")
42   end
43
44   test "combine files  with repeated names into new collection" do
45     post(:combine_selected_files_into_collection, {
46            selection: ['zzzzz-4zz18-znfnqtbbv4spc3w/foo',
47                        'zzzzz-4zz18-00000nonamecoll/foo',
48                        'zzzzz-4zz18-abcd6fx123409f7/foo',
49                        'zzzzz-4zz18-ehbhgtheo8909or/bar',
50                        'zzzzz-4zz18-y9vne9npefyxh8g/baz',
51                        '7a6ef4c162a5c6413070a8bd0bffc818+150'],
52            format: "json"},
53          session_for(:active))
54
55     assert_response 302   # collection created and redirected to new collection page
56
57     assert_includes(response.headers['Location'], '/collections/')
58     new_collection_uuid = response.headers['Location'].split('/')[-1]
59
60     use_token :active
61     collection = Collection.select([:uuid, :manifest_text]).where(uuid: new_collection_uuid).first
62     manifest_text = collection['manifest_text']
63     assert_includes(manifest_text, "foo(1)")
64     assert_includes(manifest_text, "foo(2)")
65     assert_includes(manifest_text, "bar")
66     assert_includes(manifest_text, "baz")
67     assert_includes(manifest_text, "0:0:file1 0:0:file2 0:0:file3")
68     assert_includes(manifest_text, "dir1/subdir")
69     assert_includes(manifest_text, "dir2")
70   end
71
72   test "combine collections with repeated filenames in almost similar directories and expect files with proper suffixes" do
73     post(:combine_selected_files_into_collection, {
74            selection: ['zzzzz-4zz18-duplicatenames1',
75                        'zzzzz-4zz18-duplicatenames2',
76                        'zzzzz-4zz18-znfnqtbbv4spc3w/foo',
77                        'zzzzz-4zz18-00000nonamecoll/foo',],
78            format: "json"},
79          session_for(:active))
80
81     assert_response 302   # collection created and redirected to new collection page
82
83     assert response.headers['Location'].include? '/collections/'
84     new_collection_uuid = response.headers['Location'].split('/')[-1]
85
86     use_token :active
87     collection = Collection.select([:uuid, :manifest_text]).where(uuid: new_collection_uuid).first
88     manifest_text = collection['manifest_text']
89
90     assert_includes(manifest_text, 'foo')
91     assert_includes(manifest_text, 'foo(1)')
92
93     streams = manifest_text.split "\n"
94     streams.each do |stream|
95       if stream.start_with? './dir1'
96         # dir1 stream
97         assert_includes(stream, ':alice(1)')
98         assert_includes(stream, ':alice.txt')
99         assert_includes(stream, ':alice(1).txt')
100         assert_includes(stream, ':bob.txt')
101         assert_includes(stream, ':carol.txt')
102       elsif stream.start_with? './dir2'
103         # dir2 stream
104         assert_includes(stream, ':alice.txt')
105         assert_includes(stream, ':alice(1).txt')
106       elsif stream.start_with? '. '
107         # . stream
108         assert_includes(stream, ':foo')
109         assert_includes(stream, ':foo(1)')
110       end
111     end
112   end
113
114   test "combine collections with same filename in two different streams and expect no suffixes for filenames" do
115     post(:combine_selected_files_into_collection, {
116            selection: ['zzzzz-4zz18-znfnqtbbv4spc3w',
117                        'zzzzz-4zz18-foonbarfilesdir'],
118            format: "json"},
119          session_for(:active))
120
121     assert_response 302   # collection created and redirected to new collection page
122
123     assert_includes(response.headers['Location'], '/collections/')
124     new_collection_uuid = response.headers['Location'].split('/')[-1]
125
126     use_token :active
127     collection = Collection.select([:uuid, :manifest_text]).where(uuid: new_collection_uuid).first
128     manifest_text = collection['manifest_text']
129
130     streams = manifest_text.split "\n"
131     assert_equal 2, streams.length
132     streams.each do |stream|
133       if stream.start_with? './dir1'
134         assert_includes(stream, 'foo')
135       elsif stream.start_with? '. '
136         assert_includes(stream, 'foo')
137       end
138     end
139     refute_includes(manifest_text, 'foo(1)')
140   end
141
142   test "combine foo files from two different collection streams and expect proper filename suffixes" do
143     post(:combine_selected_files_into_collection, {
144            selection: ['zzzzz-4zz18-znfnqtbbv4spc3w/foo',
145                        'zzzzz-4zz18-foonbarfilesdir/dir1/foo'],
146            format: "json"},
147          session_for(:active))
148
149     assert_response 302   # collection created and redirected to new collection page
150
151     assert_includes(response.headers['Location'], '/collections/')
152     new_collection_uuid = response.headers['Location'].split('/')[-1]
153
154     use_token :active
155     collection = Collection.select([:uuid, :manifest_text]).where(uuid: new_collection_uuid).first
156     manifest_text = collection['manifest_text']
157
158     streams = manifest_text.split "\n"
159     assert_equal 1, streams.length, "Incorrect number of streams in #{manifest_text}"
160     assert_includes(manifest_text, 'foo')
161     assert_includes(manifest_text, 'foo(1)')
162   end
163
164   [
165     ['collections', 'user_agreement_in_anonymously_accessible_project'],
166     ['groups', 'anonymously_accessible_project'],
167     ['jobs', 'running_job_in_publicly_accessible_project'],
168     ['pipeline_instances', 'pipeline_in_publicly_accessible_project'],
169     ['pipeline_templates', 'pipeline_template_in_publicly_accessible_project'],
170   ].each do |dm, fixture|
171     test "access show method for public #{dm} and expect to see page" do
172       Rails.configuration.anonymous_user_token = api_fixture('api_client_authorizations')['anonymous']['api_token']
173       get(:show, {uuid: api_fixture(dm)[fixture]['uuid']})
174       assert_response :redirect
175       if dm == 'groups'
176         assert_includes @response.redirect_url, "projects/#{fixture['uuid']}"
177       else
178         assert_includes @response.redirect_url, "#{dm}/#{fixture['uuid']}"
179       end
180     end
181   end
182
183   [
184     ['collections', 'foo_collection_in_aproject', 404],
185     ['groups', 'subproject_in_asubproject_with_same_name_as_one_in_active_user_home', 404],
186     ['jobs', 'job_with_latest_version', 404],
187     ['pipeline_instances', 'pipeline_owned_by_active_in_home', 404],
188     ['pipeline_templates', 'template_in_asubproject_with_same_name_as_one_in_active_user_home', 404],
189     ['traits', 'owned_by_aproject_with_no_name', :redirect],
190   ].each do |dm, fixture, expected|
191     test "access show method for non-public #{dm} and expect #{expected}" do
192       Rails.configuration.anonymous_user_token = api_fixture('api_client_authorizations')['anonymous']['api_token']
193       get(:show, {uuid: api_fixture(dm)[fixture]['uuid']})
194       assert_response expected
195       if expected == 404
196         assert_includes @response.inspect, 'Log in'
197       else
198         assert_match /\/users\/welcome/, @response.redirect_url
199       end
200     end
201   end
202 end