Revert "add formatter"

This reverts commit ce30989adc.
This commit is contained in:
Hare Sudhan 2024-02-25 16:23:48 -05:00
parent de3ef202d5
commit c5a1b69c30
693 changed files with 26685 additions and 51240 deletions

View file

@ -11,6 +11,7 @@
/* eslint no-console: 0 */
/**
* Print useful stack on error
*/
@ -23,6 +24,7 @@ const wrapRun = (run) => async () => {
}
};
/**
* it - wrapper for assertions to provide a helpful description
* to the TestRegister

View file

@ -8,7 +8,8 @@
const assert = require("assert");
require("cyberchef").then((chef) => {
require("cyberchef").then(chef => {
const d = chef.bake("Testing, 1 2 3", [
chef.toHex,
chef.reverse,
@ -16,15 +17,16 @@ require("cyberchef").then((chef) => {
op: chef.unique,
args: {
delimiter: "Space",
},
}
},
{
op: chef.multiply,
args: {
delimiter: "Space",
},
},
}
}
]);
assert.equal(d.value, "630957449041920");
});

View file

@ -16,14 +16,14 @@ const a = bake("Testing, 1 2 3", [
op: unique,
args: {
delimiter: "Space",
},
}
},
{
op: multiply,
args: {
delimiter: "Space",
},
},
}
}
]);
assert.equal(a.value, "630957449041920");
@ -35,14 +35,14 @@ const b = chef.bake("Testing, 1 2 3", [
op: chef.unique,
args: {
delimiter: "Space",
},
}
},
{
op: chef.multiply,
args: {
delimiter: "Space",
},
},
}
}
]);
assert.equal(b.value, "630957449041920");

View file

@ -10,7 +10,10 @@
* @license Apache-2.0
*/
import { setLongTestFailure, logTestReport } from "../lib/utils.mjs";
import {
setLongTestFailure,
logTestReport,
} from "../lib/utils.mjs";
import TestRegister from "../lib/TestRegister.mjs";
import "./tests/nodeApi.mjs";
@ -25,14 +28,14 @@ const testStatus = {
allTestsPassing: true,
counts: {
total: 0,
},
}
};
setLongTestFailure();
const logOpsTestReport = logTestReport.bind(null, testStatus);
(async function () {
(async function() {
const results = await TestRegister.runApiTests();
logOpsTestReport(results);
})();

View file

@ -1,25 +1,19 @@
import TestRegister from "../../lib/TestRegister.mjs";
import Categories from "../../../src/core/config/Categories.json" assert {
type: "json",
};
import OperationConfig from "../../../src/core/config/OperationConfig.json" assert {
type: "json",
};
import Categories from "../../../src/core/config/Categories.json" assert {type: "json"};
import OperationConfig from "../../../src/core/config/OperationConfig.json" assert {type: "json"};
import it from "../assertionHandler.mjs";
import assert from "assert";
TestRegister.addApiTests([
it("Categories: operations should be in a category", () => {
const catOps = [];
Categories.forEach((cat) => {
Categories.forEach(cat => {
catOps.push(...cat.ops);
});
for (const op in OperationConfig) {
assert(
catOps.includes(op),
`'${op}' operation is not present in any category`,
);
assert(catOps.includes(op), `'${op}' operation is not present in any category`);
}
}),
]);

View file

@ -8,4 +8,5 @@ TestRegister.addApiTests([
const dish = new Dish();
assert(dish.presentAs);
}),
]);

View file

@ -2,7 +2,7 @@ import assert from "assert";
import it from "../assertionHandler.mjs";
import TestRegister from "../../lib/TestRegister.mjs";
import File from "../../../src/node/File.mjs";
import { zip, Dish } from "../../../src/node/index.mjs";
import {zip, Dish} from "../../../src/node/index.mjs";
TestRegister.addApiTests([
it("File: should exist", () => {
@ -28,13 +28,13 @@ TestRegister.addApiTests([
it("File: unknown type should have a type of application/unknown", () => {
const uint8Array = new Uint8Array(Buffer.from("hello"));
const file = new File([uint8Array], "sample.txt");
const file = new File([uint8Array], "sample.txt");
assert.strictEqual(file.type, "application/unknown");
}),
it("File: should be able to make a dish from it", () => {
const uint8Array = new Uint8Array(Buffer.from("hello"));
const file = new File([uint8Array], "sample.txt");
const file = new File([uint8Array], "sample.txt");
try {
const dish = new Dish(file, 7);
assert.ok(dish.valid());
@ -45,7 +45,7 @@ TestRegister.addApiTests([
it("File: should allow dish to translate to ArrayBuffer", () => {
const uint8Array = new Uint8Array(Buffer.from("hello"));
const file = new File([uint8Array], "sample.txt");
const file = new File([uint8Array], "sample.txt");
try {
const dish = new Dish(file, 7);
assert.ok(dish.value);
@ -53,6 +53,7 @@ TestRegister.addApiTests([
dish.get(4);
assert.strictEqual(dish.type, 4);
assert.ok(dish.valid());
} catch (e) {
assert.fail(e.message);
}
@ -60,7 +61,7 @@ TestRegister.addApiTests([
it("File: should allow dish to translate from ArrayBuffer to File", () => {
const uint8Array = new Uint8Array(Buffer.from("hello"));
const file = new File([uint8Array], "sample.txt");
const file = new File([uint8Array], "sample.txt");
try {
const dish = new Dish(file, 7);
assert.ok(dish.value);
@ -72,8 +73,10 @@ TestRegister.addApiTests([
// translate back to File
dish.get(7);
assert.ok(dish.valid());
} catch (e) {
assert.fail(e.message);
}
}),
})
]);

View file

@ -15,10 +15,7 @@ TestRegister.addApiTests([
it("Composable Dish: Should construct empty dish object", () => {
const dish = new Dish();
assert.strictEqual(
dish.value.byteLength,
new ArrayBuffer(0).byteLength,
);
assert.strictEqual(dish.value.byteLength, new ArrayBuffer(0).byteLength);
assert.strictEqual(dish.type, 4);
}),
@ -33,6 +30,7 @@ TestRegister.addApiTests([
assert.ok(result instanceof Dish);
}),
it("Composable dish: infers type from input if needed", () => {
const dish = new Dish("string input");
assert.strictEqual(dish.type, 1);
@ -40,15 +38,13 @@ TestRegister.addApiTests([
const numberDish = new Dish(333);
assert.strictEqual(numberDish.type, 2);
const arrayBufferDish = new Dish(
Buffer.from("some buffer input").buffer,
);
const arrayBufferDish = new Dish(Buffer.from("some buffer input").buffer);
assert.strictEqual(arrayBufferDish.type, 4);
const byteArrayDish = new Dish(Buffer.from("some buffer input"));
assert.strictEqual(byteArrayDish.type, 0);
const JSONDish = new Dish({ key: "value" });
const JSONDish = new Dish({key: "value"});
assert.strictEqual(JSONDish.type, 6);
}),
@ -60,21 +56,13 @@ TestRegister.addApiTests([
}),
it("Composable Dish: apply should allow set of arguments for operation", () => {
const result = new Dish("input").apply(SHA3, { size: "256" });
assert.strictEqual(
result.toString(),
"7640cc9b7e3662b2250a43d1757e318bb29fb4860276ac4373b67b1650d6d3e3",
);
const result = new Dish("input").apply(SHA3, {size: "256"});
assert.strictEqual(result.toString(), "7640cc9b7e3662b2250a43d1757e318bb29fb4860276ac4373b67b1650d6d3e3");
}),
it("Composable Dish: apply functions can be chained", () => {
const result = new Dish("input")
.apply(toBase32)
.apply(SHA3, { size: "224" });
assert.strictEqual(
result.toString(),
"493e8136b759370a415ef2cf2f7a69690441ff86592aba082bc2e2e0",
);
const result = new Dish("input").apply(toBase32).apply(SHA3, {size: "224"});
assert.strictEqual(result.toString(), "493e8136b759370a415ef2cf2f7a69690441ff86592aba082bc2e2e0");
}),
it("Dish translation: ArrayBuffer to ArrayBuffer", () => {
@ -89,13 +77,7 @@ TestRegister.addApiTests([
dish.get("array buffer");
assert.strictEqual(dish.type, 4);
assert.deepStrictEqual(
dish.value,
new Uint8Array([
0x73, 0x6f, 0x6d, 0x65, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e,
0x67,
]).buffer,
);
assert.deepStrictEqual(dish.value, new Uint8Array([0x73, 0x6f, 0x6d, 0x65, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67]).buffer);
assert.deepEqual(dish.value.byteLength, 11);
dish.get("string");
@ -108,22 +90,12 @@ TestRegister.addApiTests([
dish.get(4);
assert.strictEqual(dish.type, 4);
assert.deepStrictEqual(
dish.value,
new Uint8Array([0x31, 0x30, 0x30]).buffer,
);
assert.deepStrictEqual(dish.value, new Uint8Array([0x31, 0x30, 0x30]).buffer);
assert.strictEqual(dish.value.byteLength, 3);
// Check the data in ArrayBuffer represents 100 as a string.
const view = new DataView(dish.value, 0);
assert.strictEqual(
String.fromCharCode(
view.getUint8(0),
view.getUint8(1),
view.getUint8(2),
),
"100",
);
assert.strictEqual(String.fromCharCode(view.getUint8(0), view.getUint8(1), view.getUint8(2)), "100");
dish.get("number");
assert.strictEqual(dish.type, 2);
@ -167,30 +139,19 @@ TestRegister.addApiTests([
const dish = new Dish(number, Dish.BIG_NUMBER);
dish.get(Dish.ARRAY_BUFFER);
assert.deepStrictEqual(
dish.value,
new Uint8Array([0x34, 0x30, 0x30, 0x31]).buffer,
);
assert.deepStrictEqual(dish.value, new Uint8Array([0x34, 0x30, 0x30, 0x31]).buffer);
assert.strictEqual(dish.value.byteLength, 4);
// Check the data in ArrayBuffer represents 4001 as a string.
const view = new DataView(dish.value, 0);
assert.strictEqual(
String.fromCharCode(
view.getUint8(0),
view.getUint8(1),
view.getUint8(2),
view.getUint8(3),
),
"4001",
);
assert.strictEqual(String.fromCharCode(view.getUint8(0), view.getUint8(1), view.getUint8(2), view.getUint8(3)), "4001");
dish.get(5);
assert.deepStrictEqual(dish.value, number);
}),
it("Dish translation: ArrayBuffer and JSON", () => {
const jsonString = '{"a": 123455, "b": { "aa": [1,2,3]}}';
const jsonString = "{\"a\": 123455, \"b\": { \"aa\": [1,2,3]}}";
const dish = new Dish(JSON.parse(jsonString), Dish.JSON);
dish.get(Dish.ARRAY_BUFFER);
@ -204,23 +165,12 @@ TestRegister.addApiTests([
const dish = new Dish(file, Dish.FILE);
dish.get(Dish.ARRAY_BUFFER);
assert.deepStrictEqual(
dish.value,
new Uint8Array([0x61, 0x62, 0x63, 0x64]).buffer,
);
assert.deepStrictEqual(dish.value, new Uint8Array([0x61, 0x62, 0x63, 0x64]).buffer);
assert.strictEqual(dish.value.byteLength, 4);
// Check the data in ArrayBuffer represents "abcd"
const view = new DataView(dish.value, 0);
assert.strictEqual(
String.fromCharCode(
view.getUint8(0),
view.getUint8(1),
view.getUint8(2),
view.getUint8(3),
),
"abcd",
);
assert.strictEqual(String.fromCharCode(view.getUint8(0), view.getUint8(1), view.getUint8(2), view.getUint8(3)), "abcd");
dish.get(Dish.FILE);
@ -237,19 +187,13 @@ TestRegister.addApiTests([
const dish = new Dish([file1, file2], Dish.LIST_FILE);
dish.get(Dish.ARRAY_BUFFER);
assert.deepStrictEqual(dish.value, [
new Uint8Array([0x61, 0x62, 0x63, 0x64, 0x65]),
new Uint8Array([0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b]),
]);
assert.deepStrictEqual(dish.value, [new Uint8Array([0x61, 0x62, 0x63, 0x64, 0x65]), new Uint8Array([0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b])]);
assert.strictEqual(dish.value.length, 2);
dish.get(Dish.LIST_FILE);
const dataArray = new Uint8Array(dish.value[0].data);
// cant store chars in a Uint8Array, so make it a normal one.
const actual = Array.prototype.slice
.call(dataArray)
.map((c) => String.fromCharCode(c))
.join("");
const actual = Array.prototype.slice.call(dataArray).map(c => String.fromCharCode(c)).join("");
assert.strictEqual(actual, "abcdefghijk");
}),
]);

View file

@ -19,4 +19,5 @@ TestRegister.addApiTests([
it("Utils: should parse escaped quotes and escaped backslashes correctly", () => {
assert.equal(Utils.parseEscapedChars("\\\\\\'"), "\\'");
}),
]);

View file

@ -13,13 +13,10 @@
import assert from "assert";
import it from "../assertionHandler.mjs";
import chef from "../../../src/node/index.mjs";
import {
OperationError,
ExcludedOperationError,
} from "../../../src/core/errors/index.mjs";
import { OperationError, ExcludedOperationError } from "../../../src/core/errors/index.mjs";
import NodeDish from "../../../src/node/NodeDish.mjs";
import { toBase32, magic } from "../../../src/node/index.mjs";
import { toBase32, magic} from "../../../src/node/index.mjs";
import TestRegister from "../../lib/TestRegister.mjs";
TestRegister.addApiTests([
@ -64,7 +61,7 @@ TestRegister.addApiTests([
it("should accept arguments in object format for operations", () => {
const result = chef.setUnion("1 2 3 4:3 4 5 6", {
itemDelimiter: " ",
sampleDelimiter: ":",
sampleDelimiter: ":"
});
assert.equal(result.value, "1 2 3 4 5 6");
@ -104,7 +101,7 @@ TestRegister.addApiTests([
const result = chef.fromBase32(chef.toBase32("something"));
assert.equal(String(result), "something");
// This kind of coercion uses toValue
assert.equal("" + result, "NaN");
assert.equal(""+result, "NaN");
}),
it("should coerce to a number as you expect", () => {
@ -122,10 +119,7 @@ TestRegister.addApiTests([
assert.strictEqual(result[0].module, "Ciphers");
assert.strictEqual(result[0].inputType, "string");
assert.strictEqual(result[0].outputType, "string");
assert.strictEqual(
result[0].description,
"Triple DES applies DES three times to each block to increase key size.<br><br><b>Key:</b> Triple DES uses a key length of 24 bytes (192 bits).<br>DES uses a key length of 8 bytes (64 bits).<br><br><b>IV:</b> The Initialization Vector should be 8 bytes long. If not entered, it will default to 8 null bytes.<br><br><b>Padding:</b> In CBC and ECB mode, PKCS#7 padding will be used as a default.",
);
assert.strictEqual(result[0].description, "Triple DES applies DES three times to each block to increase key size.<br><br><b>Key:</b> Triple DES uses a key length of 24 bytes (192 bits).<br>DES uses a key length of 8 bytes (64 bits).<br><br><b>IV:</b> The Initialization Vector should be 8 bytes long. If not entered, it will default to 8 null bytes.<br><br><b>Padding:</b> In CBC and ECB mode, PKCS#7 padding will be used as a default.");
assert.strictEqual(result[0].args.length, 5);
}),
@ -156,10 +150,7 @@ TestRegister.addApiTests([
const result = chef.help("Checksum");
assert.ok(result[0].name.includes("Checksum"));
assert.ok(result[1].name.includes("Checksum"));
assert.strictEqual(
result[result.length - 1].name.includes("Checksum"),
false,
);
assert.strictEqual(result[result.length - 1].name.includes("Checksum"), false);
assert.ok(result[result.length - 1].description.includes("checksum"));
}),
@ -192,62 +183,40 @@ TestRegister.addApiTests([
it("chef.bake: should complain if recipe isnt a valid object", () => {
assert.throws(() => chef.bake("some input", 3264), {
name: "TypeError",
message: "Recipe can only contain function names or functions",
message: "Recipe can only contain function names or functions"
});
}),
it("chef.bake: Should complain if string op is invalid", () => {
assert.throws(() => chef.bake("some input", "not a valid operation"), {
name: "TypeError",
message:
"Couldn't find an operation with name 'not a valid operation'.",
message: "Couldn't find an operation with name 'not a valid operation'."
});
}),
it("chef.bake: Should take an input and an operation and perform it", () => {
const result = chef.bake(
"https://google.com/search?q=help",
chef.parseURI,
);
assert.strictEqual(
result.toString(),
"Protocol:\thttps:\nHostname:\tgoogle.com\nPath name:\t/search\nArguments:\n\tq = help\n",
);
const result = chef.bake("https://google.com/search?q=help", chef.parseURI);
assert.strictEqual(result.toString(), "Protocol:\thttps:\nHostname:\tgoogle.com\nPath name:\t/search\nArguments:\n\tq = help\n");
}),
it("chef.bake: Should complain if an invalid operation is inputted", () => {
assert.throws(
() => chef.bake("https://google.com/search?q=help", () => {}),
{
name: "TypeError",
message: "Inputted function not a Chef operation.",
},
);
assert.throws(() => chef.bake("https://google.com/search?q=help", () => {}), {
name: "TypeError",
message: "Inputted function not a Chef operation."
});
}),
it("chef.bake: accepts an array of operation names and performs them all in order", () => {
const result = chef.bake(
"https://google.com/search?q=that's a complicated question",
["URL encode", "URL decode", "Parse URI"],
);
assert.strictEqual(
result.toString(),
"Protocol:\thttps:\nHostname:\tgoogle.com\nPath name:\t/search\nArguments:\n\tq = that's a complicated question\n",
);
const result = chef.bake("https://google.com/search?q=that's a complicated question", ["URL encode", "URL decode", "Parse URI"]);
assert.strictEqual(result.toString(), "Protocol:\thttps:\nHostname:\tgoogle.com\nPath name:\t/search\nArguments:\n\tq = that's a complicated question\n");
}),
it("chef.bake: forgiving with operation names", () => {
const result = chef.bake(
"https://google.com/search?q=that's a complicated question",
["urlencode", "url decode", "parseURI"],
);
assert.strictEqual(
result.toString(),
"Protocol:\thttps:\nHostname:\tgoogle.com\nPath name:\t/search\nArguments:\n\tq = that's a complicated question\n",
);
it("chef.bake: forgiving with operation names", () =>{
const result = chef.bake("https://google.com/search?q=that's a complicated question", ["urlencode", "url decode", "parseURI"]);
assert.strictEqual(result.toString(), "Protocol:\thttps:\nHostname:\tgoogle.com\nPath name:\t/search\nArguments:\n\tq = that's a complicated question\n");
}),
it("chef.bake: forgiving with operation names", () => {
it("chef.bake: forgiving with operation names", () =>{
const result = chef.bake("hello", ["to base 64"]);
assert.strictEqual(result.toString(), "aGVsbG8=");
}),
@ -255,27 +224,18 @@ TestRegister.addApiTests([
it("chef.bake: if recipe is empty array, return input as dish", () => {
const result = chef.bake("some input", []);
assert.strictEqual(result.toString(), "some input");
assert(
result instanceof NodeDish,
"Result is not instance of NodeDish",
);
assert(result instanceof NodeDish, "Result is not instance of NodeDish");
}),
it("chef.bake: accepts an array of operations as recipe", () => {
const result = chef.bake(
"https://google.com/search?q=that's a complicated question",
[chef.URLEncode, chef.URLDecode, chef.parseURI],
);
assert.strictEqual(
result.toString(),
"Protocol:\thttps:\nHostname:\tgoogle.com\nPath name:\t/search\nArguments:\n\tq = that's a complicated question\n",
);
const result = chef.bake("https://google.com/search?q=that's a complicated question", [chef.URLEncode, chef.URLDecode, chef.parseURI]);
assert.strictEqual(result.toString(), "Protocol:\thttps:\nHostname:\tgoogle.com\nPath name:\t/search\nArguments:\n\tq = that's a complicated question\n");
}),
it("should complain if an invalid operation is inputted as part of array", () => {
assert.throws(() => chef.bake("something", [() => {}]), {
name: "TypeError",
message: "Inputted function not a Chef operation.",
message: "Inputted function not a Chef operation."
});
}),
@ -283,8 +243,8 @@ TestRegister.addApiTests([
const result = chef.bake("some input", {
op: chef.toHex,
args: {
Delimiter: "Colon",
},
Delimiter: "Colon"
}
});
assert.strictEqual(result.toString(), "73:6f:6d:65:20:69:6e:70:75:74");
}),
@ -299,42 +259,35 @@ TestRegister.addApiTests([
it("chef.bake: should take single JSON object describing op and args ARRAY", () => {
const result = chef.bake("some input", {
op: chef.toHex,
args: ["Colon"],
args: ["Colon"]
});
assert.strictEqual(result.toString(), "73:6f:6d:65:20:69:6e:70:75:74");
}),
it("chef.bake: should error if op in JSON is not chef op", () => {
assert.throws(
() =>
chef.bake("some input", {
op: () => {},
args: ["Colon"],
}),
{
name: "TypeError",
message: "Inputted function not a Chef operation.",
},
);
assert.throws(() => chef.bake("some input", {
op: () => {},
args: ["Colon"],
}), {
name: "TypeError",
message: "Inputted function not a Chef operation."
});
}),
it("chef.bake: should take multiple ops in JSON object form, some ops by string", () => {
const result = chef.bake("some input", [
{
op: chef.toHex,
args: ["Colon"],
args: ["Colon"]
},
{
op: "to octal",
args: {
delimiter: "Semi-colon",
},
},
}
}
]);
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", () => {
@ -346,13 +299,10 @@ TestRegister.addApiTests([
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",
);
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", () => {
@ -362,92 +312,70 @@ TestRegister.addApiTests([
formatOptions: "Dash/Dot",
wordDelimiter: "Comma",
letterDelimiter: "Backslash",
},
}
});
assert.strictEqual(
result.toString(),
"DotDotDot\\DashDashDash\\DashDash\\Dot,DotDot\\DashDot\\DotDashDashDot\\DotDotDash\\Dash",
);
assert.strictEqual(result.toString(), "DotDotDot\\DashDashDash\\DashDash\\Dot,DotDot\\DashDot\\DotDashDashDot\\DotDotDash\\Dash");
}),
it("chef.bake: should take compact JSON format from Chef Website as recipe", () => {
const result = chef.bake("some input", [
{ op: "To Morse Code", args: ["Dash/Dot", "Backslash", "Comma"] },
{ op: "Hex to PEM", args: ["SOMETHING"] },
{ op: "To Snake case", args: [false] },
]);
assert.strictEqual(
result.toString(),
"begin_something_anananaaaaak_da_aaak_da_aaaaananaaaaaaan_da_aaaaaaanan_da_aaak_end_something",
);
const result = chef.bake("some input", [{"op": "To Morse Code", "args": ["Dash/Dot", "Backslash", "Comma"]}, {"op": "Hex to PEM", "args": ["SOMETHING"]}, {"op": "To Snake case", "args": [false]}]);
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 as recipe", () => {
const result = chef.bake("some input", [
{ op: "To Morse Code", args: ["Dash/Dot", "Backslash", "Comma"] },
{ op: "Hex to PEM", args: ["SOMETHING"] },
{ op: "To Snake case", args: [false] },
{ "op": "To Morse Code",
"args": ["Dash/Dot", "Backslash", "Comma"] },
{ "op": "Hex to PEM",
"args": ["SOMETHING"] },
{ "op": "To Snake case",
"args": [false] }
]);
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] },
{ "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",
);
assert.strictEqual(result.toString(), "begin_something_aaaaaaaaaaaaaa_end_something");
}),
it("chef.bake: cannot accept flowControl operations in recipe", () => {
assert.throws(() => chef.bake("some input", "magic"), {
name: "TypeError",
message:
"flowControl operations like Magic are not currently allowed in recipes for chef.bake in the Node API",
message: "flowControl operations like Magic are not currently allowed in recipes for chef.bake in the Node API"
});
assert.throws(() => chef.bake("some input", magic), {
name: "TypeError",
message:
"flowControl operations like Magic are not currently allowed in recipes for chef.bake in the Node API",
message: "flowControl operations like Magic are not currently allowed in recipes for chef.bake in the Node API"
});
assert.throws(() => chef.bake("some input", ["to base 64", "magic"]), {
name: "TypeError",
message:
"flowControl operations like Magic are not currently allowed in recipes for chef.bake in the Node API",
message: "flowControl operations like Magic are not currently allowed in recipes for chef.bake in the Node API"
});
}),
it("Excluded operations: throw a sensible error when you try and call one", () => {
assert.throws(
chef.fork,
assert.throws(chef.fork,
(err) => {
assert(err instanceof ExcludedOperationError);
assert.deepEqual(
err.message,
"Sorry, the Fork operation is not available in the Node.js version of CyberChef.",
);
assert.deepEqual(err.message, "Sorry, the Fork operation is not available in the Node.js version of CyberChef.");
return true;
},
"Unexpected error type",
"Unexpected error type"
);
assert.throws(
chef.javaScriptBeautify,
assert.throws(chef.javaScriptBeautify,
(err) => {
assert(err instanceof ExcludedOperationError);
assert.deepEqual(
err.message,
"Sorry, the JavaScriptBeautify operation is not available in the Node.js version of CyberChef.",
);
assert.deepEqual(err.message, "Sorry, the JavaScriptBeautify operation is not available in the Node.js version of CyberChef.");
return true;
},
"Unexpected error type",
"Unexpected error type"
);
}),
@ -461,7 +389,7 @@ TestRegister.addApiTests([
verifyResult: {
type: "boolean",
value: false,
},
}
});
}),
@ -473,14 +401,13 @@ TestRegister.addApiTests([
assert.strictEqual(chef.bitShiftRight.args.amount.value, 1);
assert.strictEqual(chef.bitShiftRight.args.type.type, "option");
assert.ok(Array.isArray(chef.bitShiftRight.args.type.options));
}),
it("Operation arguments: should list all options excluding subheadings", () => {
// First element (subheading) removed
assert.equal(
chef.convertDistance.args.inputUnits.options[0],
"Nanometres (nm)",
);
assert.equal(chef.convertDistance.args.inputUnits.options[0], "Nanometres (nm)");
assert.equal(chef.defangURL.args.process.options[1], "Only full URLs");
}),
]);

File diff suppressed because it is too large Load diff