From 3ecdfac9f2ab5eb78485d9fe914ee3eba86d01b63d6457834783721c5e66fa32 Mon Sep 17 00:00:00 2001 From: Sergey Matveev Date: Sat, 30 Nov 2024 20:35:22 +0300 Subject: [PATCH] Unacceptable string representations Human can read either some of ASCII, some of Unicode, hexadecimal, but not escaped data. Hexadecimal data clearly does not seem to be close to Raw's argument encoding. That was definitely just copy-pasted, but should be manually crafted as a desired and expected data. --- pyac/tests/test_tai.py | 6 +++--- pyac/tests/test_uuid.py | 14 +++++++++----- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/pyac/tests/test_tai.py b/pyac/tests/test_tai.py index fa261a5..04bf3d6 100644 --- a/pyac/tests/test_tai.py +++ b/pyac/tests/test_tai.py @@ -76,7 +76,7 @@ class TestTAI64(TestCase): junk ) expected = Raw( - 26, b"\x40\x00\x00\x00\x65\x19\x5f\x65\x07\x5b\xca\x00\x07\x5b\xca\x00" + 0x1a, b"\x40\x00\x00\x00\x65\x19\x5f\x65\x07\x5b\xca\x00\x07\x5b\xca\x00" ) decoded, tail = loads(encoded) self.assertEqual(decoded, expected) @@ -96,14 +96,14 @@ class TestTAI64(TestCase): def test_large_number_of_secs(self) -> None: decoded, tail = loads(b"\x18\x70\x00\x00\x00\x65\x19\x5f\x65") - self.assertEqual(decoded, Raw(t=24, v=b"p\x00\x00\x00e\x19_e")) + self.assertEqual(decoded, Raw(t=0x18, v=b"\x70\x00\x00\x00\x65\x19\x5f\x65")) self.assertSequenceEqual(tail, b"") def test_nanoseconds_not_convertible_to_microseconds(self) -> None: decoded, tail = loads( b"\x19\x40\x00\x00\x00\x65\x19\x5f\x65\x07\x5b\xca\x01" ) - self.assertEqual(decoded, Raw(t=25, v=b"@\x00\x00\x00e\x19_e\x07[\xca\x01")) + self.assertEqual(decoded, Raw(t=0x19, v=b"\x40\x00\x00\x00\x65\x19\x5f\x65\x07\x5b\xca\x01")) self.assertSequenceEqual(tail, b"") def test_throws_when_first_bit_is_in_use(self) -> None: diff --git a/pyac/tests/test_uuid.py b/pyac/tests/test_uuid.py index 2d5a914..0673a12 100644 --- a/pyac/tests/test_uuid.py +++ b/pyac/tests/test_uuid.py @@ -14,18 +14,22 @@ class TestUUID(TestCase): uuid_str: str = "12345678-1234-5678-1234-567812345678" uuid_obj: UUID = UUID(uuid_str) encoded: bytes = dumps(uuid_obj) - self.assertSequenceEqual(encoded, b"\x04\x124Vx\x124Vx\x124Vx\x124Vx") + self.assertSequenceEqual( + encoded, + b"\x04\x12\x34\x56\x78\x12\x34\x56\x78\x12\x34\x56\x78\x12\x34\x56\x78", + ) @given(junk_st) def test_decode(self, junk: bytes) -> None: uuid_str: str = "12345678-1234-5678-1234-567812345678" - encoded: bytes = b"\x04\x124Vx\x124Vx\x124Vx\x124Vx" + encoded: bytes = b"\x04\x12\x34\x56\x78\x12\x34\x56\x78\x12\x34\x56\x78\x12\x34\x56\x78" decoded: UUID decoded, tail = loads(encoded + junk) self.assertEqual(decoded, UUID(uuid_str)) self.assertSequenceEqual(tail, junk) def test_not_enough_data(self) -> None: - encoded: bytes = b"\x04\x124Vx\x124Vx\x124Vx\x124V" - with self.assertRaises(NotEnoughData): - loads(encoded) + encoded: bytes = b"\x04\x12\x34\x56\x78\x12\x34\x56\x78\x12\x34\x56\x78\x12\x34\x56\x78" + with self.assertRaises(NotEnoughData) as err: + loads(encoded[:-4]) + self.assertEqual(err.exception.n, 1+16) -- 2.50.0