]> Cypherpunks.ru repositories - pyderasn.git/blobdiff - tests/test_pyderasn.py
OID test vector from Go
[pyderasn.git] / tests / test_pyderasn.py
index 8225fc02eaef4be07fc42093a3f28e4cbc88b933..73eea21c6151a8ac3979f103eb42c3b7632cf0b5 100644 (file)
@@ -33,6 +33,7 @@ from time import mktime
 from time import time
 from unittest import TestCase
 
+from dateutil.tz import UTC
 from hypothesis import assume
 from hypothesis import given
 from hypothesis import settings
@@ -3081,6 +3082,10 @@ class TestObjectIdentifier(CommonMixin, TestCase):
                 data,
             )))
 
+    def test_go_non_minimal_encoding(self):
+        with self.assertRaises(DecodeError):
+            ObjectIdentifier().decode(hexdec("060a2a80864886f70d01010b"))
+
     def test_x690_vector(self):
         self.assertEqual(
             ObjectIdentifier().decode(hexdec("0603883703"))[0],
@@ -4494,8 +4499,13 @@ class TestGeneralizedTime(TimeMixin, CommonMixin, TestCase):
                 mktime(obj.todatetime().timetuple()),
                 mktime(dt.timetuple()),
             )
-        elif not PY2:
-            self.assertEqual(obj.todatetime().timestamp(), dt.timestamp())
+        else:
+            try:
+                obj.todatetime().timestamp()
+            except:
+                pass
+            else:
+                self.assertEqual(obj.todatetime().timestamp(), dt.timestamp())
         self.assertEqual(obj.ber_encoded, not dered)
         self.assertEqual(obj.bered, not dered)
         self.assertEqual(obj.ber_raw, None if dered else data)
@@ -4727,6 +4737,10 @@ class TestGeneralizedTime(TimeMixin, CommonMixin, TestCase):
             with self.assertRaises(DecodeError):
                 GeneralizedTime(data)
 
+    def test_aware(self):
+        with assertRaisesRegex(self, ValueError, "only naive"):
+            GeneralizedTime(datetime(2000, 1, 1, 1, tzinfo=UTC))
+
 
 class TestUTCTime(TimeMixin, CommonMixin, TestCase):
     base_klass = UTCTime
@@ -5060,6 +5074,10 @@ class TestUTCTime(TimeMixin, CommonMixin, TestCase):
                 junk
             )
 
+    def test_aware(self):
+        with assertRaisesRegex(self, ValueError, "only naive"):
+            UTCTime(datetime(2000, 1, 1, 1, tzinfo=UTC))
+
 
 @composite
 def tlv_value_strategy(draw):