From 23c0bbc2dc007aa507b22f407c3a0048be98a1a4 Mon Sep 17 00:00:00 2001 From: Paul Kehrer Date: Fri, 25 Dec 2015 22:35:19 -0600 Subject: add invaliditydate class for crl entry extensions --- tests/test_x509.py | 6 +++--- tests/test_x509_ext.py | 24 ++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 3 deletions(-) (limited to 'tests') diff --git a/tests/test_x509.py b/tests/test_x509.py index 757df442..560324b0 100644 --- a/tests/test_x509.py +++ b/tests/test_x509.py @@ -387,9 +387,9 @@ class TestRevokedCertificate(object): x509.CertificateIssuer).value assert issuer == x509.CertificateIssuer(exp_issuer) - date = rev1.extensions.get_extension_for_oid( - x509.OID_INVALIDITY_DATE).value - assert date == datetime.datetime(2015, 1, 1, 0, 0) + date = rev1.extensions.get_extension_for_class( + x509.InvalidityDate).value + assert date == x509.InvalidityDate(datetime.datetime(2015, 1, 1, 0, 0)) # Check if all reason flags can be found in the CRL. flags = set(x509.ReasonFlags) diff --git a/tests/test_x509_ext.py b/tests/test_x509_ext.py index b8105a4b..91a07654 100644 --- a/tests/test_x509_ext.py +++ b/tests/test_x509_ext.py @@ -5,6 +5,7 @@ from __future__ import absolute_import, division, print_function import binascii +import datetime import ipaddress import os @@ -135,6 +136,29 @@ class TestCRLReason(object): ) +class TestInvalidityDate(object): + def test_invalid_invalidity_date(self): + with pytest.raises(TypeError): + x509.InvalidityDate("notadate") + + def test_eq(self): + invalid1 = x509.InvalidityDate(datetime.datetime(2015, 1, 1, 1, 1)) + invalid2 = x509.InvalidityDate(datetime.datetime(2015, 1, 1, 1, 1)) + assert invalid1 == invalid2 + + def test_ne(self): + invalid1 = x509.InvalidityDate(datetime.datetime(2015, 1, 1, 1, 1)) + invalid2 = x509.InvalidityDate(datetime.datetime(2015, 1, 1, 1, 2)) + assert invalid1 != invalid2 + assert invalid1 != object() + + def test_repr(self): + invalid1 = x509.InvalidityDate(datetime.datetime(2015, 1, 1, 1, 1)) + assert repr(invalid1) == ( + "" + ) + + class TestNoticeReference(object): def test_notice_numbers_not_all_int(self): with pytest.raises(TypeError): -- cgit v1.2.3 From 67cde769bd98f701e88e051b74a9db7ae4f03f00 Mon Sep 17 00:00:00 2001 From: Paul Kehrer Date: Sat, 26 Dec 2015 11:37:14 -0600 Subject: add __hash__ to InvalidityDate --- tests/test_x509_ext.py | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'tests') diff --git a/tests/test_x509_ext.py b/tests/test_x509_ext.py index 91a07654..d0f4cac9 100644 --- a/tests/test_x509_ext.py +++ b/tests/test_x509_ext.py @@ -158,6 +158,12 @@ class TestInvalidityDate(object): "" ) + def test_hash(self): + invalid1 = x509.InvalidityDate(datetime.datetime(2015, 1, 1, 1, 1)) + invalid2 = x509.InvalidityDate(datetime.datetime(2015, 1, 1, 1, 1)) + invalid3 = x509.InvalidityDate(datetime.datetime(2015, 1, 1, 1, 2)) + assert hash(invalid1) == hash(invalid2) + assert hash(invalid1) != hash(invalid3) class TestNoticeReference(object): def test_notice_numbers_not_all_int(self): -- cgit v1.2.3 From c0297ddb9ec205a6ee9844bde9d4e8eb0cc1009e Mon Sep 17 00:00:00 2001 From: Paul Kehrer Date: Sat, 26 Dec 2015 11:37:57 -0600 Subject: ...pep8 --- tests/test_x509_ext.py | 1 + 1 file changed, 1 insertion(+) (limited to 'tests') diff --git a/tests/test_x509_ext.py b/tests/test_x509_ext.py index d0f4cac9..f7be4bbe 100644 --- a/tests/test_x509_ext.py +++ b/tests/test_x509_ext.py @@ -165,6 +165,7 @@ class TestInvalidityDate(object): assert hash(invalid1) == hash(invalid2) assert hash(invalid1) != hash(invalid3) + class TestNoticeReference(object): def test_notice_numbers_not_all_int(self): with pytest.raises(TypeError): -- cgit v1.2.3