diff --git a/packages/zowe-explorer-api/CHANGELOG.md b/packages/zowe-explorer-api/CHANGELOG.md index 4157d5312d..41812f88a0 100644 --- a/packages/zowe-explorer-api/CHANGELOG.md +++ b/packages/zowe-explorer-api/CHANGELOG.md @@ -9,7 +9,6 @@ All notable changes to the "zowe-explorer-api" extension will be documented in t ### Bug fixes - Fixed an issue where the `responseTimeout` profile property was ignored for z/OSMF MVS and USS API calls. [#3225](https://github.com/zowe/zowe-explorer-vscode/issues/3225) -- Deprecated the method `ProfilesCache.updateProfilesArrays`. Use `ProfilesCache.updateCachedProfile` instead, which handles updating credentials cached in memory when `autoStore` is false. [#3120](https://github.com/zowe/zowe-explorer-vscode/issues/3120) - Updated the `@zowe/cli` dependency to v7.29.7 for technical currency. [#3342](https://github.com/zowe/zowe-explorer-vscode/pull/3342) ## `2.18.0` diff --git a/packages/zowe-explorer-api/__tests__/__unit__/profiles/ProfilesCache.unit.test.ts b/packages/zowe-explorer-api/__tests__/__unit__/profiles/ProfilesCache.unit.test.ts index b9023dcb17..d1155b58e9 100644 --- a/packages/zowe-explorer-api/__tests__/__unit__/profiles/ProfilesCache.unit.test.ts +++ b/packages/zowe-explorer-api/__tests__/__unit__/profiles/ProfilesCache.unit.test.ts @@ -230,35 +230,6 @@ describe("ProfilesCache", () => { expect((profCache as any).defaultProfileByType.get("zosmf").profile).toMatchObject(lpar2Profile.profile); }); - it("updateCachedProfile should refresh all profiles when autoStore is true", async () => { - const profCache = new ProfilesCache(fakeLogger as unknown as zowe.imperative.Logger); - jest.spyOn(profCache, "getProfileInfo").mockResolvedValueOnce({ - getTeamConfig: jest.fn().mockReturnValue({ properties: { autoStore: true } }), - } as unknown as zowe.imperative.ProfileInfo); - const refreshSpy = jest.spyOn(profCache, "refresh").mockImplementation(); - await profCache.updateCachedProfile({ - ...lpar1Profile, - profile: lpar2Profile.profile, - } as zowe.imperative.IProfileLoaded); - expect(refreshSpy).toHaveBeenCalledTimes(1); - }); - - it("updateCachedProfile should update cached profile when autoStore is false", async () => { - const profCache = new ProfilesCache(fakeLogger as unknown as zowe.imperative.Logger); - profCache.allProfiles = [lpar1Profile as zowe.imperative.IProfileLoaded]; - (profCache as any).defaultProfileByType = new Map([["zosmf", { ...profCache.allProfiles[0] }]]); - expect(profCache.allProfiles[0].profile).toMatchObject(lpar1Profile.profile); - jest.spyOn(profCache, "getProfileInfo").mockResolvedValueOnce({ - getTeamConfig: jest.fn().mockReturnValue({ properties: { autoStore: false } }), - } as unknown as zowe.imperative.ProfileInfo); - await profCache.updateCachedProfile({ - ...lpar1Profile, - profile: lpar2Profile.profile, - } as zowe.imperative.IProfileLoaded); - expect(profCache.allProfiles[0].profile).toMatchObject(lpar2Profile.profile); - expect((profCache as any).defaultProfileByType.get("zosmf").profile).toMatchObject(lpar2Profile.profile); - }); - it("getDefaultProfile should find default profile given type", () => { const profCache = new ProfilesCache(fakeLogger as unknown as zowe.imperative.Logger); (profCache as any).defaultProfileByType = new Map([["zosmf", lpar1Profile]]); diff --git a/packages/zowe-explorer-api/__tests__/__unit__/vscode/ZoweVsCodeExtension.unit.test.ts b/packages/zowe-explorer-api/__tests__/__unit__/vscode/ZoweVsCodeExtension.unit.test.ts index ffc3b79e77..4889a4927f 100644 --- a/packages/zowe-explorer-api/__tests__/__unit__/vscode/ZoweVsCodeExtension.unit.test.ts +++ b/packages/zowe-explorer-api/__tests__/__unit__/vscode/ZoweVsCodeExtension.unit.test.ts @@ -219,7 +219,7 @@ describe("ZoweVsCodeExtension", () => { mergeArgsForProfile: jest.fn().mockReturnValue({ knownArgs: [] }), }), refresh: jest.fn(), - updateCachedProfile: jest.fn(), + updateProfilesArrays: jest.fn(), }; beforeEach(() => { @@ -376,7 +376,7 @@ describe("ZoweVsCodeExtension", () => { expect(loginSpy).not.toHaveBeenCalled(); expect(testSpy).not.toHaveBeenCalled(); expect(testCache.updateBaseProfileFileLogin).toHaveBeenCalledWith(baseProfile, updProfile, false); - expect(testCache.updateCachedProfile).toHaveBeenCalledWith(serviceProfile, testNode, testRegister); + expect(testCache.updateProfilesArrays).toHaveBeenCalledWith(serviceProfile, testNode); quickPickMock.mockRestore(); }); }); @@ -461,7 +461,6 @@ describe("ZoweVsCodeExtension", () => { updateProperty: mockUpdateProperty, }), refresh: jest.fn(), - updateCachedProfile: jest.fn(), }); const showInputBoxSpy = jest.spyOn(Gui, "showInputBox").mockResolvedValueOnce("fakeUser").mockResolvedValueOnce("fakePassword"); const saveCredentialsSpy = jest.spyOn(ZoweVsCodeExtension as any, "saveCredentials"); @@ -487,7 +486,6 @@ describe("ZoweVsCodeExtension", () => { updateProperty: mockUpdateProperty, }), refresh: jest.fn(), - updateCachedProfile: jest.fn(), }); const showInputBoxSpy = jest.spyOn(Gui, "showInputBox").mockResolvedValueOnce("fakeUser").mockResolvedValueOnce("fakePassword"); const saveCredentialsSpy = jest.spyOn(ZoweVsCodeExtension as any, "saveCredentials"); @@ -516,7 +514,6 @@ describe("ZoweVsCodeExtension", () => { updateProperty: mockUpdateProperty, }), refresh: jest.fn(), - updateCachedProfile: jest.fn(), }); const showInputBoxSpy = jest.spyOn(Gui, "showInputBox").mockResolvedValueOnce("fakeUser").mockResolvedValueOnce("fakePassword"); jest.spyOn(Gui, "showMessage").mockResolvedValueOnce("yes"); @@ -543,7 +540,6 @@ describe("ZoweVsCodeExtension", () => { updateProperty: mockUpdateProperty, }), refresh: jest.fn(), - updateCachedProfile: jest.fn(), }); const showInputBoxSpy = jest.spyOn(Gui, "showInputBox").mockResolvedValueOnce("fakeUser").mockResolvedValueOnce("fakePassword"); jest.spyOn(Gui, "showMessage").mockResolvedValueOnce(undefined); diff --git a/packages/zowe-explorer-api/src/profiles/ProfilesCache.ts b/packages/zowe-explorer-api/src/profiles/ProfilesCache.ts index 90ba3c9260..4ea919cc98 100644 --- a/packages/zowe-explorer-api/src/profiles/ProfilesCache.ts +++ b/packages/zowe-explorer-api/src/profiles/ProfilesCache.ts @@ -128,11 +128,11 @@ export class ProfilesCache { /** * Updates profile in allProfiles array and if default updates defaultProfileByType - * @deprecated Use `updateCachedProfile` instead * @param {string} profileLoaded + * @param {IZoweNodeType} profileNode * @returns {void} */ - public updateProfilesArrays(profileLoaded: zowe.imperative.IProfileLoaded): void { + public updateProfilesArrays(profileLoaded: zowe.imperative.IProfileLoaded, profileNode?: IZoweNodeType): void { // update allProfiles array const promptedTypeIndex = this.allProfiles.findIndex( (profile) => profile?.type === profileLoaded?.type && profile?.name === profileLoaded?.name @@ -143,24 +143,6 @@ export class ProfilesCache { if (defaultProf?.name === profileLoaded?.name) { this.defaultProfileByType.set(profileLoaded?.type, profileLoaded); } - } - - public async updateCachedProfile( - profileLoaded: zowe.imperative.IProfileLoaded, - profileNode?: IZoweNodeType, - zeRegister?: ZoweExplorerApi.IApiRegisterClient - ): Promise { - if ((await this.getProfileInfo()).getTeamConfig().properties.autoStore) { - await this.refresh(zeRegister); - } else { - // Note: When autoStore is disabled, nested profiles within this service profile may not have their credentials updated. - const profIndex = this.allProfiles.findIndex((profile) => profile.type === profileLoaded.type && profile.name === profileLoaded.name); - this.allProfiles[profIndex].profile = profileLoaded.profile; - const defaultProf = this.defaultProfileByType.get(profileLoaded.type); - if (defaultProf != null && defaultProf.name === profileLoaded.name) { - this.defaultProfileByType.set(profileLoaded.type, profileLoaded); - } - } profileNode?.setProfileToChoice(profileLoaded); } diff --git a/packages/zowe-explorer-api/src/vscode/ZoweVsCodeExtension.ts b/packages/zowe-explorer-api/src/vscode/ZoweVsCodeExtension.ts index 53397307e9..dc50d282a3 100644 --- a/packages/zowe-explorer-api/src/vscode/ZoweVsCodeExtension.ts +++ b/packages/zowe-explorer-api/src/vscode/ZoweVsCodeExtension.ts @@ -143,7 +143,7 @@ export class ZoweVsCodeExtension { await profInfo.updateProperty({ ...upd, property: "user", value: creds[0], setSecure }); await profInfo.updateProperty({ ...upd, property: "password", value: creds[1], setSecure }); } - await cache.updateCachedProfile(loadProfile, undefined, apiRegister); + await cache.refresh(apiRegister); return loadProfile; } @@ -232,7 +232,7 @@ export class ZoweVsCodeExtension { await cache.updateBaseProfileFileLogin(profileToUpdate, updBaseProfile, !connOk); serviceProfile.profile = { ...serviceProfile.profile, ...updBaseProfile }; - await cache.updateCachedProfile(serviceProfile, node, zeRegister); + cache.updateProfilesArrays(serviceProfile, node); return true; } @@ -273,7 +273,7 @@ export class ZoweVsCodeExtension { const connOk = serviceProfile.profile.host === baseProfile.profile.host && serviceProfile.profile.port === baseProfile.profile.port; await cache.updateBaseProfileFileLogout(connOk ? baseProfile : serviceProfile); serviceProfile.profile = { ...serviceProfile.profile, tokenType: undefined, tokenValue: undefined }; - await cache.updateCachedProfile(serviceProfile, undefined, zeRegister); + cache.updateProfilesArrays(serviceProfile); } } diff --git a/packages/zowe-explorer/src/Profiles.ts b/packages/zowe-explorer/src/Profiles.ts index b1a1307ead..2187ea8d36 100644 --- a/packages/zowe-explorer/src/Profiles.ts +++ b/packages/zowe-explorer/src/Profiles.ts @@ -970,7 +970,8 @@ export class Profiles extends ProfilesCache { return; // See https://github.com/zowe/zowe-explorer-vscode/issues/1827 } - const returnValue: string[] = [promptInfo.profile.user, promptInfo.profile.password]; + const returnValue: string[] = [promptInfo.profile.user, promptInfo.profile.password, promptInfo.profile.base64EncodedAuth]; + this.updateProfilesArrays(promptInfo); return returnValue; } @@ -1503,11 +1504,11 @@ export class Profiles extends ProfilesCache { !serviceProfile.profile.tokenType?.startsWith(zowe.imperative.SessConstants.TOKEN_TYPE_APIML) ) { await ZoweExplorerApiRegister.getInstance().getCommonApi(serviceProfile).logout(node.getSession()); - await Profiles.getInstance().updateCachedProfile(serviceProfile, node); } else { await ZoweVsCodeExtension.logoutWithBaseProfile(serviceProfile, ZoweExplorerApiRegister.getInstance(), this); } Gui.showMessage(localize("ssoLogout.successful", "Logout from authentication service was successful for {0}.", serviceProfile.name)); + await Profiles.getInstance().refresh(ZoweExplorerApiRegister.getInstance()); } catch (error) { const message = localize("ssoLogout.error", "Unable to log out with {0}. {1}", serviceProfile.name, error?.message); ZoweLogger.error(message); @@ -1558,7 +1559,7 @@ export class Profiles extends ProfilesCache { session.ISession.user = creds[0]; session.ISession.password = creds[1]; await ZoweExplorerApiRegister.getInstance().getCommonApi(serviceProfile).login(session); - await Profiles.getInstance().updateCachedProfile(serviceProfile, node); + Profiles.getInstance().updateProfilesArrays(serviceProfile, node); return true; }