diff --git a/packages/imperative/CHANGELOG.md b/packages/imperative/CHANGELOG.md index aac3c4283..c48e87903 100644 --- a/packages/imperative/CHANGELOG.md +++ b/packages/imperative/CHANGELOG.md @@ -9,6 +9,7 @@ All notable changes to the Imperative package will be documented in this file. - Deprecated the static method `ProfileInfo.onlyV1ProfilesExist` and replaced it with an `onlyV1ProfilesExist` instance method on the `ProfileInfo` class. - BugFix: Fixed an issue where the `ConvertV1Profiles.convert` method may create team configuration files in the wrong directory if the environment variable `ZOWE_CLI_HOME` is set. [#2312](https://github.com/zowe/zowe-cli/issues/2312) - BugFix: Fixed an issue where the Imperative Event Emitter would fire event callbacks for the same app that triggered the event. [#2279](https://github.com/zowe/zowe-cli/issues/2279) +- BugFix: Fixed an issue where the `ProfileInfo.updateKnownProperty` method could rewrite team config file to disk without any changes when storing secure value. [#2324](https://github.com/zowe/zowe-cli/issues/2324) ## `8.2.0` 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 0c2302211..8b62c37b8 100644 --- a/packages/imperative/src/config/__tests__/ProfileInfo.TeamConfig.unit.test.ts +++ b/packages/imperative/src/config/__tests__/ProfileInfo.TeamConfig.unit.test.ts @@ -1306,7 +1306,7 @@ describe("TeamConfig ProfileInfo tests", () => { }); describe("updateKnownProperty", () => { - it("should throw and error if the property location type is invalid", async () => { + it("should throw an error if the property location type is invalid", async () => { const profInfo = createNewProfInfo(teamProjDir); await profInfo.readProfilesFromDisk(); let caughtError; @@ -1345,6 +1345,7 @@ describe("TeamConfig ProfileInfo tests", () => { const profInfo = createNewProfInfo(teamProjDir); await profInfo.readProfilesFromDisk(); const jsonPathMatchesSpy = jest.spyOn(ConfigUtils, "jsonPathMatches"); + const configSaveSpy = jest.spyOn(profInfo.getTeamConfig(), "save"); const prof = profInfo.mergeArgsForProfile(profInfo.getAllProfiles("dummy")[0]); const ret = await profInfo.updateKnownProperty({ mergedArgs: prof, property: "host", value: "example.com" }); @@ -1353,6 +1354,26 @@ describe("TeamConfig ProfileInfo tests", () => { expect(newHost).toEqual("example.com"); expect(ret).toBe(true); expect(jsonPathMatchesSpy).toHaveBeenCalled(); // Verify that profile names are matched correctly + expect(configSaveSpy).toHaveBeenCalled(); + }); + + it("should update the given property in the vault and return true", async () => { + const profInfo = createNewProfInfo(teamProjDir); + await profInfo.readProfilesFromDisk(); + const jsonPathMatchesSpy = jest.spyOn(ConfigUtils, "jsonPathMatches"); + jest.spyOn(profInfo.getTeamConfig().api.secure, "secureFields").mockReturnValue(["profiles.LPAR4.properties.host"]); + const configSaveSpy = jest.spyOn(profInfo.getTeamConfig(), "save"); + const configSecureSaveSpy = jest.spyOn(profInfo.getTeamConfig().api.secure, "save"); + + const prof = profInfo.mergeArgsForProfile(profInfo.getAllProfiles("dummy")[0]); + const ret = await profInfo.updateKnownProperty({ mergedArgs: prof, property: "host", value: "example.com", setSecure: true }); + const newHost = profInfo.getTeamConfig().api.layers.get().properties.profiles.LPAR4.properties.host; + + expect(newHost).toEqual("example.com"); + expect(ret).toBe(true); + expect(jsonPathMatchesSpy).toHaveBeenCalled(); // Verify that profile names are matched correctly + expect(configSaveSpy).not.toHaveBeenCalled(); + expect(configSecureSaveSpy).toHaveBeenCalled(); }); it("should remove the given property if the value specified if undefined", async () => { diff --git a/packages/imperative/src/config/src/ProfileInfo.ts b/packages/imperative/src/config/src/ProfileInfo.ts index 61a95dcec..8c849d4d6 100644 --- a/packages/imperative/src/config/src/ProfileInfo.ts +++ b/packages/imperative/src/config/src/ProfileInfo.ts @@ -298,8 +298,13 @@ export class ProfileInfo { this.getTeamConfig().api.layers.activate(osLoc.user, osLoc.global); } + const updateVaultOnly = options.setSecure && this.getTeamConfig().api.secure.secureFields().includes(toUpdate.argLoc.jsonLoc); this.getTeamConfig().set(toUpdate.argLoc.jsonLoc, options.value, { secure: options.setSecure }); - await this.getTeamConfig().save(false); + if (!updateVaultOnly) { + await this.getTeamConfig().save(false); + } else { + await this.getTeamConfig().api.secure.save(false); + } if (oldLayer) { this.getTeamConfig().api.layers.activate(oldLayer.user, oldLayer.global);