|
@@ -1,4 +1,4 @@
|
|
-import unittest, os, sys, tempfile
|
|
|
|
|
|
+import unittest, os, sys, tempfile, logging
|
|
from subprocess import Popen, PIPE
|
|
from subprocess import Popen, PIPE
|
|
try:
|
|
try:
|
|
from StringIO import StringIO # Python 2
|
|
from StringIO import StringIO # Python 2
|
|
@@ -36,8 +36,7 @@ class TestModule(unittest.TestCase):
|
|
sys.stdout.seek(0)
|
|
sys.stdout.seek(0)
|
|
crt = sys.stdout.read().encode("utf8")
|
|
crt = sys.stdout.read().encode("utf8")
|
|
sys.stdout = old_stdout
|
|
sys.stdout = old_stdout
|
|
- out, err = Popen(["openssl", "x509", "-text", "-noout"], stdin=PIPE,
|
|
|
|
- stdout=PIPE, stderr=PIPE).communicate(crt)
|
|
|
|
|
|
+ out, err = Popen(["openssl", "x509", "-text", "-noout"], stdin=PIPE, stdout=PIPE, stderr=PIPE).communicate(crt)
|
|
self.assertIn("Issuer: CN=Fake LE Intermediate", out.decode("utf8"))
|
|
self.assertIn("Issuer: CN=Fake LE Intermediate", out.decode("utf8"))
|
|
|
|
|
|
def test_success_san(self):
|
|
def test_success_san(self):
|
|
@@ -53,8 +52,7 @@ class TestModule(unittest.TestCase):
|
|
sys.stdout.seek(0)
|
|
sys.stdout.seek(0)
|
|
crt = sys.stdout.read().encode("utf8")
|
|
crt = sys.stdout.read().encode("utf8")
|
|
sys.stdout = old_stdout
|
|
sys.stdout = old_stdout
|
|
- out, err = Popen(["openssl", "x509", "-text", "-noout"], stdin=PIPE,
|
|
|
|
- stdout=PIPE, stderr=PIPE).communicate(crt)
|
|
|
|
|
|
+ out, err = Popen(["openssl", "x509", "-text", "-noout"], stdin=PIPE, stdout=PIPE, stderr=PIPE).communicate(crt)
|
|
self.assertIn("Issuer: CN=Fake LE Intermediate", out.decode("utf8"))
|
|
self.assertIn("Issuer: CN=Fake LE Intermediate", out.decode("utf8"))
|
|
|
|
|
|
def test_success_cli(self):
|
|
def test_success_cli(self):
|
|
@@ -66,8 +64,7 @@ class TestModule(unittest.TestCase):
|
|
"--acme-dir", self.tempdir,
|
|
"--acme-dir", self.tempdir,
|
|
"--directory-url", self.DIR_URL,
|
|
"--directory-url", self.DIR_URL,
|
|
], stdout=PIPE, stderr=PIPE).communicate()
|
|
], stdout=PIPE, stderr=PIPE).communicate()
|
|
- out, err = Popen(["openssl", "x509", "-text", "-noout"], stdin=PIPE,
|
|
|
|
- stdout=PIPE, stderr=PIPE).communicate(crt)
|
|
|
|
|
|
+ out, err = Popen(["openssl", "x509", "-text", "-noout"], stdin=PIPE, stdout=PIPE, stderr=PIPE).communicate(crt)
|
|
self.assertIn("Issuer: CN=Fake LE Intermediate", out.decode("utf8"))
|
|
self.assertIn("Issuer: CN=Fake LE Intermediate", out.decode("utf8"))
|
|
|
|
|
|
def test_missing_account_key(self):
|
|
def test_missing_account_key(self):
|
|
@@ -154,3 +151,31 @@ class TestModule(unittest.TestCase):
|
|
self.assertIsInstance(result, ValueError)
|
|
self.assertIsInstance(result, ValueError)
|
|
self.assertIn("certificate public key must be different than account key", result.args[0])
|
|
self.assertIn("certificate public key must be different than account key", result.args[0])
|
|
|
|
|
|
|
|
+ def test_contact(self):
|
|
|
|
+ """ Make sure optional contact details can be set """
|
|
|
|
+ # add a logging handler that captures the info log output
|
|
|
|
+ log_output = StringIO()
|
|
|
|
+ debug_handler = logging.StreamHandler(log_output)
|
|
|
|
+ acme_tiny.LOGGER.addHandler(debug_handler)
|
|
|
|
+ # call acme_tiny with new contact details
|
|
|
|
+ old_stdout = sys.stdout
|
|
|
|
+ sys.stdout = StringIO()
|
|
|
|
+ result = acme_tiny.main([
|
|
|
|
+ "--account-key", KEYS['account_key'].name,
|
|
|
|
+ "--csr", KEYS['domain_csr'].name,
|
|
|
|
+ "--acme-dir", self.tempdir,
|
|
|
|
+ "--directory-url", self.DIR_URL,
|
|
|
|
+ "--contact", "mailto:devteam@example.com", "mailto:boss@example.com",
|
|
|
|
+ ])
|
|
|
|
+ sys.stdout.seek(0)
|
|
|
|
+ crt = sys.stdout.read().encode("utf8")
|
|
|
|
+ sys.stdout = old_stdout
|
|
|
|
+ log_output.seek(0)
|
|
|
|
+ log_string = log_output.read().encode("utf8")
|
|
|
|
+ # make sure the certificate was issued and the contact details were updated
|
|
|
|
+ out, err = Popen(["openssl", "x509", "-text", "-noout"], stdin=PIPE, stdout=PIPE, stderr=PIPE).communicate(crt)
|
|
|
|
+ self.assertIn("Issuer: CN=Fake LE Intermediate", out.decode("utf8"))
|
|
|
|
+ self.assertIn("Updated contact details:\nmailto:devteam@example.com\nmailto:boss@example.com", log_string)
|
|
|
|
+ # remove logging capture
|
|
|
|
+ acme_tiny.LOGGER.removeHandler(debug_handler)
|
|
|
|
+
|