diff options
author | Aldo Cortesi <aldo@nullcube.com> | 2012-02-29 13:20:53 +1300 |
---|---|---|
committer | Aldo Cortesi <aldo@nullcube.com> | 2012-02-29 13:20:53 +1300 |
commit | 8b841bc9e370370716b473f26e001c65e2eee2af (patch) | |
tree | 328b55b51a48ae1fcabcced82f76ee71f9401c65 /test | |
parent | 0bed5fae277c06435594fdbe09f7b75791fdc311 (diff) | |
download | mitmproxy-8b841bc9e370370716b473f26e001c65e2eee2af.tar.gz mitmproxy-8b841bc9e370370716b473f26e001c65e2eee2af.tar.bz2 mitmproxy-8b841bc9e370370716b473f26e001c65e2eee2af.zip |
Factor out cert operations in to certutils.py.
Diffstat (limited to 'test')
-rw-r--r-- | test/test_certutils.py | 69 | ||||
-rw-r--r-- | test/test_utils.py | 63 |
2 files changed, 69 insertions, 63 deletions
diff --git a/test/test_certutils.py b/test/test_certutils.py new file mode 100644 index 00000000..15e81f74 --- /dev/null +++ b/test/test_certutils.py @@ -0,0 +1,69 @@ +import os +import libpry +from libmproxy import certutils + + +class udummy_ca(libpry.AutoTree): + def test_all(self): + d = self.tmpdir() + 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 udummy_cert(libpry.AutoTree): + def test_with_ca(self): + d = self.tmpdir() + 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): + d = self.tmpdir() + p = certutils.dummy_cert( + d, + None, + "foo.com", + [] + ) + assert os.path.exists(p) + + +class uparse_text_cert(libpry.AutoTree): + def test_simple(self): + c = file("data/text_cert", "r").read() + cn, san = certutils.parse_text_cert(c) + assert cn == "google.com" + assert len(san) == 436 + + c = file("data/text_cert_2", "r").read() + cn, san = certutils.parse_text_cert(c) + assert cn == "www.inode.co.nz" + assert len(san) == 2 + + +tests = [ + uparse_text_cert(), + udummy_ca(), + udummy_cert(), +] diff --git a/test/test_utils.py b/test/test_utils.py index 79ddf53d..17c677a7 100644 --- a/test/test_utils.py +++ b/test/test_utils.py @@ -127,52 +127,6 @@ class u_urldecode(libpry.AutoTree): assert len(utils.urldecode(s)) == 2 -class udummy_ca(libpry.AutoTree): - def test_all(self): - d = self.tmpdir() - path = os.path.join(d, "foo/cert.cnf") - assert utils.dummy_ca(path) - assert os.path.exists(path) - - path = os.path.join(d, "foo/cert2.pem") - assert utils.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 udummy_cert(libpry.AutoTree): - def test_with_ca(self): - d = self.tmpdir() - cacert = os.path.join(d, "foo/cert.cnf") - assert utils.dummy_ca(cacert) - p = utils.dummy_cert( - os.path.join(d, "foo"), - cacert, - "foo.com", - ["one.com", "two.com", "*.three.com"] - ) - assert os.path.exists(p) - - # Short-circuit - assert utils.dummy_cert( - os.path.join(d, "foo"), - cacert, - "foo.com", - [] - ) - - def test_no_ca(self): - d = self.tmpdir() - p = utils.dummy_cert( - d, - None, - "foo.com", - [] - ) - assert os.path.exists(p) - - class uLRUCache(libpry.AutoTree): def test_one(self): class Foo: @@ -259,22 +213,7 @@ class u_parse_size(libpry.AutoTree): libpry.raises(ValueError, utils.parse_size, "ak") -class uparse_text_cert(libpry.AutoTree): - def test_simple(self): - c = file("data/text_cert", "r").read() - cn, san = utils.parse_text_cert(c) - assert cn == "google.com" - assert len(san) == 436 - - c = file("data/text_cert_2", "r").read() - cn, san = utils.parse_text_cert(c) - assert cn == "www.inode.co.nz" - assert len(san) == 2 - - - tests = [ - uparse_text_cert(), uformat_timestamp(), uisBin(), uisXML(), @@ -285,8 +224,6 @@ tests = [ upretty_json(), u_urldecode(), udel_all(), - udummy_ca(), - udummy_cert(), uLRUCache(), u_parse_url(), u_parse_proxy_spec(), |