Skip to content

Commit

Permalink
Merge branch 'next' into dep/next-ssh2-vulnerability
Browse files Browse the repository at this point in the history
  • Loading branch information
JillieBeanSim authored Jan 3, 2024
2 parents ba9c220 + 81aed7c commit 4ca6909
Show file tree
Hide file tree
Showing 5 changed files with 218 additions and 36 deletions.
5 changes: 5 additions & 0 deletions docs/early-access/v3/Extenders.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,8 @@
- `ZoweVsCodeExtension.showVsCodeMessage` removed in favor of `Gui.showMessage`.
- `ZoweVsCodeExtension.inputBox` removed in favor of `Gui.showInputBox`.
- `ZoweVsCodeExtension.promptCredentials` removed in favor of `ZoweVsCodeExtension.updateCredentials`.

## New APIs Added

- `ICommand.issueUnixCommand` added for issuing Unix Commands
- Optional `ICommand.sshProfileRequired` API returning a boolean value for extenders that would like to use the ssh profile for issuing UNIX commands via Zowe Explorer.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import { ZoweLogger } from "../../../src/utils/LoggerUtils";
import { SshSession } from "@zowe/zos-uss-for-zowe-sdk";
import { ZoweLocalStorage } from "../../../src/utils/ZoweLocalStorage";
import { ProfileManagement } from "../../../src/utils/ProfileManagement";
import { profile } from "console";

