end
def check_encoding
+ return true if !manifest_text
if manifest_text.encoding.name == 'UTF-8' and manifest_text.valid_encoding?
true
else
Keep::Manifest.validate! manifest_text
true
rescue => e
- logger.warn e
+ errors.add :manifest_text, e.message
false
end
end
}
}
assert_response 422
+ response_errors = json_response['errors']
+ assert_not_nil response_errors, 'Expected error in response'
+ if manifest_text
+ assert(response_errors.first.include?('Invalid manifest'),
+ "Expected 'Invalid manifest' error in #{response_errors.first}")
+ else
+ assert(response_errors.first.include?('No manifest found'),
+ "Expected 'No manifest found' error in #{response_errors.first}")
+ end
+ end
+ end
+
+ [
+ nil,
+ ". 0:0:foo.txt",
+ ". d41d8cd98f00b204e9800998ecf8427e foo.txt",
+ "d41d8cd98f00b204e9800998ecf8427e 0:0:foo.txt",
+ ". d41d8cd98f00b204e9800998ecf8427e 0:0:foo.txt",
+ ].each do |manifest_text|
+ test "update collection with invalid manifest #{manifest_text}" do
+ authorize_with :active
+ post :update, {
+ id: 'zzzzz-4zz18-bv31uwvy3neko21',
+ collection: {
+ manifest_text: manifest_text,
+ }
+ }
+ assert_response 422
+ response_errors = json_response['errors']
+ assert_not_nil response_errors, 'Expected error in response'
+ if manifest_text
+ assert(response_errors.first.include?('Invalid manifest'),
+ "Expected 'Invalid manifest' error in #{response_errors.first}")
+ else
+ assert(response_errors.first.include?('No manifest found'),
+ "Expected 'No manifest found' error in #{response_errors.first}")
+ end
end
end
end
end
end
+ [
+ nil,
+ ". 0:0:foo.txt",
+ ". d41d8cd98f00b204e9800998ecf8427e foo.txt",
+ "d41d8cd98f00b204e9800998ecf8427e 0:0:foo.txt",
+ ". d41d8cd98f00b204e9800998ecf8427e 0:0:foo.txt",
+ ].each do |manifest_text|
+ test "create collection with invalid manifest text #{manifest_text} and expect error" do
+ act_as_system_user do
+ c = Collection.create(manifest_text: manifest_text)
+ assert !c.valid?
+ end
+ end
+ end
+
+ [
+ nil,
+ ". 0:0:foo.txt",
+ ". d41d8cd98f00b204e9800998ecf8427e foo.txt",
+ "d41d8cd98f00b204e9800998ecf8427e 0:0:foo.txt",
+ ". d41d8cd98f00b204e9800998ecf8427e 0:0:foo.txt",
+ ].each do |manifest_text|
+ test "update collection with invalid manifest text #{manifest_text} and expect error" do
+ act_as_system_user do
+ c = create_collection 'foo', Encoding::US_ASCII
+ assert c.valid?
+
+ c.update_attribute 'manifest_text', manifest_text
+ assert !c.valid?
+ end
+ end
+ end
+
test 'create and update collection and verify file_names' do
act_as_system_user do
c = create_collection 'foo', Encoding::US_ASCII
# appear as underscores in the fuse mount.)
_disallowed_filename_characters = re.compile('[\x00/]')
+# '.' and '..' are not reachable if API server is newer than #6277
def sanitize_filename(dirty):
"""Replace disallowed filename characters with harmless "_"."""
if dirty is None: