Paul Kehrer | 8cf2642 | 2015-03-21 09:50:24 -0500 | [diff] [blame] | 1 | # 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 | |
| 5 | from __future__ import absolute_import, division, print_function |
| 6 | |
| 7 | import pytest |
| 8 | |
| 9 | from cryptography import x509 |
| 10 | |
| 11 | |
Paul Kehrer | 8589466 | 2015-03-22 13:19:31 -0500 | [diff] [blame^] | 12 | class 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 Kehrer | 8cf2642 | 2015-03-21 09:50:24 -0500 | [diff] [blame] | 33 | class TestBasicConstraints(object): |
| 34 | def test_ca_not_boolean(self): |
| 35 | with pytest.raises(TypeError): |
Paul Kehrer | 8589466 | 2015-03-22 13:19:31 -0500 | [diff] [blame^] | 36 | x509.BasicConstraints("notbool", None) |
Paul Kehrer | 8cf2642 | 2015-03-21 09:50:24 -0500 | [diff] [blame] | 37 | |
| 38 | def test_path_length_not_ca(self): |
| 39 | with pytest.raises(ValueError): |
Paul Kehrer | 8589466 | 2015-03-22 13:19:31 -0500 | [diff] [blame^] | 40 | x509.BasicConstraints(False, 0) |
Paul Kehrer | 8cf2642 | 2015-03-21 09:50:24 -0500 | [diff] [blame] | 41 | |
| 42 | def test_path_length_not_int(self): |
| 43 | with pytest.raises(TypeError): |
Paul Kehrer | 8589466 | 2015-03-22 13:19:31 -0500 | [diff] [blame^] | 44 | x509.BasicConstraints(True, 1.1) |
Paul Kehrer | 8cf2642 | 2015-03-21 09:50:24 -0500 | [diff] [blame] | 45 | |
| 46 | with pytest.raises(TypeError): |
Paul Kehrer | 8589466 | 2015-03-22 13:19:31 -0500 | [diff] [blame^] | 47 | x509.BasicConstraints(True, "notint") |
Paul Kehrer | 8cf2642 | 2015-03-21 09:50:24 -0500 | [diff] [blame] | 48 | |
| 49 | def test_path_length_negative(self): |
| 50 | with pytest.raises(TypeError): |
Paul Kehrer | 8589466 | 2015-03-22 13:19:31 -0500 | [diff] [blame^] | 51 | x509.BasicConstraints(True, -1) |
Paul Kehrer | 8cf2642 | 2015-03-21 09:50:24 -0500 | [diff] [blame] | 52 | |
| 53 | def test_repr(self): |
Paul Kehrer | 8589466 | 2015-03-22 13:19:31 -0500 | [diff] [blame^] | 54 | na = x509.BasicConstraints(True, None) |
Paul Kehrer | 8cf2642 | 2015-03-21 09:50:24 -0500 | [diff] [blame] | 55 | assert repr(na) == ( |
Paul Kehrer | 8589466 | 2015-03-22 13:19:31 -0500 | [diff] [blame^] | 56 | "<BasicConstraints(ca=True, path_length=None)>" |
Paul Kehrer | 8cf2642 | 2015-03-21 09:50:24 -0500 | [diff] [blame] | 57 | ) |