vomebook commited on
Commit
6bb5e3f
·
1 Parent(s): d9f67eb

Isolate catalog source hash from path policy

Browse files
Files changed (1) hide show
  1. tests/test_reader_v3_catalog.py +15 -0
tests/test_reader_v3_catalog.py CHANGED
@@ -139,6 +139,21 @@ class CatalogTests(unittest.TestCase):
139
  with self.subTest(index=index), self.assertRaisesRegex(ValueError, "invalid v3 reading reference"):
140
  v3.decode_catalog(pointer, packed)
141
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
142
 
143
  class Response:
144
  def __init__(self, raw, status=200):
 
139
  with self.subTest(index=index), self.assertRaisesRegex(ValueError, "invalid v3 reading reference"):
140
  v3.decode_catalog(pointer, packed)
141
 
142
+ def test_source_digest_is_validated_before_dynamic_path_policy(self):
143
+ _, raw = fixture()
144
+ original = json.loads(raw)
145
+ key, entry = next(iter(original['files'].items()))
146
+ invalid_source = 'g' * 64
147
+ invalid_path = f'objects/{invalid_source[:2]}/{invalid_source}/' + 'c' * 16 + '/reading-manifest.json'
148
+ invalid = {**entry, 'source_sha256': invalid_source,
149
+ 'resource': {**entry['resource'], 'path': invalid_path}}
150
+ pointer, packed = repack_catalog({**original, 'files': {key: invalid}})
151
+ # The app treats this module binding dynamically. A permissive test
152
+ # double lets us isolate the digest validation from the path regex.
153
+ with patch('backend.reader_assets.READER_BUCKET_PATH_RE', SimpleNamespace(fullmatch=lambda _: True)):
154
+ with self.assertRaisesRegex(ValueError, 'invalid v3 reading reference'):
155
+ v3.decode_catalog(pointer, packed)
156
+
157
 
158
  class Response:
159
  def __init__(self, raw, status=200):