fix(pki-test): recognize explicit cert-auth chain rejection without accepting unrelated errors

This commit is contained in:
2026-11-20 21:33:47 +03:00
parent 67224e1512
commit d97403b03a
2 changed files with 49 additions and 1 deletions
+15 -1
View File
@@ -145,6 +145,18 @@ def preserve_lb():
} }
def cert_auth_denied(response):
body = response.json()
if body.get("auth"):
return False
if response.status_code in {401, 403}:
return bool(body.get("errors"))
return response.status_code == 400 and any(
"no chain matching all constraints could be found" in error
for error in body.get("errors", [])
)
def revoke(operator, leaf): def revoke(operator, leaf):
assert leaf["expires_at"] > time.time() + 5, ( assert leaf["expires_at"] > time.time() + 5, (
"Revocation must be tested before natural expiry" "Revocation must be tested before natural expiry"
@@ -213,7 +225,7 @@ def revoke(operator, leaf):
"ttl": "120s", "ttl": "120s",
}, },
) )
assert auth.status_code in {401, 403}, ( assert cert_auth_denied(auth), (
"Revoked certificate could authenticate again" "Revoked certificate could authenticate again"
) )
assert issue.status_code in {401, 403}, ( assert issue.status_code in {401, 403}, (
@@ -227,6 +239,8 @@ def revoke(operator, leaf):
"still_unexpired_at_check": leaf["expires_at"] > time.time(), "still_unexpired_at_check": leaf["expires_at"] > time.time(),
"new_tls_connection_denied": True, "new_tls_connection_denied": True,
"bao_crl_updated": True, "bao_crl_updated": True,
"bao_old_certificate_login_status": auth.status_code,
"bao_old_token_issue_status": issue.status_code,
"revoked_lb_service_tokens": revoked_tokens, "revoked_lb_service_tokens": revoked_tokens,
"old_certificate_new_auth_denied": True, "old_certificate_new_auth_denied": True,
"old_token_pki_issue_denied": True, "old_token_pki_issue_denied": True,
+34
View File
@@ -0,0 +1,34 @@
import httpx
import pytest
from scripts.pki import cert_auth_denied
@pytest.mark.parametrize(
("status", "body", "denied"),
[
(
400,
{
"errors": [
"no chain matching all constraints could be found "
"for this login certificate"
]
},
True,
),
(403, {"errors": ["permission denied"]}, True),
(400, {"errors": ["invalid JSON"]}, False),
(200, {"auth": {"client_token": "synthetic-token"}}, False),
(
403,
{
"auth": {"client_token": "synthetic-token"},
"errors": ["permission denied"],
},
False,
),
],
)
def test_revoked_login_requires_an_actual_denial(status, body, denied):
assert cert_auth_denied(httpx.Response(status, json=body)) is denied