blob: 74d14c57f2195cc500bdae9b88bc4461b5ca05eb [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):
Paul Kehrera5c6e9a2015-03-23 19:23:43 -050014 bc = x509.BasicConstraints(ca=False, path_length=None)
Paul Kehrer85894662015-03-22 13:19:31 -050015 with pytest.raises(TypeError):
16 x509.Extension("notanoid", True, bc)
17
18 def test_critical_not_a_bool(self):
Paul Kehrera5c6e9a2015-03-23 19:23:43 -050019 bc = x509.BasicConstraints(ca=False, path_length=None)
Paul Kehrer85894662015-03-22 13:19:31 -050020 with pytest.raises(TypeError):
21 x509.Extension(x509.OID_BASIC_CONSTRAINTS, "notabool", bc)
22
23 def test_repr(self):
Paul Kehrera5c6e9a2015-03-23 19:23:43 -050024 bc = x509.BasicConstraints(ca=False, path_length=None)
Paul Kehrer85894662015-03-22 13:19:31 -050025 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 Kehrera5c6e9a2015-03-23 19:23:43 -050036 x509.BasicConstraints(ca="notbool", path_length=None)
Paul Kehrer8cf26422015-03-21 09:50:24 -050037
38 def test_path_length_not_ca(self):
39 with pytest.raises(ValueError):
Paul Kehrera5c6e9a2015-03-23 19:23:43 -050040 x509.BasicConstraints(ca=False, path_length=0)
Paul Kehrer8cf26422015-03-21 09:50:24 -050041
42 def test_path_length_not_int(self):
43 with pytest.raises(TypeError):
Paul Kehrera5c6e9a2015-03-23 19:23:43 -050044 x509.BasicConstraints(ca=True, path_length=1.1)
Paul Kehrer8cf26422015-03-21 09:50:24 -050045
46 with pytest.raises(TypeError):
Paul Kehrera5c6e9a2015-03-23 19:23:43 -050047 x509.BasicConstraints(ca=True, path_length="notint")
Paul Kehrer8cf26422015-03-21 09:50:24 -050048
49 def test_path_length_negative(self):
50 with pytest.raises(TypeError):
Paul Kehrera5c6e9a2015-03-23 19:23:43 -050051 x509.BasicConstraints(ca=True, path_length=-1)
Paul Kehrer8cf26422015-03-21 09:50:24 -050052
53 def test_repr(self):
Paul Kehrera5c6e9a2015-03-23 19:23:43 -050054 na = x509.BasicConstraints(ca=True, path_length=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 )