describe("UnixCommand Actions Unit Testing", () => {
const showQuickPick = jest.fn();
Expand All @@ -37,6 +36,7 @@ describe("UnixCommand Actions Unit Testing", () => {
const mockLoadNamedProfile = jest.fn();
const mockdefaultProfile = jest.fn();
const getConfiguration = jest.fn();
const getProfileInfomock = jest.fn();

const session = new imperative.Session({
user: "fake",
Expand Down Expand Up @@ -128,6 +128,7 @@ describe("UnixCommand Actions Unit Testing", () => {
Object.defineProperty(vscode.window, "createQuickPick", { value: createQuickPick });
Object.defineProperty(vscode.window, "createOutputChannel", { value: createOutputChannel });
Object.defineProperty(vscode.workspace, "getConfiguration", { value: getConfiguration });
Object.defineProperty(imperative.ProfileInfo, "profAttrsToProfLoaded", { value: () => ({ profile: {} }) });
Object.defineProperty(imperative.ConnectionPropsForSessCfg, "addPropsOrPrompt", {
value: jest.fn(() => {
return { privateKey: undefined, keyPassphrase: undefined, handshakeTimeout: undefined, type: "basic", port: 22 };
Expand Down Expand Up @@ -165,6 +166,20 @@ describe("UnixCommand Actions Unit Testing", () => {
return { privateKey: undefined, keyPassphrase: undefined, handshakeTimeout: undefined };
});

getProfileInfomock.mockReturnValue({
usingTeamConfig: true,
getAllProfiles: jest.fn().mockReturnValue(["dummy"]),
mergeArgsForProfile: jest.fn().mockReturnValue({
knownArgs: [
{ argName: "port", argValue: "TEST", secure: false },
{ argName: "host", argValue: "TEST", secure: false },
{ argName: "user", secure: true },
{ argName: "password", secure: true },
],
}),
loadSecureArg: jest.fn().mockReturnValue("fake"),
} as any);

it("test the issueUnixCommand function", async () => {
Object.defineProperty(profileLoader.Profiles, "getInstance", {
value: jest.fn(() => {
Expand All @@ -179,6 +194,7 @@ describe("UnixCommand Actions Unit Testing", () => {
getBaseProfile: jest.fn(),
getDefaultProfile: mockdefaultProfile,
validProfile: ValidProfileEnum.VALID,
getProfileInfo: getProfileInfomock,
};
}),
});
Expand Down Expand Up @@ -232,6 +248,7 @@ describe("UnixCommand Actions Unit Testing", () => {
getBaseProfile: jest.fn(),
getDefaultProfile: mockdefaultProfile,
validProfile: ValidProfileEnum.VALID,
getProfileInfo: getProfileInfomock,
};
}),
});
Expand Down Expand Up @@ -284,6 +301,7 @@ describe("UnixCommand Actions Unit Testing", () => {
getBaseProfile: jest.fn(),
getDefaultProfile: mockdefaultProfile,
validProfile: ValidProfileEnum.VALID,
getProfileInfo: getProfileInfomock,
};
}),
});
Expand Down Expand Up @@ -329,6 +347,7 @@ describe("UnixCommand Actions Unit Testing", () => {
getBaseProfile: jest.fn(),
getDefaultProfile: mockdefaultProfile,
validProfile: ValidProfileEnum.VALID,
getProfileInfo: getProfileInfomock,
};
}),
});
Expand Down Expand Up @@ -371,6 +390,7 @@ describe("UnixCommand Actions Unit Testing", () => {
getBaseProfile: jest.fn(),
getDefaultProfile: mockdefaultProfile,
validProfile: ValidProfileEnum.VALID,
getProfileInfo: getProfileInfomock,
};
}),
});
Expand All @@ -397,6 +417,7 @@ describe("UnixCommand Actions Unit Testing", () => {
getBaseProfile: jest.fn(),
getDefaultProfile: mockdefaultProfile,
validProfile: ValidProfileEnum.VALID,
getProfileInfo: getProfileInfomock,
};
}),
});
Expand All @@ -422,6 +443,7 @@ describe("UnixCommand Actions Unit Testing", () => {
getBaseProfile: jest.fn(),
getDefaultProfile: mockdefaultProfile,
validProfile: ValidProfileEnum.VALID,
getProfileInfo: getProfileInfomock,
};
}),
});
Expand Down Expand Up @@ -465,6 +487,7 @@ describe("UnixCommand Actions Unit Testing", () => {
getBaseProfile: jest.fn(),
validProfile: ValidProfileEnum.VALID,
getDefaultProfile: mockdefaultProfile,
getProfileInfo: getProfileInfomock,
};
}),
});
Expand Down Expand Up @@ -521,6 +544,7 @@ describe("UnixCommand Actions Unit Testing", () => {
}),
validProfile: ValidProfileEnum.INVALID,
getDefaultProfile: mockdefaultProfile,
getProfileInfo: getProfileInfomock,
};
}),
});
Expand Down Expand Up @@ -589,6 +613,7 @@ describe("UnixCommand Actions Unit Testing", () => {
checkCurrentProfile: jest.fn(),
zosmfProfile: mockLoadNamedProfile,
getDefaultProfile: mockdefaultProfile,
getProfileInfo: getProfileInfomock,
};
}),
});
Expand All @@ -609,17 +634,72 @@ describe("UnixCommand Actions Unit Testing", () => {
});

it("ssh profile not found", async () => {
mockdefaultProfile.mockReset();
mockdefaultProfile.mockReturnValueOnce(undefined);
Object.defineProperty(profileLoader.Profiles, "getInstance", {
value: jest.fn(() => {
return {
getDefaultProfile: mockdefaultProfile,
getProfileInfo: jest.fn().mockReturnValue({
usingTeamConfig: true,
getAllProfiles: jest.fn().mockReturnValue(undefined),
} as any),
};
}),
});
await unixActions.setsshSession();
expect(showErrorMessage.mock.calls.length).toBe(1);
expect(showErrorMessage.mock.calls[0][0]).toEqual("No SSH profile found. Please create an SSH profile before issuing Unix commands.");
});

it("tests the selectSshProfile function", async () => {
showQuickPick.mockReturnValueOnce("test1" as any);
await expect(
(unixActions as any).selectSshProfile([
{
name: "test1",
},
{
name: "test2",
},
])
).resolves.toEqual({
name: "test1",
});
});

