aboutsummaryrefslogtreecommitdiffstats
path: root/test/test_utils.py
diff options
context:
space:
mode:
authorAldo Cortesi <aldo@nullcube.com>2011-02-20 12:12:55 +1300
committerAldo Cortesi <aldo@nullcube.com>2011-02-20 12:17:10 +1300
commit4fc807cedd9a481db9e0fc1633d8c169f53f4a8e (patch)
treefdb9ebc487e50d7546e8eb8b50e29223458b9ec4 /test/test_utils.py
parentd7ace1ce9ef3832fc766c25067f8cd23fea62d8a (diff)
downloadmitmproxy-4fc807cedd9a481db9e0fc1633d8c169f53f4a8e.tar.gz
mitmproxy-4fc807cedd9a481db9e0fc1633d8c169f53f4a8e.tar.bz2
mitmproxy-4fc807cedd9a481db9e0fc1633d8c169f53f4a8e.zip
Clean up certificate generation.
- Use templates for config files. We can re-introduce customization of the certificate attributes when we need them. - Split CA and cert generation into separate functions. - Generation methods provide an error return when generation fails. - When the user explicitly specifies a certificate, we don't generate it, but fail if it doesn't exist.
Diffstat (limited to 'test/test_utils.py')
-rw-r--r--test/test_utils.py44
1 files changed, 33 insertions, 11 deletions
diff --git a/test/test_utils.py b/test/test_utils.py
index 5cf81e2e..a52c8e3b 100644
--- a/test/test_utils.py
+++ b/test/test_utils.py
@@ -217,16 +217,6 @@ class uisSequenceLike(libpry.AutoTree):
assert not utils.isSequenceLike(1)
-class umake_bogus_cert(libpry.AutoTree):
- def test_all(self):
- d = self.tmpdir()
- path = os.path.join(d, "foo", "cert")
- utils.make_bogus_cert(path)
-
- d = open(path).read()
- assert "PRIVATE KEY" in d
- assert "CERTIFICATE" in d
-
class upretty_xmlish(libpry.AutoTree):
def test_tagre(self):
@@ -284,12 +274,42 @@ class upretty_xmlish(libpry.AutoTree):
assert utils.pretty_xmlish(s) == ["gobbledygook"]
+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)
+
+
+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)
+ assert utils.dummy_cert(
+ os.path.join(d, "foo"),
+ cacert,
+ "foo.com"
+ )
+ assert os.path.exists(os.path.join(d, "foo", "foo.com.pem"))
+
+ def test_no_ca(self):
+ d = self.tmpdir()
+ assert utils.dummy_cert(
+ d,
+ None,
+ "foo.com"
+ )
+ assert os.path.exists(os.path.join(d, "foo.com.pem"))
+
+
+
tests = [
uformat_timestamp(),
- umake_bogus_cert(),
uisBin(),
uhexdump(),
upretty_size(),
@@ -299,4 +319,6 @@ tests = [
uHeaders(),
uData(),
upretty_xmlish(),
+ udummy_ca(),
+ udummy_cert(),
]