summaryrefslogtreecommitdiff
path: root/tests/test_pyderasn.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/test_pyderasn.py')
-rw-r--r--tests/test_pyderasn.py57
1 files changed, 51 insertions, 6 deletions
diff --git a/tests/test_pyderasn.py b/tests/test_pyderasn.py
index d112a60..9a38fdd 100644
--- a/tests/test_pyderasn.py
+++ b/tests/test_pyderasn.py
@@ -3462,9 +3462,7 @@ class StringMixin(object):
repr(err.exception)
def text_alphabet(self):
- if self.base_klass.encoding in ("ascii", "iso-8859-1"):
- return printable + whitespace
- return None
+ return "".join(six_unichr(c) for c in six_xrange(256))
@given(booleans())
def test_optional(self, optional):
@@ -3828,7 +3826,7 @@ class TestNumericString(StringMixin, CommonMixin, TestCase):
@given(text(alphabet=ascii_letters, min_size=1, max_size=5))
def test_non_numeric(self, non_numeric_text):
- with assertRaisesRegex(self, DecodeError, "non-numeric"):
+ with assertRaisesRegex(self, DecodeError, "alphabet value"):
self.base_klass(non_numeric_text)
@given(
@@ -3878,7 +3876,7 @@ class TestPrintableString(
@given(text(alphabet=sorted(set(whitespace) - set(" ")), min_size=1, max_size=5))
def test_non_printable(self, non_printable_text):
- with assertRaisesRegex(self, DecodeError, "non-printable"):
+ with assertRaisesRegex(self, DecodeError, "alphabet value"):
self.base_klass(non_printable_text)
@given(
@@ -3912,7 +3910,7 @@ class TestPrintableString(
for prop in kwargs.keys():
self.assertFalse(getattr(obj, prop))
s += c
- with assertRaisesRegex(self, DecodeError, "non-printable"):
+ with assertRaisesRegex(self, DecodeError, "alphabet value"):
self.base_klass(s)
self.base_klass(s, **kwargs)
klass = self.base_klass(**kwargs)
@@ -3951,6 +3949,18 @@ class TestIA5String(
):
base_klass = IA5String
+ def text_alphabet(self):
+ return "".join(six_unichr(c) for c in six_xrange(128))
+
+ @given(integers(min_value=128, max_value=255))
+ def test_alphabet_bad(self, code):
+ with self.assertRaises(DecodeError):
+ self.base_klass().decod(
+ self.base_klass.tag_default +
+ len_encode(1) +
+ bytes(bytearray([code])),
+ )
+
class TestGraphicString(
UnicodeDecodeErrorMixin,
@@ -3969,6 +3979,9 @@ class TestVisibleString(
):
base_klass = VisibleString
+ def text_alphabet(self):
+ return " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~"
+
def test_x690_vector(self):
obj, tail = VisibleString().decode(hexdec("1A054A6F6E6573"))
self.assertSequenceEqual(tail, b"")
@@ -4005,6 +4018,38 @@ class TestVisibleString(
self.assertTrue(obj.lenindef)
self.assertTrue(obj.bered)
+ @given(one_of((
+ integers(min_value=0, max_value=ord(" ") - 1),
+ integers(min_value=ord("~") + 1, max_value=255),
+ )))
+ def test_alphabet_bad(self, code):
+ with self.assertRaises(DecodeError):
+ self.base_klass().decod(
+ self.base_klass.tag_default +
+ len_encode(1) +
+ bytes(bytearray([code])),
+ )
+
+ @given(
+ sets(integers(min_value=0, max_value=10), min_size=2, max_size=2),
+ integers(min_value=0),
+ decode_path_strat,
+ )
+ def test_invalid_bounds_while_decoding(self, ints, offset, decode_path):
+ value, bound_min = list(sorted(ints))
+
+ class String(self.base_klass):
+ bounds = (bound_min, bound_min)
+ with self.assertRaises(DecodeError) as err:
+ String().decode(
+ self.base_klass(b"1" * value).encode(),
+ offset=offset,
+ decode_path=decode_path,
+ )
+ repr(err.exception)
+ self.assertEqual(err.exception.offset, offset)
+ self.assertEqual(err.exception.decode_path, decode_path)
+
class TestGeneralString(
UnicodeDecodeErrorMixin,