add level 3

This commit is contained in:
Матвей
2026-11-07 15:00:53 +03:00
parent eafb825657
commit 7b6c10cde9
54 changed files with 1593 additions and 120 deletions
+31
View File
@@ -0,0 +1,31 @@
"""Run inside the Compose network using temporary test identities."""
import socket
import ssl
def call(host, cert=None):
context = ssl.create_default_context(cafile="/certs/ca.crt")
if cert:
context.load_cert_chain(cert)
with socket.create_connection((host, 8444), timeout=5) as raw:
with context.wrap_socket(raw, server_hostname=host) as conn:
conn.sendall(b"GET /health/ready HTTP/1.1\r\nHost: localhost\r\nConnection: close\r\n\r\n")
return conn.recv(4096).split(b"\r\n", 1)[0]
for host in ("api-a", "api-b"):
assert b" 200 " in call(host, "/certs/lb.pem"), f"{host}: valid LB certificate rejected"
for certificate in (None, "/certs/foreign.pem"):
try:
result = call(host, certificate)
except (ssl.SSLError, ConnectionResetError, BrokenPipeError):
continue
raise AssertionError(f"{host}: bad certificate unexpectedly received {result!r}")
assert b" 403 " in call(host, "/certs/wrong-role.pem"), f"{host}: wrong role not denied"
try:
socket.create_connection((host, 8080), timeout=3).close()
except ConnectionRefusedError:
pass
else:
raise AssertionError(f"{host}: application port reachable without mTLS")
print(f"PASS {host}: valid identity accepted; no cert, foreign CA and wrong role rejected; direct API closed")