Skip to content

Commit

Permalink
Don't change user/password on session when input box is cancelled
Browse files Browse the repository at this point in the history
Signed-off-by: Timothy Johnson <[email protected]>
  • Loading branch information
t1m0thyj committed Jul 23, 2024
1 parent b8c96d0 commit 7b161e4
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -467,10 +467,11 @@ describe("ZoweVsCodeExtension", () => {
});

it("should do nothing if user input is cancelled", async () => {
const fakeProfile = { user: "fakeUser", password: "fakePass" };
const mockUpdateProperty = jest.fn();
jest.spyOn(ZoweVsCodeExtension as any, "profilesCache", "get").mockReturnValue({
getLoadedProfConfig: jest.fn().mockReturnValue({
profile: {},
profile: fakeProfile,
}),
getProfileInfo: jest.fn().mockReturnValue({
isSecured: jest.fn().mockReturnValue(true),
Expand All @@ -479,17 +480,23 @@ describe("ZoweVsCodeExtension", () => {
refresh: jest.fn(),
});
const showInputBoxSpy = jest.spyOn(Gui, "showInputBox").mockResolvedValueOnce(undefined);
const profileLoaded = await ZoweVsCodeExtension.updateCredentials(promptCredsOptions, undefined as unknown as Types.IApiRegisterClient);
const profileLoaded = await ZoweVsCodeExtension.updateCredentials(
{ ...promptCredsOptions, rePrompt: true },
undefined as unknown as Types.IApiRegisterClient
);
expect(profileLoaded).toBeUndefined();
expect(showInputBoxSpy).toHaveBeenCalledTimes(1);
expect(mockUpdateProperty).toHaveBeenCalledTimes(0);
expect(fakeProfile.user).toBeDefined();
expect(fakeProfile.password).toBeDefined();
});

it("should do nothing if password input is cancelled", async () => {
const fakeProfile = { user: "fakeUser", password: "fakePass" };
const mockUpdateProperty = jest.fn();
jest.spyOn(ZoweVsCodeExtension as any, "profilesCache", "get").mockReturnValue({
getLoadedProfConfig: jest.fn().mockReturnValue({
profile: {},
profile: fakeProfile,
}),
getProfileInfo: jest.fn().mockReturnValue({
isSecured: jest.fn().mockReturnValue(true),
Expand All @@ -498,10 +505,15 @@ describe("ZoweVsCodeExtension", () => {
refresh: jest.fn(),
});
const showInputBoxSpy = jest.spyOn(Gui, "showInputBox").mockResolvedValueOnce("fakeUser").mockResolvedValueOnce(undefined);
const profileLoaded = await ZoweVsCodeExtension.updateCredentials(promptCredsOptions, undefined as unknown as Types.IApiRegisterClient);
const profileLoaded = await ZoweVsCodeExtension.updateCredentials(
{ ...promptCredsOptions, rePrompt: true },
undefined as unknown as Types.IApiRegisterClient
);
expect(profileLoaded).toBeUndefined();
expect(showInputBoxSpy).toHaveBeenCalledTimes(2);
expect(mockUpdateProperty).toHaveBeenCalledTimes(0);
expect(fakeProfile.user).toBeDefined();
expect(fakeProfile.password).toBeDefined();
});

it("should do nothing if profile and sessionName args are not provided", async () => {
Expand Down
6 changes: 3 additions & 3 deletions packages/zowe-explorer-api/src/vscode/ZoweVsCodeExtension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,6 @@ export class ZoweVsCodeExtension {
value: newUser,
...(options.userInputBoxOptions ?? {}),
});
options.session.user = newUser;
}
if (!newUser || (options.rePrompt && newUser === "")) {
return undefined;
Expand All @@ -307,13 +306,14 @@ export class ZoweVsCodeExtension {
value: newPass,
...(options.passwordInputBoxOptions ?? {}),
});
options.session.password = newPass;
}
if (!newPass || (options.rePrompt && newPass === "")) {
return undefined;
}

return [newUser.trim(), newPass.trim()];
options.session.user = newUser.trim();
options.session.password = newPass.trim();
return [options.session.user, options.session.password];
}

private static async promptCertificate(options: PromptCredentialsOptions.CertificateOptions): Promise<void> {
Expand Down
2 changes: 1 addition & 1 deletion packages/zowe-explorer/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ All notable changes to the "vscode-extension-for-zowe" extension will be documen
- Fixed issue where saving changes to favorited PDS member fails when custom temp folder is set on Windows. [#2880](https://github.com/zowe/zowe-explorer-vscode/issues/2880)
- Fixed issue where multiple extensions that contribute profiles to a tree view using the Zowe Explorer API may fail to load. [#2888](https://github.com/zowe/zowe-explorer-vscode/issues/2888)
- Fixed regression where `getProviderForNode` returned the wrong tree provider after performing an action on a Zowe tree node, causing some commands to fail silently. [#2967](https://github.com/zowe/zowe-explorer-vscode/issues/2967)
- Fixed issue where creating new team configuration file could cause Zowe Explorer to crash, resulting in all sessions disappearing from trees. [#2906](https://github.com/zowe/zowe-explorer-vscode/issues/2906)
- Fixed issue where creating a new team configuration file could cause Zowe Explorer to crash, resulting in all sessions disappearing from trees. [#2906](https://github.com/zowe/zowe-explorer-vscode/issues/2906)

## `3.0.0-next.202404242037`

Expand Down

0 comments on commit 7b161e4

Please sign in to comment.