Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/certbot/certbot.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'acme/tests/standalone_test.py')
-rw-r--r--acme/tests/standalone_test.py57
1 files changed, 56 insertions, 1 deletions
diff --git a/acme/tests/standalone_test.py b/acme/tests/standalone_test.py
index 83ced12b0..e2817b29c 100644
--- a/acme/tests/standalone_test.py
+++ b/acme/tests/standalone_test.py
@@ -10,7 +10,10 @@ from six.moves import http_client # pylint: disable=import-error
from six.moves import socketserver # type: ignore # pylint: disable=import-error
from acme import challenges
+from acme import crypto_util
+from acme import errors
from acme.magic_typing import Set # pylint: disable=unused-import, no-name-in-module
+
import test_util
@@ -84,6 +87,59 @@ class HTTP01ServerTest(unittest.TestCase):
self.assertFalse(self._test_http01(add=False))
+@unittest.skipIf(not challenges.TLSALPN01.is_supported(), "pyOpenSSL too old")
+class TLSALPN01ServerTest(unittest.TestCase):
+ """Test for acme.standalone.TLSALPN01Server."""
+
+ def setUp(self):
+ self.certs = {b'localhost': (
+ test_util.load_pyopenssl_private_key('rsa2048_key.pem'),
+ test_util.load_cert('rsa2048_cert.pem'),
+ )}
+ # Use different certificate for challenge.
+ self.challenge_certs = {b'localhost': (
+ test_util.load_pyopenssl_private_key('rsa1024_key.pem'),
+ test_util.load_cert('rsa1024_cert.pem'),
+ )}
+ from acme.standalone import TLSALPN01Server
+ self.server = TLSALPN01Server(("localhost", 0), certs=self.certs,
+ challenge_certs=self.challenge_certs)
+ # pylint: disable=no-member
+ self.thread = threading.Thread(target=self.server.serve_forever)
+ self.thread.start()
+
+ def tearDown(self):
+ self.server.shutdown() # pylint: disable=no-member
+ self.thread.join()
+
+ # TODO: This is not implemented yet, see comments in standalone.py
+ # def test_certs(self):
+ # host, port = self.server.socket.getsockname()[:2]
+ # cert = crypto_util.probe_sni(
+ # b'localhost', host=host, port=port, timeout=1)
+ # # Expect normal cert when connecting without ALPN.
+ # self.assertEqual(jose.ComparableX509(cert),
+ # jose.ComparableX509(self.certs[b'localhost'][1]))
+
+ def test_challenge_certs(self):
+ host, port = self.server.socket.getsockname()[:2]
+ cert = crypto_util.probe_sni(
+ b'localhost', host=host, port=port, timeout=1,
+ alpn_protocols=[b"acme-tls/1"])
+ # Expect challenge cert when connecting with ALPN.
+ self.assertEqual(
+ jose.ComparableX509(cert),
+ jose.ComparableX509(self.challenge_certs[b'localhost'][1])
+ )
+
+ def test_bad_alpn(self):
+ host, port = self.server.socket.getsockname()[:2]
+ with self.assertRaises(errors.Error):
+ crypto_util.probe_sni(
+ b'localhost', host=host, port=port, timeout=1,
+ alpn_protocols=[b"bad-alpn"])
+
+
class BaseDualNetworkedServersTest(unittest.TestCase):
"""Test for acme.standalone.BaseDualNetworkedServers."""
@@ -138,7 +194,6 @@ class BaseDualNetworkedServersTest(unittest.TestCase):
class HTTP01DualNetworkedServersTest(unittest.TestCase):
"""Tests for acme.standalone.HTTP01DualNetworkedServers."""
-
def setUp(self):
self.account_key = jose.JWK.load(
test_util.load_vector('rsa1024_key.pem'))