it("tests the selectSshProfile function when user escapes", async () => {
showQuickPick.mockReturnValueOnce(undefined);
await expect(
(unixActions as any).selectSshProfile([
{
name: "test1",
},
{
name: "test2",
},
])
).resolves.toBe(undefined);
expect(showInformationMessage.mock.calls[0][0]).toEqual("Operation Cancelled");
});
it("ssh profile doesn't contain credentials", async () => {
Object.defineProperty(profileLoader.Profiles, "getInstance", {
value: jest.fn(() => {
return {
getProfileInfo: getProfileInfomock.mockReturnValue({
usingTeamConfig: true,
getAllProfiles: jest.fn().mockReturnValue(["dummy"]),
mergeArgsForProfile: jest.fn().mockReturnValue({
knownArgs: [
{ argName: "port", argValue: "TEST", secure: false },
{ argName: "host", argValue: "TEST", secure: false },
{ argName: "user", secure: true },
{ argName: "password", secure: true },
],
}),
loadSecureArg: jest.fn().mockReturnValue(undefined),
} as any)
}
})
});
await (unixActions as any).getSshProfile();
expect(showErrorMessage.mock.calls[0][0]).toEqual("Credentials are missing for SSH profile");
})
});
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ describe("unixCommandActions unit testing", () => {
return { privateKey: undefined, keyPassphrase: undefined, handshakeTimeout: undefined, type: "basic", port: 22 };
}),
});
Object.defineProperty(imperative.ProfileInfo, "profAttrsToProfLoaded", { value: () => ({ profile: {} }) });
Object.defineProperty(ProfileManagement, "getRegisteredProfileNameList", {
value: jest.fn().mockReturnValue(["firstName", "secondName"]),
configurable: true,
Expand Down Expand Up @@ -147,6 +148,19 @@ describe("unixCommandActions unit testing", () => {
getBaseProfile: jest.fn(),
getDefaultProfile: mockdefaultProfile,
validProfile: ValidProfileEnum.VALID,
getProfileInfo: jest.fn().mockReturnValue({
usingTeamConfig: true,
getAllProfiles: jest.fn().mockReturnValue(["dummy"]),
mergeArgsForProfile: jest.fn().mockReturnValue({
knownArgs: [
{ argName: "port", argValue: "TEST", secure: false },
{ argName: "host", argValue: "TEST", secure: false },
{ argName: "user", argValue: "TEST", secure: true },
{ argName: "password", argValue: "TEST", secure: true },
],
}),
loadSecureArg: jest.fn().mockReturnValue("user"),
} as any),
};
}),
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@
"issueUnixCommand.outputchannel.title": "Zowe Unix Command",
"issueUnixCommand.quickPickOption": "Select the Profile to use to submit the Unix command",
"issueUnixCommand.cancelled": "Operation Cancelled",
"issueUnixCommand.apiNonExisting": "Not implemented yet for profile of type: ",
"unixCommand.HomeDirectory": "Redirecting to Home Directory",
"issueUnixCommand.checkProfile": "Profile is invalid",
"issueUnixCommand.noProfilesLoaded": "No profiles available",
"path.notselected": "Enter a UNIX file filter search to enable Issue Unix Command from the tree view.",
"issueUnixCommand.options.nopathentered": "Operation cancelled.",
"issueUnixCommand.apiNonExisting": "Not implemented yet for profile of type: ",
"issueUnixCommand.sshProfile.quickPickOption": "Select the ssh Profile.",
"setsshProfile.couldnotfindprofile": "No SSH profile found. Please create an SSH profile before issuing Unix commands.",
"sshcredentialsMissing": "Credentials are missing for SSH profile",
"issueUnixCommand.command.hostname": "Select a Unix command to run against ",
"issueUnixCommand.command.edit": " (An option to edit will follow)",
"issueUnixCommand.options.noselection": "No selection made. Operation cancelled.",
Expand Down
Loading

0 comments on commit 4ca6909

Please sign in to comment.