Exemplo n.º 1
0
    def setUp(self):
        self.account_key = jose.JWK.load(
            test_util.load_vector('rsa1024_key.pem'))
        self.resources = set()

        from acme.standalone import SimpleHTTPServer
        self.server = SimpleHTTPServer(('', 0), resources=self.resources)

        # pylint: disable=no-member
        self.port = self.server.socket.getsockname()[1]
        self.thread = threading.Thread(target=self.server.handle_request)
        self.thread.start()
Exemplo n.º 2
0
class SimpleHTTPServerTest(unittest.TestCase):
    """Tests for acme.standalone.SimpleHTTPServer."""
    def setUp(self):
        self.account_key = jose.JWK.load(
            test_util.load_vector('rsa1024_key.pem'))
        self.resources = set()

        from acme.standalone import SimpleHTTPServer
        self.server = SimpleHTTPServer(('', 0), resources=self.resources)

        # pylint: disable=no-member
        self.port = self.server.socket.getsockname()[1]
        self.thread = threading.Thread(target=self.server.handle_request)
        self.thread.start()

    def tearDown(self):
        self.server.shutdown2()
        self.thread.join()

    def test_index(self):
        response = requests.get('http://localhost:{0}'.format(self.port),
                                verify=False)
        self.assertEqual(response.text,
                         'ACME client standalone challenge solver')
        self.assertTrue(response.ok)

    def test_404(self):
        response = requests.get('http://localhost:{0}/foo'.format(self.port),
                                verify=False)
        self.assertEqual(response.status_code, http_client.NOT_FOUND)

    def _test_simple_http(self, add):
        chall = challenges.SimpleHTTP(token=(b'x' * 16))
        response = challenges.SimpleHTTPResponse(tls=False)

        from acme.standalone import SimpleHTTPRequestHandler
        resource = SimpleHTTPRequestHandler.SimpleHTTPResource(
            chall=chall,
            response=response,
            validation=response.gen_validation(chall, self.account_key))
        if add:
            self.resources.add(resource)
        return resource.response.simple_verify(resource.chall,
                                               'localhost',
                                               self.account_key.public_key(),
                                               port=self.port)

    def test_simple_http_found(self):
        self.assertTrue(self._test_simple_http(add=True))

    def test_simple_http_not_found(self):
        self.assertFalse(self._test_simple_http(add=False))
Exemplo n.º 3
0
class SimpleHTTPServerTest(unittest.TestCase):
    """Tests for acme.standalone.SimpleHTTPServer."""

    def setUp(self):
        self.account_key = jose.JWK.load(
            test_util.load_vector('rsa1024_key.pem'))
        self.resources = set()

        from acme.standalone import SimpleHTTPServer
        self.server = SimpleHTTPServer(('', 0), resources=self.resources)

        # pylint: disable=no-member
        self.port = self.server.socket.getsockname()[1]
        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()

    def test_index(self):
        response = requests.get(
            'http://localhost:{0}'.format(self.port), verify=False)
        self.assertEqual(
            response.text, 'ACME client standalone challenge solver')
        self.assertTrue(response.ok)

    def test_404(self):
        response = requests.get(
            'http://localhost:{0}/foo'.format(self.port), verify=False)
        self.assertEqual(response.status_code, http_client.NOT_FOUND)

    def _test_simple_http(self, add):
        chall = challenges.SimpleHTTP(token=(b'x' * 16))
        response = challenges.SimpleHTTPResponse(tls=False)

        from acme.standalone import SimpleHTTPRequestHandler
        resource = SimpleHTTPRequestHandler.SimpleHTTPResource(
            chall=chall, response=response, validation=response.gen_validation(
                chall, self.account_key))
        if add:
            self.resources.add(resource)
        return resource.response.simple_verify(
            resource.chall, 'localhost', self.account_key.public_key(),
            port=self.port)

    def test_simple_http_found(self):
        self.assertTrue(self._test_simple_http(add=True))

    def test_simple_http_not_found(self):
        self.assertFalse(self._test_simple_http(add=False))
Exemplo n.º 4
0
    def setUp(self):
        self.account_key = jose.JWK.load(
            test_util.load_vector('rsa1024_key.pem'))
        self.resources = set()

        from acme.standalone import SimpleHTTPServer
        self.server = SimpleHTTPServer(('', 0), resources=self.resources)

        # pylint: disable=no-member
        self.port = self.server.socket.getsockname()[1]
        self.thread = threading.Thread(target=self.server.serve_forever)
        self.thread.start()