1 # Copyright (C) The Arvados Authors. All rights reserved.
3 # SPDX-License-Identifier: AGPL-3.0
7 class CollectionsControllerTest < ActionController::TestCase
8 # These tests don't do state-changing API calls. Save some time by
9 # skipping the database reset.
10 reset_api_fixtures :after_each_test, false
11 reset_api_fixtures :after_suite, true
13 include PipelineInstancesHelper
15 NONEXISTENT_COLLECTION = "ffffffffffffffffffffffffffffffff+0"
17 def config_anonymous enable
18 Rails.configuration.anonymous_user_token =
20 api_fixture('api_client_authorizations')['anonymous']['api_token']
26 def collection_params(collection_name, file_name=nil)
27 uuid = api_fixture('collections')[collection_name.to_s]['uuid']
28 params = {uuid: uuid, id: uuid}
29 params[:file] = file_name if file_name
33 def assert_hash_includes(actual_hash, expected_hash, msg=nil)
34 expected_hash.each do |key, value|
35 assert_equal(value, actual_hash[key], msg)
40 assert_hash_includes(session, {arvados_api_token: nil},
41 "session includes unexpected API token")
44 def assert_session_for_auth(client_auth)
46 api_fixture('api_client_authorizations')[client_auth.to_s]['api_token']
47 assert_hash_includes(session, {arvados_api_token: api_token},
48 "session token does not belong to #{client_auth}")
51 def show_collection(params, session={}, response=:success)
52 params = collection_params(params) if not params.is_a? Hash
53 session = session_for(session) if not session.is_a? Hash
54 get(:show, params, session)
55 assert_response response
58 test "viewing a collection" do
59 show_collection(:foo_file, :active)
60 assert_equal([['.', 'foo', 3]], assigns(:object).files)
63 test "viewing a collection with spaces in filename" do
64 show_collection(:w_a_z_file, :active)
65 assert_equal([['.', 'w a z', 5]], assigns(:object).files)
68 test "download a file with spaces in filename" do
70 collection = api_fixture('collections')['w_a_z_file']
72 uuid: collection['uuid'],
74 }, session_for(:active)
75 assert_response :redirect
76 assert_match /w%20a%20z/, response.redirect_url
79 test "viewing a collection fetches related projects" do
80 show_collection({id: api_fixture('collections')["foo_file"]['portable_data_hash']}, :active)
81 assert_includes(assigns(:same_pdh).map(&:owner_uuid),
82 api_fixture('groups')['aproject']['uuid'],
83 "controller did not find linked project")
86 test "viewing a collection fetches related permissions" do
87 show_collection(:bar_file, :active)
88 assert_includes(assigns(:permissions).map(&:uuid),
89 api_fixture('links')['bar_file_readable_by_active']['uuid'],
90 "controller did not find permission link")
93 test "viewing a collection fetches jobs that output it" do
94 show_collection(:bar_file, :active)
95 assert_includes(assigns(:output_of).map(&:uuid),
96 api_fixture('jobs')['foobar']['uuid'],
97 "controller did not find output job")
100 test "viewing a collection fetches jobs that logged it" do
101 show_collection(:baz_file, :active)
102 assert_includes(assigns(:log_of).map(&:uuid),
103 api_fixture('jobs')['foobar']['uuid'],
104 "controller did not find logger job")
107 test "sharing auths available to admin" do
108 show_collection("collection_owned_by_active", "admin_trustedclient")
109 assert_not_nil assigns(:search_sharing)
112 test "sharing auths available to owner" do
113 show_collection("collection_owned_by_active", "active_trustedclient")
114 assert_not_nil assigns(:search_sharing)
117 test "sharing auths available to reader" do
118 show_collection("foo_collection_in_aproject",
119 "project_viewer_trustedclient")
120 assert_not_nil assigns(:search_sharing)
123 test "viewing collection files with a reader token" do
124 params = collection_params(:foo_file)
125 params[:reader_token] = api_fixture("api_client_authorizations",
126 "active_all_collections", "api_token")
127 get(:show_file_links, params)
128 assert_response :redirect
132 test "fetching collection file with reader token" do
134 params = collection_params(:foo_file, "foo")
135 params[:reader_token] = api_fixture("api_client_authorizations",
136 "active_all_collections", "api_token")
137 get(:show_file, params)
138 assert_response :redirect
139 assert_match /foo/, response.redirect_url
143 test "reader token Collection links end with trailing slash" do
144 # Testing the fix for #2937.
145 session = session_for(:active_trustedclient)
146 post(:share, collection_params(:foo_file), session)
147 assert(@controller.download_link.ends_with? '/',
148 "Collection share link does not end with slash for wget")
151 test "getting a file from Keep" do
153 params = collection_params(:foo_file, 'foo')
154 sess = session_for(:active)
155 get(:show_file, params, sess)
156 assert_response :redirect
157 assert_match /foo/, response.redirect_url
160 test 'anonymous download' do
162 config_anonymous true
164 uuid: api_fixture('collections')['user_agreement_in_anonymously_accessible_project']['uuid'],
165 file: 'GNU_General_Public_License,_version_3.pdf',
167 assert_response :redirect
168 assert_match /GNU_General_Public_License/, response.redirect_url
171 test "can't get a file from Keep without permission" do
172 params = collection_params(:foo_file, 'foo')
173 sess = session_for(:spectator)
174 get(:show_file, params, sess)
178 test "getting a file from Keep with a good reader token" do
180 params = collection_params(:foo_file, 'foo')
181 read_token = api_fixture('api_client_authorizations')['active']['api_token']
182 params[:reader_token] = read_token
183 get(:show_file, params)
184 assert_response :redirect
185 assert_match /foo/, response.redirect_url
186 assert_not_equal(read_token, session[:arvados_api_token],
187 "using a reader token set the session's API token")
190 [false, true].each do |anon|
191 test "download a file using a reader token with insufficient scope, anon #{anon}" do
192 config_anonymous anon
193 params = collection_params(:foo_file, 'foo')
194 params[:reader_token] =
195 api_fixture('api_client_authorizations')['active_noscope']['api_token']
196 get(:show_file, params)
198 # Some files can be shown without a valid token, but not this one.
201 # No files will ever be shown without a valid token. You
202 # should log in and try again.
203 assert_response :redirect
208 test "can get a file with an unpermissioned auth but in-scope reader token" do
210 params = collection_params(:foo_file, 'foo')
211 sess = session_for(:expired)
212 read_token = api_fixture('api_client_authorizations')['active']['api_token']
213 params[:reader_token] = read_token
214 get(:show_file, params, sess)
215 assert_response :redirect
216 assert_not_equal(read_token, session[:arvados_api_token],
217 "using a reader token set the session's API token")
220 test "inactive user can retrieve user agreement" do
222 ua_collection = api_fixture('collections')['user_agreement']
223 # Here we don't test whether the agreement can be retrieved from
224 # Keep. We only test that show_file decides to send file content.
226 uuid: ua_collection['uuid'],
227 file: ua_collection['manifest_text'].match(/ \d+:\d+:(\S+)/)[1]
228 }, session_for(:inactive)
229 assert_nil(assigns(:unsigned_user_agreements),
230 "Did not skip check_user_agreements filter " +
231 "when showing the user agreement.")
232 assert_response :redirect
235 test "requesting nonexistent Collection returns 404" do
236 show_collection({uuid: NONEXISTENT_COLLECTION, id: NONEXISTENT_COLLECTION},
240 test "show file in a subdirectory of a collection" do
242 params = collection_params(:collection_with_files_in_subdir, 'subdir2/subdir3/subdir4/file1_in_subdir4.txt')
243 get(:show_file, params, session_for(:user1_with_load))
244 assert_response :redirect
245 assert_match /subdir2\/subdir3\/subdir4\/file1_in_subdir4\.txt/, response.redirect_url
248 test 'provenance graph' do
251 obj = find_fixture Collection, "graph_test_collection3"
253 provenance = obj.provenance.stringify_keys
255 [obj[:portable_data_hash]].each do |k|
256 assert_not_nil provenance[k], "Expected key #{k} in provenance set"
259 prov_svg = ProvenanceHelper::create_provenance_graph(provenance, "provenance_svg",
260 {:request => RequestDuck,
261 :direction => :bottom_up,
262 :combine_jobs => :script_only})
264 stage1 = find_fixture Job, "graph_stage1"
265 stage3 = find_fixture Job, "graph_stage3"
266 previous_job_run = find_fixture Job, "previous_job_run"
268 obj_id = obj.portable_data_hash.gsub('+', '\\\+')
269 stage1_out = stage1.output.gsub('+', '\\\+')
270 stage1_id = "#{stage1.script}_#{Digest::MD5.hexdigest(stage1[:script_parameters].to_json)}"
271 stage3_id = "#{stage3.script}_#{Digest::MD5.hexdigest(stage3[:script_parameters].to_json)}"
273 assert /#{obj_id}->#{stage3_id}/.match(prov_svg)
275 assert /#{stage3_id}->#{stage1_out}/.match(prov_svg)
277 assert /#{stage1_out}->#{stage1_id}/.match(prov_svg)
281 test 'used_by graph' do
283 obj = find_fixture Collection, "graph_test_collection1"
285 used_by = obj.used_by.stringify_keys
287 used_by_svg = ProvenanceHelper::create_provenance_graph(used_by, "used_by_svg",
288 {:request => RequestDuck,
289 :direction => :top_down,
290 :combine_jobs => :script_only,
291 :pdata_only => true})
293 stage2 = find_fixture Job, "graph_stage2"
294 stage3 = find_fixture Job, "graph_stage3"
296 stage2_id = "#{stage2.script}_#{Digest::MD5.hexdigest(stage2[:script_parameters].to_json)}"
297 stage3_id = "#{stage3.script}_#{Digest::MD5.hexdigest(stage3[:script_parameters].to_json)}"
299 obj_id = obj.portable_data_hash.gsub('+', '\\\+')
300 stage3_out = stage3.output.gsub('+', '\\\+')
302 assert /#{obj_id}->#{stage2_id}/.match(used_by_svg)
304 assert /#{obj_id}->#{stage3_id}/.match(used_by_svg)
306 assert /#{stage3_id}->#{stage3_out}/.match(used_by_svg)
308 assert /#{stage3_id}->#{stage3_out}/.match(used_by_svg)
312 test "view collection with empty properties" do
313 fixture_name = :collection_with_empty_properties
314 show_collection(fixture_name, :active)
315 assert_equal(api_fixture('collections')[fixture_name.to_s]['name'], assigns(:object).name)
316 assert_not_nil(assigns(:object).properties)
317 assert_empty(assigns(:object).properties)
320 test "view collection with one property" do
321 fixture_name = :collection_with_one_property
322 show_collection(fixture_name, :active)
323 fixture = api_fixture('collections')[fixture_name.to_s]
324 assert_equal(fixture['name'], assigns(:object).name)
325 assert_equal(fixture['properties'][0], assigns(:object).properties[0])
328 test "create collection with properties" do
331 name: 'collection created with properties',
334 property_1: 'value_1'
338 }, session_for(:active)
339 assert_response :success
340 assert_not_nil assigns(:object).uuid
341 assert_equal 'collection created with properties', assigns(:object).name
342 assert_equal 'value_1', assigns(:object).properties[:property_1]
345 test "update description and check manifest_text is not lost" do
346 collection = api_fixture("collections")["multilevel_collection_1"]
348 id: collection["uuid"],
350 description: 'test description update'
353 }, session_for(:active)
354 assert_response :success
355 assert_not_nil assigns(:object)
356 # Ensure the Workbench response still has the original manifest_text
357 assert_equal 'test description update', assigns(:object).description
358 assert_equal true, strip_signatures_and_compare(collection['manifest_text'], assigns(:object).manifest_text)
359 # Ensure the API server still has the original manifest_text after
360 # we called arvados.v1.collections.update
362 assert_equal true, strip_signatures_and_compare(Collection.find(collection['uuid']).manifest_text,
363 collection['manifest_text'])
367 # Since we got the initial collection from fixture, there are no signatures in manifest_text.
368 # However, after update or find, the collection retrieved will have singed manifest_text.
369 # Hence, let's compare each line after excluding signatures.
370 def strip_signatures_and_compare m1, m2
371 m1_lines = m1.split "\n"
372 m2_lines = m2.split "\n"
374 return false if m1_lines.size != m2_lines.size
376 m1_lines.each_with_index do |line, i|
378 line.split.each do |word|
379 m1_words << word.split('+A')[0]
382 m2_lines[i].split.each do |word|
383 m2_words << word.split('+A')[0]
385 return false if !m1_words.join(' ').eql?(m2_words.join(' '))
391 test "view collection and verify none of the file types listed are disabled" do
392 show_collection(:collection_with_several_supported_file_types, :active)
394 files = assigns(:object).files
395 assert_equal true, files.length>0, "Expected one or more files in collection"
397 disabled = css_select('[disabled="disabled"]').collect do |el|
400 assert_equal 0, disabled.length, "Expected no disabled files in collection viewables list"
403 test "view collection and verify file types listed are all disabled" do
404 show_collection(:collection_with_several_unsupported_file_types, :active)
406 files = assigns(:object).files.collect do |_, file, _|
409 assert_equal true, files.length>0, "Expected one or more files in collection"
411 disabled = css_select('[disabled="disabled"]').collect do |el|
412 el.attributes['title'].split[-1]
415 assert_equal files.sort, disabled.sort, "Expected to see all collection files in disabled list of files"
418 test "anonymous user accesses collection in shared project" do
419 config_anonymous true
420 collection = api_fixture('collections')['public_text_file']
421 get(:show, {id: collection['uuid']})
423 response_object = assigns(:object)
424 assert_equal collection['name'], response_object['name']
425 assert_equal collection['uuid'], response_object['uuid']
426 assert_includes @response.body, 'Hello world'
427 assert_includes @response.body, 'Content address'
428 refute_nil css_select('[href="#Advanced"]')
431 test "can view empty collection" do
432 get :show, {id: 'd41d8cd98f00b204e9800998ecf8427e+0'}, session_for(:active)
433 assert_includes @response.body, 'The following collections have this content'
436 test "collection portable data hash redirect" do
437 di = api_fixture('collections')['docker_image']
438 get :show, {id: di['portable_data_hash']}, session_for(:active)
439 assert_match /\/collections\/#{di['uuid']}/, @response.redirect_url
442 test "collection portable data hash with multiple matches" do
443 pdh = api_fixture('collections')['foo_file']['portable_data_hash']
444 get :show, {id: pdh}, session_for(:admin)
445 matches = api_fixture('collections').select {|k,v| v["portable_data_hash"] == pdh}
446 assert matches.size > 1
448 matches.each do |k,v|
449 assert_match /href="\/collections\/#{v['uuid']}">.*#{v['name']}<\/a>/, @response.body
452 assert_includes @response.body, 'The following collections have this content:'
453 assert_not_includes @response.body, 'more results are not shown'
454 assert_not_includes @response.body, 'Activity'
455 assert_not_includes @response.body, 'Sharing and permissions'
458 test "collection page renders name" do
459 collection = api_fixture('collections')['foo_file']
460 get :show, {id: collection['uuid']}, session_for(:active)
461 assert_includes @response.body, collection['name']
462 assert_match /not authorized to manage collection sharing links/, @response.body
465 test "No Upload tab on non-writable collection" do
466 get :show, {id: api_fixture('collections')['user_agreement']['uuid']}, session_for(:active)
467 assert_not_includes @response.body, '<a href="#Upload"'
470 def setup_for_keep_web cfg='https://%{uuid_or_pdh}.example', dl_cfg=false
471 Rails.configuration.keep_web_url = cfg
472 Rails.configuration.keep_web_download_url = dl_cfg
475 %w(uuid portable_data_hash).each do |id_type|
476 test "Redirect to keep_web_url via #{id_type}" do
478 tok = api_fixture('api_client_authorizations')['active']['api_token']
479 id = api_fixture('collections')['w_a_z_file'][id_type]
480 get :show_file, {uuid: id, file: "w a z"}, session_for(:active)
481 assert_response :redirect
482 assert_equal "https://#{id.sub '+', '-'}.example/_/w%20a%20z?api_token=#{tok}", @response.redirect_url
485 test "Redirect to keep_web_url via #{id_type} with reader token" do
487 tok = api_fixture('api_client_authorizations')['active']['api_token']
488 id = api_fixture('collections')['w_a_z_file'][id_type]
489 get :show_file, {uuid: id, file: "w a z", reader_token: tok}, session_for(:expired)
490 assert_response :redirect
491 assert_equal "https://#{id.sub '+', '-'}.example/t=#{tok}/_/w%20a%20z", @response.redirect_url
494 test "Redirect to keep_web_url via #{id_type} with no token" do
496 config_anonymous true
497 id = api_fixture('collections')['public_text_file'][id_type]
498 get :show_file, {uuid: id, file: "Hello World.txt"}
499 assert_response :redirect
500 assert_equal "https://#{id.sub '+', '-'}.example/_/Hello%20World.txt", @response.redirect_url
503 test "Redirect to keep_web_url via #{id_type} with disposition param" do
505 config_anonymous true
506 id = api_fixture('collections')['public_text_file'][id_type]
509 file: "Hello World.txt",
510 disposition: 'attachment',
512 assert_response :redirect
513 assert_equal "https://#{id.sub '+', '-'}.example/_/Hello%20World.txt?disposition=attachment", @response.redirect_url
516 test "Redirect to keep_web_download_url via #{id_type}" do
517 setup_for_keep_web('https://collections.example/c=%{uuid_or_pdh}',
518 'https://download.example/c=%{uuid_or_pdh}')
519 tok = api_fixture('api_client_authorizations')['active']['api_token']
520 id = api_fixture('collections')['w_a_z_file'][id_type]
521 get :show_file, {uuid: id, file: "w a z"}, session_for(:active)
522 assert_response :redirect
523 assert_equal "https://download.example/c=#{id.sub '+', '-'}/_/w%20a%20z?api_token=#{tok}", @response.redirect_url
526 test "Redirect to keep_web_url via #{id_type} when trust_all_content enabled" do
527 Rails.configuration.trust_all_content = true
528 setup_for_keep_web('https://collections.example/c=%{uuid_or_pdh}',
529 'https://download.example/c=%{uuid_or_pdh}')
530 tok = api_fixture('api_client_authorizations')['active']['api_token']
531 id = api_fixture('collections')['w_a_z_file'][id_type]
532 get :show_file, {uuid: id, file: "w a z"}, session_for(:active)
533 assert_response :redirect
534 assert_equal "https://collections.example/c=#{id.sub '+', '-'}/_/w%20a%20z?api_token=#{tok}", @response.redirect_url
538 [false, true].each do |anon|
539 test "No redirect to keep_web_url if collection not found, anon #{anon}" do
541 config_anonymous anon
542 id = api_fixture('collections')['w_a_z_file']['uuid']
543 get :show_file, {uuid: id, file: "w a z"}, session_for(:spectator)
547 test "Redirect download to keep_web_download_url, anon #{anon}" do
548 config_anonymous anon
549 setup_for_keep_web('https://collections.example/c=%{uuid_or_pdh}',
550 'https://download.example/c=%{uuid_or_pdh}')
551 tok = api_fixture('api_client_authorizations')['active']['api_token']
552 id = api_fixture('collections')['public_text_file']['uuid']
555 file: 'Hello world.txt',
556 disposition: 'attachment',
557 }, session_for(:active)
558 assert_response :redirect
559 expect_url = "https://download.example/c=#{id.sub '+', '-'}/_/Hello%20world.txt"
561 expect_url += "?api_token=#{tok}"
563 assert_equal expect_url, @response.redirect_url
567 test "Error if file is impossible to retrieve from keep_web_url" do
568 # Cannot pass a session token using a single-origin keep-web URL,
569 # cannot read this collection without a session token.
570 setup_for_keep_web 'https://collections.example/c=%{uuid_or_pdh}', false
571 id = api_fixture('collections')['w_a_z_file']['uuid']
572 get :show_file, {uuid: id, file: "w a z"}, session_for(:active)
576 [false, true].each do |trust_all_content|
577 test "Redirect preview to keep_web_download_url when preview is disabled and trust_all_content is #{trust_all_content}" do
578 Rails.configuration.trust_all_content = trust_all_content
579 setup_for_keep_web false, 'https://download.example/c=%{uuid_or_pdh}'
580 tok = api_fixture('api_client_authorizations')['active']['api_token']
581 id = api_fixture('collections')['w_a_z_file']['uuid']
582 get :show_file, {uuid: id, file: "w a z"}, session_for(:active)
583 assert_response :redirect
584 assert_equal "https://download.example/c=#{id.sub '+', '-'}/_/w%20a%20z?api_token=#{tok}", @response.redirect_url
588 test "remove selected files from collection" do
591 # create a new collection to test; using existing collections will cause other tests to fail,
592 # and resetting fixtures after each test makes it take almost 4 times to run this test file.
593 manifest_text = ". d41d8cd98f00b204e9800998ecf8427e+0 0:0:file1 0:0:file2\n./dir1 d41d8cd98f00b204e9800998ecf8427e+0 0:0:file1 0:0:file2\n"
595 collection = Collection.create(manifest_text: manifest_text)
596 assert_includes(collection['manifest_text'], "0:0:file1")
598 # now remove all files named 'file1' from the collection
599 post :remove_selected_files, {
600 id: collection['uuid'],
601 selection: ["#{collection['uuid']}/file1",
602 "#{collection['uuid']}/dir1/file1"],
604 }, session_for(:active)
605 assert_response :success
607 # verify no 'file1' in the updated collection
608 collection = Collection.select([:uuid, :manifest_text]).where(uuid: collection['uuid']).first
609 assert_not_includes(collection['manifest_text'], "0:0:file1")
610 assert_includes(collection['manifest_text'], "0:0:file2") # but other files still exist
613 test "remove all files from a subdir of a collection" do
616 # create a new collection to test
617 manifest_text = ". d41d8cd98f00b204e9800998ecf8427e+0 0:0:file1 0:0:file2\n./dir1 d41d8cd98f00b204e9800998ecf8427e+0 0:0:file1 0:0:file2\n"
619 collection = Collection.create(manifest_text: manifest_text)
620 assert_includes(collection['manifest_text'], "0:0:file1")
622 # now remove all files from "dir1" subdir of the collection
623 post :remove_selected_files, {
624 id: collection['uuid'],
625 selection: ["#{collection['uuid']}/dir1/file1",
626 "#{collection['uuid']}/dir1/file2"],
628 }, session_for(:active)
629 assert_response :success
631 # verify that "./dir1" no longer exists in this collection's manifest text
632 collection = Collection.select([:uuid, :manifest_text]).where(uuid: collection['uuid']).first
633 assert_match /. d41d8cd98f00b204e9800998ecf8427e\+0\+A(.*) 0:0:file1 0:0:file2\n$/, collection['manifest_text']
634 assert_not_includes(collection['manifest_text'], 'dir1')
637 test "rename file in a collection" do
640 # create a new collection to test
641 manifest_text = ". d41d8cd98f00b204e9800998ecf8427e+0 0:0:file1 0:0:file2\n./dir1 d41d8cd98f00b204e9800998ecf8427e+0 0:0:dir1file1 0:0:dir1file2 0:0:dir1imagefile.png\n"
643 collection = Collection.create(manifest_text: manifest_text)
644 assert_includes(collection['manifest_text'], "0:0:file1")
646 # rename 'file1' as 'file1renamed' and verify
648 id: collection['uuid'],
650 'rename-file-path:file1' => 'file1renamed'
653 }, session_for(:active)
654 assert_response :success
656 collection = Collection.select([:uuid, :manifest_text]).where(uuid: collection['uuid']).first
657 assert_match /. d41d8cd98f00b204e9800998ecf8427e\+0\+A(.*) 0:0:file1renamed 0:0:file2\n.\/dir1 d41d8cd98f00b204e9800998ecf8427e\+0\+A(.*) 0:0:dir1file1 0:0:dir1file2 0:0:dir1imagefile.png\n$/, collection['manifest_text']
659 # now rename 'file2' such that it is moved into 'dir1'
662 id: collection['uuid'],
664 'rename-file-path:file2' => 'dir1/file2'
667 }, session_for(:active)
668 assert_response :success
670 collection = Collection.select([:uuid, :manifest_text]).where(uuid: collection['uuid']).first
671 assert_match /. d41d8cd98f00b204e9800998ecf8427e\+0\+A(.*) 0:0:file1renamed\n.\/dir1 d41d8cd98f00b204e9800998ecf8427e\+0\+A(.*) 0:0:dir1file1 0:0:dir1file2 0:0:dir1imagefile.png 0:0:file2\n$/, collection['manifest_text']
673 # now rename 'dir1/dir1file1' such that it is moved into a new subdir
676 id: collection['uuid'],
678 'rename-file-path:dir1/dir1file1' => 'dir2/dir3/dir1file1moved'
681 }, session_for(:active)
682 assert_response :success
684 collection = Collection.select([:uuid, :manifest_text]).where(uuid: collection['uuid']).first
685 assert_match /. d41d8cd98f00b204e9800998ecf8427e\+0\+A(.*) 0:0:file1renamed\n.\/dir1 d41d8cd98f00b204e9800998ecf8427e\+0\+A(.*) 0:0:dir1file2 0:0:dir1imagefile.png 0:0:file2\n.\/dir2\/dir3 d41d8cd98f00b204e9800998ecf8427e\+0\+A(.*) 0:0:dir1file1moved\n$/, collection['manifest_text']
687 # now rename the image file 'dir1/dir1imagefile.png'
690 id: collection['uuid'],
692 'rename-file-path:dir1/dir1imagefile.png' => 'dir1/dir1imagefilerenamed.png'
695 }, session_for(:active)
696 assert_response :success
698 collection = Collection.select([:uuid, :manifest_text]).where(uuid: collection['uuid']).first
699 assert_match /. d41d8cd98f00b204e9800998ecf8427e\+0\+A(.*) 0:0:file1renamed\n.\/dir1 d41d8cd98f00b204e9800998ecf8427e\+0\+A(.*) 0:0:dir1file2 0:0:dir1imagefilerenamed.png 0:0:file2\n.\/dir2\/dir3 d41d8cd98f00b204e9800998ecf8427e\+0\+A(.*) 0:0:dir1file1moved\n$/, collection['manifest_text']
702 test "renaming file with a duplicate name in same stream not allowed" do
705 # rename 'file2' as 'file1' and expect error
707 id: 'zzzzz-4zz18-pyw8yp9g3pr7irn',
709 'rename-file-path:file2' => 'file1'
712 }, session_for(:active)
714 assert_includes json_response['errors'], 'Duplicate file path'
717 test "renaming file with a duplicate name as another stream not allowed" do
720 # rename 'file1' as 'dir1/file1' and expect error
722 id: 'zzzzz-4zz18-pyw8yp9g3pr7irn',
724 'rename-file-path:file1' => 'dir1/file1'
727 }, session_for(:active)
729 assert_includes json_response['errors'], 'Duplicate file path'