blob: de3ca31200921db8f74574b7c5c341a56f98bc11 [file] [log] [blame]
Paul Kehrer8cf26422015-03-21 09:50:24 -05001# This file is dual licensed under the terms of the Apache License, Version
2# 2.0, and the BSD License. See the LICENSE file in the root of this repository
3# for complete details.
4
5from __future__ import absolute_import, division, print_function
6
7import pytest
8
9from cryptography import x509
10
11
Paul Kehrer85894662015-03-22 13:19:31 -050012class TestExtension(object):
13 def test_not_an_oid(self):
14 bc = x509.BasicConstraints(False, None)
15 with pytest.raises(TypeError):
16 x509.Extension("notanoid", True, bc)
17
18 def test_critical_not_a_bool(self):
19 bc = x509.BasicConstraints(False, None)
20 with pytest.raises(TypeError):
21 x509.Extension(x509.OID_BASIC_CONSTRAINTS, "notabool", bc)
22
23 def test_repr(self):
24 bc = x509.BasicConstraints(False, None)
25 ext = x509.Extension(x509.OID_BASIC_CONSTRAINTS, True, bc)
26 assert repr(ext) == (
27 "<Extension(oid=<ObjectIdentifier(oid=2.5.29.19, name=basicConst"
28 "raints)>, critical=True, value=<BasicConstraints(ca=False, path"
29 "_length=None)>)>"
30 )
31
32
Paul Kehrer8cf26422015-03-21 09:50:24 -050033class TestBasicConstraints(object):
34 def test_ca_not_boolean(self):
35 with pytest.raises(TypeError):
Paul Kehrer85894662015-03-22 13:19:31 -050036 x509.BasicConstraints("notbool", None)
Paul Kehrer8cf26422015-03-21 09:50:24 -050037
38 def test_path_length_not_ca(self):
39 with pytest.raises(ValueError):
Paul Kehrer85894662015-03-22 13:19:31 -050040 x509.BasicConstraints(False, 0)
Paul Kehrer8cf26422015-03-21 09:50:24 -050041
42 def test_path_length_not_int(self):
43 with pytest.raises(TypeError):
Paul Kehrer85894662015-03-22 13:19:31 -050044 x509.BasicConstraints(True, 1.1)
Paul Kehrer8cf26422015-03-21 09:50:24 -050045
46 with pytest.raises(TypeError):
Paul Kehrer85894662015-03-22 13:19:31 -050047 x509.BasicConstraints(True, "notint")
Paul Kehrer8cf26422015-03-21 09:50:24 -050048
49 def test_path_length_negative(self):
50 with pytest.raises(TypeError):
Paul Kehrer85894662015-03-22 13:19:31 -050051 x509.BasicConstraints(True, -1)
Paul Kehrer8cf26422015-03-21 09:50:24 -050052
53 def test_repr(self):
Paul Kehrer85894662015-03-22 13:19:31 -050054 na = x509.BasicConstraints(True, None)
Paul Kehrer8cf26422015-03-21 09:50:24 -050055 assert repr(na) == (
Paul Kehrer85894662015-03-22 13:19:31 -050056 "<BasicConstraints(ca=True, path_length=None)>"
Paul Kehrer8cf26422015-03-21 09:50:24 -050057 )