From c76000349fc93617f5546ecf4ea933f8d368b0e05e4c76323193fb4e6efa922f Mon Sep 17 00:00:00 2001 From: Sergey Matveev Date: Sat, 30 Nov 2024 19:45:35 +0300 Subject: [PATCH] Add junk during UUID decoding --- pyac/tests/test_uuid.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/pyac/tests/test_uuid.py b/pyac/tests/test_uuid.py index f0263cf..a519ec4 100644 --- a/pyac/tests/test_uuid.py +++ b/pyac/tests/test_uuid.py @@ -1,9 +1,12 @@ from unittest import TestCase from uuid import UUID +from hypothesis import given + from pyac import dumps from pyac import loads from pyac import NotEnoughData +from tests.strategies import junk_st class TestUUID(TestCase): @@ -13,12 +16,14 @@ class TestUUID(TestCase): encoded: bytes = dumps(uuid_obj) self.assertSequenceEqual(encoded, b"\x04\x124Vx\x124Vx\x124Vx\x124Vx") - def test_uuid_decode(self) -> None: + @given(junk_st) + def test_uuid_decode(self, junk: bytes) -> None: uuid_str: str = "12345678-1234-5678-1234-567812345678" encoded: bytes = b"\x04\x124Vx\x124Vx\x124Vx\x124Vx" decoded: UUID - decoded, _ = loads(encoded) + decoded, tail = loads(encoded + junk) self.assertEqual(decoded, UUID(uuid_str)) + self.assertSequenceEqual(tail, junk) def test_uuid_not_enough_data(self) -> None: encoded: bytes = b"\x04\x124Vx\x124Vx\x124Vx\x124V" -- 2.48.1