コード例 #1
0
ファイル: util_test.py プロジェクト: Ghostff/letsencrypt
    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")
コード例 #2
0
ファイル: util_test.py プロジェクト: 792685970/bootking
    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')
コード例 #3
0
    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
コード例 #4
0
ファイル: crypto_util_test.py プロジェクト: yunghuffy/certbot
    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
コード例 #5
0
    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'))
コード例 #6
0
ファイル: standalone_test.py プロジェクト: certbot/certbot
 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'))
コード例 #7
0
 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
コード例 #8
0
    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'))
コード例 #9
0
 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'))
コード例 #10
0
 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
コード例 #11
0
ファイル: standalone_test.py プロジェクト: JackZ0/TCP-IP
    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()
コード例 #12
0
    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()
コード例 #13
0
ファイル: messages_test.py プロジェクト: MichalMMac/certbot
"""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):
コード例 #14
0
"""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)
コード例 #15
0
ファイル: messages_test.py プロジェクト: 792685970/bootking
"""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):
コード例 #16
0
ファイル: jws_test.py プロジェクト: Ghostff/letsencrypt
"""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
コード例 #17
0
"""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):