def setUp(self): # test_util.load_comparable_{csr,cert} return ComparableX509 self.req1 = test_util.load_comparable_csr("csr.pem") self.req2 = test_util.load_comparable_csr("csr.pem") self.req_other = test_util.load_comparable_csr("csr-san.pem") self.cert1 = test_util.load_comparable_cert("cert.pem") self.cert2 = test_util.load_comparable_cert("cert.pem") self.cert_other = test_util.load_comparable_cert("cert-san.pem")
def setUp(self): # test_util.load_comparable_{csr,cert} return ComparableX509 self.req1 = test_util.load_comparable_csr('csr.pem') self.req2 = test_util.load_comparable_csr('csr.pem') self.req_other = test_util.load_comparable_csr('csr-san.pem') self.cert1 = test_util.load_comparable_cert('cert.pem') self.cert2 = test_util.load_comparable_cert('cert.pem') self.cert_other = test_util.load_comparable_cert('cert-san.pem')
def setUp(self): self.cert = test_util.load_comparable_cert("rsa2048_cert.pem") key = test_util.load_pyopenssl_private_key("rsa2048_key.pem") # pylint: disable=protected-access certs = {b"foo": (key, self.cert.wrapped)} from acme.crypto_util import SSLSocket class _TestServer(socketserver.TCPServer): # pylint: disable=too-few-public-methods # six.moves.* | pylint: disable=attribute-defined-outside-init,no-init def server_bind(self): # pylint: disable=missing-docstring self.socket = SSLSocket(socket.socket(), certs=certs) socketserver.TCPServer.server_bind(self) self.server = _TestServer(("", 0), socketserver.BaseRequestHandler) self.port = self.server.socket.getsockname()[1] self.server_thread = threading.Thread( # pylint: disable=no-member target=self.server.handle_request ) self.server_thread.start() time.sleep(1) # TODO: avoid race conditions in other way
def setUp(self): self.cert = test_util.load_comparable_cert('rsa2048_cert.pem') key = test_util.load_pyopenssl_private_key('rsa2048_key.pem') # pylint: disable=protected-access certs = {b'foo': (key, self.cert.wrapped)} from acme.crypto_util import SSLSocket class _TestServer(socketserver.TCPServer): # pylint: disable=too-few-public-methods # six.moves.* | pylint: disable=attribute-defined-outside-init,no-init def server_bind(self): # pylint: disable=missing-docstring self.socket = SSLSocket(socket.socket(), certs) socketserver.TCPServer.server_bind(self) self.server = _TestServer(('', 0), socketserver.BaseRequestHandler) self.port = self.server.socket.getsockname()[1] self.server_thread = threading.Thread( # pylint: disable=no-member target=self.server.handle_request) self.server_thread.start() time.sleep(1) # TODO: avoid race conditions in other way
def test_it(self, mock_logger): # Use a Queue because mock objects aren't thread safe. q = queue.Queue() # type: queue.Queue[int] # Add port number to the queue. mock_logger.info.side_effect = lambda *args: q.put(args[-1]) self.thread.start() # After the timeout, an exception is raised if the queue is empty. port = q.get(timeout=5) cert = crypto_util.probe_sni(b'localhost', b'0.0.0.0', port) self.assertEqual(jose.ComparableX509(cert), test_util.load_comparable_cert('rsa2048_cert.pem'))
def test_live(self): self.process.start() cert = None for _ in range(50): time.sleep(0.1) try: cert = crypto_util.probe_sni(b'localhost', b'127.0.0.1', self.port) break except errors.Error: # pragma: no cover pass self.assertEqual(jose.ComparableX509(cert), test_util.load_comparable_cert('rsa2048_cert.pem'))
def test_it(self): max_attempts = 5 while max_attempts: max_attempts -= 1 try: cert = crypto_util.probe_sni(b"localhost", b"0.0.0.0", self.port) except errors.Error: self.assertTrue(max_attempts > 0, "Timeout!") time.sleep(1) # wait until thread starts else: self.assertEqual(jose.ComparableX509(cert), test_util.load_comparable_cert("cert.pem")) break
def test_it(self, mock_logger): # Use a Queue because mock objects aren't thread safe. q = queue.Queue() # type: queue.Queue[int] # Add port number to the queue. mock_logger.info.side_effect = lambda *args: q.put(args[-1]) self.thread.start() # After the timeout, an exception is raised if the queue is empty. port = q.get(timeout=5) cert = crypto_util.probe_sni(b'localhost', b'0.0.0.0', port) self.assertEqual(jose.ComparableX509(cert), test_util.load_comparable_cert( 'rsa2048_cert.pem'))
def test_it(self): max_attempts = 5 while max_attempts: max_attempts -= 1 try: cert = crypto_util.probe_sni(b'localhost', b'0.0.0.0', self.port) except errors.Error: self.assertTrue(max_attempts > 0, "Timeout!") time.sleep(1) # wait until thread starts else: self.assertEqual(jose.ComparableX509(cert), test_util.load_comparable_cert('cert.pem')) break
def test_it(self): max_attempts = 5 for attempt in range(max_attempts): try: cert = crypto_util.probe_sni(b'localhost', b'0.0.0.0', self.port) except errors.Error: self.assertTrue(attempt + 1 < max_attempts, "Timeout!") time.sleep(1) # wait until thread starts else: self.assertEqual( jose.ComparableX509(cert), test_util.load_comparable_cert('rsa2048_cert.pem')) break if attempt == 0: # the first attempt is always meant to fail, so we can test # the socket failure code-path for probe_sni, as well self.thread.start()
def test_it(self): max_attempts = 5 for attempt in range(max_attempts): try: cert = crypto_util.probe_sni( b'localhost', b'0.0.0.0', self.port) except errors.Error: self.assertTrue(attempt + 1 < max_attempts, "Timeout!") time.sleep(1) # wait until thread starts else: self.assertEqual(jose.ComparableX509(cert), test_util.load_comparable_cert( 'rsa2048_cert.pem')) break if attempt == 0: # the first attempt is always meant to fail, so we can test # the socket failure code-path for probe_sni, as well self.thread.start()
"""Tests for acme.messages.""" import unittest import mock from acme import challenges from acme import jose from acme import test_util CERT = test_util.load_comparable_cert('cert.der') CSR = test_util.load_comparable_csr('csr.der') KEY = test_util.load_rsa_private_key('rsa512_key.pem') class ErrorTest(unittest.TestCase): """Tests for acme.messages.Error.""" def setUp(self): from acme.messages import Error, ERROR_PREFIX self.error = Error( detail='foo', typ=ERROR_PREFIX + 'malformed', title='title') self.jobj = { 'detail': 'foo', 'title': 'some title', 'type': ERROR_PREFIX + 'malformed', } self.error_custom = Error(typ='custom', detail='bar') self.jobj_custom = {'type': 'custom', 'detail': 'bar'} def test_default_typ(self):
"""Tests for acme.challenges.""" import unittest import josepy as jose import mock import requests from six.moves.urllib import parse as urllib_parse # pylint: disable=relative-import from acme import test_util CERT = test_util.load_comparable_cert('cert.pem') KEY = jose.JWKRSA(key=test_util.load_rsa_private_key('rsa512_key.pem')) class ChallengeTest(unittest.TestCase): def test_from_json_unrecognized(self): from acme.challenges import Challenge from acme.challenges import UnrecognizedChallenge chall = UnrecognizedChallenge({"type": "foo"}) # pylint: disable=no-member self.assertEqual(chall, Challenge.from_json(chall.jobj)) class UnrecognizedChallengeTest(unittest.TestCase): def setUp(self): from acme.challenges import UnrecognizedChallenge self.jobj = {"type": "foo"} self.chall = UnrecognizedChallenge(self.jobj)
"""Tests for acme.messages.""" import unittest import mock from acme import challenges from acme import jose from acme import test_util CERT = test_util.load_comparable_cert('cert.der') CSR = test_util.load_comparable_csr('csr.der') KEY = test_util.load_rsa_private_key('rsa512_key.pem') class ErrorTest(unittest.TestCase): """Tests for acme.messages.Error.""" def setUp(self): from acme.messages import Error, ERROR_PREFIX self.error = Error( detail='foo', typ=ERROR_PREFIX + 'malformed', title='title') self.jobj = { 'detail': 'foo', 'title': 'some title', 'type': ERROR_PREFIX + 'malformed', } self.error_custom = Error(typ='custom', detail='bar') self.jobj_cusom = {'type': 'custom', 'detail': 'bar'} def test_default_typ(self):
"""Tests for acme.jose.jws.""" import base64 import unittest import mock import OpenSSL from acme import test_util from acme.jose import errors from acme.jose import json_util from acme.jose import jwa from acme.jose import jwk CERT = test_util.load_comparable_cert("cert.pem") KEY = jwk.JWKRSA.load(test_util.load_vector("rsa512_key.pem")) class MediaTypeTest(unittest.TestCase): """Tests for acme.jose.jws.MediaType.""" def test_decode(self): from acme.jose.jws import MediaType self.assertEqual("application/app", MediaType.decode("application/app")) self.assertEqual("application/app", MediaType.decode("app")) self.assertRaises(errors.DeserializationError, MediaType.decode, "app;foo") def test_encode(self): from acme.jose.jws import MediaType
"""Tests for acme.challenges.""" import unittest import mock import OpenSSL import requests from six.moves.urllib import parse as urllib_parse # pylint: disable=import-error from acme import errors from acme import jose from acme import test_util from acme.dns_resolver import DNS_REQUIREMENT CERT = test_util.load_comparable_cert('cert.pem') KEY = jose.JWKRSA(key=test_util.load_rsa_private_key('rsa512_key.pem')) class ChallengeTest(unittest.TestCase): def test_from_json_unrecognized(self): from acme.challenges import Challenge from acme.challenges import UnrecognizedChallenge chall = UnrecognizedChallenge({"type": "foo"}) # pylint: disable=no-member self.assertEqual(chall, Challenge.from_json(chall.jobj)) class UnrecognizedChallengeTest(unittest.TestCase): def setUp(self):