From 848beb8b2410fb4ebd5156dffbb715494d2d9b31 Mon Sep 17 00:00:00 2001 From: Timothy Johnson Date: Wed, 6 Nov 2024 14:22:59 -0500 Subject: [PATCH] Fix profileManagerWillLoad depending on config API Signed-off-by: Timothy Johnson --- .../ProfileInfo.TeamConfig.unit.test.ts | 2 +- .../src/config/src/ProfileCredentials.ts | 30 ++++++++++++------- .../imperative/src/config/src/ProfileInfo.ts | 2 +- 3 files changed, 21 insertions(+), 13 deletions(-) diff --git a/packages/imperative/src/config/__tests__/ProfileInfo.TeamConfig.unit.test.ts b/packages/imperative/src/config/__tests__/ProfileInfo.TeamConfig.unit.test.ts index a0095db5f5..31a9e0da34 100644 --- a/packages/imperative/src/config/__tests__/ProfileInfo.TeamConfig.unit.test.ts +++ b/packages/imperative/src/config/__tests__/ProfileInfo.TeamConfig.unit.test.ts @@ -304,7 +304,7 @@ describe("TeamConfig ProfileInfo tests", () => { it("should return false if secure credentials fail to load", async () => { const profInfo = createNewProfInfo(teamProjDir); jest.spyOn((profInfo as any).mCredentials, "isCredentialManagerInAppSettings").mockReturnValueOnce(true); - jest.spyOn((profInfo as any).mCredentials, "loadManager").mockImplementationOnce(async () => { + jest.spyOn((profInfo as any).mCredentials, "activateCredMgrOverride").mockImplementationOnce(async () => { throw new Error("bad credential manager"); }); diff --git a/packages/imperative/src/config/src/ProfileCredentials.ts b/packages/imperative/src/config/src/ProfileCredentials.ts index f67b663cdf..8d433e1262 100644 --- a/packages/imperative/src/config/src/ProfileCredentials.ts +++ b/packages/imperative/src/config/src/ProfileCredentials.ts @@ -74,6 +74,25 @@ export class ProfileCredentials { throw new ImperativeError({ msg: "Secure credential storage is not enabled" }); } + await this.activateCredMgrOverride(); + + if (this.mProfileInfo.usingTeamConfig) { + await this.mProfileInfo.getTeamConfig().api.secure.load({ + load: (key: string): Promise => { + return CredentialManagerFactory.manager.load(key, true); + }, + save: (key: string, value: any): Promise => { + return CredentialManagerFactory.manager.save(key, value); + } + }); + } + } + + /** + * Attempt to initialize `CredentialManagerFactory` with the specified override. + * @internal + */ + public async activateCredMgrOverride(): Promise { if (!CredentialManagerFactory.initialized) { try { // TODO? Make CredentialManagerFactory.initialize params optional @@ -86,17 +105,6 @@ export class ProfileCredentials { }); } } - - if (this.mProfileInfo.usingTeamConfig) { - await this.mProfileInfo.getTeamConfig().api.secure.load({ - load: ((key: string): Promise => { - return CredentialManagerFactory.manager.load(key, true); - }), - save: ((key: string, value: any): Promise => { - return CredentialManagerFactory.manager.save(key, value); - }) - }); - } } /** diff --git a/packages/imperative/src/config/src/ProfileInfo.ts b/packages/imperative/src/config/src/ProfileInfo.ts index ec89094cb6..601ce36bc5 100644 --- a/packages/imperative/src/config/src/ProfileInfo.ts +++ b/packages/imperative/src/config/src/ProfileInfo.ts @@ -1018,7 +1018,7 @@ export class ProfileInfo { public async profileManagerWillLoad(): Promise { if (this.mCredentials.isCredentialManagerInAppSettings()) { try { - await this.mCredentials.loadManager(); + await this.mCredentials.activateCredMgrOverride(); return true; } catch (err) { this.mImpLogger.warn("Failed to initialize secure credential manager: " + err.message);