test: verify HTTP2 proxy negotiation
This commit is contained in:
@@ -73,6 +73,7 @@ http {{
|
|||||||
|
|
||||||
server {{
|
server {{
|
||||||
listen 127.0.0.1:{edge_port} ssl;
|
listen 127.0.0.1:{edge_port} ssl;
|
||||||
|
http2 on;
|
||||||
ssl_certificate /etc/nginx/certs/cert.pem;
|
ssl_certificate /etc/nginx/certs/cert.pem;
|
||||||
ssl_certificate_key /etc/nginx/certs/key.pem;
|
ssl_certificate_key /etc/nginx/certs/key.pem;
|
||||||
|
|
||||||
@@ -146,6 +147,28 @@ def wait_for_proxy(edge_port: int, timeout: float) -> None:
|
|||||||
raise RuntimeError(f"Nginx proxy did not become healthy: {last_error}")
|
raise RuntimeError(f"Nginx proxy did not become healthy: {last_error}")
|
||||||
|
|
||||||
|
|
||||||
|
def verify_http2(edge_port: int) -> None:
|
||||||
|
expected = b'{"code":"OK","message":"success","data":{"status":"ok"},"requestId":"proxyCheck"}\n'
|
||||||
|
result = subprocess.run(
|
||||||
|
[
|
||||||
|
"curl", "--silent", "--show-error", "--fail", "--http2", "--insecure",
|
||||||
|
"-H", "X-Request-ID: proxyCheck", "-w", "\\n%{http_version}",
|
||||||
|
f"https://127.0.0.1:{edge_port}/health",
|
||||||
|
],
|
||||||
|
capture_output=True,
|
||||||
|
check=False,
|
||||||
|
)
|
||||||
|
if result.returncode != 0:
|
||||||
|
raise AssertionError(f"HTTP/2 curl failed: {result.stderr.decode(errors='replace')}")
|
||||||
|
output = result.stdout
|
||||||
|
try:
|
||||||
|
body, version = output.rsplit(b"\n", 1)
|
||||||
|
except ValueError as error:
|
||||||
|
raise AssertionError(f"HTTP/2 curl output missing protocol version: {output!r}") from error
|
||||||
|
if version != b"2" or body != expected:
|
||||||
|
raise AssertionError(f"expected HTTP/2 response, got version={version!r} body={body!r}")
|
||||||
|
|
||||||
|
|
||||||
def verify_timeout(edge_port: int) -> None:
|
def verify_timeout(edge_port: int) -> None:
|
||||||
context = ssl._create_unverified_context()
|
context = ssl._create_unverified_context()
|
||||||
connection = http.client.HTTPSConnection("127.0.0.1", edge_port, context=context, timeout=3)
|
connection = http.client.HTTPSConnection("127.0.0.1", edge_port, context=context, timeout=3)
|
||||||
@@ -166,6 +189,8 @@ def main() -> None:
|
|||||||
raise SystemExit("docker is required for proxy verification")
|
raise SystemExit("docker is required for proxy verification")
|
||||||
if shutil.which("openssl") is None:
|
if shutil.which("openssl") is None:
|
||||||
raise SystemExit("openssl is required for proxy verification")
|
raise SystemExit("openssl is required for proxy verification")
|
||||||
|
if shutil.which("curl") is None:
|
||||||
|
raise SystemExit("curl with HTTP/2 support is required for proxy verification")
|
||||||
if not Path("/proc").exists():
|
if not Path("/proc").exists():
|
||||||
raise SystemExit("proxy verification must run on Linux")
|
raise SystemExit("proxy verification must run on Linux")
|
||||||
|
|
||||||
@@ -231,6 +256,8 @@ def main() -> None:
|
|||||||
raise RuntimeError(
|
raise RuntimeError(
|
||||||
f"{error}; nginx logs={nginx_logs!r}; backend logs={backend_logs!r}"
|
f"{error}; nginx logs={nginx_logs!r}; backend logs={backend_logs!r}"
|
||||||
) from error
|
) from error
|
||||||
|
verify_http2(edge_port)
|
||||||
|
print("PASS Nginx HTTP/2 edge negotiation and HTTP/1.1 native backhaul", flush=True)
|
||||||
verify_keep_alive(edge_port)
|
verify_keep_alive(edge_port)
|
||||||
verify_timeout(edge_port)
|
verify_timeout(edge_port)
|
||||||
print("PASS Nginx TLS proxy, Keep-Alive and upstream timeout", flush=True)
|
print("PASS Nginx TLS proxy, Keep-Alive and upstream timeout", flush=True)
|
||||||
|
|||||||
Reference in New Issue
Block a user