mirror of
https://github.com/gchq/CyberChef.git
synced 2025-05-11 00:31:31 -04:00
Update NodeRecipe so args is optional in bake config
This commit is contained in:
parent
c2d06cd3fb
commit
13aceb9256
2 changed files with 38 additions and 2 deletions
|
@ -44,10 +44,13 @@ class NodeRecipe {
|
||||||
throw new TypeError("Inputted function not a Chef operation.");
|
throw new TypeError("Inputted function not a Chef operation.");
|
||||||
}
|
}
|
||||||
// CASE: op with configuration
|
// CASE: op with configuration
|
||||||
} else if (ing.op && ing.args) {
|
} else if (ing.op) {
|
||||||
// Return op and args pair for opList item.
|
// Return op and args pair for opList item.
|
||||||
const sanitisedOp = this._validateIngredient(ing.op);
|
const sanitisedOp = this._validateIngredient(ing.op);
|
||||||
return {op: sanitisedOp, args: ing.args};
|
if (ing.args) {
|
||||||
|
return {op: sanitisedOp, args: ing.args};
|
||||||
|
}
|
||||||
|
return sanitisedOp;
|
||||||
} else {
|
} else {
|
||||||
throw new TypeError("Recipe can only contain function names or functions");
|
throw new TypeError("Recipe can only contain function names or functions");
|
||||||
}
|
}
|
||||||
|
|
|
@ -259,6 +259,13 @@ TestRegister.addApiTests([
|
||||||
assert.strictEqual(result.toString(), "73:6f:6d:65:20:69:6e:70:75:74");
|
assert.strictEqual(result.toString(), "73:6f:6d:65:20:69:6e:70:75:74");
|
||||||
}),
|
}),
|
||||||
|
|
||||||
|
it("chef.bake: should take single JSON object desribing op with optional args", () => {
|
||||||
|
const result = chef.bake("some input", {
|
||||||
|
op: chef.toHex,
|
||||||
|
});
|
||||||
|
assert.strictEqual(result.toString(), "73 6f 6d 65 20 69 6e 70 75 74");
|
||||||
|
}),
|
||||||
|
|
||||||
it("chef.bake: should take single JSON object describing op and args ARRAY", () => {
|
it("chef.bake: should take single JSON object describing op and args ARRAY", () => {
|
||||||
const result = chef.bake("some input", {
|
const result = chef.bake("some input", {
|
||||||
op: chef.toHex,
|
op: chef.toHex,
|
||||||
|
@ -295,6 +302,21 @@ TestRegister.addApiTests([
|
||||||
assert.strictEqual(result.toString(), "67;63;72;66;146;72;66;144;72;66;65;72;62;60;72;66;71;72;66;145;72;67;60;72;67;65;72;67;64");
|
assert.strictEqual(result.toString(), "67;63;72;66;146;72;66;144;72;66;65;72;62;60;72;66;71;72;66;145;72;67;60;72;67;65;72;67;64");
|
||||||
}),
|
}),
|
||||||
|
|
||||||
|
it("chef.bake: should take multiple ops in JSON object form, some without args", () => {
|
||||||
|
const result = chef.bake("some input", [
|
||||||
|
{
|
||||||
|
op: chef.toHex,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
op: "to octal",
|
||||||
|
args: {
|
||||||
|
delimiter: "Semi-colon",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]);
|
||||||
|
assert.strictEqual(result.toString(), "67;63;40;66;146;40;66;144;40;66;65;40;62;60;40;66;71;40;66;145;40;67;60;40;67;65;40;67;64");
|
||||||
|
}),
|
||||||
|
|
||||||
it("chef.bake: should handle op with multiple args", () => {
|
it("chef.bake: should handle op with multiple args", () => {
|
||||||
const result = chef.bake("some input", {
|
const result = chef.bake("some input", {
|
||||||
op: "to morse code",
|
op: "to morse code",
|
||||||
|
@ -324,6 +346,17 @@ TestRegister.addApiTests([
|
||||||
assert.strictEqual(result.toString(), "begin_something_anananaaaaak_da_aaak_da_aaaaananaaaaaaan_da_aaaaaaanan_da_aaak_end_something");
|
assert.strictEqual(result.toString(), "begin_something_anananaaaaak_da_aaak_da_aaaaananaaaaaaan_da_aaaaaaanan_da_aaak_end_something");
|
||||||
}),
|
}),
|
||||||
|
|
||||||
|
it("chef.bake: should accept Clean JSON format from Chef website - args optional", () => {
|
||||||
|
const result = chef.bake("some input", [
|
||||||
|
{ "op": "To Morse Code" },
|
||||||
|
{ "op": "Hex to PEM",
|
||||||
|
"args": ["SOMETHING"] },
|
||||||
|
{ "op": "To Snake case",
|
||||||
|
"args": [false] }
|
||||||
|
]);
|
||||||
|
assert.strictEqual(result.toString(), "begin_something_aaaaaaaaaaaaaa_end_something");
|
||||||
|
}),
|
||||||
|
|
||||||
it("Excluded operations: throw a sensible error when you try and call one", () => {
|
it("Excluded operations: throw a sensible error when you try and call one", () => {
|
||||||
try {
|
try {
|
||||||
chef.fork();
|
chef.fork();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue