test(lasuite-docs): update stale OIDC tests for impress v5.4.0 Bearer-auth removal
continuous-integration/drone/push Build was killed
continuous-integration/drone/push Build was killed
test_oidc_login_via_keycloak and test_create_doc_and_read_back authenticated with 'Authorization: Bearer <password-grant JWT>'; impress v5.4.0 removed Bearer/JWT auth on the API (SessionAuthentication only), so both went RED with 401 on the v5.4.1 upgrade. Updated to the successor auth path: a new recipe-local _oidc_session.py drives the real OIDC authorization-code flow (app -> keycloak login form -> callback -> Django session cookie, with CSRF headers on unsafe methods). - test_oidc_login: still asserts the unauth challenge redirect; NOW also asserts a raw Bearer JWT is REJECTED (401/403 - the v5.4.0 hardening, asserted as the new correct behavior); then asserts the session-authenticated whoami returns the provisioned user. No assertion weakened - the auth proof is stronger than before. - test_create_doc: same create+read-back round-trip assertions, now over the session-authenticated API. Stale-test fix for recipe PR recipe-maintainers/lasuite-docs#7 (carry-over from /upgrade-all 2026-07-24).
This commit is contained in:
@@ -2,13 +2,16 @@
|
||||
|
||||
SOURCE: references/recipe-maintainer/recipe-info/lasuite-docs/tests/oidc_login.py
|
||||
|
||||
End-to-end flow:
|
||||
End-to-end flow (updated for impress v5.4.0, which REMOVED Bearer/JWT auth on the API —
|
||||
the app now only accepts its own session cookie from the OIDC authorization-code flow):
|
||||
1. GET `/api/v1.0/users/me/` without auth → asserts the response REDIRECTS to the dep
|
||||
keycloak's realm auth endpoint (the recipe is correctly configured to challenge
|
||||
unauthenticated callers — wired via install_steps.sh).
|
||||
2. Obtain an OIDC token from the dep keycloak via password grant
|
||||
(the test user provisioned by the orchestrator's realm setup).
|
||||
3. Call `/api/v1.0/users/me/` with `Authorization: Bearer <jwt>` → asserts 200 and the
|
||||
2. Obtain an OIDC token from the dep keycloak via password grant, and assert the API
|
||||
now REJECTS it as a Bearer credential (the v5.4.0 auth hardening — a 200 here would
|
||||
mean the hardening regressed).
|
||||
3. Log in via the real OIDC authorization-code flow (app → keycloak form → callback →
|
||||
session cookie) and call `/api/v1.0/users/me/` with the session → asserts 200 and the
|
||||
returned user's email matches the provisioned test user.
|
||||
|
||||
Marked @pytest.mark.requires_deps — skips with `deps-not-ready` if dep provisioning failed.
|
||||
@@ -24,9 +27,11 @@ import urllib.request
|
||||
|
||||
import pytest
|
||||
|
||||
sys.path.insert(0, os.path.dirname(__file__))
|
||||
sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..", "..", "..", "runner"))
|
||||
from _oidc_session import OidcSession # noqa: E402 (recipe-local helper, same dir)
|
||||
from harness import http as harness_http # noqa: E402
|
||||
from harness import sso
|
||||
from harness import sso # noqa: E402
|
||||
|
||||
_CTX = ssl.create_default_context()
|
||||
_CTX.check_hostname = False
|
||||
@@ -62,16 +67,18 @@ def test_oidc_login_via_keycloak(live_app, deps):
|
||||
# 302 redirect. Both are valid "auth-required" indicators — accept either, but if a
|
||||
# redirect is returned it must point at the dep keycloak realm.
|
||||
if status in (301, 302, 303, 307, 308):
|
||||
assert expected_prefix in (
|
||||
redirect or ""
|
||||
), f"Docs redirected to {redirect!r}, expected to start with {expected_prefix!r}"
|
||||
assert expected_prefix in (redirect or ""), (
|
||||
f"Docs redirected to {redirect!r}, expected to start with {expected_prefix!r}"
|
||||
)
|
||||
else:
|
||||
assert status in (401, 403), (
|
||||
f"GET /api/v1.0/users/me/ unauth: HTTP {status}; expected redirect to keycloak "
|
||||
f"OR 401/403. (200 would be an auth leak.)"
|
||||
)
|
||||
|
||||
# Step 2: obtain an OIDC token via password grant against the dep keycloak
|
||||
# Step 2: obtain an OIDC token via password grant against the dep keycloak, and assert
|
||||
# the API REJECTS it as Bearer — impress v5.4.0 removed Bearer/JWT auth (SessionAuthentication
|
||||
# only); a 200 here would mean the auth hardening regressed.
|
||||
creds = {
|
||||
"client_id": kc["client_id"],
|
||||
"client_secret": kc["client_secret"],
|
||||
@@ -81,14 +88,19 @@ def test_oidc_login_via_keycloak(live_app, deps):
|
||||
}
|
||||
access_token = sso.oidc_password_grant(creds)
|
||||
assert isinstance(access_token, str) and access_token.count(".") == 2, "expected JWT"
|
||||
|
||||
# Step 3: call the protected API with the Bearer token; assert 200 + user email
|
||||
status, body = harness_http.http_get(
|
||||
f"https://{live_app}/api/v1.0/users/me/",
|
||||
headers={"Authorization": f"Bearer {access_token}"},
|
||||
)
|
||||
assert status == 200, f"GET /api/v1.0/users/me/ with token HTTP {status}: {body!r}"
|
||||
assert isinstance(body, dict), f"unexpected response: {body!r}"
|
||||
assert (
|
||||
body.get("email") == kc["email"]
|
||||
), f"unexpected user email: got {body.get('email')!r}, expected {kc['email']!r}"
|
||||
assert status in (401, 403), (
|
||||
f"GET /api/v1.0/users/me/ with a Bearer JWT returned HTTP {status} — impress >= v5.4.0 "
|
||||
f"must reject raw Bearer tokens (got body {body!r})"
|
||||
)
|
||||
|
||||
# Step 3: the successor auth path — real OIDC authorization-code login (session cookie);
|
||||
# the session-authenticated whoami must return the provisioned user.
|
||||
sess = OidcSession(f"https://{live_app}")
|
||||
me = sess.login(kc["user"], kc["password"])
|
||||
assert me.get("email") == kc["email"], (
|
||||
f"unexpected user email: got {me.get('email')!r}, expected {kc['email']!r}"
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user