3 class Arvados::V1::CollectionsControllerTest < ActionController::TestCase
5 PERM_TOKEN_RE = /\+A[[:xdigit:]]+@[[:xdigit:]]{8}\b/
7 def permit_unsigned_manifests isok=true
8 # Set security model for the life of a test.
9 Rails.configuration.permit_create_collection_with_unsigned_manifest = isok
12 def assert_signed_manifest manifest_text, label=''
13 assert_not_nil manifest_text, "#{label} manifest_text was nil"
14 manifest_text.scan(/ [[:xdigit:]]{32}\S*/) do |tok|
15 assert_match(PERM_TOKEN_RE, tok,
16 "Locator in #{label} manifest_text was not signed")
20 def assert_unsigned_manifest resp, label=''
21 txt = resp['unsigned_manifest_text']
22 assert_not_nil(txt, "#{label} unsigned_manifest_text was nil")
24 txt.scan(/ [[:xdigit:]]{32}\S*/) do |tok|
26 refute_match(PERM_TOKEN_RE, tok,
27 "Locator in #{label} unsigned_manifest_text was signed: #{tok}")
32 test "should get index" do
33 authorize_with :active
35 assert_response :success
36 assert(assigns(:objects).andand.any?, "no Collections returned in index")
37 refute(json_response["items"].any? { |c| c.has_key?("manifest_text") },
38 "basic Collections index included manifest_text")
41 test "collections.get returns signed locators, and no unsigned_manifest_text" do
42 permit_unsigned_manifests
43 authorize_with :active
44 get :show, {id: collections(:foo_file).uuid}
45 assert_response :success
46 assert_signed_manifest json_response['manifest_text'], 'foo_file'
47 refute_includes json_response, 'unsigned_manifest_text'
50 test "index with manifest_text selected returns signed locators" do
51 columns = %w(uuid owner_uuid manifest_text)
52 authorize_with :active
53 get :index, select: columns
54 assert_response :success
55 assert(assigns(:objects).andand.any?,
56 "no Collections returned for index with columns selected")
57 json_response["items"].each do |coll|
58 assert_equal(coll.keys - ['kind'], columns,
59 "Collections index did not respect selected columns")
60 assert_signed_manifest coll['manifest_text'], coll['uuid']
64 test "index with unsigned_manifest_text selected returns only unsigned locators" do
65 authorize_with :active
66 get :index, select: ['unsigned_manifest_text']
67 assert_response :success
68 assert_operator json_response["items"].count, :>, 0
70 json_response["items"].each do |coll|
71 assert_equal(coll.keys - ['kind'], ['unsigned_manifest_text'],
72 "Collections index did not respect selected columns")
73 locs += assert_unsigned_manifest coll, coll['uuid']
75 assert_operator locs, :>, 0, "no locators found in any manifests"
78 [0,1,2].each do |limit|
79 test "get index with limit=#{limit}" do
80 authorize_with :active
81 get :index, limit: limit
82 assert_response :success
83 assert_equal limit, assigns(:objects).count
84 resp = JSON.parse(@response.body)
85 assert_equal limit, resp['limit']
89 test "items.count == items_available" do
90 authorize_with :active
91 get :index, limit: 100000
92 assert_response :success
93 resp = JSON.parse(@response.body)
94 assert_equal resp['items_available'], assigns(:objects).length
95 assert_equal resp['items_available'], resp['items'].count
96 unique_uuids = resp['items'].collect { |i| i['uuid'] }.compact.uniq
97 assert_equal unique_uuids.count, resp['items'].count
100 test "items.count == items_available with filters" do
101 authorize_with :active
104 filters: [['uuid','=',collections(:foo_file).uuid]]
106 assert_response :success
107 assert_equal 1, assigns(:objects).length
108 assert_equal 1, json_response['items_available']
109 assert_equal 1, json_response['items'].count
112 test "get index with limit=2 offset=99999" do
113 # Assume there are not that many test fixtures.
114 authorize_with :active
115 get :index, limit: 2, offset: 99999
116 assert_response :success
117 assert_equal 0, assigns(:objects).count
118 resp = JSON.parse(@response.body)
119 assert_equal 2, resp['limit']
120 assert_equal 99999, resp['offset']
123 def request_capped_index(params={})
124 authorize_with :user1_with_load
125 coll1 = collections(:collection_1_of_201)
126 Rails.configuration.max_index_database_read =
127 yield(coll1.manifest_text.size)
129 select: %w(uuid manifest_text),
130 filters: [["owner_uuid", "=", coll1.owner_uuid]],
135 test "index with manifest_text limited by max_index_database_read returns non-empty" do
136 request_capped_index() { |_| 1 }
137 assert_response :success
138 assert_equal(1, json_response["items"].size)
139 assert_equal(1, json_response["limit"])
140 assert_equal(201, json_response["items_available"])
143 test "max_index_database_read size check follows same order as real query" do
144 authorize_with :user1_with_load
145 txt = '.' + ' d41d8cd98f00b204e9800998ecf8427e+0'*1000 + " 0:0:empty.txt\n"
146 c = Collection.create! manifest_text: txt, name: '0000000000000000000'
147 request_capped_index(select: %w(uuid manifest_text name),
149 filters: [['name','>=',c.name]]) do |_|
152 assert_response :success
153 assert_equal(1, json_response["items"].size)
154 assert_equal(1, json_response["limit"])
155 assert_equal(c.uuid, json_response["items"][0]["uuid"])
156 # The effectiveness of the test depends on >1 item matching the filters.
157 assert_operator(1, :<, json_response["items_available"])
160 test "index with manifest_text limited by max_index_database_read" do
161 request_capped_index() { |size| (size * 3) + 1 }
162 assert_response :success
163 assert_equal(3, json_response["items"].size)
164 assert_equal(3, json_response["limit"])
165 assert_equal(201, json_response["items_available"])
168 test "max_index_database_read does not interfere with limit" do
169 request_capped_index(limit: 5) { |size| size * 20 }
170 assert_response :success
171 assert_equal(5, json_response["items"].size)
172 assert_equal(5, json_response["limit"])
173 assert_equal(201, json_response["items_available"])
176 test "max_index_database_read does not interfere with order" do
177 request_capped_index(select: %w(uuid manifest_text name),
178 order: "name DESC") { |size| (size * 11) + 1 }
179 assert_response :success
180 assert_equal(11, json_response["items"].size)
181 assert_empty(json_response["items"].reject do |coll|
182 coll["name"] =~ /^Collection_9/
184 assert_equal(11, json_response["limit"])
185 assert_equal(201, json_response["items_available"])
188 test "admin can create collection with unsigned manifest" do
189 authorize_with :admin
191 manifest_text: <<-EOS
192 . d41d8cd98f00b204e9800998ecf8427e+0 0:0:foo.txt
193 . acbd18db4cc2f85cedef654fccc4a4d8+3 0:3:bar.txt
194 . acbd18db4cc2f85cedef654fccc4a4d8+3 0:3:bar.txt
195 ./baz acbd18db4cc2f85cedef654fccc4a4d8+3 0:3:bar.txt
198 test_collection[:portable_data_hash] =
199 Digest::MD5.hexdigest(test_collection[:manifest_text]) +
201 test_collection[:manifest_text].length.to_s
203 # post :create will modify test_collection in place, so we save a copy first.
204 # Hash.deep_dup is not sufficient as it preserves references of strings (??!?)
205 post_collection = Marshal.load(Marshal.dump(test_collection))
207 collection: post_collection
210 assert_response :success
211 assert_nil assigns(:objects)
213 response_collection = assigns(:object)
215 stored_collection = Collection.select([:uuid, :portable_data_hash, :manifest_text]).
216 where(portable_data_hash: response_collection['portable_data_hash']).first
218 assert_equal test_collection[:portable_data_hash], stored_collection['portable_data_hash']
220 # The manifest in the response will have had permission hints added.
221 # Remove any permission hints in the response before comparing it to the source.
222 stripped_manifest = stored_collection['manifest_text'].gsub(/\+A[A-Za-z0-9@_-]+/, '')
223 assert_equal test_collection[:manifest_text], stripped_manifest
225 # TBD: create action should add permission signatures to manifest_text in the response,
226 # and we need to check those permission signatures here.
229 [:admin, :active].each do |user|
230 test "#{user} can get collection using portable data hash" do
233 foo_collection = collections(:foo_file)
235 # Get foo_file using its portable data hash
237 id: foo_collection[:portable_data_hash]
239 assert_response :success
240 assert_not_nil assigns(:object)
241 resp = assigns(:object)
242 assert_equal foo_collection[:portable_data_hash], resp['portable_data_hash']
243 assert_signed_manifest resp['manifest_text']
245 # The manifest in the response will have had permission hints added.
246 # Remove any permission hints in the response before comparing it to the source.
247 stripped_manifest = resp['manifest_text'].gsub(/\+A[A-Za-z0-9@_-]+/, '')
248 assert_equal foo_collection[:manifest_text], stripped_manifest
252 test "create with owner_uuid set to owned group" do
253 permit_unsigned_manifests
254 authorize_with :active
255 manifest_text = ". d41d8cd98f00b204e9800998ecf8427e 0:0:foo.txt\n"
258 owner_uuid: 'zzzzz-j7d0g-rew6elm53kancon',
259 manifest_text: manifest_text,
260 portable_data_hash: "d30fe8ae534397864cb96c544f4cf102+47"
263 assert_response :success
264 resp = JSON.parse(@response.body)
265 assert_equal 'zzzzz-j7d0g-rew6elm53kancon', resp['owner_uuid']
268 test "create fails with duplicate name" do
269 permit_unsigned_manifests
270 authorize_with :admin
271 manifest_text = ". d41d8cd98f00b204e9800998ecf8427e 0:0:foo.txt\n"
274 owner_uuid: 'zzzzz-tpzed-000000000000000',
275 manifest_text: manifest_text,
276 portable_data_hash: "d30fe8ae534397864cb96c544f4cf102+47",
281 response_errors = json_response['errors']
282 assert_not_nil response_errors, 'Expected error in response'
283 assert(response_errors.first.include?('duplicate key'),
284 "Expected 'duplicate key' error in #{response_errors.first}")
287 [false, true].each do |unsigned|
288 test "create with duplicate name, ensure_unique_name, unsigned=#{unsigned}" do
289 permit_unsigned_manifests unsigned
290 authorize_with :active
291 manifest_text = ". acbd18db4cc2f85cedef654fccc4a4d8+3 0:0:foo.txt\n"
293 manifest_text = Collection.sign_manifest manifest_text, api_token(:active)
297 owner_uuid: users(:active).uuid,
298 manifest_text: manifest_text,
299 name: "owned_by_active"
301 ensure_unique_name: true
303 assert_response :success
304 assert_equal 'owned_by_active (2)', json_response['name']
308 test "create with owner_uuid set to group i can_manage" do
309 permit_unsigned_manifests
310 authorize_with :active
311 manifest_text = ". d41d8cd98f00b204e9800998ecf8427e 0:0:foo.txt\n"
314 owner_uuid: groups(:active_user_has_can_manage).uuid,
315 manifest_text: manifest_text,
316 portable_data_hash: "d30fe8ae534397864cb96c544f4cf102+47"
319 assert_response :success
320 resp = JSON.parse(@response.body)
321 assert_equal groups(:active_user_has_can_manage).uuid, resp['owner_uuid']
324 test "create with owner_uuid fails on group with only can_read permission" do
325 permit_unsigned_manifests
326 authorize_with :active
327 manifest_text = ". d41d8cd98f00b204e9800998ecf8427e 0:0:foo.txt\n"
330 owner_uuid: groups(:all_users).uuid,
331 manifest_text: manifest_text,
332 portable_data_hash: "d30fe8ae534397864cb96c544f4cf102+47"
338 test "create with owner_uuid fails on group with no permission" do
339 permit_unsigned_manifests
340 authorize_with :active
341 manifest_text = ". d41d8cd98f00b204e9800998ecf8427e 0:0:foo.txt\n"
344 owner_uuid: groups(:public).uuid,
345 manifest_text: manifest_text,
346 portable_data_hash: "d30fe8ae534397864cb96c544f4cf102+47"
352 test "admin create with owner_uuid set to group with no permission" do
353 permit_unsigned_manifests
354 authorize_with :admin
355 manifest_text = ". d41d8cd98f00b204e9800998ecf8427e 0:0:foo.txt\n"
358 owner_uuid: 'zzzzz-j7d0g-it30l961gq3t0oi',
359 manifest_text: manifest_text,
360 portable_data_hash: "d30fe8ae534397864cb96c544f4cf102+47"
363 assert_response :success
366 test "should create with collection passed as json" do
367 permit_unsigned_manifests
368 authorize_with :active
372 "manifest_text":". d41d8cd98f00b204e9800998ecf8427e 0:0:foo.txt\n",\
373 "portable_data_hash":"d30fe8ae534397864cb96c544f4cf102+47"\
377 assert_response :success
380 test "should fail to create with checksum mismatch" do
381 permit_unsigned_manifests
382 authorize_with :active
386 "manifest_text":". d41d8cd98f00b204e9800998ecf8427e 0:0:bar.txt\n",\
387 "portable_data_hash":"d30fe8ae534397864cb96c544f4cf102+47"\
394 test "collection UUID is normalized when created" do
395 permit_unsigned_manifests
396 authorize_with :active
399 manifest_text: ". d41d8cd98f00b204e9800998ecf8427e 0:0:foo.txt\n",
400 portable_data_hash: "d30fe8ae534397864cb96c544f4cf102+47+Khint+Xhint+Zhint"
403 assert_response :success
404 assert_not_nil assigns(:object)
405 resp = JSON.parse(@response.body)
406 assert_equal "d30fe8ae534397864cb96c544f4cf102+47", resp['portable_data_hash']
409 test "get full provenance for baz file" do
410 authorize_with :active
411 get :provenance, id: 'ea10d51bcf88862dbcc36eb292017dfd+45'
412 assert_response :success
413 resp = JSON.parse(@response.body)
414 assert_not_nil resp['ea10d51bcf88862dbcc36eb292017dfd+45'] # baz
415 assert_not_nil resp['fa7aeb5140e2848d39b416daeef4ffc5+45'] # bar
416 assert_not_nil resp['1f4b0bc7583c2a7f9102c395f4ffc5e3+45'] # foo
417 assert_not_nil resp['zzzzz-8i9sb-cjs4pklxxjykyuq'] # bar->baz
418 assert_not_nil resp['zzzzz-8i9sb-aceg2bnq7jt7kon'] # foo->bar
421 test "get no provenance for foo file" do
422 # spectator user cannot even see baz collection
423 authorize_with :spectator
424 get :provenance, id: '1f4b0bc7583c2a7f9102c395f4ffc5e3+45'
428 test "get partial provenance for baz file" do
429 # spectator user can see bar->baz job, but not foo->bar job
430 authorize_with :spectator
431 get :provenance, id: 'ea10d51bcf88862dbcc36eb292017dfd+45'
432 assert_response :success
433 resp = JSON.parse(@response.body)
434 assert_not_nil resp['ea10d51bcf88862dbcc36eb292017dfd+45'] # baz
435 assert_not_nil resp['fa7aeb5140e2848d39b416daeef4ffc5+45'] # bar
436 assert_not_nil resp['zzzzz-8i9sb-cjs4pklxxjykyuq'] # bar->baz
437 assert_nil resp['zzzzz-8i9sb-aceg2bnq7jt7kon'] # foo->bar
438 assert_nil resp['1f4b0bc7583c2a7f9102c395f4ffc5e3+45'] # foo
441 test "search collections with 'any' operator" do
442 expect_pdh = collections(:docker_image).portable_data_hash
443 authorize_with :active
445 where: { any: ['contains', expect_pdh[5..25]] }
447 assert_response :success
448 found = assigns(:objects)
449 assert_equal 1, found.count
450 assert_equal expect_pdh, found.first.portable_data_hash
453 [false, true].each do |permit_unsigned|
454 test "create collection with signed manifest, permit_unsigned=#{permit_unsigned}" do
455 permit_unsigned_manifests permit_unsigned
456 authorize_with :active
458 d41d8cd98f00b204e9800998ecf8427e+0
459 acbd18db4cc2f85cedef654fccc4a4d8+3
460 ea10d51bcf88862dbcc36eb292017dfd+45)
462 unsigned_manifest = locators.map { |loc|
463 ". " + loc + " 0:0:foo.txt\n"
465 manifest_uuid = Digest::MD5.hexdigest(unsigned_manifest) +
467 unsigned_manifest.length.to_s
469 # Build a manifest with both signed and unsigned locators.
471 key: Rails.configuration.blob_signing_key,
472 api_token: api_token(:active),
474 signed_locators = locators.collect do |x|
475 Blob.sign_locator x, signing_opts
478 # Leave a non-empty blob unsigned.
479 signed_locators[1] = locators[1]
481 # Leave the empty blob unsigned. This should still be allowed.
482 signed_locators[0] = locators[0]
485 ". " + signed_locators[0] + " 0:0:foo.txt\n" +
486 ". " + signed_locators[1] + " 0:0:foo.txt\n" +
487 ". " + signed_locators[2] + " 0:0:foo.txt\n"
491 manifest_text: signed_manifest,
492 portable_data_hash: manifest_uuid,
495 assert_response :success
496 assert_not_nil assigns(:object)
497 resp = JSON.parse(@response.body)
498 assert_equal manifest_uuid, resp['portable_data_hash']
499 # All of the locators in the output must be signed.
500 resp['manifest_text'].lines.each do |entry|
501 m = /([[:xdigit:]]{32}\+\S+)/.match(entry)
503 assert Blob.verify_signature m[0], signing_opts
509 test "create collection with signed manifest and explicit TTL" do
510 authorize_with :active
512 d41d8cd98f00b204e9800998ecf8427e+0
513 acbd18db4cc2f85cedef654fccc4a4d8+3
514 ea10d51bcf88862dbcc36eb292017dfd+45)
516 unsigned_manifest = locators.map { |loc|
517 ". " + loc + " 0:0:foo.txt\n"
519 manifest_uuid = Digest::MD5.hexdigest(unsigned_manifest) +
521 unsigned_manifest.length.to_s
523 # build a manifest with both signed and unsigned locators.
524 # TODO(twp): in phase 4, all locators will need to be signed, so
525 # this test should break and will need to be rewritten. Issue #2755.
527 key: Rails.configuration.blob_signing_key,
528 api_token: api_token(:active),
532 ". " + locators[0] + " 0:0:foo.txt\n" +
533 ". " + Blob.sign_locator(locators[1], signing_opts) + " 0:0:foo.txt\n" +
534 ". " + Blob.sign_locator(locators[2], signing_opts) + " 0:0:foo.txt\n"
538 manifest_text: signed_manifest,
539 portable_data_hash: manifest_uuid,
542 assert_response :success
543 assert_not_nil assigns(:object)
544 resp = JSON.parse(@response.body)
545 assert_equal manifest_uuid, resp['portable_data_hash']
546 # All of the locators in the output must be signed.
547 resp['manifest_text'].lines.each do |entry|
548 m = /([[:xdigit:]]{32}\+\S+)/.match(entry)
550 assert Blob.verify_signature m[0], signing_opts
555 test "create fails with invalid signature" do
556 authorize_with :active
558 key: Rails.configuration.blob_signing_key,
559 api_token: api_token(:active),
562 # Generate a locator with a bad signature.
563 unsigned_locator = "acbd18db4cc2f85cedef654fccc4a4d8+3"
564 bad_locator = unsigned_locator + "+Affffffffffffffffffffffffffffffffffffffff@ffffffff"
565 assert !Blob.verify_signature(bad_locator, signing_opts)
567 # Creating a collection with this locator should
568 # produce 403 Permission denied.
569 unsigned_manifest = ". #{unsigned_locator} 0:0:foo.txt\n"
570 manifest_uuid = Digest::MD5.hexdigest(unsigned_manifest) +
572 unsigned_manifest.length.to_s
574 bad_manifest = ". #{bad_locator} 0:0:foo.txt\n"
577 manifest_text: bad_manifest,
578 portable_data_hash: manifest_uuid
585 test "create fails with uuid of signed manifest" do
586 authorize_with :active
588 key: Rails.configuration.blob_signing_key,
589 api_token: api_token(:active),
592 unsigned_locator = "d41d8cd98f00b204e9800998ecf8427e+0"
593 signed_locator = Blob.sign_locator(unsigned_locator, signing_opts)
594 signed_manifest = ". #{signed_locator} 0:0:foo.txt\n"
595 manifest_uuid = Digest::MD5.hexdigest(signed_manifest) +
597 signed_manifest.length.to_s
601 manifest_text: signed_manifest,
602 portable_data_hash: manifest_uuid
609 test "reject manifest with unsigned block as stream name" do
610 authorize_with :active
613 manifest_text: "00000000000000000000000000000000+1234 d41d8cd98f00b204e9800998ecf8427e+0 0:0:foo.txt\n"
616 assert_includes [422, 403], response.code.to_i
619 test "multiple locators per line" do
620 permit_unsigned_manifests
621 authorize_with :active
623 d41d8cd98f00b204e9800998ecf8427e+0
624 acbd18db4cc2f85cedef654fccc4a4d8+3
625 ea10d51bcf88862dbcc36eb292017dfd+45)
627 manifest_text = [".", *locators, "0:0:foo.txt\n"].join(" ")
628 manifest_uuid = Digest::MD5.hexdigest(manifest_text) +
630 manifest_text.length.to_s
633 manifest_text: manifest_text,
634 portable_data_hash: manifest_uuid,
636 post_collection = Marshal.load(Marshal.dump(test_collection))
638 collection: post_collection
640 assert_response :success
641 assert_not_nil assigns(:object)
642 resp = JSON.parse(@response.body)
643 assert_equal manifest_uuid, resp['portable_data_hash']
645 # The manifest in the response will have had permission hints added.
646 # Remove any permission hints in the response before comparing it to the source.
647 stripped_manifest = resp['manifest_text'].gsub(/\+A[A-Za-z0-9@_-]+/, '')
648 assert_equal manifest_text, stripped_manifest
651 test "multiple signed locators per line" do
652 permit_unsigned_manifests
653 authorize_with :active
655 d41d8cd98f00b204e9800998ecf8427e+0
656 acbd18db4cc2f85cedef654fccc4a4d8+3
657 ea10d51bcf88862dbcc36eb292017dfd+45)
660 key: Rails.configuration.blob_signing_key,
661 api_token: api_token(:active),
664 unsigned_manifest = [".", *locators, "0:0:foo.txt\n"].join(" ")
665 manifest_uuid = Digest::MD5.hexdigest(unsigned_manifest) +
667 unsigned_manifest.length.to_s
669 signed_locators = locators.map { |loc| Blob.sign_locator loc, signing_opts }
670 signed_manifest = [".", *signed_locators, "0:0:foo.txt\n"].join(" ")
674 manifest_text: signed_manifest,
675 portable_data_hash: manifest_uuid,
678 assert_response :success
679 assert_not_nil assigns(:object)
680 resp = JSON.parse(@response.body)
681 assert_equal manifest_uuid, resp['portable_data_hash']
682 # All of the locators in the output must be signed.
683 # Each line is of the form "path locator locator ... 0:0:file.txt"
684 # entry.split[1..-2] will yield just the tokens in the middle of the line
685 returned_locator_count = 0
686 resp['manifest_text'].lines.each do |entry|
687 entry.split[1..-2].each do |tok|
688 returned_locator_count += 1
689 assert Blob.verify_signature tok, signing_opts
692 assert_equal locators.count, returned_locator_count
695 test 'Reject manifest with unsigned blob' do
696 permit_unsigned_manifests false
697 authorize_with :active
698 unsigned_manifest = ". 0cc175b9c0f1b6a831c399e269772661+1 0:1:a.txt\n"
699 manifest_uuid = Digest::MD5.hexdigest(unsigned_manifest)
702 manifest_text: unsigned_manifest,
703 portable_data_hash: manifest_uuid,
707 "Creating a collection with unsigned blobs should respond 403"
708 assert_empty Collection.where('uuid like ?', manifest_uuid+'%'),
709 "Collection should not exist in database after failed create"
712 test 'List expired collection returns empty list' do
713 authorize_with :active
715 where: {name: 'expired_collection'},
717 assert_response :success
718 found = assigns(:objects)
719 assert_equal 0, found.count
722 test 'Show expired collection returns 404' do
723 authorize_with :active
725 id: 'zzzzz-4zz18-mto52zx1s7sn3ih',
730 test 'Update expired collection returns 404' do
731 authorize_with :active
733 id: 'zzzzz-4zz18-mto52zx1s7sn3ih',
735 name: "still expired"
741 test 'List collection with future expiration time succeeds' do
742 authorize_with :active
744 where: {name: 'collection_expires_in_future'},
746 found = assigns(:objects)
747 assert_equal 1, found.count
751 test 'Show collection with future expiration time succeeds' do
752 authorize_with :active
754 id: 'zzzzz-4zz18-padkqo7yb8d9i3j',
756 assert_response :success
759 test 'Update collection with future expiration time succeeds' do
760 authorize_with :active
762 id: 'zzzzz-4zz18-padkqo7yb8d9i3j',
764 name: "still not expired"
767 assert_response :success
770 test "get collection and verify that file_names is not included" do
771 authorize_with :active
772 get :show, {id: collections(:foo_file).uuid}
773 assert_response :success
774 assert_equal collections(:foo_file).uuid, json_response['uuid']
775 assert_nil json_response['file_names']
776 assert json_response['manifest_text']
782 ].each do |description_size, expected_response|
783 test "create collection with description size #{description_size}
784 and expect response #{expected_response}" do
785 skip "(Descriptions are not part of search indexes. Skip until full-text search
786 is implemented, at which point replace with a search in description.)"
788 authorize_with :active
790 description = 'here is a collection with a very large description'
791 while description.length < description_size
792 description = description + description
795 post :create, collection: {
796 manifest_text: ". d41d8cd98f00b204e9800998ecf8427e+0 0:0:foo.txt\n",
797 description: description,
800 assert_response expected_response
804 [1, 5, nil].each do |ask|
805 test "Set replication_desired=#{ask.inspect}" do
806 Rails.configuration.default_collection_replication = 2
807 authorize_with :active
809 id: collections(:replication_undesired_unconfirmed).uuid,
811 replication_desired: ask,
814 assert_response :success
815 assert_equal ask, json_response['replication_desired']
819 test "get collection with properties" do
820 authorize_with :active
821 get :show, {id: collections(:collection_with_one_property).uuid}
822 assert_response :success
823 assert_not_nil json_response['uuid']
824 assert_equal 'value1', json_response['properties']['property1']
827 test "create collection with properties" do
828 authorize_with :active
829 manifest_text = ". d41d8cd98f00b204e9800998ecf8427e 0:0:foo.txt\n"
832 manifest_text: manifest_text,
833 portable_data_hash: "d30fe8ae534397864cb96c544f4cf102+47",
834 properties: {'property_1' => 'value_1'}
837 assert_response :success
838 assert_not_nil json_response['uuid']
839 assert_equal 'value_1', json_response['properties']['property_1']
844 ". d41d8cd98f00b204e9800998ecf8427e foo.txt",
845 "d41d8cd98f00b204e9800998ecf8427e 0:0:foo.txt",
846 ". d41d8cd98f00b204e9800998ecf8427e 0:0:foo.txt",
847 ].each do |manifest_text|
848 test "create collection with invalid manifest #{manifest_text} and expect error" do
849 authorize_with :active
852 manifest_text: manifest_text,
853 portable_data_hash: "d41d8cd98f00b204e9800998ecf8427e+0"
857 response_errors = json_response['errors']
858 assert_not_nil response_errors, 'Expected error in response'
859 assert(response_errors.first.include?('Invalid manifest'),
860 "Expected 'Invalid manifest' error in #{response_errors.first}")
865 [nil, "d41d8cd98f00b204e9800998ecf8427e+0"],
866 ["", "d41d8cd98f00b204e9800998ecf8427e+0"],
867 [". d41d8cd98f00b204e9800998ecf8427e 0:0:foo.txt\n", "d30fe8ae534397864cb96c544f4cf102+47"],
868 ].each do |manifest_text, pdh|
869 test "create collection with valid manifest #{manifest_text.inspect} and expect success" do
870 authorize_with :active
873 manifest_text: manifest_text,
874 portable_data_hash: pdh
883 ". d41d8cd98f00b204e9800998ecf8427e foo.txt",
884 "d41d8cd98f00b204e9800998ecf8427e 0:0:foo.txt",
885 ". d41d8cd98f00b204e9800998ecf8427e 0:0:foo.txt",
886 ].each do |manifest_text|
887 test "update collection with invalid manifest #{manifest_text} and expect error" do
888 authorize_with :active
890 id: 'zzzzz-4zz18-bv31uwvy3neko21',
892 manifest_text: manifest_text,
896 response_errors = json_response['errors']
897 assert_not_nil response_errors, 'Expected error in response'
898 assert(response_errors.first.include?('Invalid manifest'),
899 "Expected 'Invalid manifest' error in #{response_errors.first}")
906 ". d41d8cd98f00b204e9800998ecf8427e 0:0:foo.txt\n",
907 ].each do |manifest_text|
908 test "update collection with valid manifest #{manifest_text.inspect} and expect success" do
909 authorize_with :active
911 id: 'zzzzz-4zz18-bv31uwvy3neko21',
913 manifest_text: manifest_text,