aboutsummaryrefslogtreecommitdiffstats
path: root/tests/test_x509_ext.py
diff options
context:
space:
mode:
authorAlex Gaynor <alex.gaynor@gmail.com>2015-03-23 21:49:25 -0500
committerAlex Gaynor <alex.gaynor@gmail.com>2015-03-23 21:49:25 -0500
commit8c8ee123cbe76fc7cdfca9c9313b16e11059b511 (patch)
treeff769206a473cd59c12979efc4530b7cf2c7e191 /tests/test_x509_ext.py
parenta1f968aec9fa396739fbe0280c60262a8fbb6675 (diff)
parent5553d576f3bc3f65b84de99a2561360f82fc110f (diff)
downloadcryptography-8c8ee123cbe76fc7cdfca9c9313b16e11059b511.tar.gz
cryptography-8c8ee123cbe76fc7cdfca9c9313b16e11059b511.tar.bz2
cryptography-8c8ee123cbe76fc7cdfca9c9313b16e11059b511.zip
Merge pull request #1768 from reaperhulk/basic-constraints
basic constraints class & extensions interface
Diffstat (limited to 'tests/test_x509_ext.py')
-rw-r--r--tests/test_x509_ext.py57
1 files changed, 57 insertions, 0 deletions
diff --git a/tests/test_x509_ext.py b/tests/test_x509_ext.py
new file mode 100644
index 00000000..74d14c57
--- /dev/null
+++ b/tests/test_x509_ext.py
@@ -0,0 +1,57 @@
+# This file is dual licensed under the terms of the Apache License, Version
+# 2.0, and the BSD License. See the LICENSE file in the root of this repository
+# for complete details.
+
+from __future__ import absolute_import, division, print_function
+
+import pytest
+
+from cryptography import x509
+
+
+class TestExtension(object):
+ def test_not_an_oid(self):
+ bc = x509.BasicConstraints(ca=False, path_length=None)
+ with pytest.raises(TypeError):
+ x509.Extension("notanoid", True, bc)
+
+ def test_critical_not_a_bool(self):
+ bc = x509.BasicConstraints(ca=False, path_length=None)
+ with pytest.raises(TypeError):
+ x509.Extension(x509.OID_BASIC_CONSTRAINTS, "notabool", bc)
+
+ def test_repr(self):
+ bc = x509.BasicConstraints(ca=False, path_length=None)
+ ext = x509.Extension(x509.OID_BASIC_CONSTRAINTS, True, bc)
+ assert repr(ext) == (
+ "<Extension(oid=<ObjectIdentifier(oid=2.5.29.19, name=basicConst"
+ "raints)>, critical=True, value=<BasicConstraints(ca=False, path"
+ "_length=None)>)>"
+ )
+
+
+class TestBasicConstraints(object):
+ def test_ca_not_boolean(self):
+ with pytest.raises(TypeError):
+ x509.BasicConstraints(ca="notbool", path_length=None)
+
+ def test_path_length_not_ca(self):
+ with pytest.raises(ValueError):
+ x509.BasicConstraints(ca=False, path_length=0)
+
+ def test_path_length_not_int(self):
+ with pytest.raises(TypeError):
+ x509.BasicConstraints(ca=True, path_length=1.1)
+
+ with pytest.raises(TypeError):
+ x509.BasicConstraints(ca=True, path_length="notint")
+
+ def test_path_length_negative(self):
+ with pytest.raises(TypeError):
+ x509.BasicConstraints(ca=True, path_length=-1)
+
+ def test_repr(self):
+ na = x509.BasicConstraints(ca=True, path_length=None)
+ assert repr(na) == (
+ "<BasicConstraints(ca=True, path_length=None)>"
+ )