diff --git a/.gitignore b/.gitignore index b8db61b24..54d944eda 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +.idea # build artifacts *.tsbuildinfo diff --git a/src/UserManager.test.ts b/src/UserManager.test.ts index a079a7c31..8811ea70c 100644 --- a/src/UserManager.test.ts +++ b/src/UserManager.test.ts @@ -2,7 +2,13 @@ // Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information. import { once } from "events"; -import { RedirectNavigator, type PopupWindow, PopupNavigator, IFrameNavigator } from "./navigators"; +import { + RedirectNavigator, + type PopupWindow, + PopupNavigator, + IFrameNavigator, + type NavigateResponse, +} from "./navigators"; import type { SigninResponse } from "./SigninResponse"; import type { SignoutResponse } from "./SignoutResponse"; import { UserManager, type SigninPopupArgs, type SigninRedirectArgs, type SigninSilentArgs, type SignoutSilentArgs } from "./UserManager"; @@ -33,6 +39,7 @@ describe("UserManager", () => { userStore: userStoreMock, metadata: { authorization_endpoint: "http://sts/oidc/authorize", + end_session_endpoint: "http://sts/oidc/logout", token_endpoint: "http://sts/oidc/token", revocation_endpoint: "http://sts/oidc/revoke", }, @@ -838,6 +845,33 @@ describe("UserManager", () => { }); }); + describe("signoutRedirect", () => { + it("must remove the user before requesting the logout", async () => { + // arrange + const navigateMock = jest.fn().mockReturnValue(Promise.resolve({ + url: "http://localhost:8080", + } as NavigateResponse)); + jest.spyOn(subject["_redirectNavigator"], "prepare").mockReturnValue(Promise.resolve({ + navigate: navigateMock, + close: () => {}, + })); + const user = new User({ + access_token: "access_token", + token_type: "token_type", + profile: {} as UserProfile, + }); + await subject.storeUser(user); + + // act + await subject.signoutRedirect(); + + // assert + expect(navigateMock).toHaveBeenCalledTimes(1); + const storageString = await subject.settings.userStore.get(subject["_userStoreKey"]); + expect(storageString).toBeNull(); + }); + }); + describe("storeUser", () => { it("should add user to store", async () => { // arrange