aboutsummaryrefslogtreecommitdiffstats
path: root/test/test_certutils.py
diff options
context:
space:
mode:
authorAldo Cortesi <aldo@nullcube.com>2012-06-28 09:57:33 +1200
committerAldo Cortesi <aldo@nullcube.com>2012-06-28 09:57:33 +1200
commitbae86480d49eac9d776872bdcf92c0c42aaff24f (patch)
tree9c1464e91de790696336158e1d48d6707d229305 /test/test_certutils.py
parent92c7d38bd343a0436d73c0a984fe111996e15059 (diff)
parenta1491a6ae037b7874dd71de11f5cd43e10aa46e7 (diff)
downloadmitmproxy-bae86480d49eac9d776872bdcf92c0c42aaff24f.tar.gz
mitmproxy-bae86480d49eac9d776872bdcf92c0c42aaff24f.tar.bz2
mitmproxy-bae86480d49eac9d776872bdcf92c0c42aaff24f.zip
Merge branch 'master' of github.com:cortesi/netlib
Diffstat (limited to 'test/test_certutils.py')
-rw-r--r--test/test_certutils.py72
1 files changed, 72 insertions, 0 deletions
diff --git a/test/test_certutils.py b/test/test_certutils.py
new file mode 100644
index 00000000..85dce600
--- /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.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.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")
+ 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