1 # Copyright (C) The Arvados Authors. All rights reserved.
3 # SPDX-License-Identifier: AGPL-3.0
7 class ActionsControllerTest < ActionController::TestCase
10 post :report_issue, params: {format: 'js'}, session: session_for(:admin)
11 assert_response :success
14 ActionMailer::Base.deliveries.andand.each do |email|
15 if email.subject.include? "Issue reported by admin"
20 assert_equal true, found_email, 'Expected email after issue reported'
23 test "combine files into new collection" do
24 post(:combine_selected_files_into_collection, params: {
25 selection: ['zzzzz-4zz18-znfnqtbbv4spc3w/foo',
26 'zzzzz-4zz18-ehbhgtheo8909or/bar',
27 'zzzzz-4zz18-y9vne9npefyxh8g/baz',
28 '7a6ef4c162a5c6413070a8bd0bffc818+150'],
30 session: session_for(:active))
32 assert_response 302 # collection created and redirected to new collection page
34 assert_includes(response.headers['Location'], '/collections/')
35 new_collection_uuid = response.headers['Location'].split('/')[-1]
38 collection = Collection.select([:uuid, :manifest_text]).where(uuid: new_collection_uuid).first
39 manifest_text = collection['manifest_text']
40 assert_includes(manifest_text, "foo")
41 assert_includes(manifest_text, "bar")
42 assert_includes(manifest_text, "baz")
43 assert_includes(manifest_text, "0:0:file1 0:0:file2 0:0:file3")
44 assert_includes(manifest_text, "dir1/subdir")
45 assert_includes(manifest_text, "dir2")
48 test "combine files with repeated names into new collection" do
49 post(:combine_selected_files_into_collection, params: {
50 selection: ['zzzzz-4zz18-znfnqtbbv4spc3w/foo',
51 'zzzzz-4zz18-00000nonamecoll/foo',
52 'zzzzz-4zz18-abcd6fx123409f7/foo',
53 'zzzzz-4zz18-ehbhgtheo8909or/bar',
54 'zzzzz-4zz18-y9vne9npefyxh8g/baz',
55 '7a6ef4c162a5c6413070a8bd0bffc818+150'],
57 session: session_for(:active))
59 assert_response 302 # collection created and redirected to new collection page
61 assert_includes(response.headers['Location'], '/collections/')
62 new_collection_uuid = response.headers['Location'].split('/')[-1]
65 collection = Collection.select([:uuid, :manifest_text]).where(uuid: new_collection_uuid).first
66 manifest_text = collection['manifest_text']
67 assert_includes(manifest_text, "foo(1)")
68 assert_includes(manifest_text, "foo(2)")
69 assert_includes(manifest_text, "bar")
70 assert_includes(manifest_text, "baz")
71 assert_includes(manifest_text, "0:0:file1 0:0:file2 0:0:file3")
72 assert_includes(manifest_text, "dir1/subdir")
73 assert_includes(manifest_text, "dir2")
76 test "combine collections with repeated filenames in almost similar directories and expect files with proper suffixes" do
77 post(:combine_selected_files_into_collection, params: {
78 selection: ['zzzzz-4zz18-duplicatenames1',
79 'zzzzz-4zz18-duplicatenames2',
80 'zzzzz-4zz18-znfnqtbbv4spc3w/foo',
81 'zzzzz-4zz18-00000nonamecoll/foo',],
83 session: session_for(:active))
85 assert_response 302 # collection created and redirected to new collection page
87 assert response.headers['Location'].include? '/collections/'
88 new_collection_uuid = response.headers['Location'].split('/')[-1]
91 collection = Collection.select([:uuid, :manifest_text]).where(uuid: new_collection_uuid).first
92 manifest_text = collection['manifest_text']
94 assert_includes(manifest_text, 'foo')
95 assert_includes(manifest_text, 'foo(1)')
97 streams = manifest_text.split "\n"
98 streams.each do |stream|
99 if stream.start_with? './dir1'
101 assert_includes(stream, ':alice(1)')
102 assert_includes(stream, ':alice.txt')
103 assert_includes(stream, ':alice(1).txt')
104 assert_includes(stream, ':bob.txt')
105 assert_includes(stream, ':carol.txt')
106 elsif stream.start_with? './dir2'
108 assert_includes(stream, ':alice.txt')
109 assert_includes(stream, ':alice(1).txt')
110 elsif stream.start_with? '. '
112 assert_includes(stream, ':foo')
113 assert_includes(stream, ':foo(1)')
118 test "combine collections with same filename in two different streams and expect no suffixes for filenames" do
119 post(:combine_selected_files_into_collection, params: {
120 selection: ['zzzzz-4zz18-znfnqtbbv4spc3w',
121 'zzzzz-4zz18-foonbarfilesdir'],
123 session: session_for(:active))
125 assert_response 302 # collection created and redirected to new collection page
127 assert_includes(response.headers['Location'], '/collections/')
128 new_collection_uuid = response.headers['Location'].split('/')[-1]
131 collection = Collection.select([:uuid, :manifest_text]).where(uuid: new_collection_uuid).first
132 manifest_text = collection['manifest_text']
134 streams = manifest_text.split "\n"
135 assert_equal 2, streams.length
136 streams.each do |stream|
137 if stream.start_with? './dir1'
138 assert_includes(stream, 'foo')
139 elsif stream.start_with? '. '
140 assert_includes(stream, 'foo')
143 refute_includes(manifest_text, 'foo(1)')
146 test "combine foo files from two different collection streams and expect proper filename suffixes" do
147 post(:combine_selected_files_into_collection, params: {
148 selection: ['zzzzz-4zz18-znfnqtbbv4spc3w/foo',
149 'zzzzz-4zz18-foonbarfilesdir/dir1/foo'],
151 session: session_for(:active))
153 assert_response 302 # collection created and redirected to new collection page
155 assert_includes(response.headers['Location'], '/collections/')
156 new_collection_uuid = response.headers['Location'].split('/')[-1]
159 collection = Collection.select([:uuid, :manifest_text]).where(uuid: new_collection_uuid).first
160 manifest_text = collection['manifest_text']
162 streams = manifest_text.split "\n"
163 assert_equal 1, streams.length, "Incorrect number of streams in #{manifest_text}"
164 assert_includes(manifest_text, 'foo')
165 assert_includes(manifest_text, 'foo(1)')
169 ['collections', 'user_agreement_in_anonymously_accessible_project'],
170 ['groups', 'anonymously_accessible_project'],
171 ['jobs', 'running_job_in_publicly_accessible_project'],
172 ['pipeline_instances', 'pipeline_in_publicly_accessible_project'],
173 ['pipeline_templates', 'pipeline_template_in_publicly_accessible_project'],
174 ].each do |dm, fixture|
175 test "access show method for public #{dm} and expect to see page" do
176 Rails.configuration.Users.AnonymousUserToken = api_fixture('api_client_authorizations')['anonymous']['api_token']
177 get(:show, params: {uuid: api_fixture(dm)[fixture]['uuid']})
178 assert_response :redirect
180 assert_includes @response.redirect_url, "projects/#{fixture['uuid']}"
182 assert_includes @response.redirect_url, "#{dm}/#{fixture['uuid']}"
188 ['collections', 'foo_collection_in_aproject', 404],
189 ['groups', 'subproject_in_asubproject_with_same_name_as_one_in_active_user_home', 404],
190 ['jobs', 'job_with_latest_version', 404],
191 ['pipeline_instances', 'pipeline_owned_by_active_in_home', 404],
192 ['pipeline_templates', 'template_in_asubproject_with_same_name_as_one_in_active_user_home', 404],
193 ['traits', 'owned_by_aproject_with_no_name', :redirect],
194 ].each do |dm, fixture, expected|
195 test "access show method for non-public #{dm} and expect #{expected}" do
196 Rails.configuration.Users.AnonymousUserToken = api_fixture('api_client_authorizations')['anonymous']['api_token']
197 get(:show, params: {uuid: api_fixture(dm)[fixture]['uuid']})
198 assert_response expected
200 assert_includes @response.inspect, 'Log in'
202 assert_match /\/users\/welcome/, @response.redirect_url