]> Cypherpunks.ru repositories - pyderasn.git/blobdiff - tests/test_pyderasn.py
Strict default values existence validation option
[pyderasn.git] / tests / test_pyderasn.py
index 498b160a23698a7ba37848c3a2cbf87e9f627034..5b98ea60cf1012c829ef6b9d396ac245e858343b 100644 (file)
@@ -5112,3 +5112,26 @@ class TestAbsDecodePath(TestCase):
             abs_decode_path(decode_path, tuple([".."] * number_of_dots) + rel_path),
             decode_path[:-number_of_dots] + rel_path,
         )
             abs_decode_path(decode_path, tuple([".."] * number_of_dots) + rel_path),
             decode_path[:-number_of_dots] + rel_path,
         )
+
+
+class TestStrictDefaultExistence(TestCase):
+    @given(data_strategy())
+    def runTest(self, d):
+        count = d.draw(integers(min_value=1, max_value=10))
+        chosen = d.draw(integers(min_value=0, max_value=count - 1))
+        _schema = [
+            ("int%d" % i, Integer(expl=tag_ctxc(i + 1)))
+            for i in range(count)
+        ]
+
+        class Seq(Sequence):
+            schema = _schema
+        seq = Seq()
+        for i in range(count):
+            seq["int%d" % i] = Integer(123)
+        raw = seq.encode()
+        chosen = "int%d" % chosen
+        seq.specs[chosen] = seq.specs[chosen](default=123)
+        seq.decode(raw)
+        with assertRaisesRegex(self, DecodeError, "DEFAULT value met"):
+            seq.decode(raw, ctx={"strict_default_existence": True})