Пример #1
0
 def setUp(self):
     from certbot._internal.plugins.standalone import ServerManager
     self.certs: Dict[bytes, Tuple[OpenSSL.crypto.PKey,
                                   OpenSSL.crypto.X509]] = {}
     self.http_01_resources: Set[
         acme_standalone.HTTP01RequestHandler.HTTP01Resource] = {}
     self.mgr = ServerManager(self.certs, self.http_01_resources)
Пример #2
0
class ServerManagerTest(unittest.TestCase):
    """Tests for certbot._internal.plugins.standalone.ServerManager."""
    def setUp(self):
        from certbot._internal.plugins.standalone import ServerManager
        self.certs: Dict[bytes, Tuple[OpenSSL.crypto.PKey,
                                      OpenSSL.crypto.X509]] = {}
        self.http_01_resources: Set[
            acme_standalone.HTTP01RequestHandler.HTTP01Resource] = {}
        self.mgr = ServerManager(self.certs, self.http_01_resources)

    def test_init(self):
        self.assertTrue(self.mgr.certs is self.certs)
        self.assertTrue(self.mgr.http_01_resources is self.http_01_resources)

    def _test_run_stop(self, challenge_type):
        server = self.mgr.run(port=0, challenge_type=challenge_type)
        port = server.getsocknames()[0][1]
        self.assertEqual(self.mgr.running(), {port: server})
        self.mgr.stop(port=port)
        self.assertEqual(self.mgr.running(), {})

    def test_run_stop_http_01(self):
        self._test_run_stop(challenges.HTTP01)

    def test_run_idempotent(self):
        server = self.mgr.run(port=0, challenge_type=challenges.HTTP01)
        port = server.getsocknames()[0][1]
        server2 = self.mgr.run(port=port, challenge_type=challenges.HTTP01)
        self.assertEqual(self.mgr.running(), {port: server})
        self.assertTrue(server is server2)
        self.mgr.stop(port)
        self.assertEqual(self.mgr.running(), {})

    def test_run_bind_error(self):
        some_server = socket.socket(socket.AF_INET6)
        some_server.bind(("", 0))
        port = some_server.getsockname()[1]
        maybe_another_server = socket.socket()
        try:
            maybe_another_server.bind(("", port))
        except socket.error:
            pass
        self.assertRaises(errors.StandaloneBindError,
                          self.mgr.run,
                          port,
                          challenge_type=challenges.HTTP01)
        self.assertEqual(self.mgr.running(), {})
        some_server.close()
        maybe_another_server.close()