From f7fcb1c80b2874df05db4603549c6a24d12e58c0 Mon Sep 17 00:00:00 2001 From: Aldo Cortesi Date: Wed, 27 Jun 2012 16:42:00 +1200 Subject: Add certutils to netlib. --- test/test_certutils.py | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 test/test_certutils.py (limited to 'test/test_certutils.py') diff --git a/test/test_certutils.py b/test/test_certutils.py new file mode 100644 index 00000000..5229fc2a --- /dev/null +++ b/test/test_certutils.py @@ -0,0 +1,72 @@ +import os +from netlib import certutils +import tutils + + +def test_dummy_ca(): + with tutils.tmpdir() as d: + path = os.path.join(d, "foo/cert.cnf") + assert certutils.dummy_ca(path) + assert os.path.exists(path) + + path = os.path.join(d, "foo/cert2.pem") + assert certutils.dummy_ca(path) + assert os.path.exists(path) + assert os.path.exists(os.path.join(d, "foo/cert2-cert.pem")) + assert os.path.exists(os.path.join(d, "foo/cert2-cert.p12")) + + +class TestDummyCert: + def test_with_ca(self): + with tutils.tmpdir() as d: + cacert = os.path.join(d, "foo/cert.cnf") + assert certutils.dummy_ca(cacert) + p = certutils.dummy_cert( + os.path.join(d, "foo"), + cacert, + "foo.com", + ["one.com", "two.com", "*.three.com"] + ) + assert os.path.exists(p) + + # Short-circuit + assert certutils.dummy_cert( + os.path.join(d, "foo"), + cacert, + "foo.com", + [] + ) + + def test_no_ca(self): + with tutils.tmpdir() as d: + p = certutils.dummy_cert( + d, + None, + "foo.com", + [] + ) + assert os.path.exists(p) + + +class TestSSLCert: + def test_simple(self): + c = certutils.SSLCert(file(tutils.test_data.path("data/text_cert"), "r").read()) + assert c.cn == "google.com" + assert len(c.altnames) == 436 + + c = certutils.SSLCert(file(tutils.test_data.path("data/text_cert_2"), "r").read()) + assert c.cn == "www.inode.co.nz" + assert len(c.altnames) == 2 + assert c.digest("sha1") + assert c.notbefore + assert c.notafter + assert c.subject + assert c.keyinfo == ("RSA", 2048) + assert c.serial + assert c.issuer + c.has_expired + + def test_der(self): + d = file(tutils.test_data.path("data/dercert")).read() + s = certutils.SSLCert.from_der(d) + assert s.cn -- cgit v1.2.3 From b0ef9ad07ba4b805f3130237dcf9207434c33d84 Mon Sep 17 00:00:00 2001 From: Aldo Cortesi Date: Wed, 27 Jun 2012 22:11:58 +1200 Subject: Refactor certutils.SSLCert API. --- test/test_certutils.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'test/test_certutils.py') diff --git a/test/test_certutils.py b/test/test_certutils.py index 5229fc2a..85dce600 100644 --- a/test/test_certutils.py +++ b/test/test_certutils.py @@ -50,11 +50,11 @@ class TestDummyCert: class TestSSLCert: def test_simple(self): - c = certutils.SSLCert(file(tutils.test_data.path("data/text_cert"), "r").read()) + c = certutils.SSLCert.from_pem(file(tutils.test_data.path("data/text_cert"), "r").read()) assert c.cn == "google.com" assert len(c.altnames) == 436 - c = certutils.SSLCert(file(tutils.test_data.path("data/text_cert_2"), "r").read()) + c = certutils.SSLCert.from_pem(file(tutils.test_data.path("data/text_cert_2"), "r").read()) assert c.cn == "www.inode.co.nz" assert len(c.altnames) == 2 assert c.digest("sha1") -- cgit v1.2.3