Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion psCommandService.js
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ PSCommandService.prototype._generateCommand = function(commandConfig, argument2V

var passedArgValue = passedArgValues[i];

var valueToSet;
var valueToSet = "";

if (passedArgValue && passedArgValue != 'undefined') {
valueToSet = passedArgValue;
Expand Down
72 changes: 72 additions & 0 deletions test/unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,29 @@ const commandRegistry = {
type: "text",
},
},
setContent: {
command: "Set-Content {{{arguments}}}",
arguments: {
'Path': {},
'Value': {},
'Filter': {},
},
},
getContent: {
command: "Get-Content {{{arguments}}}",
arguments: {
'Path': {},
},
return: {
type: "text",
},
},
removeItem: {
command: "Remove-Item {{{arguments}}}",
arguments: {
'Path': {},
},
},
};


Expand Down Expand Up @@ -580,4 +603,53 @@ describe("test PSCommandService w/ o365CommandRegistry", function () {
throw e;
}
});
it("Should test value bleeding", async function () {
this.timeout(10000);
const statefulProcessCommandProxy = new StatefulProcessCommandProxy({
name: "Powershell pool",
max: 1,
min: 1,
idleTimeoutMS: 30000,

logFunction: logFunction,
processCommand: "pwsh",
processArgs: ["-Command", "-"],
processRetainMaxCmdHistory: 30,
processCwd: null,
processEnvMap: null,
processUid: null,
processGid: null,
initCommands: initCommands,
validateFunction: (processProxy) => processProxy.isValid(),
});

const psCommandService = new PSCommandService(
statefulProcessCommandProxy,
commandRegistry,
myLogFunction
);
try {
const newResult = await psCommandService.execute("setContent", {
Path: "./test.txt",
Value: "Test",
Filter: ""
});
assert.equal(newResult.command.trim(), "Set-Content -Path './test.txt' -Value 'Test'");
assert.equal(newResult.stderr, "");
const getResult = await psCommandService.execute("getContent", {
Path: "./test.txt",
});
assert.equal(getResult.stderr, "");
assert.equal(getResult.stdout, "Test");
} catch (e) {
assert.fail(e);
} finally {
await psCommandService.execute("removeItem", {
Path: "./test.txt",
});
setTimeout(() => {
statefulProcessCommandProxy.shutdown();
}, 5000);
}
});
});