Validate ARC timestamps and reject bad responses
Add strict validation and error handling for ARC timestamps: require exactly 8 bytes and raise a ValueError for out-of-range timestamps (wraps OverflowError/OSError/ValueError from datetime). parse_arc_response now catches timestamp decode failures and returns an empty list for invalid ARC responses. Added a unit test that injects invalid timestamp noise to ensure the parser rejects such responses.
This commit is contained in:
parent
0c9026284c
commit
1144e33a57
2 changed files with 20 additions and 2 deletions
|
|
@ -356,6 +356,16 @@ class BoundaryExportTests(unittest.TestCase):
|
|||
self.assertEqual(decoded[0]["reward_type"], "arc")
|
||||
self.assertEqual(decoded[0]["reward_key_hex"], reference_rows[0]["arc_key_hex"])
|
||||
|
||||
def test_arc_response_parser_rejects_invalid_timestamp_noise(self):
|
||||
response = bytearray(0x4C)
|
||||
response += (10).to_bytes(4, "little")
|
||||
response += bytes.fromhex("ccdee4d6be")
|
||||
response += (8).to_bytes(4, "little")
|
||||
response += b"garb"
|
||||
response += (0xFFFFFFFFFFFFFFFF).to_bytes(8, "little")
|
||||
|
||||
self.assertEqual(parse_arc_response(bytes(response)), [])
|
||||
|
||||
def test_arc_partial_timestamp_group_is_exported_without_warning(self):
|
||||
rows = load_arc_csv("arc_pages_1_to_5_v2.csv")
|
||||
pairs = []
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue