vomebook commited on
Commit ·
f21d400
1
Parent(s): 9816630
Isolate Reader catalog length and path guards
Browse files83 unmodified lines84858687888927 unmodified lines11711811912012112235 unmodified lines15815916016116216383 unmodified lines("bytes", v3.MAX_BYTES + 1), ("sha256", "A" * 64)):with self.subTest(field=field, value=value), self.assertRaisesRegex(ValueError, "v3 catalog resource mismatch"):v3.decode_catalog({**pointer, "catalog": {**ref, field: value}}, raw)def test_self_consistent_transport_cannot_mask_invalid_catalog_identity(self):_, original = fixture()27 unmodified lines{**entry, "resource": {**resource, "bucket": "foreign/bucket"}},{**entry, "resource": {**resource, "role": "archive"}},{**entry, "resource": {**resource, "path": "https://foreign.example/reading-manifest.json"}},{**entry, "resource": {**resource, "path": resource["path"].replace("objects/aa/", "objects/bb/")}},{**entry, "resource": {**resource, "path": resource["path"].replace("reading-manifest.json", "other.json")}},{**entry, "resource": {**resource, "sha256": "x" * 64}},35 unmodified linesself.assertEqual(session.get.await_count, 3)self.assertTrue(all(response.released for response in responses))async def test_base_and_catalog_refresh_overlap_without_partial_publication(self):pointer,raw=fixture();catalog=v3.decode_catalog(pointer,raw)packed=gzip.compress(json.dumps({'v':1,'f':{'other':{'s':4}}}).encode())83 unmodified lines848586878889909192939427 unmodified lines12212312412512612712812913013135 unmodified lines16716816917017117217317417517617717817918018118218318418518618718818983 unmodified lines("bytes", v3.MAX_BYTES + 1), ("sha256", "A" * 64)):with self.subTest(field=field, value=value), self.assertRaisesRegex(ValueError, "v3 catalog resource mismatch"):v3.decode_catalog({**pointer, "catalog": {**ref, field: value}}, raw)with self.assertRaisesRegex(ValueError, "v3 catalog resource mismatch"):v3.decode_catalog({**pointer, "catalog": {**ref, "bytes": len(raw) + 1}}, raw)with patch.object(v3, "MAX_BYTES", len(raw) - 1):with self.assertRaisesRegex(ValueError, "v3 catalog resource mismatch"):v3.decode_catalog(pointer, raw)def test_self_consistent_transport_cannot_mask_invalid_catalog_identity(self):_, original = fixture()27 unmodified lines{**entry, "resource": {**resource, "bucket": "foreign/bucket"}},{**entry, "resource": {**resource, "role": "archive"}},{**entry, "resource": {**resource, "path": "https://foreign.example/reading-manifest.json"}},{**entry, "resource": {**resource, "path": resource["path"].replace("/reading-manifest.json", "/bad/reading-manifest.json")}},{**entry, "resource": {**resource, "path": resource["path"].replace("reading-manifest.json", "page-map.json.gz")}},{**entry, "resource": {**resource, "path": resource["path"].replace("objects/aa/", "objects/bb/")}},{**entry, "resource": {**resource, "path": resource["path"].replace("reading-manifest.json", "other.json")}},{**entry, "resource": {**resource, "sha256": "x" * 64}},35 unmodified linesself.assertEqual(session.get.await_count, 3)self.assertTrue(all(response.released for response in responses))async def test_pinned_base_with_valid_digest_but_wrong_length_is_rejected(self):_, raw = fixture()catalog = json.loads(raw)packed = gzip.compress(b'{"v":1,"f":{}}')digest = hashlib.sha256(packed).hexdigest()catalog["base_sidecar"] = {"bucket": v3.BUCKET, "role": "runtime", "bytes": len(packed) + 1,"sha256": digest, "path": f"reader-index/snapshots/{digest}/reader_assets.json.gz"}pointer, raw = repack_catalog(catalog)responses = [Response(json.dumps(pointer).encode()), Response(raw), Response(packed)]session = SimpleNamespace(get=AsyncMock(side_effect=responses))with patch('backend.reader_assets.decode_reader_assets') as decode:with self.assertRaisesRegex(ValueError, 'unified base sidecar checksum mismatch'):await v3.load_reading_catalog(session)decode.assert_not_called()self.assertEqual(session.get.await_count, 3)self.assertTrue(all(response.released for response in responses))async def test_base_and_catalog_refresh_overlap_without_partial_publication(self):pointer,raw=fixture();catalog=v3.decode_catalog(pointer,raw)packed=gzip.compress(json.dumps({'v':1,'f':{'other':{'s':4}}}).encode())
tests/test_reader_v3_catalog.py+26