Skip to content

Commit

Permalink
Merge branch 'maintenance' into prepare-2.16.2
Browse files Browse the repository at this point in the history
  • Loading branch information
JillieBeanSim authored Jun 13, 2024
2 parents 4046009 + 1300578 commit 6cdb75e
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 4 deletions.
1 change: 1 addition & 0 deletions packages/zowe-explorer-api/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ All notable changes to the "zowe-explorer-api" extension will be documented in t

### Bug fixes

- Fixed an issue where the `onProfilesUpdate` event did not fire after secure credentials were updated. [#2822](https://github.com/zowe/zowe-explorer-vscode/issues/2822)
- Update dependencies for technical currency purposes.

## `2.16.1`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

import * as fs from "fs";
import * as path from "path";
import { Gui, ProfilesCache, ZoweVsCodeExtension } from "@zowe/zowe-explorer-api";
import { EventTypes, Gui, ProfilesCache, ZoweVsCodeExtension } from "@zowe/zowe-explorer-api";
import * as util from "util";
import * as globals from "../../../src/globals";
import * as profUtils from "../../../src/utils/ProfilesUtils";
Expand Down Expand Up @@ -495,6 +495,36 @@ describe("ProfilesUtils unit tests", () => {
expect(mockProfileInstance.getProfileInfo).toHaveBeenCalled();
expect(Gui.showMessage).toHaveBeenCalledWith('"Update Credentials" operation not supported when "autoStore" is false');
});

it("fires onProfilesUpdate event if secure credentials are enabled", async () => {
const mockProfileInstance = new Profiles(zowe.imperative.Logger.getAppLogger());
const prof = {
getAllProfiles: jest.fn().mockReturnValue([]),
isSecured: jest.fn().mockReturnValue(true),
readProfilesFromDisk: jest.fn(),
};
jest.spyOn(ProfilesCache.prototype, "getProfileInfo").mockResolvedValue(prof as unknown as any);
jest.spyOn(ProfilesCache.prototype, "getLoadedProfConfig").mockResolvedValue({
profile: prof,
} as unknown as zowe.imperative.IProfileLoaded);
const getInstanceMock = jest.spyOn(Profiles, "getInstance").mockReturnValueOnce(mockProfileInstance);
Object.defineProperty(vscode.window, "showInputBox", {
value: jest.fn().mockResolvedValue("testConfig"),
configurable: true,
});
Object.defineProperty(Gui, "showMessage", {
value: jest.fn(),
configurable: true,
});
jest.spyOn(Profiles.prototype, "promptCredentials").mockResolvedValue(["some_user", "some_pass", "c29tZV9iYXNlNjRfc3RyaW5n"]);
const eventFireMock = jest.spyOn(vscode.EventEmitter.prototype, "fire");
const secureCredsMock = jest.spyOn(SettingsConfig, "getDirectValue").mockReturnValueOnce(true);
await profUtils.ProfilesUtils.promptCredentials(null as any);
expect(Gui.showMessage).toHaveBeenCalledWith("Credentials for testConfig were successfully updated");
expect(eventFireMock).toHaveBeenCalledWith(EventTypes.UPDATE);
secureCredsMock.mockRestore();
getInstanceMock.mockRestore();
});
});

describe("initializeZoweFolder", () => {
Expand Down
11 changes: 8 additions & 3 deletions packages/zowe-explorer/src/utils/ProfilesUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@ import * as globals from "../globals";
import * as path from "path";
import * as fs from "fs";
import * as util from "util";
import { IZoweTreeNode, ZoweTreeNode, getZoweDir, getFullPath, Gui, ProfilesCache } from "@zowe/zowe-explorer-api";
import { IZoweTreeNode, ZoweTreeNode, getZoweDir, getFullPath, Gui, ProfilesCache, EventTypes } from "@zowe/zowe-explorer-api";
import { Profiles } from "../Profiles";
import * as nls from "vscode-nls";
import { imperative, getImperativeConfig } from "@zowe/cli";
import { ZoweExplorerExtender } from "../ZoweExplorerExtender";
import { ZoweLogger } from "./LoggerUtils";
import { SettingsConfig } from "./SettingsConfig";
import { ZoweExplorerApiRegister } from "../ZoweExplorerApiRegister";

// Set up localization
nls.config({
Expand Down Expand Up @@ -598,8 +599,12 @@ export class ProfilesUtils {
);
ZoweLogger.info(successMsg);
Gui.showMessage(successMsg);
// config file watcher isn't noticing changes for secure fields
await vscode.commands.executeCommand("zowe.extRefresh");

// If secure credentials are enabled, the config file won't change after updating existing credentials
// (as the "secure" fields are already set). Fire the event emitter to notify extenders of the change.
if (SettingsConfig.getDirectValue<boolean>(globals.SETTINGS_SECURE_CREDENTIALS_ENABLED)) {
ZoweExplorerApiRegister.getInstance().onProfilesUpdateEmitter.fire(EventTypes.UPDATE);
}
}
}

Expand Down

0 comments on commit 6cdb75e

Please sign in to comment.