From 8cf26425504d22dbcf463ff702a167cbe3567e6a Mon Sep 17 00:00:00 2001 From: Paul Kehrer Date: Sat, 21 Mar 2015 09:50:24 -0500 Subject: basic constraints class & extensions interface --- tests/test_x509_ext.py | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 tests/test_x509_ext.py (limited to 'tests/test_x509_ext.py') diff --git a/tests/test_x509_ext.py b/tests/test_x509_ext.py new file mode 100644 index 00000000..9fde1be1 --- /dev/null +++ b/tests/test_x509_ext.py @@ -0,0 +1,40 @@ +# 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 TestBasicConstraints(object): + def test_ca_not_boolean(self): + with pytest.raises(TypeError): + x509.BasicConstraints("notbool", None, False) + + def test_critical_not_boolean(self): + with pytest.raises(TypeError): + x509.BasicConstraints(False, None, "notbool") + + def test_path_length_not_ca(self): + with pytest.raises(ValueError): + x509.BasicConstraints(False, 0, True) + + def test_path_length_not_int(self): + with pytest.raises(TypeError): + x509.BasicConstraints(True, 1.1, True) + + with pytest.raises(TypeError): + x509.BasicConstraints(True, "notint", True) + + def test_path_length_negative(self): + with pytest.raises(TypeError): + x509.BasicConstraints(True, -1, True) + + def test_repr(self): + na = x509.BasicConstraints(True, None, True) + assert repr(na) == ( + "" + ) -- cgit v1.2.3 From 8589466c0a12835cda03bf91043cf51b657d9e46 Mon Sep 17 00:00:00 2001 From: Paul Kehrer Date: Sun, 22 Mar 2015 13:19:31 -0500 Subject: rework BasicConstraints and Extension. --- tests/test_x509_ext.py | 39 ++++++++++++++++++++++++++++----------- 1 file changed, 28 insertions(+), 11 deletions(-) (limited to 'tests/test_x509_ext.py') diff --git a/tests/test_x509_ext.py b/tests/test_x509_ext.py index 9fde1be1..de3ca312 100644 --- a/tests/test_x509_ext.py +++ b/tests/test_x509_ext.py @@ -9,32 +9,49 @@ import pytest from cryptography import x509 -class TestBasicConstraints(object): - def test_ca_not_boolean(self): +class TestExtension(object): + def test_not_an_oid(self): + bc = x509.BasicConstraints(False, None) with pytest.raises(TypeError): - x509.BasicConstraints("notbool", None, False) + x509.Extension("notanoid", True, bc) + + def test_critical_not_a_bool(self): + bc = x509.BasicConstraints(False, None) + with pytest.raises(TypeError): + x509.Extension(x509.OID_BASIC_CONSTRAINTS, "notabool", bc) + + def test_repr(self): + bc = x509.BasicConstraints(False, None) + ext = x509.Extension(x509.OID_BASIC_CONSTRAINTS, True, bc) + assert repr(ext) == ( + ", critical=True, value=)>" + ) + - def test_critical_not_boolean(self): +class TestBasicConstraints(object): + def test_ca_not_boolean(self): with pytest.raises(TypeError): - x509.BasicConstraints(False, None, "notbool") + x509.BasicConstraints("notbool", None) def test_path_length_not_ca(self): with pytest.raises(ValueError): - x509.BasicConstraints(False, 0, True) + x509.BasicConstraints(False, 0) def test_path_length_not_int(self): with pytest.raises(TypeError): - x509.BasicConstraints(True, 1.1, True) + x509.BasicConstraints(True, 1.1) with pytest.raises(TypeError): - x509.BasicConstraints(True, "notint", True) + x509.BasicConstraints(True, "notint") def test_path_length_negative(self): with pytest.raises(TypeError): - x509.BasicConstraints(True, -1, True) + x509.BasicConstraints(True, -1) def test_repr(self): - na = x509.BasicConstraints(True, None, True) + na = x509.BasicConstraints(True, None) assert repr(na) == ( - "" + "" ) -- cgit v1.2.3 From a5c6e9a89242bb42dbc98f29681d2f74aec12b02 Mon Sep 17 00:00:00 2001 From: Paul Kehrer Date: Mon, 23 Mar 2015 19:23:43 -0500 Subject: use kwargs for BasicConstraints creation Also check path_length using integer_types --- tests/test_x509_ext.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'tests/test_x509_ext.py') diff --git a/tests/test_x509_ext.py b/tests/test_x509_ext.py index de3ca312..74d14c57 100644 --- a/tests/test_x509_ext.py +++ b/tests/test_x509_ext.py @@ -11,17 +11,17 @@ from cryptography import x509 class TestExtension(object): def test_not_an_oid(self): - bc = x509.BasicConstraints(False, None) + 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(False, None) + 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(False, None) + bc = x509.BasicConstraints(ca=False, path_length=None) ext = x509.Extension(x509.OID_BASIC_CONSTRAINTS, True, bc) assert repr(ext) == ( "" ) -- cgit v1.2.3