+ @backtick_mock_failure = true
+ e = assert_raises RuntimeError do
+ salvage_collection collections('user_agreement').uuid
+ end
+ assert_match(/Error during arv-put: pid \d+ exit \d+ \(cmd was \"arv-put .*\"\)/, e.message)
+ end
+
+ # This test uses BAD_MANIFEST, which has the following flaws:
+ # Missing stream name with locator in it's place
+ # Invalid locators:
+ # foo-faafaafaabd78ad0d6fc3f5b926b450e+foo
+ # bar-baabaabaabd78ad0d6fc3f5b926b450e
+ # bad12345dae58ad0d6fc3f5b926b450e+
+ # 341dabea2bd78ad0d6fc3f5b926b450e+abc
+ # 341dabea2bd78ad0d6fc3f5b926abcdf
+ # Expectation: All these locators are preserved in salvaged_data
+ test "invalid locators preserved during salvaging" do
+ locator_data = salvage_collection_locator_data BAD_MANIFEST
+ assert_equal \
+ ["faafaafaabd78ad0d6fc3f5b926b450e",
+ "baabaabaabd78ad0d6fc3f5b926b450e",
+ "bad12345dae58ad0d6fc3f5b926b450e",
+ "341dabea2bd78ad0d6fc3f5b926b450e",
+ "341dabea2bd78ad0d6fc3f5b926abcdf",
+ "abcdabea2bd78ad0d6fc3f5b926b450e+1000",
+ "d7321a918923627c972d8f8080c07d29+2000",
+ ], locator_data[0]
+ assert_equal 1000+2000, locator_data[1]
+ end
+
+ test "salvage a collection with invalid manifest text" do
+ # create a collection to test salvaging
+ src_collection = Collection.new name: "test collection", manifest_text: BAD_MANIFEST, owner_uuid: 'zzzzz-tpzed-000000000000000'
+ src_collection.save!(validate: false)
+
+ # salvage this collection
+ salvage_collection src_collection.uuid, 'test salvage collection - see #6277, #6859'
+
+ # verify the updated src_collection data
+ updated_src_collection = Collection.find_by_uuid src_collection.uuid
+ updated_name = updated_src_collection.name
+ assert_equal true, updated_name.include?(src_collection.name)
+
+ match = updated_name.match(/^test collection.*salvaged data at (.*)\)$/)
+ assert_not_nil match
+ assert_not_nil match[1]
+ assert_empty updated_src_collection.manifest_text
+
+ # match[1] is the uuid of the new collection created from src_collection's salvaged data
+ # use this to get the new collection and verify
+ new_collection = Collection.find_by_uuid match[1]
+ match = new_collection.name.match(/^salvaged from (.*),.*/)
+ assert_not_nil match
+ assert_equal src_collection.uuid, match[1]
+ # verify the new collection's manifest includes the bad locators
+ expected_manifest = ". " + Digest::MD5.hexdigest(BAD_MANIFEST) + "+" + BAD_MANIFEST.length.to_s +
+ " 0:" + BAD_MANIFEST.length.to_s + ":invalid_manifest_text.txt\n. faafaafaabd78ad0d6fc3f5b926b450e baabaabaabd78ad0d6fc3f5b926b450e bad12345dae58ad0d6fc3f5b926b450e 341dabea2bd78ad0d6fc3f5b926b450e 341dabea2bd78ad0d6fc3f5b926abcdf abcdabea2bd78ad0d6fc3f5b926b450e+1000 d7321a918923627c972d8f8080c07d29+2000 0:3000:salvaged_data\n"
+ assert_equal expected_manifest, new_collection.manifest_text