From 2b62258a39880518403456bab487360b46ff02f7 Mon Sep 17 00:00:00 2001 From: Paul Kehrer Date: Wed, 15 Apr 2015 11:04:29 -0400 Subject: certificate policies extension support Adds a bunch of ancillary classes to support this. --- tests/test_x509_ext.py | 117 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 117 insertions(+) (limited to 'tests/test_x509_ext.py') diff --git a/tests/test_x509_ext.py b/tests/test_x509_ext.py index 06a68600..c6303432 100644 --- a/tests/test_x509_ext.py +++ b/tests/test_x509_ext.py @@ -39,6 +39,123 @@ class TestExtension(object): ) +class TestNoticeReference(object): + def test_notice_numbers_not_all_int(self): + with pytest.raises(TypeError): + x509.NoticeReference("org", [1, 2, "three"]) + + def test_notice_numbers_none(self): + nr = x509.NoticeReference("org", None) + assert nr.organization == "org" + assert nr.notice_numbers is None + + def test_repr(self): + nr = x509.NoticeReference("org", [1, 3, 4]) + + assert repr(nr) == ( + "" + ) + + +class TestUserNotice(object): + def test_notice_reference_invalid(self): + with pytest.raises(TypeError): + x509.UserNotice("invalid", None) + + def test_notice_reference_none(self): + un = x509.UserNotice(None, "text") + assert un.notice_reference is None + assert un.explicit_text == "text" + + def test_repr(self): + un = x509.UserNotice(x509.NoticeReference("org", None), "text") + assert repr(un) == ( + ", explicit_text=text)>" + ) + + +class TestPolicyQualifierInfo(object): + def test_invalid_qualifier(self): + with pytest.raises(ValueError): + x509.PolicyQualifierInfo(None) + + def test_string_qualifier(self): + pqi = x509.PolicyQualifierInfo("1.2.3") + assert pqi.policy_qualifier_id == x509.OID_CPS_QUALIFIER + assert pqi.qualifier == "1.2.3" + + def test_user_notice_qualifier(self): + pqi = x509.PolicyQualifierInfo(x509.UserNotice(None, "text")) + assert pqi.policy_qualifier_id == x509.OID_CPS_USER_NOTICE + assert isinstance(pqi.qualifier, x509.UserNotice) + + def test_repr(self): + pqi = x509.PolicyQualifierInfo("1.2.3.4") + assert repr(pqi) == ( + ", qualifier=1.2.3.4)>" + ) + + +class TestPolicyInformation(object): + def test_invalid_policy_identifier(self): + with pytest.raises(TypeError): + x509.PolicyInformation("notanoid", None) + + def test_none_policy_qualifiers(self): + pi = x509.PolicyInformation(x509.ObjectIdentifier("1.2.3"), None) + assert pi.policy_identifier == x509.ObjectIdentifier("1.2.3") + assert pi.policy_qualifiers is None + + def test_policy_qualifiers(self): + pq = [x509.PolicyQualifierInfo("string")] + pi = x509.PolicyInformation(x509.ObjectIdentifier("1.2.3"), pq) + assert pi.policy_identifier == x509.ObjectIdentifier("1.2.3") + assert pi.policy_qualifiers == pq + + def test_invalid_policy_identifiers(self): + with pytest.raises(TypeError): + x509.PolicyInformation(x509.ObjectIdentifier("1.2.3"), [1, 2]) + + def test_repr(self): + pq = [x509.PolicyQualifierInfo("string")] + pi = x509.PolicyInformation(x509.ObjectIdentifier("1.2.3"), pq) + assert repr(pi) == ( + ", policy_qualifiers=[, qualifier=string)>])>" + ) + + +class TestCertificatePolicies(object): + def test_invalid_policies(self): + pq = [x509.PolicyQualifierInfo("string")] + pi = x509.PolicyInformation(x509.ObjectIdentifier("1.2.3"), pq) + with pytest.raises(TypeError): + x509.CertificatePolicies([1, pi]) + + def test_iter_len(self): + pq = [x509.PolicyQualifierInfo("string")] + pi = x509.PolicyInformation(x509.ObjectIdentifier("1.2.3"), pq) + cp = x509.CertificatePolicies([pi]) + assert len(cp) == 1 + for policyinfo in cp: + assert policyinfo == pi + + def test_repr(self): + pq = [x509.PolicyQualifierInfo("string")] + pi = x509.PolicyInformation(x509.ObjectIdentifier("1.2.3"), pq) + cp = x509.CertificatePolicies([pi]) + assert repr(cp) == ( + ", policy_qualifiers=[, qualifier=string)>])>])>" + ) + + class TestKeyUsage(object): def test_key_agreement_false_encipher_decipher_true(self): with pytest.raises(ValueError): -- cgit v1.2.3 From ba35b3ba85c374dfd0659992cae01255c530679d Mon Sep 17 00:00:00 2001 From: Paul Kehrer Date: Sun, 10 May 2015 13:07:59 -0500 Subject: remove policyqualifierinfo object --- tests/test_x509_ext.py | 69 +++++++++++++++++++++----------------------------- 1 file changed, 29 insertions(+), 40 deletions(-) (limited to 'tests/test_x509_ext.py') diff --git a/tests/test_x509_ext.py b/tests/test_x509_ext.py index c6303432..10afa1b7 100644 --- a/tests/test_x509_ext.py +++ b/tests/test_x509_ext.py @@ -75,29 +75,6 @@ class TestUserNotice(object): ) -class TestPolicyQualifierInfo(object): - def test_invalid_qualifier(self): - with pytest.raises(ValueError): - x509.PolicyQualifierInfo(None) - - def test_string_qualifier(self): - pqi = x509.PolicyQualifierInfo("1.2.3") - assert pqi.policy_qualifier_id == x509.OID_CPS_QUALIFIER - assert pqi.qualifier == "1.2.3" - - def test_user_notice_qualifier(self): - pqi = x509.PolicyQualifierInfo(x509.UserNotice(None, "text")) - assert pqi.policy_qualifier_id == x509.OID_CPS_USER_NOTICE - assert isinstance(pqi.qualifier, x509.UserNotice) - - def test_repr(self): - pqi = x509.PolicyQualifierInfo("1.2.3.4") - assert repr(pqi) == ( - ", qualifier=1.2.3.4)>" - ) - - class TestPolicyInformation(object): def test_invalid_policy_identifier(self): with pytest.raises(TypeError): @@ -109,7 +86,7 @@ class TestPolicyInformation(object): assert pi.policy_qualifiers is None def test_policy_qualifiers(self): - pq = [x509.PolicyQualifierInfo("string")] + pq = [u"string"] pi = x509.PolicyInformation(x509.ObjectIdentifier("1.2.3"), pq) assert pi.policy_identifier == x509.ObjectIdentifier("1.2.3") assert pi.policy_qualifiers == pq @@ -119,25 +96,31 @@ class TestPolicyInformation(object): x509.PolicyInformation(x509.ObjectIdentifier("1.2.3"), [1, 2]) def test_repr(self): - pq = [x509.PolicyQualifierInfo("string")] + pq = [u"string", x509.UserNotice(None, "hi")] pi = x509.PolicyInformation(x509.ObjectIdentifier("1.2.3"), pq) - assert repr(pi) == ( - ", policy_qualifiers=[, qualifier=string)>])>" - ) + if six.PY3: + assert repr(pi) == ( + ", policy_qualifiers=['string', ])>" + ) + else: + assert repr(pi) == ( + ", policy_qualifiers=[u'string', ])>" + ) class TestCertificatePolicies(object): def test_invalid_policies(self): - pq = [x509.PolicyQualifierInfo("string")] + pq = [u"string"] pi = x509.PolicyInformation(x509.ObjectIdentifier("1.2.3"), pq) with pytest.raises(TypeError): x509.CertificatePolicies([1, pi]) def test_iter_len(self): - pq = [x509.PolicyQualifierInfo("string")] + pq = [u"string"] pi = x509.PolicyInformation(x509.ObjectIdentifier("1.2.3"), pq) cp = x509.CertificatePolicies([pi]) assert len(cp) == 1 @@ -145,15 +128,21 @@ class TestCertificatePolicies(object): assert policyinfo == pi def test_repr(self): - pq = [x509.PolicyQualifierInfo("string")] + pq = [u"string"] pi = x509.PolicyInformation(x509.ObjectIdentifier("1.2.3"), pq) cp = x509.CertificatePolicies([pi]) - assert repr(cp) == ( - ", policy_qualifiers=[, qualifier=string)>])>])>" - ) + if six.PY3: + assert repr(cp) == ( + ", policy_qualifi" + "ers=['string'])>])>" + ) + else: + assert repr(cp) == ( + ", policy_qualifi" + "ers=[u'string'])>])>" + ) class TestKeyUsage(object): -- cgit v1.2.3 From 9aaef9e516ae1c54c79f07b0441c21c29f8aeb15 Mon Sep 17 00:00:00 2001 From: Paul Kehrer Date: Mon, 11 May 2015 10:49:20 -0500 Subject: use !r for explicit_text in NoticeReference repr --- tests/test_x509_ext.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'tests/test_x509_ext.py') diff --git a/tests/test_x509_ext.py b/tests/test_x509_ext.py index 10afa1b7..fa025d9c 100644 --- a/tests/test_x509_ext.py +++ b/tests/test_x509_ext.py @@ -71,7 +71,7 @@ class TestUserNotice(object): un = x509.UserNotice(x509.NoticeReference("org", None), "text") assert repr(un) == ( ", explicit_text=text)>" + "notice_numbers=None)>, explicit_text='text')>" ) @@ -102,13 +102,13 @@ class TestPolicyInformation(object): assert repr(pi) == ( ", policy_qualifiers=['string', ])>" + "tice(notice_reference=None, explicit_text='hi')>])>" ) else: assert repr(pi) == ( ", policy_qualifiers=[u'string', ])>" + "otice(notice_reference=None, explicit_text='hi')>])>" ) -- cgit v1.2.3 From 73be2ca86049fd15f1ab37d7201a9b32264402ab Mon Sep 17 00:00:00 2001 From: Paul Kehrer Date: Mon, 11 May 2015 21:22:38 -0500 Subject: alter the repr a bit, pass unicode everywhere --- tests/test_x509_ext.py | 35 ++++++++++++++++++++++++----------- 1 file changed, 24 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 fa025d9c..ae69f5fc 100644 --- a/tests/test_x509_ext.py +++ b/tests/test_x509_ext.py @@ -50,11 +50,18 @@ class TestNoticeReference(object): assert nr.notice_numbers is None def test_repr(self): - nr = x509.NoticeReference("org", [1, 3, 4]) + nr = x509.NoticeReference(u"org", [1, 3, 4]) - assert repr(nr) == ( - "" - ) + if six.PY3: + assert repr(nr) == ( + "" + ) + else: + assert repr(nr) == ( + "" + ) class TestUserNotice(object): @@ -68,11 +75,17 @@ class TestUserNotice(object): assert un.explicit_text == "text" def test_repr(self): - un = x509.UserNotice(x509.NoticeReference("org", None), "text") - assert repr(un) == ( - ", explicit_text='text')>" - ) + un = x509.UserNotice(x509.NoticeReference(u"org", None), u"text") + if six.PY3: + assert repr(un) == ( + ", explicit_text='text')>" + ) + else: + assert repr(un) == ( + ", explicit_text=u'text')>" + ) class TestPolicyInformation(object): @@ -96,7 +109,7 @@ class TestPolicyInformation(object): x509.PolicyInformation(x509.ObjectIdentifier("1.2.3"), [1, 2]) def test_repr(self): - pq = [u"string", x509.UserNotice(None, "hi")] + pq = [u"string", x509.UserNotice(None, u"hi")] pi = x509.PolicyInformation(x509.ObjectIdentifier("1.2.3"), pq) if six.PY3: assert repr(pi) == ( @@ -108,7 +121,7 @@ class TestPolicyInformation(object): assert repr(pi) == ( ", policy_qualifiers=[u'string', ])>" + "otice(notice_reference=None, explicit_text=u'hi')>])>" ) -- cgit v1.2.3