Exemplo n.º 1
0
def _build_server(tmpdir, host):
    ca = trustme.CA()
    ca_cert_path = str(tmpdir / "ca.pem")
    ca.cert_pem.write_to_path(ca_cert_path)

    server_cert = ca.issue_cert(host)
    context = ssl.create_default_context(ssl.Purpose.CLIENT_AUTH)
    server_crt = server_cert.cert_chain_pems[0]
    server_key = server_cert.private_key_pem
    with server_crt.tempfile() as crt_file, server_key.tempfile() as key_file:
        context.load_cert_chain(crt_file, key_file)

    server = HTTPServer(ssl_context=context)
    # Fake what the client expects from Elasticsearch
    server.expect_request("/").respond_with_json(
        headers={
            "x-elastic-product": "Elasticsearch",
        },
        response_json={"version": {
            "number": "8.0.0",
        }},
    )
    server.start()

    yield server, ca, ca_cert_path

    server.clear()
    if server.is_running():
        server.stop()
Exemplo n.º 2
0
def test_api_is_up_bad(httpserver: HTTPServer):
    assert httpserver.is_running()
    httpserver.expect_request("/api/v1.0/system/test").respond_with_json(
        {"status": "bad"})
    assert api_is_up() == False
    httpserver.stop()