]> Cypherpunks.ru repositories - pyderasn.git/blobdiff - tests/test_pyderasn.py
Fix *Time encoding error capture
[pyderasn.git] / tests / test_pyderasn.py
index 864c66bbbc847b6ed2ae573bedb4ce67e9d4ee66..03e10813999f56ff20276290ff170a9992229c42 100644 (file)
@@ -3609,6 +3609,13 @@ class TestGeneralizedTime(TimeMixin, CommonMixin, TestCase):
             datetime(2010, 1, 2, 3, 4, 5, 0),
         )
 
+    def test_encoding(self):
+        raw = GeneralizedTime(b"20100102030405Z").encode()
+        with assertRaisesRegex(self, DecodeError, "encoding"):
+            GeneralizedTime().decode(raw.replace(b"201001", "привет".encode("utf-8")))
+        with self.assertRaises(DecodeError):
+            GeneralizedTime().decode(raw.replace(b"20100", b"hello"))
+
 
 class TestUTCTime(TimeMixin, CommonMixin, TestCase):
     base_klass = UTCTime
@@ -3673,6 +3680,13 @@ class TestUTCTime(TimeMixin, CommonMixin, TestCase):
             1900 + year,
         )
 
+    def test_encoding(self):
+        raw = UTCTime(b"910506234540Z").encode()
+        with assertRaisesRegex(self, DecodeError, "encoding"):
+            UTCTime().decode(raw.replace(b"910506", "привет".encode("utf-8")))
+        with self.assertRaises(DecodeError):
+            UTCTime().decode(raw.replace(b"91050", b"hello"))
+
 
 @composite
 def any_values_strategy(draw, do_expl=False):