test: close auth-route regression gaps for previously-open routes (PER-15250) - #326
Conversation
…R-15250) Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
🔍 Vulnerabilities of
|
| digest | sha256:7c07bb0cb998865572207a5f89f025fb4e747ddfc22740d752fdeb5f4c3648a5 |
| vulnerabilities | |
| platform | linux/amd64 |
| size | 133 MB |
| packages | 248 |
📦 Base Image python:3.13-alpine3.23
| also known as |
|
| digest | sha256:72c39ab9dbf2227aa91ec2246e6492260ee2530c36bdf37b208394b42d757b60 |
| vulnerabilities |
Description
Description
Description
Description
Description
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Description
Description
Description
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Description
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Description
|
🔍 Vulnerabilities of
|
| digest | sha256:7c07bb0cb998865572207a5f89f025fb4e747ddfc22740d752fdeb5f4c3648a5 |
| vulnerabilities | |
| platform | linux/amd64 |
| size | 133 MB |
| packages | 248 |
📦 Base Image python:3.13-alpine3.23
| also known as |
|
| digest | sha256:72c39ab9dbf2227aa91ec2246e6492260ee2530c36bdf37b208394b42d757b60 |
| vulnerabilities |
Description
Description
|
There was a problem hiding this comment.
Pull request overview
Adds missing integration-test coverage for previously open/auth-regressed routes in the Horizon PDP test suite, completing PER-15250 without changing production code.
Changes:
- Strengthens OPAL trigger-route “valid token” tests to assert real
200 {"status":"ok"}responses by boundary-mocking OPAL updaters, instead of only asserting “not 401”. - Adds parameterized malformed-
Authorizationheader coverage to ensure gated routes return401(and never500), including legacy update aliases and all protected enforcer endpoints. - Tightens legacy-route missing-header assertions from a transitional
(401|422)allowance to strict401+ expected detail message.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| horizon/tests/test_opal_trigger_auth.py | Replaces the “!= 401” valid-token assertion with deterministic 200 tests by AsyncMock’ing OPAL updater calls. |
| horizon/tests/test_legacy_update_routes.py | Tightens missing-header checks to 401 and adds malformed-header param tests ensuring updater methods are not awaited. |
| horizon/tests/test_enforcer_api.py | Adds malformed-header param test across all protected enforcer endpoints to pin 401 behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…eviously-open-routes-missing-bad
…eviously-open-routes-missing-bad
) Docker Scout began flagging two HIGH CVEs in cryptography 48.0.1 on 2026-08-04, turning docker-scout red on every open PR (#326, #327) and on main. Neither is caused by any code change - the pin has been cryptography>=48.0.1,<49 since #318. CVE-2026-69249 CVSS 8.7 fixed in 49.0.0 CVE-2026-69247 CVSS 8.2 affects >=44.0.0, fixed only in 50.0.0 (Observable Timing Discrepancy) Clearing both requires 50.0.0, so the floor moves past our own <49 major cap. Nothing external bounds cryptography: opal-common 0.9.6 requires it unpinned and its pyjwt[crypto]<3,>=2.4.0 carries no upper bound, so the new <51 cap is ours - it keeps a major out of an image build that has no lockfile, same reasoning as the websockets pin. musllinux_1_2 cp311-abi3 wheels are published for x86_64 and aarch64, so the alpine image keeps installing a prebuilt wheel and still needs no Rust toolchain. No VEX changes: both CVEs are fixable by upgrade, so neither needs a waiver in .docker/scout/pdp-v2.vex.json. Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
zeevmoney
left a comment
There was a problem hiding this comment.
Approved — no CRITICAL or HIGH issues found.
Non-blocking:
- LOW
horizon/tests/test_enforcer_api.py:101— Malformed-header set never uses a non-bearer scheme, so the scheme check stays untested - LOW
horizon/tests/test_legacy_update_routes.py:50— Malformed-header value list now copy-pasted verbatim across three test files
Details are in the inline comments on each line.
Outside this diff (not blocking this PR, listed for awareness — these lines are
not changed here, so they could not be posted as inline comments):
- LOW
horizon/enforcer/api.py:70— Second auth parser echoes the raw Authorization header into the 401 body
|
|
||
|
|
||
| @pytest.mark.parametrize("endpoint", PROTECTED_ENFORCER_ENDPOINTS) | ||
| @pytest.mark.parametrize("value", ["garbage", "Bearer", "Bearer ", "Bearer a b c"]) |
There was a problem hiding this comment.
[LOW] Malformed-header set never uses a non-bearer scheme, so the scheme check stays untested
Problem: The four parametrized values only exercise two states of the header parser: an empty credential ("garbage", "Bearer", "Bearer " all partition to an empty param) and a well-formed bearer with a wrong token ("Bearer a b c" partitions to scheme="Bearer", credentials="a b c", which is the same path test_enforcer_endpoint_invalid_token_returns_401 already covers). The one branch that is genuinely load-bearing and genuinely untested is a non-bearer scheme carrying a non-empty credential — e.g. Authorization: Basic mock_api_key. horizon/authentication.py:37-38 documents that exact case as behaviour the design depends on ("auto_error=False makes it return None ... for a missing, malformed, or non-bearer header"), and horizon/tests/test_authentication.py:4-5 explicitly delegates it away: "Header parsing itself is now delegated to fastapi.security.HTTPBearer (and exercised end-to-end with real header strings in test_opal_trigger_auth.py)". Neither file actually covers it. Mutation check: neutering HTTPBearer's scheme comparison so any scheme is accepted leaves the entire 162-test suite green, while making Basic <api-key> and Negotiate <api-key> authenticate against every gated route. The PR's whole stated purpose is pinning malformed-Authorization handling, so this is the variant most worth having.
Suggestion: Add a non-bearer scheme carrying a syntactically valid credential to the shared value list, at all four parametrize sites (test_enforcer_api.py:101, test_legacy_update_routes.py:50 and :96, test_opal_trigger_auth.py:93). Using the real API key as the credential is the strongest form, because it fails only if the scheme check itself is gone.
Example:
@pytest.mark.parametrize(
"value",
[
"garbage",
"Bearer",
"Bearer ",
"Bearer a b c",
f"Basic {sidecar_config.API_KEY}", # right secret, wrong scheme -> must still 401
f"basic {sidecar_config.API_KEY}",
],
)
| trigger.assert_not_awaited() | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("value", ["garbage", "Bearer", "Bearer ", "Bearer a b c"]) |
There was a problem hiding this comment.
[LOW] Malformed-header value list now copy-pasted verbatim across three test files
Problem: ["garbage", "Bearer", "Bearer ", "Bearer a b c"] now appears identically at four parametrize sites in three files. This PR added three of the four, crossing the "same code written three times" threshold. Concretely, this is what makes finding 1 a four-place edit instead of a one-place edit: any future addition to the malformed set (a non-bearer scheme, a Bearer\ttoken, a non-ASCII credential) has to be applied four times or the coverage silently diverges between routers. A shared constant is already trivially reachable — test_legacy_update_routes.py:10 demonstrates the suite's cross-module import convention (from test_enforcer_api import MockPermitPDP, basename import because CI installs the package non-editably).
Suggestion: Hoist the list to a single module-level constant (e.g. MALFORMED_AUTH_HEADERS in test_enforcer_api.py next to PROTECTED_ENFORCER_ENDPOINTS, or in horizon/tests/conftest.py) and import it at the other three sites, matching the existing basename-import convention.
Example:
# test_enforcer_api.py, next to PROTECTED_ENFORCER_ENDPOINTS
MALFORMED_AUTH_HEADERS = ["garbage", "Bearer", "Bearer ", "Bearer a b c"]
# test_legacy_update_routes.py / test_opal_trigger_auth.py
from test_enforcer_api import MalformedAuthHeaders # noqa: same basename convention as MockPermitPDP
@pytest.mark.parametrize("value", MALFORMED_AUTH_HEADERS)
Closes PER-15250.
What & why
PER-15250 asked for integration tests covering the routes that were gated by the auth-hardening work (PER-15244/15245/15246). Those PRs (#317/#320/#321) shipped most of the requested coverage alongside the fixes; this PR closes the two remaining gaps and tightens now-obsolete assertions. No production code changes — tests only.
Changes
1. Trigger routes now assert a real
200, not just!= 401(test_opal_trigger_auth.py)The valid-token test previously only asserted the request wasn't blocked. Replaced it with two tests that boundary-mock the real (unstarted) updater instances on
_sidecar._opaland assert an actual200 {"status": "ok"}with the correct awaited kwargs (force_full_update=True/data_fetch_reason="request from sdk"). Docstring updated to match.2. Malformed-
Authorization-header coverage on every gated route (test_legacy_update_routes.py,test_enforcer_api.py)Parametrized
["garbage", "Bearer", "Bearer ", "Bearer a b c"]→ 401, never 500 for the legacy aliases (asserting the updater is never awaited) and across all 9PROTECTED_ENFORCER_ENDPOINTS(covers/kong,/allowed, etc.). Pins the header-safe handling from PER-15245.3. Tightened obsolete dual-regime assertions (
test_legacy_update_routes.py)assert status in (401, 422)→== 401(+ detail) now thatenforce_pdp_tokendefaults its credentials param; removed the stale merge-order comments.Issue-case → test map
test_trigger_route_without_token_is_401,test_trigger_route_with_wrong_token_is_401test_{policy,data}_updater_trigger_route_with_valid_token_returns_200test_update_policy*(missing-token check tightened here)/kong401 (integration off & on), 200 w/ token+OPA, 503 orderingtest_kong_endpoint_*,test_enforcer_endpoint_{missing,invalid}_token_returns_401[/kong]/healthstays publictest_health_endpoint_is_public,test_health_is_public/allowedspot-checktest_enforce_endpoint[/allowed]test_*_malformed_header_is_401_not_500(three files)test_route_auth_audit.py(pre-existing)Deliberate deviation from the issue text
The issue (written before its blockers merged) specified a new file
test_unauthenticated_routes_regression.py. Those blockers created purpose-built test files that already carry the exact fixtures these cases need, so the new cases are appended next to the routes they gate rather than duplicating a fourthMockPermitPDPscaffold. The issue'senforce_pdp_tokensplit(" ")→ValueErrorpremise and itsmock_opafixture reference are also stale (superseded byHTTPBearer(auto_error=False)and theaioresponsespattern).Verification
python -m pytest horizon/tests/ -q→ 162 passed, 0 failedruff format --checkandruff check→ clean🤖 Generated with Claude Code