Skip to content

Commit

Permalink
Merge pull request #1282 from zowe/next-staging
Browse files Browse the repository at this point in the history
Update next with changes from next-staging
  • Loading branch information
zFernand0 authored Jan 25, 2022
2 parents 8f19e12 + dbd3370 commit dd0fd6a
Show file tree
Hide file tree
Showing 20 changed files with 625 additions and 274 deletions.
5 changes: 3 additions & 2 deletions __tests__/__integration__/imperative.integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,9 @@ describe("imperative create profile", () => {
expect(response.stdout.toString()).toContain("Profile created successfully!");
expect(response.stdout.toString()).toContain("FAKEHOST");
expect(response.stdout.toString()).toContain("22");
expect(response.stdout.toString()).toContain("FAKEUSER");
expect(response.stdout.toString()).toContain("managed by Zowe CLI");
expect(response.stdout.toString()).not.toContain("FAKEUSER");
expect(response.stdout.toString()).toContain("user: managed by Zowe CLI");
expect(response.stdout.toString()).toContain("password: managed by Zowe CLI");
});

it("should successfully create a profile without username, password, or host", async () => {
Expand Down
156 changes: 78 additions & 78 deletions package-lock.json

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
],
"scripts": {
"build": "gulp updateLicense && lerna run build && npm run lint && npm run checkTestsCompile && npm run circularDependencyCheck",
"build:exe": "cd zowex && cargo build && cargo test",
"build:exe": "cd zowex && cargo build && cargo clippy && cargo test",
"clean": "lerna run --parallel clean",
"clean:exe": "cd zowex && cargo clean",
"installWithBuild": "npm install && npm run build",
Expand All @@ -28,6 +28,7 @@
"test:system": "cross-env FORCE_COLOR=1 jest \".*__tests__.*\\**\\.system\\.(spec|test)\\.ts\\$\" --coverage false",
"test:unit": "cross-env FORCE_COLOR=1 jest \".*__tests__.*\\**\\.unit\\.(spec|test)\\.ts\\$\" --coverage",
"watch": "lerna run --parallel watch",
"watch:exe": "cd zowex && cargo install cargo-watch && cargo watch -x build -x clippy -x test",
"watch:test": "jest --watch",
"doc:clean": "rimraf docs/CLIReadme.md",
"doc:generate": "npm run doc:clean && gulp doc",
Expand Down
7 changes: 7 additions & 0 deletions packages/cli/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

All notable changes to the Zowe CLI package will be documented in this file.

## Recent Changes

- BugFix: Fixed 'daemon disable' command to kill any running zowe daemon on Linux and Mac. [#1270](https://github.com/zowe/zowe-cli/issues/1270)
- BugFix: Fixed stdin data being corrupted when daemon server processes CLI command containing double-byte characters.
- Enhancement: Added a user message within 'daemon enable' and disable to open a new terminal when needed.
- **BREAKING** Enhancement: Make the `user` field on SSH profiles secure. [#682](https://github.com/zowe/zowe-cli/issues/682)

## `7.0.0-next.202201121428`

- BugFix: Set executable attribute on zowe executable file on Linux and Mac.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ let testEnvironment: ITestEnvironment<ITestPropertiesSchema>;
describe("daemon disable", () => {
const rimrafSync = require("rimraf").sync;
const fakeExeContent = "This is not a real executable";
const zoweCmdRegEx = "zowe.*[/|\\\\]cli[/|\\\\]lib[/|\\\\]main.js.* --daemon" + "|" +
"[/|\\\\]bin[/|\\\\]zowe.* --daemon";

let exePath: string;
let pathToBin: string;
Expand Down Expand Up @@ -116,6 +118,11 @@ describe("daemon disable", () => {
const response = runCliScript(__dirname + "/__scripts__/daemon_disable.sh", testEnvironment);
const stdoutStr = response.stdout.toString();
expect(stdoutStr).toContain("Zowe CLI daemon mode is disabled.");
if (ProcessUtils.getBasicSystemInfo().platform === "win32") {
expect(stdoutStr).not.toContain("close this terminal and open a new terminal");
} else {
expect(stdoutStr).toContain("close this terminal and open a new terminal");
}
expect(response.status).toBe(0);
}
});
Expand Down Expand Up @@ -143,9 +150,8 @@ describe("daemon disable", () => {
const procArray = await findProc('name', 'node', true);

// match and kill any running Zowe daemon
const zoweCmdRegEx = "@zowe[/|\\\\]cli[/|\\\\]lib[/|\\\\]main.js";
for (const nextProc of procArray) {
if (nextProc.cmd.match(zoweCmdRegEx) && nextProc.cmd.includes("--daemon")) {
if (nextProc.cmd.match(zoweCmdRegEx)) {
process.kill(nextProc.pid, "SIGINT");
}
}
Expand Down Expand Up @@ -173,12 +179,14 @@ describe("daemon disable", () => {
// match any running Zowe daemon
const findProc = require('find-process');
const procArray = await findProc('name', 'node', true);
const zoweCmdRegEx = "@zowe[/|\\\\]cli[/|\\\\]lib[/|\\\\]main.js";
let weFoundDaemon = false;
for (const nextProc of procArray) {
if (nextProc.cmd.match(zoweCmdRegEx) && nextProc.cmd.includes("--daemon")) {
expect("we should not find a daemon").toContain("so the disable command failed.");
if (nextProc.cmd.match(zoweCmdRegEx)) {
weFoundDaemon = true;
break;
}
}
expect(weFoundDaemon).toBe(false);
}
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ describe("daemon enable", () => {
if (willRunNodeJsZowe()) {
const response = runCliScript(__dirname + "/__scripts__/daemon_enable.sh", testEnvironment);
const stdoutStr = response.stdout.toString();
expect(stdoutStr).toContain("Zowe CLI daemon mode enabled");
expect(stdoutStr).toContain("Zowe CLI daemon mode is enabled");
expect(stdoutStr).toContain("Zowe CLI native executable version =");
expect(IO.existsSync(exePath)).toBe(true);
expect(response.status).toBe(0);
Expand All @@ -176,7 +176,7 @@ describe("daemon enable", () => {
fs.mkdirSync(pathToBin, 0o755);
const response = runCliScript(__dirname + "/__scripts__/daemon_enable.sh", testEnvironment);
const stdoutStr = response.stdout.toString();
expect(stdoutStr).toContain("Zowe CLI daemon mode enabled");
expect(stdoutStr).toContain("Zowe CLI daemon mode is enabled");
expect(stdoutStr).toContain("Zowe CLI native executable version =");
expect(IO.existsSync(exePath)).toBe(true);
expect(response.status).toBe(0);
Expand All @@ -191,7 +191,7 @@ describe("daemon enable", () => {
const response = runCliScript(__dirname + "/__scripts__/daemon_enable.sh", testEnvironment);

const stdoutStr = response.stdout.toString();
expect(stdoutStr).toContain("Zowe CLI daemon mode enabled");
expect(stdoutStr).toContain("Zowe CLI daemon mode is enabled");
expect(IO.existsSync(exePath)).toBe(true);

// our test tgz file is more than 10 bytes larger than this fake tgz
Expand All @@ -205,10 +205,11 @@ describe("daemon enable", () => {
if (willRunNodeJsZowe()) {
const response = runCliScript(__dirname + "/__scripts__/daemon_enable.sh", testEnvironment);
const stdoutStr = response.stdout.toString();
expect(stdoutStr).toContain("Zowe CLI daemon mode enabled");
expect(stdoutStr).toContain("Zowe CLI daemon mode is enabled");
expect(stdoutStr).toContain("Zowe CLI native executable version =");
expect(stdoutStr).toContain(`Add '${pathToBin}' to your PATH`);
expect(stdoutStr).toContain(`Manually add '${pathToBin}' to your PATH`);
expect(stdoutStr).toContain("Otherwise, you will continue to run the classic Zowe CLI interpreter");
expect(stdoutStr).toContain("close this terminal and open a new terminal");
expect(IO.existsSync(exePath)).toBe(true);
expect(response.status).toBe(0);
}
Expand All @@ -222,9 +223,14 @@ describe("daemon enable", () => {
testEnvironment.env["PATH"] = pathOrig;

const stdoutStr = response.stdout.toString();
expect(stdoutStr).toContain("Zowe CLI daemon mode enabled");
expect(stdoutStr).toContain("Zowe CLI daemon mode is enabled");
expect(stdoutStr).toContain("Zowe CLI native executable version =");
expect(stdoutStr).not.toContain(`Add '${pathToBin}' to your PATH`);
if (ProcessUtils.getBasicSystemInfo().platform === "win32") {
expect(stdoutStr).not.toContain("close this terminal and open a new terminal");
} else {
expect(stdoutStr).toContain("close this terminal and open a new terminal");
}
expect(IO.existsSync(exePath)).toBe(true);
expect(response.status).toBe(0);
}
Expand All @@ -237,7 +243,7 @@ describe("daemon enable", () => {
delete testEnvironment.env.ZOWE_USE_DAEMON;

const stdoutStr = response.stdout.toString();
expect(stdoutStr).toContain("Zowe CLI daemon mode enabled");
expect(stdoutStr).toContain("Zowe CLI daemon mode is enabled");
expect(stdoutStr).toContain("Zowe CLI native executable version =");
expect(stdoutStr).toContain("Your ZOWE_USE_DAEMON environment variable is set to 'no'");
expect(stdoutStr).toContain("You must remove it, or set it to 'yes' to use daemon mode");
Expand All @@ -251,7 +257,7 @@ describe("daemon enable", () => {
delete testEnvironment.env.ZOWE_USE_DAEMON;
const response = runCliScript(__dirname + "/__scripts__/daemon_enable.sh", testEnvironment);
const stdoutStr = response.stdout.toString();
expect(stdoutStr).toContain("Zowe CLI daemon mode enabled");
expect(stdoutStr).toContain("Zowe CLI daemon mode is enabled");
expect(testEnvironment.env["ZOWE_USE_DAEMON"]).toBeFalsy();
expect(stdoutStr).not.toContain("Your ZOWE_USE_DAEMON environment variable is set to");
expect(IO.existsSync(exePath)).toBe(true);
Expand All @@ -266,7 +272,7 @@ describe("daemon enable", () => {
delete testEnvironment.env.ZOWE_USE_DAEMON;

const stdoutStr = response.stdout.toString();
expect(stdoutStr).toContain("Zowe CLI daemon mode enabled");
expect(stdoutStr).toContain("Zowe CLI daemon mode is enabled");
expect(stdoutStr).not.toContain("Your ZOWE_USE_DAEMON environment variable is set to");
expect(IO.existsSync(exePath)).toBe(true);
expect(response.status).toBe(0);
Expand Down
42 changes: 24 additions & 18 deletions packages/cli/__tests__/daemon/__unit__/DaemonClient.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ describe("DaemonClient tests", () => {

const daemonClient = new DaemonClient(client as any, server, "fake");
const daemonResponse: IDaemonResponse = {
argv: ["feed", "dog"],
argv: ["feed", "🐶"],
cwd: "fake",
env: {},
env: { FORCE_COLOR: "0" },
stdinLength: 0,
stdin: null,
user: Buffer.from("fake").toString('base64')
Expand All @@ -61,9 +61,10 @@ describe("DaemonClient tests", () => {
daemonClient.run();
// force `data` call and verify input is from instantiation of DaemonClient
// and is what is passed to mocked Imperative.parse via snapshot
(daemonClient as any).data(JSON.stringify(daemonResponse));
const stringData = JSON.stringify(daemonResponse);
(daemonClient as any).data(Buffer.from(stringData));

expect(log).toHaveBeenLastCalledWith('daemon input command: feed dog');
expect(log).toHaveBeenLastCalledWith('daemon input command: feed 🐶');
expect(log).toHaveBeenCalledTimes(2);
expect(parse).toHaveBeenCalled();
});
Expand Down Expand Up @@ -99,9 +100,9 @@ describe("DaemonClient tests", () => {
};

const daemonClient = new DaemonClient(client as any, server, "fake");
const stdinData = String.fromCharCode(...Array(256).keys());
const stdinData = String.fromCharCode(...Array(1024).keys());
const daemonResponse: IDaemonResponse = {
argv: ["feed", "cat"],
argv: ["feed", "🐱"],
cwd: "fake",
env: {},
stdinLength: stdinData.length,
Expand All @@ -114,11 +115,11 @@ describe("DaemonClient tests", () => {
// force `data` call and verify input is from instantiation of DaemonClient
// and is what is passed to mocked Imperative.parse via snapshot
const stringData = JSON.stringify(daemonResponse) + "\f" + stdinData;
await (daemonClient as any).data(stringData);
await (daemonClient as any).data(Buffer.from(stringData));

expect(log).toHaveBeenLastCalledWith('daemon input command: feed cat');
expect(log).toHaveBeenLastCalledWith('daemon input command: feed 🐱');
expect(log).toHaveBeenCalledTimes(2);
expect(writeToStdinSpy).toHaveBeenCalledWith(stdinData, stdinData.length);
expect(writeToStdinSpy).toHaveBeenCalledWith(Buffer.from(stdinData), stdinData.length);
expect(parse).toHaveBeenCalled();
});

Expand Down Expand Up @@ -157,7 +158,7 @@ describe("DaemonClient tests", () => {
daemonClient.run();
// force `data` call and verify input is from instantiation of DaemonClient
// and is what is passed to mocked Imperative.parse via snapshot
(daemonClient as any).data("not json");
(daemonClient as any).data(Buffer.from("not json"));

expect(log).toHaveBeenCalledTimes(3);
expect(log).toHaveBeenLastCalledWith("First 1024 bytes of daemon request:\n", "not json");
Expand Down Expand Up @@ -200,7 +201,8 @@ describe("DaemonClient tests", () => {
// force `data` call and verify input is from instantiation of DaemonClient
// and is what is passed to mocked Imperative.parse via snapshot
const promptResponse = { stdin: "some answer", user: Buffer.from("fake").toString('base64') };
(daemonClient as any).data(JSON.stringify(promptResponse));
const stringData = JSON.stringify(promptResponse);
(daemonClient as any).data(Buffer.from(stringData));

expect(log).toHaveBeenCalledTimes(1);
expect(parse).not.toHaveBeenCalled();
Expand Down Expand Up @@ -246,7 +248,8 @@ describe("DaemonClient tests", () => {
daemonClient.run();
// force `data` call and verify write method is called with termination message
const shutdownResponse = { stdin: DaemonClient.CTRL_C_CHAR, user: Buffer.from("fake").toString('base64') };
(daemonClient as any).data(JSON.stringify(shutdownResponse));
const stringData = JSON.stringify(shutdownResponse);
(daemonClient as any).data(Buffer.from(stringData));

expect(log).toHaveBeenCalledTimes(2);
expect(shutdownSpy).toHaveBeenCalledTimes(1);
Expand Down Expand Up @@ -339,7 +342,7 @@ describe("DaemonClient tests", () => {

const daemonClient = new DaemonClient(client as any, server, "fake");
const daemonResponse: IDaemonResponse = {
argv: ["feed", "dog"],
argv: ["feed", "🐶"],
cwd: "fake",
env: {},
stdinLength: 0,
Expand All @@ -350,7 +353,8 @@ describe("DaemonClient tests", () => {
daemonClient.run();
// force `data` call and verify input is from instantiation of DaemonClient
// and is what is passed to mocked Imperative.parse via snapshot
(daemonClient as any).data(JSON.stringify(daemonResponse));
const stringData = JSON.stringify(daemonResponse);
(daemonClient as any).data(Buffer.from(stringData));

expect(log).toHaveBeenCalledTimes(2);
expect(log).toHaveBeenLastCalledWith("The user 'ekaf' attempted to connect.");
Expand Down Expand Up @@ -390,7 +394,7 @@ describe("DaemonClient tests", () => {

const daemonClient = new DaemonClient(client as any, server, "fake");
const daemonResponse: IDaemonResponse = {
argv: ["feed", "dog"],
argv: ["feed", "🐶"],
cwd: "fake",
env: {},
stdinLength: 0,
Expand All @@ -400,7 +404,8 @@ describe("DaemonClient tests", () => {
daemonClient.run();
// force `data` call and verify input is from instantiation of DaemonClient
// and is what is passed to mocked Imperative.parse via snapshot
(daemonClient as any).data(JSON.stringify(daemonResponse));
const stringData = JSON.stringify(daemonResponse);
(daemonClient as any).data(Buffer.from(stringData));

expect(log).toHaveBeenCalledTimes(2);
expect(log).toHaveBeenLastCalledWith("A connection was attempted without a valid user.");
Expand Down Expand Up @@ -440,7 +445,7 @@ describe("DaemonClient tests", () => {

const daemonClient = new DaemonClient(client as any, server, "fake");
const daemonResponse: IDaemonResponse = {
argv: ["feed", "dog"],
argv: ["feed", "🐶"],
cwd: "fake",
env: {},
stdinLength: 0,
Expand All @@ -451,7 +456,8 @@ describe("DaemonClient tests", () => {
daemonClient.run();
// force `data` call and verify input is from instantiation of DaemonClient
// and is what is passed to mocked Imperative.parse via snapshot
(daemonClient as any).data(JSON.stringify(daemonResponse));
const stringData = JSON.stringify(daemonResponse);
(daemonClient as any).data(Buffer.from(stringData));

expect(log).toHaveBeenCalledTimes(2);
expect(log).toHaveBeenLastCalledWith("The user 'zF�' attempted to connect.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
exports[`DaemonClient tests should process data when received 1`] = `
Array [
"feed",
"dog",
"🐶",
]
`;

Expand All @@ -12,10 +12,12 @@ Object {
"daemonResponse": Object {
"argv": Array [
"feed",
"dog",
"🐶",
],
"cwd": "fake",
"env": Object {},
"env": Object {
"FORCE_COLOR": "0",
},
"stdin": null,
"stdinLength": 0,
"user": "ZmFrZQ==",
Expand Down Expand Up @@ -60,7 +62,7 @@ Object {
exports[`DaemonClient tests should process response with binary stdin data when received 1`] = `
Array [
"feed",
"cat",
"🐱",
]
`;

Expand All @@ -69,12 +71,12 @@ Object {
"daemonResponse": Object {
"argv": Array [
"feed",
"cat",
"🐱",
],
"cwd": "fake",
"env": Object {},
"stdin": null,
"stdinLength": 256,
"stdinLength": 1024,
"user": "ZmFrZQ==",
},
"stream": Object {
Expand Down
Loading

0 comments on commit dd0fd6a

Please sign in to comment.