From eb419c16478a7e41f40905827b507a1021096abb Mon Sep 17 00:00:00 2001 From: Jian Shen Date: Wed, 5 Mar 2025 14:42:01 +0000 Subject: [PATCH] Fix --- .../src/app/PublicClientApplication.ts | 4 ++++ .../src/controllers/IController.ts | 2 ++ .../controllers/NestedAppAuthController.ts | 4 ++++ .../src/controllers/StandardController.ts | 4 ++++ .../UnknownOperatingContextController.ts | 4 ++++ lib/msal-browser/src/event/EventHandler.ts | 7 +++++++ .../src/CustomAuthPublicClientApplication.ts | 4 ++++ .../src/ICustomAuthPublicClientApplication.ts | 2 ++ .../CustomAuthPublicClientApplication.spec.ts | 2 ++ .../CustomAuthStandardController.spec.ts | 1 + .../test/integration_tests/GetAccount.spec.ts | 1 + .../integration_tests/ResetPassword.spec.ts | 1 + .../test/integration_tests/SignIn.spec.ts | 1 + .../test/integration_tests/SignUp.spec.ts | 1 + .../test/test_resources/CustomAuthConfig.ts | 21 +------------------ 15 files changed, 39 insertions(+), 20 deletions(-) diff --git a/lib/msal-browser/src/app/PublicClientApplication.ts b/lib/msal-browser/src/app/PublicClientApplication.ts index e9b9e8e36f..226d42ada0 100644 --- a/lib/msal-browser/src/app/PublicClientApplication.ts +++ b/lib/msal-browser/src/app/PublicClientApplication.ts @@ -428,6 +428,10 @@ export class PublicClientApplication implements IPublicClientApplication { clearCache(logoutRequest?: ClearCacheRequest): Promise { return this.controller.clearCache(logoutRequest); } + + closeEventHandlerChannel(): void { + this.controller.closeEventHandlerChannel(); + } } /** diff --git a/lib/msal-browser/src/controllers/IController.ts b/lib/msal-browser/src/controllers/IController.ts index 856f4abc38..23e64d4e85 100644 --- a/lib/msal-browser/src/controllers/IController.ts +++ b/lib/msal-browser/src/controllers/IController.ts @@ -121,4 +121,6 @@ export interface IController { /** @internal */ getPerformanceClient(): IPerformanceClient; + + closeEventHandlerChannel(): void; } diff --git a/lib/msal-browser/src/controllers/NestedAppAuthController.ts b/lib/msal-browser/src/controllers/NestedAppAuthController.ts index 609302c140..f82c7b6a7c 100644 --- a/lib/msal-browser/src/controllers/NestedAppAuthController.ts +++ b/lib/msal-browser/src/controllers/NestedAppAuthController.ts @@ -881,4 +881,8 @@ export class NestedAppAuthController implements IController { ); return this.browserStorage.hydrateCache(result, request); } + + closeEventHandlerChannel(): void { + this.eventHandler.closeBroadcastChannel(); + } } diff --git a/lib/msal-browser/src/controllers/StandardController.ts b/lib/msal-browser/src/controllers/StandardController.ts index 9378993af0..d3bbb519b5 100644 --- a/lib/msal-browser/src/controllers/StandardController.ts +++ b/lib/msal-browser/src/controllers/StandardController.ts @@ -2322,6 +2322,10 @@ export class StandardController implements IController { ); return res; } + + closeEventHandlerChannel(): void { + this.eventHandler.closeBroadcastChannel(); + } } /** diff --git a/lib/msal-browser/src/controllers/UnknownOperatingContextController.ts b/lib/msal-browser/src/controllers/UnknownOperatingContextController.ts index 4ea6330785..f5e6d07ac7 100644 --- a/lib/msal-browser/src/controllers/UnknownOperatingContextController.ts +++ b/lib/msal-browser/src/controllers/UnknownOperatingContextController.ts @@ -380,4 +380,8 @@ export class UnknownOperatingContextController implements IController { blockAPICallsBeforeInitialize(this.initialized); blockNonBrowserEnvironment(); } + + closeEventHandlerChannel(): void { + this.eventHandler.closeBroadcastChannel(); + } } diff --git a/lib/msal-browser/src/event/EventHandler.ts b/lib/msal-browser/src/event/EventHandler.ts index b82921709e..b42ce04d34 100644 --- a/lib/msal-browser/src/event/EventHandler.ts +++ b/lib/msal-browser/src/event/EventHandler.ts @@ -158,4 +158,11 @@ export class EventHandler { this.invokeCrossTabCallbacks ); } + + /** + * Close the broadcast channel + */ + closeBroadcastChannel(): void { + this.broadcastChannel.close(); + } } diff --git a/lib/msal-custom-auth/src/CustomAuthPublicClientApplication.ts b/lib/msal-custom-auth/src/CustomAuthPublicClientApplication.ts index 8c9e222460..b1ecc42aa7 100644 --- a/lib/msal-custom-auth/src/CustomAuthPublicClientApplication.ts +++ b/lib/msal-custom-auth/src/CustomAuthPublicClientApplication.ts @@ -100,6 +100,10 @@ export class CustomAuthPublicClientApplication return this.customAuthController.resetPassword(resetPasswordInputs); } + close(): void { + this.closeEventHandlerChannel(); + } + /** * Validates the configuration to ensure it is a valid CustomAuthConfiguration object. * @param config The configuration object for the PublicClientApplication. diff --git a/lib/msal-custom-auth/src/ICustomAuthPublicClientApplication.ts b/lib/msal-custom-auth/src/ICustomAuthPublicClientApplication.ts index b49bce1416..75089ed2e2 100644 --- a/lib/msal-custom-auth/src/ICustomAuthPublicClientApplication.ts +++ b/lib/msal-custom-auth/src/ICustomAuthPublicClientApplication.ts @@ -37,4 +37,6 @@ export interface ICustomAuthPublicClientApplication { * @returns {Promise} A promise that resolves to ResetPasswordStartResult */ resetPassword(resetPasswordInputs: ResetPasswordInputs): Promise; + + close(): void; } diff --git a/lib/msal-custom-auth/test/CustomAuthPublicClientApplication.spec.ts b/lib/msal-custom-auth/test/CustomAuthPublicClientApplication.spec.ts index 605c22bfe0..a89974a450 100644 --- a/lib/msal-custom-auth/test/CustomAuthPublicClientApplication.spec.ts +++ b/lib/msal-custom-auth/test/CustomAuthPublicClientApplication.spec.ts @@ -65,6 +65,8 @@ describe("CustomAuthPublicClientApplication", () => { const app = await CustomAuthPublicClientApplication.create(customAuthConfig); expect(app).toBeInstanceOf(CustomAuthPublicClientApplication); + + app.close(); }); }); diff --git a/lib/msal-custom-auth/test/controller/CustomAuthStandardController.spec.ts b/lib/msal-custom-auth/test/controller/CustomAuthStandardController.spec.ts index 4601d86167..f15e61b160 100644 --- a/lib/msal-custom-auth/test/controller/CustomAuthStandardController.spec.ts +++ b/lib/msal-custom-auth/test/controller/CustomAuthStandardController.spec.ts @@ -90,6 +90,7 @@ describe("CustomAuthStandardController", () => { }); afterEach(() => { + controller.closeEventHandlerChannel(); jest.clearAllMocks(); // Clear mocks between tests }); diff --git a/lib/msal-custom-auth/test/integration_tests/GetAccount.spec.ts b/lib/msal-custom-auth/test/integration_tests/GetAccount.spec.ts index e36f04cdc6..6c84179aab 100644 --- a/lib/msal-custom-auth/test/integration_tests/GetAccount.spec.ts +++ b/lib/msal-custom-auth/test/integration_tests/GetAccount.spec.ts @@ -20,6 +20,7 @@ describe("GetAccount", () => { }); afterEach(() => { + app.close(); jest.clearAllMocks(); // Clear mocks between tests }); diff --git a/lib/msal-custom-auth/test/integration_tests/ResetPassword.spec.ts b/lib/msal-custom-auth/test/integration_tests/ResetPassword.spec.ts index 63120bdb17..c5d34fc117 100644 --- a/lib/msal-custom-auth/test/integration_tests/ResetPassword.spec.ts +++ b/lib/msal-custom-auth/test/integration_tests/ResetPassword.spec.ts @@ -55,6 +55,7 @@ describe("Reset password", () => { }); afterEach(() => { + app.close(); // Close the app jest.clearAllMocks(); // Clear mocks between tests }); diff --git a/lib/msal-custom-auth/test/integration_tests/SignIn.spec.ts b/lib/msal-custom-auth/test/integration_tests/SignIn.spec.ts index d80a8817b8..4b2e4f95ee 100644 --- a/lib/msal-custom-auth/test/integration_tests/SignIn.spec.ts +++ b/lib/msal-custom-auth/test/integration_tests/SignIn.spec.ts @@ -52,6 +52,7 @@ describe("Sign in", () => { }); afterEach(() => { + app.close(); jest.clearAllMocks(); // Clear mocks between tests }); diff --git a/lib/msal-custom-auth/test/integration_tests/SignUp.spec.ts b/lib/msal-custom-auth/test/integration_tests/SignUp.spec.ts index 30874da78d..46cce2f0b6 100644 --- a/lib/msal-custom-auth/test/integration_tests/SignUp.spec.ts +++ b/lib/msal-custom-auth/test/integration_tests/SignUp.spec.ts @@ -59,6 +59,7 @@ describe("Sign up", () => { }); afterEach(() => { + app.close(); jest.clearAllMocks(); // Clear mocks between tests }); diff --git a/lib/msal-custom-auth/test/test_resources/CustomAuthConfig.ts b/lib/msal-custom-auth/test/test_resources/CustomAuthConfig.ts index 37c8ea427b..92a04c7963 100644 --- a/lib/msal-custom-auth/test/test_resources/CustomAuthConfig.ts +++ b/lib/msal-custom-auth/test/test_resources/CustomAuthConfig.ts @@ -3,7 +3,6 @@ * Licensed under the MIT License. */ -import { LogLevel } from "@azure/msal-browser"; import { CustomAuthConfiguration } from "../../src/configuration/CustomAuthConfiguration.js"; export const customAuthConfig: CustomAuthConfiguration = { @@ -25,25 +24,7 @@ export const customAuthConfig: CustomAuthConfiguration = { system: { loggerOptions: { loggerCallback: (level, message, containsPii) => { - if (containsPii) { - return; - } - switch (level) { - case LogLevel.Error: - console.info(`[Error] ${message}`); - return; - case LogLevel.Info: - console.info(`[Info] ${message}`); - return; - case LogLevel.Verbose: - console.info(`[Verbose] ${message}`); - return; - case LogLevel.Warning: - console.info(`[Warning] ${message}`); - return; - default: - return; - } + return; }, }, },