fix(auth): ensure Keycloak logout clears secure session
This commit is contained in:
@@ -48,7 +48,7 @@ describe("GET /api/auth/keycloak-logout", () => {
|
||||
{
|
||||
headers: {
|
||||
cookie:
|
||||
"__Secure-next-auth.session-token.0=first; __Secure-next-auth.session-token.1=second",
|
||||
"__Secure-next-auth.session-token.0=first; __Secure-next-auth.session-token.1=second; next-auth.session-token=local",
|
||||
},
|
||||
},
|
||||
);
|
||||
@@ -65,11 +65,22 @@ describe("GET /api/auth/keycloak-logout", () => {
|
||||
);
|
||||
expect(logoutUrl.searchParams.get("client_id")).toBe("tjwater");
|
||||
expect(logoutUrl.searchParams.get("post_logout_redirect_uri")).toBeNull();
|
||||
expect(response.cookies.get("__Secure-next-auth.session-token.0")?.value).toBe("");
|
||||
expect(response.cookies.get("__Secure-next-auth.session-token.1")?.value).toBe("");
|
||||
expect(
|
||||
response.cookies.get("__Secure-next-auth.session-token.0"),
|
||||
).toMatchObject({ value: "", path: "/", secure: true });
|
||||
expect(
|
||||
response.cookies.get("__Secure-next-auth.session-token.1"),
|
||||
).toMatchObject({ value: "", path: "/", secure: true });
|
||||
expect(response.cookies.get("next-auth.session-token")).toMatchObject({
|
||||
value: "",
|
||||
path: "/",
|
||||
});
|
||||
expect(
|
||||
response.cookies.get("next-auth.session-token")?.secure,
|
||||
).toBeFalsy();
|
||||
});
|
||||
|
||||
it("uses an explicitly configured post-logout redirect URI", async () => {
|
||||
it("ignores a legacy automatic post-logout redirect setting", async () => {
|
||||
process.env.KEYCLOAK_POST_LOGOUT_REDIRECT_URI =
|
||||
"https://frontend.example.com/login";
|
||||
getTokenMock.mockResolvedValue({ idToken: "header.payload.signature" });
|
||||
@@ -81,8 +92,6 @@ describe("GET /api/auth/keycloak-logout", () => {
|
||||
);
|
||||
const logoutUrl = new URL(response.headers.get("location") ?? "");
|
||||
|
||||
expect(logoutUrl.searchParams.get("post_logout_redirect_uri")).toBe(
|
||||
"https://frontend.example.com/login",
|
||||
);
|
||||
expect(logoutUrl.searchParams.get("post_logout_redirect_uri")).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user