Skip to content

Commit

Permalink
Improve reporting for bad digestAlgorithm
Browse files Browse the repository at this point in the history
  • Loading branch information
zimeon committed Oct 21, 2024
1 parent 74e6f2f commit 117aec9
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 16 deletions.
22 changes: 11 additions & 11 deletions ocfl/data/validation-errors.json
Original file line number Diff line number Diff line change
Expand Up @@ -136,16 +136,22 @@
"en": "OCFL Object %s manifest does not include files listed in previous version manifests (%s)"
}
},
"E024": {
"params": ["where", "path"],
"description": {
"en": "OCFL Object version %s content directory includes empty path %s"
}
},
"E025a": {
"params": ["where", "digest", "algorithm"],
"params": ["where", "digest_algorithm"],
"description": {
"en": "OCFL Object %s inventory manifest block includes a digest (%s) that doesn't have the correct form for the %s algorithm"
"en": "OCFL Object %s inventory `digestAlgorithm` attribute not an allowed digest type (got '%s')"
}
},
"E024": {
"params": ["where", "path"],
"E025b": {
"params": ["where", "digest", "algorithm"],
"description": {
"en": "OCFL Object version %s content directory includes empty path %s"
"en": "OCFL Object %s inventory manifest block includes a digest (%s) that doesn't have the correct form for the %s algorithm"
}
},
"E026a": {
Expand Down Expand Up @@ -214,12 +220,6 @@
"en": "OCFL Object %s inventory `type` attribute has an unsupported specification version number (%s), will proceed as if using version %s"
}
},
"E039": {
"params": ["where", "digest_algorithm"],
"description": {
"en": "OCFL Object %s inventory `digestAlgorithm` attribute not an allowed value (got '%s')"
}
},
"E040": {
"params": ["where", "got", "expected"],
"description": {
Expand Down
5 changes: 3 additions & 2 deletions ocfl/inventory_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@ def validate(self, inventory, force_spec_version=None):
self.warning("W004")
self.digest_algorithm = inventory['digestAlgorithm']
else:
self.error("E039", digest_algorithm=inventory['digestAlgorithm'])
self.error("E025a", digest_algorithm=inventory['digestAlgorithm'])
return
if 'contentDirectory' in inventory:
# Careful only to set self.content_directory if value is safe
cd = inventory['contentDirectory']
Expand Down Expand Up @@ -180,7 +181,7 @@ def validate_manifest(self, manifest):
for digest in manifest:
m = re.match(self.digest_regex(), digest)
if not m:
self.error('E025a', digest=digest, algorithm=self.digest_algorithm) # wrong form of digest
self.error('E025b', digest=digest, algorithm=self.digest_algorithm) # wrong form of digest
elif not isinstance(manifest[digest], list):
self.error('E092', digest=digest) # must have path list value
else:
Expand Down
6 changes: 3 additions & 3 deletions tests/test_inventory_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def test_validate(self):
log.clear()
iv.validate({"id": "like:uri", "type": "wrong type", "digestAlgorithm": "my_digest"})
self.assertIn('E038b', log.errors)
self.assertIn('E039', log.errors)
self.assertIn('E025a', log.errors)
log.clear()
iv.validate({"id": "like:uri", "type": "wrong type", "digestAlgorithm": "my_digest"})
self.assertIn('E038b', log.errors)
Expand All @@ -79,7 +79,7 @@ def test_validate(self):
iv = InventoryValidator(log=log, lax_digests=True)
log.clear()
iv.validate({"id": "like:uri", "type": "wrong type", "digestAlgorithm": "my_digest"})
self.assertNotIn('E039', log.errors)
self.assertNotIn('E025a', log.errors)
self.assertEqual(iv.digest_algorithm, "my_digest")
iv = InventoryValidator(log=log)
log.clear()
Expand All @@ -100,7 +100,7 @@ def test_validate_manifest(self):
self.assertIn('E041c', log.errors)
log.clear()
self.assertEqual(iv.validate_manifest({"xxx": []}), ({}, [], set()))
self.assertIn('E025a', log.errors)
self.assertIn('E025b', log.errors)
log.clear()
self.assertEqual(iv.validate_manifest({"067eca3f5b024afa00aeac03a3c42dc0042bf43cba56104037abea8b365c0cf672f0e0c14c91b82bbce6b1464e231ac285d630a82cd4d4a7b194bea04d4b2eb7": "not an array"}), ({}, [], set()))
self.assertIn('E092', log.errors)
Expand Down

0 comments on commit 117aec9

Please sign in to comment.