Merge remote-tracking branch 'upstream/master' into ssh-host-key

Bring up to date with master
This commit is contained in:
j433866 2019-08-13 13:26:40 +01:00
commit 1cdcaebb4d
540 changed files with 30965 additions and 5829 deletions

View file

@ -82,6 +82,7 @@ module.exports = {
browser
.useCss()
.setValue("#input-text", "Don't Panic.")
.pause(1000)
.click("#bake");
// Check output

View file

@ -5,37 +5,49 @@
* ensure that they will get run by the frontend.
*
* @author tlwr [toby@toby.codes]
* @copyright Crown Copyright 2017
* @author d98762625 [d98762625@gmail.com]
* @copyright Crown Copyright 2018
* @license Apache-2.0
*/
import Chef from "../../src/core/Chef";
import Chef from "../../src/core/Chef.mjs";
/**
* Object to store and run the list of tests.
*
* @class
* @constructor
*/
class TestRegister {
(function() {
/**
* Object to store and run the list of tests.
*
* @class
* @constructor
* initialise with no tests
*/
function TestRegister() {
constructor() {
this.tests = [];
this.apiTests = [];
}
/**
* Add a list of tests to the register.
*
* @param {Object[]} tests
*/
TestRegister.prototype.addTests = function(tests) {
addTests(tests) {
this.tests = this.tests.concat(tests);
};
}
/**
* Add a list of api tests to the register
* @param {Object[]} tests
*/
addApiTests(tests) {
this.apiTests = this.apiTests.concat(tests);
}
/**
* Runs all the tests in the register.
*/
TestRegister.prototype.runTests = function() {
runTests () {
return Promise.all(
this.tests.map(function(test, i) {
const chef = new Chef();
@ -66,7 +78,7 @@ import Chef from "../../src/core/Chef";
ret.output = "Expected an error but did not receive one.";
} else if (result.result === test.expectedOutput) {
ret.status = "passing";
} else if (test.hasOwnProperty("expectedMatch") && test.expectedMatch.test(result.result)) {
} else if ("expectedMatch" in test && test.expectedMatch.test(result.result)) {
ret.status = "passing";
} else {
ret.status = "failing";
@ -85,12 +97,29 @@ import Chef from "../../src/core/Chef";
});
})
);
};
}
/**
* Run all api related tests and wrap results in report format
*/
runApiTests() {
return Promise.all(this.apiTests.map(async function(test, i) {
const result = {
test: test,
status: null,
output: null,
};
try {
await test.run();
result.status = "passing";
} catch (e) {
result.status = "erroring";
result.output = e.message;
}
return result;
}));
}
}
// Singleton TestRegister, keeping things simple and obvious.
global.TestRegister = global.TestRegister || new TestRegister();
})();
export default global.TestRegister;
// Export an instance to make a singleton
export default new TestRegister();

84
tests/lib/utils.mjs Normal file
View file

@ -0,0 +1,84 @@
/**
* Utils for test suite
*
* @author d98762625@gmail.com
* @author tlwr [toby@toby.codes]
* @author n1474335 [n1474335@gmail.com]
* @copyright Crown Copyright 2018
* @license Apache-2.0
*/
/**
* Helper function to convert a status to an icon.
*
* @param {string} status
* @returns {string}
*/
const statusToIcon = function statusToIcon(status) {
const icons = {
erroring: "🔥",
failing: "❌",
passing: "✔️️",
};
return icons[status] || "?";
};
/**
* Displays a given test result in the console.
* Counts test statuses.
*
* @param {Object} testStatusCounts
* @param {Object} testResult
*/
function handleTestResult(testStatus, testResult) {
testStatus.allTestsPassing = testStatus.allTestsPassing && testResult.status === "passing";
const newCount = (testStatus.counts[testResult.status] || 0) + 1;
testStatus.counts[testResult.status] = newCount;
testStatus.counts.total += 1;
console.log([
statusToIcon(testResult.status),
testResult.test.name
].join(" "));
if (testResult.output) {
console.log(
testResult.output
.trim()
.replace(/^/, "\t")
.replace(/\n/g, "\n\t")
);
}
}
/**
* Log each test result, count tests and failures. Log test suite run duration.
*
* @param {Object} testStatus - object describing test run data
* @param {Object[]} results - results from TestRegister
*/
export function logTestReport(testStatus, results) {
results.forEach(r => handleTestResult(testStatus, r));
console.log("\n");
for (const testStatusCount in testStatus.counts) {
const count = testStatus.counts[testStatusCount];
if (count > 0) {
console.log(testStatusCount.toUpperCase(), count);
}
}
process.exit(testStatus.allTestsPassing ? 0 : 1);
}
/**
* Fail if the process takes longer than 60 seconds.
*/
export function setLongTestFailure() {
setTimeout(function() {
console.log("Tests took longer than 60 seconds to run, returning.");
process.exit(1);
}, 60 * 1000);
}

View file

@ -0,0 +1,60 @@
/**
* assertionHandler.mjs
*
* Pair native node assertions with a description for
* the benefit of the TestRegister.
*
* @author d98762625 [d98762625@gmail.com]
* @copyright Crown Copyright 2019
* @license Apache-2.0
*/
/* eslint no-console: 0 */
/**
* Print useful stack on error
*/
const wrapRun = (run) => () => {
try {
run();
} catch (e) {
console.dir(e);
throw e;
}
};
/**
* it - wrapper for assertions to provide a helpful description
* to the TestRegister
* @namespace ApiTests
* @param {String} description - The description of the test
* @param {Function} assertion - The test
*
* @example
* // One assertion
* it("should run one assertion", () => assert.equal(1,1))
*
* @example
* // multiple assertions
* it("should handle multiple assertions", () => {
* assert.equal(1,1)
* assert.notEqual(3,4)
* })
*
* @example
* // async assertions
* it("should handle async", async () => {
* let r = await asyncFunc()
* assert(r)
* })
*/
export function it(name, run) {
return {
name: `Node API: ${name}`,
run: wrapRun(run),
};
}
export default it;

View file

@ -0,0 +1,29 @@
/**
* Tests to ensure that a consuming app can use CJS require
*
* @author d98762625 [d98762625@gmail.com]
* @copyright Crown Copyright 2019
* @license Apache-2.0
*/
const chef = require("cyberchef");
const assert = require("assert");
const d = chef.bake("Testing, 1 2 3", [
chef.toHex,
chef.reverse,
{
op: chef.unique,
args: {
delimiter: "Space",
}
},
{
op: chef.multiply,
args: {
delimiter: "Space",
}
}
]);
assert.equal(d.value, "630957449041920");

View file

@ -0,0 +1,28 @@
/**
* Tests to ensure that a consuming app can use ESM imports
*
* @author d98762625 [d98762625@gmail.com]
* @copyright Crown Copyright 2019
* @license Apache-2.0
*/
import assert from "assert";
import chef from "cyberchef";
const d = chef.bake("Testing, 1 2 3", [
chef.toHex,
chef.reverse,
{
op: chef.unique,
args: {
delimiter: "Space",
}
},
{
op: chef.multiply,
args: {
delimiter: "Space",
}
}
]);
assert.equal(d.value, "630957449041920");

View file

@ -0,0 +1,28 @@
/**
* Tests to ensure that a consuming app can use named imports from deep import patch
*
* @author d98762625 [d98762625@gmail.com]
* @copyright Crown Copyright 2019
* @license Apache-2.0
*/
import assert from "assert";
import { bake, toHex, reverse, unique, multiply } from "cyberchef/src/node/index.mjs";
const d = bake("Testing, 1 2 3", [
toHex,
reverse,
{
op: unique,
args: {
delimiter: "Space",
}
},
{
op: multiply,
args: {
delimiter: "Space",
}
}
]);
assert.equal(d.value, "630957449041920");

37
tests/node/index.mjs Normal file
View file

@ -0,0 +1,37 @@
/* eslint no-console: 0 */
/**
* Node API Test Runner
*
* @author d98762625 [d98762625@gmail.com]
* @author tlwr [toby@toby.codes]
* @author n1474335 [n1474335@gmail.com]
* @copyright Crown Copyright 2018
* @license Apache-2.0
*/
import {
setLongTestFailure,
logTestReport,
} from "../lib/utils";
import TestRegister from "../lib/TestRegister.mjs";
import "./tests/nodeApi";
import "./tests/operations";
import "./tests/File";
import "./tests/NodeDish";
const testStatus = {
allTestsPassing: true,
counts: {
total: 0,
}
};
setLongTestFailure();
const logOpsTestReport = logTestReport.bind(null, testStatus);
TestRegister.runApiTests()
.then(logOpsTestReport);

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 KiB

82
tests/node/tests/File.mjs Normal file
View file

@ -0,0 +1,82 @@
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";
TestRegister.addApiTests([
it("File: should exist", () => {
assert(File);
}),
it("File: Should have same properties as DOM File object", () => {
const uint8Array = new Uint8Array(Buffer.from("hello"));
const file = new File([uint8Array], "name.txt");
assert.equal(file.name, "name.txt");
assert(typeof file.lastModified, "number");
assert(file.lastModifiedDate instanceof Date);
assert.equal(file.size, uint8Array.length);
assert.equal(file.type, "application/unknown");
}),
it("File: Should determine the type of a file", () => {
const zipped = zip("hello");
const file = new File([zipped.value]);
assert(file);
assert.strictEqual(file.type, "application/zip");
}),
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");
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");
try {
const dish = new Dish(file, 7);
assert.ok(dish.valid());
} catch (e) {
assert.fail(e.message);
}
}),
it("File: should allow dish to translate to ArrayBuffer", () => {
const uint8Array = new Uint8Array(Buffer.from("hello"));
const file = new File([uint8Array], "sample.txt");
try {
const dish = new Dish(file, 7);
assert.ok(dish.value);
dish.get(4);
assert.strictEqual(dish.type, 4);
assert.ok(dish.valid());
} catch (e) {
assert.fail(e.message);
}
}),
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");
try {
const dish = new Dish(file, 7);
assert.ok(dish.value);
// translate to ArrayBuffer
dish.get(4);
assert.ok(dish.valid());
// translate back to File
dish.get(7);
assert.ok(dish.valid());
} catch (e) {
assert.fail(e.message);
}
})
]);

View file

@ -0,0 +1,199 @@
import assert from "assert";
import it from "../assertionHandler.mjs";
import fs from "fs";
import BigNumber from "bignumber.js";
import { Dish, toBase32, SHA3 } from "../../../src/node/index.mjs";
import File from "../../../src/node/File.mjs";
import TestRegister from "../../lib/TestRegister.mjs";
TestRegister.addApiTests([
it("Composable Dish: Should have top level Dish object", () => {
assert.ok(Dish);
}),
it("Composable Dish: Should construct empty dish object", () => {
const dish = new Dish();
assert.strictEqual(dish.value.byteLength, new ArrayBuffer(0).byteLength);
assert.strictEqual(dish.type, 4);
}),
it("Composable Dish: constructed dish should have apply prototype functions", () => {
const dish = new Dish();
assert.ok(dish.apply);
assert.throws(() => dish.someInvalidFunction());
}),
it("Composable Dish: composed function returns another dish", () => {
const result = new Dish("some input").apply(toBase32);
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);
const numberDish = new Dish(333);
assert.strictEqual(numberDish.type, 2);
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"});
assert.strictEqual(JSONDish.type, 6);
}),
it("Composable dish: Buffer type dishes should be converted to strings", () => {
fs.writeFileSync("test.txt", "abc");
const dish = new Dish(fs.readFileSync("test.txt"));
assert.strictEqual(dish.type, 0);
fs.unlinkSync("test.txt");
}),
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");
}),
it("Composable Dish: apply functions can be chained", () => {
const result = new Dish("input").apply(toBase32).apply(SHA3, {size: "224"});
assert.strictEqual(result.toString(), "493e8136b759370a415ef2cf2f7a69690441ff86592aba082bc2e2e0");
}),
it("Dish translation: ArrayBuffer to ArrayBuffer", () => {
const dish = new Dish(new ArrayBuffer(10), 4);
dish.get("array buffer");
assert.strictEqual(dish.value.byteLength, 10);
assert.strictEqual(dish.type, 4);
}),
it("Dish translation: ArrayBuffer and String", () => {
const dish = new Dish("some string", 1);
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.deepEqual(dish.value.byteLength, 11);
dish.get("string");
assert.strictEqual(dish.type, 1);
assert.strictEqual(dish.value, "some string");
}),
it("Dish translation: ArrayBuffer and number", () => {
const dish = new Dish(100, 2);
dish.get(4);
assert.strictEqual(dish.type, 4);
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");
dish.get("number");
assert.strictEqual(dish.type, 2);
assert.strictEqual(dish.value, 100);
}),
it("Dish translation: ArrayBuffer and byte array", () => {
const dish = new Dish(new Uint8Array([1, 2, 3]), 0);
dish.get(4);
// Check intermediate value
const check = new Uint8Array(dish.value);
assert.deepEqual(check, new Uint8Array([1, 2, 3]));
// Check converts back OK
dish.get(0);
assert.deepEqual(dish.value, [1, 2, 3]);
}),
it("Dish translation: ArrayBuffer and HTML", () => {
const html = `<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
</head>
<body>
<a href="https://github.com">Click here</a>
<script src="script.js"></script>
</body>
</html>`.replace(/\n|\s{4}/g, ""); //remove newlines, tabs
const dish = new Dish(html, Dish.HTML);
dish.get(4);
dish.get(3);
assert.strictEqual(dish.value, "Click here");
}),
it("Dish translation: ArrayBuffer and BigNumber", () => {
const number = BigNumber(4001);
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.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");
dish.get(5);
assert.deepStrictEqual(dish.value, number);
}),
it("Dish translation: ArrayBuffer and JSON", () => {
const jsonString = "{\"a\": 123455, \"b\": { \"aa\": [1,2,3]}}";
const dish = new Dish(JSON.parse(jsonString), Dish.JSON);
dish.get(Dish.ARRAY_BUFFER);
dish.get(Dish.JSON);
assert.deepStrictEqual(dish.value, JSON.parse(jsonString));
}),
it("Dish translation: ArrayBuffer and File", () => {
const file = new File("abcd", "unknown");
const dish = new Dish(file, Dish.FILE);
dish.get(Dish.ARRAY_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");
dish.get(Dish.FILE);
assert.deepStrictEqual(dish.value.data, file.data);
assert.strictEqual(dish.value.name, file.name);
assert.strictEqual(dish.value.type, file.type);
// Do not test lastModified
}),
it("Dish translation: ArrayBuffer and ListFile", () => {
const file1 = new File("abcde", "unknown");
const file2 = new File("fghijk", "unknown");
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, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b]).buffer);
assert.strictEqual(dish.value.byteLength, 11);
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("");
assert.strictEqual(actual, "abcdefghijk");
}),
]);

View file

@ -0,0 +1,375 @@
/* eslint no-console: 0 */
/**
* nodeApi.js
*
* Test node api utilities
*
* @author d98762625 [d98762625@gmail.com]
* @copyright Crown Copyright 2018
* @license Apache-2.0
*/
import assert from "assert";
import it from "../assertionHandler.mjs";
import chef from "../../../src/node/index.mjs";
import OperationError from "../../../src/core/errors/OperationError.mjs";
import NodeDish from "../../../src/node/NodeDish.mjs";
import { toBase32} from "../../../src/node/index.mjs";
import TestRegister from "../../lib/TestRegister.mjs";
TestRegister.addApiTests([
it("should have some operations", () => {
assert(chef);
assert(chef.toBase32);
assert(chef.setUnion);
assert(!chef.randomFunction);
}),
it("should export other functions at top level", () => {
assert(toBase32);
}),
it("should be synchronous", () => {
try {
const result = chef.toBase32("input");
assert.notEqual("something", result);
} catch (e) {
// shouldnt reach here
assert(false);
}
try {
const fail = chef.setUnion("1");
// shouldnt get here
assert(!fail || false);
} catch (e) {
assert(true);
}
}),
it("should not catch Errors", () => {
try {
chef.setUnion("1");
assert(false);
} catch (e) {
assert(e instanceof OperationError);
}
}),
it("should accept arguments in object format for operations", () => {
const result = chef.setUnion("1 2 3 4:3 4 5 6", {
itemDelimiter: " ",
sampleDelimiter: ":"
});
assert.equal(result.value, "1 2 3 4 5 6");
}),
it("should accept just some of the optional arguments being overriden", () => {
const result = chef.setIntersection("1 2 3 4 5\\n\\n3 4 5", {
itemDelimiter: " ",
});
assert.equal(result.value, "3 4 5");
}),
it("should accept no override arguments and just use the default values", () => {
const result = chef.powerSet("1,2,3");
assert.equal(result.value, "\n3\n2\n1\n2,3\n1,3\n1,2\n1,2,3\n");
}),
it("should return an object with a .to method", () => {
const result = chef.toBase32("input");
assert(result.to);
assert.equal(result.to("string"), "NFXHA5LU");
}),
it("should return an object with a .get method", () => {
const result = chef.toBase32("input");
assert(result.get);
assert.equal(result.get("string"), "NFXHA5LU");
}),
it("should return a NodeDish", async () => {
const result = chef.toBase32("input");
assert(result instanceof NodeDish);
}),
it("should coerce to a string as you expect", () => {
const result = chef.fromBase32(chef.toBase32("something"));
assert.equal(String(result), "something");
// This kind of coercion uses toValue
assert.equal(""+result, "NaN");
}),
it("should coerce to a number as you expect", () => {
const result = chef.fromBase32(chef.toBase32("32"));
assert.equal(3 + result, 35);
}),
it("chef.help: should exist", () => {
assert(chef.help);
}),
it("chef.help: should describe a operation", () => {
const result = chef.help("tripleDESDecrypt");
assert.strictEqual(result[0].name, "Triple DES Decrypt");
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.");
assert.strictEqual(result[0].args.length, 5);
}),
it("chef.help: null for invalid operation", () => {
const result = chef.help("some invalid function name");
assert.strictEqual(result, null);
}),
it("chef.help: takes a wrapped operation as input", () => {
const result = chef.help(chef.toBase32);
assert.strictEqual(result[0].name, "To Base32");
assert.strictEqual(result[0].module, "Default");
}),
it("chef.help: returns multiple results", () => {
const result = chef.help("base 64");
assert.strictEqual(result.length, 10);
}),
it("chef.help: looks in description for matches too", () => {
// string only in one operation's description.
const result = chef.help("Converts a unit of data to another format.");
assert.strictEqual(result.length, 1);
assert.strictEqual(result[0].name, "Convert data units");
}),
it("chef.help: lists name matches before desc matches", () => {
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.ok(result[result.length - 1].description.includes("checksum"));
}),
it("chef.help: exact name match only returns one result", () => {
const result = chef.help("MD5");
assert.strictEqual(result.length, 1);
assert.strictEqual(result[0].name, "MD5");
}),
it("chef.help: exact match ignores whitespace", () => {
const result = chef.help("tobase64");
assert.strictEqual(result.length, 1);
assert.strictEqual(result[0].name, "To Base64");
}),
it("chef.bake: should exist", () => {
assert(chef.bake);
}),
it("chef.bake: should return NodeDish", () => {
const result = chef.bake("input", "to base 64");
assert(result instanceof NodeDish);
}),
it("chef.bake: should take an input and an op name and perform it", () => {
const result = chef.bake("some input", "to base 32");
assert.strictEqual(result.toString(), "ONXW2ZJANFXHA5LU");
}),
it("chef.bake: should complain if recipe isnt a valid object", () => {
try {
chef.bake("some input", 3264);
} catch (e) {
assert.strictEqual(e.name, "TypeError");
assert.strictEqual(e.message, "Recipe can only contain function names or functions");
}
}),
it("chef.bake: Should complain if string op is invalid", () => {
try {
chef.bake("some input", "not a valid operation");
assert.fail("Shouldn't be hit");
} catch (e) {
assert.strictEqual(e.name, "TypeError");
assert.strictEqual(e.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");
}),
it("chef.bake: Should complain if an invalid operation is inputted", () => {
try {
chef.bake("https://google.com/search?q=help", () => {});
assert.fail("Shouldn't be hit");
} catch (e) {
assert.strictEqual(e.name, "TypeError");
assert.strictEqual(e.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");
}),
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("hello", ["to base 64"]);
assert.strictEqual(result.toString(), "aGVsbG8=");
}),
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");
}),
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");
}),
it("should complain if an invalid operation is inputted as part of array", () => {
try {
chef.bake("something", [() => {}]);
} catch (e) {
assert.strictEqual(e.name, "TypeError");
assert.strictEqual(e.message, "Inputted function not a Chef operation.");
}
}),
it("chef.bake: should take single JSON object describing op and args OBJ", () => {
const result = chef.bake("some input", {
op: chef.toHex,
args: {
Delimiter: "Colon"
}
});
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", () => {
const result = chef.bake("some input", {
op: chef.toHex,
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", () => {
try {
chef.bake("some input", {
op: () => {},
args: ["Colon"],
});
} catch (e) {
assert.strictEqual(e.name, "TypeError");
assert.strictEqual(e.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"]
},
{
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");
}),
it("chef.bake: should handle op with multiple args", () => {
const result = chef.bake("some input", {
op: "to morse code",
args: {
formatOptions: "Dash/Dot",
wordDelimiter: "Comma",
letterDelimiter: "Backslash",
}
});
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");
}),
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] }
]);
assert.strictEqual(result.toString(), "begin_something_anananaaaaak_da_aaak_da_aaaaananaaaaaaan_da_aaaaaaanan_da_aaak_end_something");
}),
it("Excluded operations: throw a sensible error when you try and call one", () => {
try {
chef.fork();
} catch (e) {
assert.strictEqual(e.type, "ExcludedOperationError");
assert.strictEqual(e.message, "Sorry, the Fork operation is not available in the Node.js version of CyberChef.");
}
}),
it("Excluded operations: throw a sensible error when you try and call one", () => {
try {
chef.renderImage();
} catch (e) {
assert.strictEqual(e.type, "ExcludedOperationError");
assert.strictEqual(e.message, "Sorry, the RenderImage operation is not available in the Node.js version of CyberChef.");
}
}),
it("Operation arguments: should be accessible from operation object if op has array arg", () => {
assert.ok(chef.toCharcode.args);
assert.deepEqual(chef.unzip.args, {
password: {
type: "binaryString",
value: "",
},
verifyResult: {
type: "boolean",
value: false,
}
});
}),
it("Operation arguments: should have key for each argument in operation", () => {
assert.ok(chef.convertDistance.args.inputUnits);
assert.ok(chef.convertDistance.args.outputUnits);
assert.strictEqual(chef.bitShiftRight.args.amount.type, "number");
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.defangURL.args.process.options[1], "Only full URLs");
}),
]);

File diff suppressed because it is too large Load diff

12
tests/operations/Dish.mjs Normal file
View file

@ -0,0 +1,12 @@
import TestRegister from "../../lib/TestRegister.mjs";
import Dish from "../../src/core/Dish.mjs";
import it from "../node/assertionHandler.mjs";
import assert from "assert";
TestRegister.addApiTests([
it("Dish - presentAs: should exist", () => {
const dish = new Dish();
assert(dish.presentAs);
}),
]);

View file

@ -11,18 +11,12 @@
* @license Apache-2.0
*/
// Define global environment functions
global.ENVIRONMENT_IS_WORKER = function() {
return typeof importScripts === "function";
};
global.ENVIRONMENT_IS_NODE = function() {
return typeof process === "object" && typeof require === "function";
};
global.ENVIRONMENT_IS_WEB = function() {
return typeof window === "object";
};
import {
setLongTestFailure,
logTestReport,
} from "../lib/utils";
import TestRegister from "./TestRegister";
import TestRegister from "../lib/TestRegister.mjs";
import "./tests/BCD";
import "./tests/BSON";
import "./tests/Base58";
@ -49,9 +43,11 @@ import "./tests/Hash";
import "./tests/HaversineDistance";
import "./tests/Hexdump";
import "./tests/Image";
import "./tests/IndexOfCoincidence";
import "./tests/Jump";
import "./tests/JSONBeautify";
import "./tests/JSONMinify";
import "./tests/JSONtoCSV";
import "./tests/JWTDecode";
import "./tests/JWTSign";
import "./tests/JWTVerify";
@ -95,81 +91,20 @@ import "./tests/ParseSSHHostKey";
// Cannot test operations that use the File type yet
//import "./tests/SplitColourChannels";
let allTestsPassing = true;
const testStatusCounts = {
total: 0,
// import "./tests/nodeApi/nodeApi";
// import "./tests/nodeApi/ops";
const testStatus = {
allTestsPassing: true,
counts: {
total: 0,
}
};
setLongTestFailure();
/**
* Helper function to convert a status to an icon.
*
* @param {string} status
* @returns {string}
*/
function statusToIcon(status) {
const icons = {
erroring: "🔥",
failing: "❌",
passing: "✔️️",
};
return icons[status] || "?";
}
/**
* Displays a given test result in the console.
*
* @param {Object} testResult
*/
function handleTestResult(testResult) {
allTestsPassing = allTestsPassing && testResult.status === "passing";
const newCount = (testStatusCounts[testResult.status] || 0) + 1;
testStatusCounts[testResult.status] = newCount;
testStatusCounts.total += 1;
console.log([
statusToIcon(testResult.status),
testResult.test.name
].join(" "));
if (testResult.output) {
console.log(
testResult.output
.trim()
.replace(/^/, "\t")
.replace(/\n/g, "\n\t")
);
}
}
/**
* Fail if the process takes longer than 60 seconds.
*/
setTimeout(function() {
console.log("Tests took longer than 60 seconds to run, returning.");
process.exit(1);
}, 60 * 1000);
const logOpsTestReport = logTestReport.bind(null, testStatus);
TestRegister.runTests()
.then(function(results) {
results.forEach(handleTestResult);
.then(logOpsTestReport);
console.log("\n");
for (const testStatus in testStatusCounts) {
const count = testStatusCounts[testStatus];
if (count > 0) {
console.log(testStatus.toUpperCase(), count);
}
}
if (!allTestsPassing) {
console.log("\nFailing tests:\n");
results.filter(r => r.status !== "passing").forEach(handleTestResult);
}
process.exit(allTestsPassing ? 0 : 1);
});

View file

@ -5,7 +5,7 @@
* @copyright Crown Copyright 2017
* @license Apache-2.0
*/
import TestRegister from "../TestRegister";
import TestRegister from "../../lib/TestRegister.mjs";
TestRegister.addTests([
{

View file

@ -5,7 +5,7 @@
* @copyright Crown Copyright 2019
* @license Apache-2.0
*/
import TestRegister from "../TestRegister";
import TestRegister from "../../lib/TestRegister.mjs";
TestRegister.addTests([
{

View file

@ -5,7 +5,7 @@
* @copyright Crown Copyright 2019
* @license Apache-2.0
*/
import TestRegister from "../TestRegister";
import TestRegister from "../../lib/TestRegister.mjs";
TestRegister.addTests([
{

View file

@ -6,7 +6,7 @@
* @copyright Crown Copyright 2018
* @license Apache-2.0
*/
import TestRegister from "../TestRegister";
import TestRegister from "../../lib/TestRegister.mjs";
TestRegister.addTests([
{

View file

@ -6,7 +6,7 @@
* @copyright Crown Copyright 2017
* @license Apache-2.0
*/
import TestRegister from "../TestRegister";
import TestRegister from "../../lib/TestRegister.mjs";
TestRegister.addTests([
{

View file

@ -7,7 +7,7 @@
* @license Apache-2.0
*/
import TestRegister from "../TestRegister";
import TestRegister from "../../lib/TestRegister.mjs";
TestRegister.addTests([
{

View file

@ -6,7 +6,7 @@
* @copyright Crown Copyright 2018
* @license Apache-2.0
*/
import TestRegister from "../TestRegister";
import TestRegister from "../../lib/TestRegister.mjs";
const ALL_BYTES = [
"\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f",

View file

@ -5,7 +5,7 @@
* @copyright Crown Copyright 2017
* @license Apache-2.0
*/
import TestRegister from "../TestRegister";
import TestRegister from "../../lib/TestRegister.mjs";
TestRegister.addTests([
{

View file

@ -4,7 +4,7 @@
* @copyright Crown Copyright 2019
* @license Apache-2.0
*/
import TestRegister from "../TestRegister";
import TestRegister from "../../lib/TestRegister.mjs";
TestRegister.addTests([
{

View file

@ -5,7 +5,7 @@
* @copyright Crown Copyright 2017
* @license Apache-2.0
*/
import TestRegister from "../TestRegister";
import TestRegister from "../../lib/TestRegister.mjs";
const ALL_BYTES = [
"\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f",

View file

@ -6,7 +6,7 @@
* @copyright Crown Copyright 2018
* @license Apache-2.0
*/
import TestRegister from "../TestRegister";
import TestRegister from "../../lib/TestRegister.mjs";
const EXAMPLE_CSV = `A,B,C,D,E,F\r
1,2,3,4,5,6\r

View file

@ -6,7 +6,7 @@
* @copyright Crown Copyright 2018
* @license Apache-2.0
*/
import TestRegister from "../TestRegister";
import TestRegister from "../../lib/TestRegister.mjs";
TestRegister.addTests([
{

View file

@ -5,7 +5,7 @@
* @copyright Crown Copyright 2017
* @license Apache-2.0
*/
import TestRegister from "../TestRegister";
import TestRegister from "../../lib/TestRegister.mjs";
TestRegister.addTests([
{

View file

@ -5,7 +5,7 @@
* @copyright Crown Copyright 2019
* @license Apache-2.0
*/
import TestRegister from "../TestRegister";
import TestRegister from "../../lib/TestRegister.mjs";
TestRegister.addTests([
{

View file

@ -5,7 +5,7 @@
* @copyright Crown Copyright 2018
* @license Apache-2.0
*/
import TestRegister from "../TestRegister";
import TestRegister from "../../lib/TestRegister.mjs";
const BASIC_STRING = "The ships hung in the sky in much the same way that bricks don't.";
const UTF8_STR = "ნუ პანიკას";
@ -29,6 +29,127 @@ const ALL_BYTES = [
].join("");
TestRegister.addTests([
{
name: "CRC-8: nothing",
input: "",
expectedOutput: "00",
recipeConfig: [
{
"op": "CRC-8 Checksum",
"args": ["CRC-8"]
}
]
},
{
name: "CRC-8: default check",
input: "123456789",
expectedOutput: "f4",
recipeConfig: [
{
"op": "CRC-8 Checksum",
"args": ["CRC-8"]
}
]
},
{
name: "CRC-8: CDMA2000",
input: "123456789",
expectedOutput: "da",
recipeConfig: [
{
"op": "CRC-8 Checksum",
"args": ["CRC-8/CDMA2000"]
}
]
},
{
name: "CRC-8: DARC",
input: "123456789",
expectedOutput: "15",
recipeConfig: [
{
"op": "CRC-8 Checksum",
"args": ["CRC-8/DARC"]
}
]
},
{
name: "CRC-8: DVB-S2",
input: "123456789",
expectedOutput: "bc",
recipeConfig: [
{
"op": "CRC-8 Checksum",
"args": ["CRC-8/DVB-S2"]
}
]
},
{
name: "CRC-8: EBU",
input: "123456789",
expectedOutput: "97",
recipeConfig: [
{
"op": "CRC-8 Checksum",
"args": ["CRC-8/EBU"]
}
]
},
{
name: "CRC-8: I-CODE",
input: "123456789",
expectedOutput: "7e",
recipeConfig: [
{
"op": "CRC-8 Checksum",
"args": ["CRC-8/I-CODE"]
}
]
},
{
name: "CRC-8: ITU",
input: "123456789",
expectedOutput: "a1",
recipeConfig: [
{
"op": "CRC-8 Checksum",
"args": ["CRC-8/ITU"]
}
]
},
{
name: "CRC-8: MAXIM",
input: "123456789",
expectedOutput: "a1",
recipeConfig: [
{
"op": "CRC-8 Checksum",
"args": ["CRC-8/MAXIM"]
}
]
},
{
name: "CRC-8: ROHC",
input: "123456789",
expectedOutput: "d0",
recipeConfig: [
{
"op": "CRC-8 Checksum",
"args": ["CRC-8/ROHC"]
}
]
},
{
name: "CRC-8: WCDMA",
input: "123456789",
expectedOutput: "25",
recipeConfig: [
{
"op": "CRC-8 Checksum",
"args": ["CRC-8/WCDMA"]
}
]
},
{
name: "CRC-16: nothing",
input: "",
@ -116,5 +237,5 @@ TestRegister.addTests([
"args": []
}
]
},
}
]);

View file

@ -7,7 +7,7 @@
* @copyright Crown Copyright 2018
* @license Apache-2.0
*/
import TestRegister from "../TestRegister";
import TestRegister from "../../lib/TestRegister.mjs";
TestRegister.addTests([

View file

@ -7,7 +7,7 @@
* @copyright Crown Copyright 2017
* @license Apache-2.0
*/
import TestRegister from "../TestRegister";
import TestRegister from "../../lib/TestRegister.mjs";
const JSON_TEST_DATA = {
"store": {

View file

@ -6,7 +6,7 @@
* @copyright Crown Copyright 2018
* @license Apache-2.0
*/
import TestRegister from "../TestRegister";
import TestRegister from "../../lib/TestRegister.mjs";
const ALL_BYTES = [
"\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f",

View file

@ -5,7 +5,7 @@
* @copyright Crown Copyright 2017
* @license Apache-2.0
*/
import TestRegister from "../TestRegister";
import TestRegister from "../../lib/TestRegister.mjs";
TestRegister.addTests([
{

View file

@ -6,7 +6,7 @@
* @copyright Crown Copyright 2018
* @license Apache-2.0
*/
import TestRegister from "../TestRegister";
import TestRegister from "../../lib/TestRegister.mjs";
TestRegister.addTests([
{

View file

@ -18,7 +18,7 @@
* UTM: 30N 699456 5709791,
*/
import TestRegister from "../TestRegister";
import TestRegister from "../../lib/TestRegister.mjs";
TestRegister.addTests([
{

View file

@ -6,7 +6,7 @@
* @copyright Crown Copyright 2018
* @license Apache-2.0
*/
import TestRegister from "../TestRegister";
import TestRegister from "../../lib/TestRegister.mjs";
TestRegister.addTests([
/**
@ -209,9 +209,9 @@ Tag: 16a3e732a605cc9ca29108f742ca0743`,
{
name: "AES Encrypt: AES-128-GCM, Binary",
input: "7a0e643132750e96d805d11e9e48e281fa39a41039286423cc1c045e5442b40bf1c3f2822bded3f9c8ef11cb25da64dda9c7ab87c246bd305385150c98f31465c2a6180fe81d31ea289b916504d5a12e1de26cb10adba84a0cb0c86f94bc14bc554f3018",
expectedOutput: `fa17fcbf5e8763322c1b0c8562e1512ed9d702ef70c1643572b9de3e34ae6b535e6c1b992432aa6d06fb6f80c861262aef66e7c26035afe77bd3861261e4e092b523f058f8ebef2143db21bc16d02f7a011efb07419300cb41c3b884d1d8d6a766b8963c
expectedOutput: `5a29debb5c5f38cdf8aee421bd94dbbf3399947faddf205f88b3ad8ecb0c51214ec0e28bf78942dfa212d7eb15259bbdcac677b4c05f473eeb9331d74f31d441d97d56eb5c73b586342d72128ca528813543dc0fc7eddb7477172cc9194c18b2e1383e4e
Tag: fa6bbb34c8cde65a3d7b93fb094fc84f`,
Tag: 70fad2ca19412c20f40fd06918736e56`,
recipeConfig: [
{
"op": "AES Encrypt",
@ -301,9 +301,9 @@ Tag: fa6bbb34c8cde65a3d7b93fb094fc84f`,
{
name: "AES Encrypt: AES-192-GCM, Binary",
input: "7a0e643132750e96d805d11e9e48e281fa39a41039286423cc1c045e5442b40bf1c3f2822bded3f9c8ef11cb25da64dda9c7ab87c246bd305385150c98f31465c2a6180fe81d31ea289b916504d5a12e1de26cb10adba84a0cb0c86f94bc14bc554f3018",
expectedOutput: `ed22946f96964d300b45f5ce2d9601ba87682da1a603c90e6d4f7738729b0602f613ee392c9bfc7792594474f1213fb99185851f02ece4df0e93995e49f97aa4d0a337d7a80d83e4219dae5a3d36658f8659cdd5ed7c32707f98656fab7fb43f7a61e37c
expectedOutput: `318b479d919d506f0cd904f2676fab263a7921b6d7e0514f36e03ae2333b77fa66ef5600babcb2ee9718aeb71fc357412343c1f2cb351d8715bb0aedae4a6468124f9c4aaf6a721b306beddbe63a978bec8baeeba4b663be33ee5bc982746bd4aed1c38b
Tag: be17cb31edb77f648b9d1032b235b33d`,
Tag: 86db597d5302595223cadbd990f1309b`,
recipeConfig: [
{
"op": "AES Encrypt",
@ -393,9 +393,9 @@ Tag: be17cb31edb77f648b9d1032b235b33d`,
{
name: "AES Encrypt: AES-256-GCM, Binary",
input: "7a0e643132750e96d805d11e9e48e281fa39a41039286423cc1c045e5442b40bf1c3f2822bded3f9c8ef11cb25da64dda9c7ab87c246bd305385150c98f31465c2a6180fe81d31ea289b916504d5a12e1de26cb10adba84a0cb0c86f94bc14bc554f3018",
expectedOutput: `e3f1b236eaf3b9df69df8133a1b417fa42b242d8ad49e4d2f3469aca7e2a41737e4f2c8a0d212143287088fad51743577dc6dfa8ed328ca90113cbeb9b137926b2168cc037bdc371777e6ee02b9d9c017b6054fd83d43b4885fbe9c044a8574f1491a893
expectedOutput: `1287f188ad4d7ab0d9ff69b3c29cb11f861389532d8cb9337181da2e8cfc74a84927e8c0dd7a28a32fd485afe694259a63c199b199b95edd87c7aa95329feac340f2b78b72956a85f367044d821766b1b7135815571df44900695f1518cf3ae38ecb650f
Tag: 23ddbd3ee4de33f98a9ea9a170bdf268`,
Tag: 821b1e5f32dad052e502775a523d957a`,
recipeConfig: [
{
"op": "AES Encrypt",

View file

@ -6,7 +6,7 @@
* @copyright Crown Copyright 2017
* @license Apache-2.0
*/
import TestRegister from "../TestRegister";
import TestRegister from "../../lib/TestRegister.mjs";
TestRegister.addTests([
{

View file

@ -4,7 +4,7 @@
* @copyright Crown Copyright 2019
* @license Apache-2.0
*/
import TestRegister from "../TestRegister";
import TestRegister from "../../lib/TestRegister.mjs";
TestRegister.addTests([
{

View file

@ -5,7 +5,7 @@
* @copyright Crown Copyright 2017
* @license Apache-2.0
*/
import TestRegister from "../TestRegister";
import TestRegister from "../../lib/TestRegister.mjs";
TestRegister.addTests([
{

View file

@ -6,7 +6,7 @@
* @copyright Crown Copyright 2018
* @license Apache-2.0
*/
import TestRegister from "../TestRegister";
import TestRegister from "../../lib/TestRegister.mjs";
TestRegister.addTests([
{

View file

@ -5,7 +5,7 @@
* @copyright Crown Copyright 2018
* @licence Apache-2.0
*/
import TestRegister from "../TestRegister";
import TestRegister from "../../lib/TestRegister.mjs";
TestRegister.addTests([
{

View file

@ -0,0 +1,55 @@
/**
* To Geohash tests
*
* @author gchq77703
* @copyright Crown Copyright 2018
* @license Apache-2.0
*/
import TestRegister from "../../lib/TestRegister.mjs";
TestRegister.addTests([
{
name: "From Geohash",
input: "ww8p1r4t8",
expectedOutput: "37.83238649368286,112.55838632583618",
recipeConfig: [
{
op: "From Geohash",
args: [],
},
],
},
{
name: "From Geohash",
input: "ww8p1r",
expectedOutput: "37.83416748046875,112.5604248046875",
recipeConfig: [
{
op: "From Geohash",
args: [],
},
],
},
{
name: "From Geohash",
input: "ww8",
expectedOutput: "37.265625,113.203125",
recipeConfig: [
{
op: "From Geohash",
args: [],
},
],
},
{
name: "From Geohash",
input: "w",
expectedOutput: "22.5,112.5",
recipeConfig: [
{
op: "From Geohash",
args: [],
},
],
},
]);

View file

@ -5,7 +5,7 @@
* @copyright Crown Copyright 2017
* @license Apache-2.0
*/
import TestRegister from "../TestRegister";
import TestRegister from "../../lib/TestRegister.mjs";
TestRegister.addTests([
{
@ -1033,6 +1033,72 @@ TestRegister.addTests([
}
]
},
{
name: "Streebog-256: Test Case 1",
input: "",
expectedOutput: "3f539a213e97c802cc229d474c6aa32a825a360b2a933a949fd925208d9ce1bb",
recipeConfig: [
{
op: "Streebog",
args: ["256"]
}
]
},
{
name: "Streebog-256: Test Case 2",
input: "The quick brown fox jumps over the lazy dog",
expectedOutput: "3e7dea7f2384b6c5a3d0e24aaa29c05e89ddd762145030ec22c71a6db8b2c1f4",
recipeConfig: [
{
op: "Streebog",
args: ["256"]
}
]
},
{
name: "Streebog-512: Test Case 1",
input: "",
expectedOutput: "8e945da209aa869f0455928529bcae4679e9873ab707b55315f56ceb98bef0a7362f715528356ee83cda5f2aac4c6ad2ba3a715c1bcd81cb8e9f90bf4c1c1a8a",
recipeConfig: [
{
op: "Streebog",
args: ["512"]
}
]
},
{
name: "Streebog-512: Test Case 2",
input: "The quick brown fox jumps over the lazy dog",
expectedOutput: "d2b793a0bb6cb5904828b5b6dcfb443bb8f33efc06ad09368878ae4cdc8245b97e60802469bed1e7c21a64ff0b179a6a1e0bb74d92965450a0adab69162c00fe",
recipeConfig: [
{
op: "Streebog",
args: ["512"]
}
]
},
{
name: "GOST R 34.11-94: Test Case 1",
input: "",
expectedOutput: "981e5f3ca30c841487830f84fb433e13ac1101569b9c13584ac483234cd656c0",
recipeConfig: [
{
op: "GOST hash",
args: ["D-A"]
}
]
},
{
name: "GOST R 34.11-94: Test Case 2",
input: "This is message, length=32 bytes",
expectedOutput: "2cefc2f7b7bdc514e18ea57fa74ff357e7fa17d652c75f69cb1be7893ede48eb",
recipeConfig: [
{
op: "GOST hash",
args: ["D-A"]
}
]
}
/*{ // This takes a LONG time to run (over a minute usually).
name: "Scrypt: RFC test vector 4",
input: "pleaseletmein",

View file

@ -5,7 +5,7 @@
* @copyright Crown Copyright 2018
* @license Apache-2.0
*/
import TestRegister from "../TestRegister";
import TestRegister from "../../lib/TestRegister.mjs";
TestRegister.addTests([
{

View file

@ -6,7 +6,7 @@
* @copyright Crown Copyright 2018
* @license Apache-2.0
*/
import TestRegister from "../TestRegister";
import TestRegister from "../../lib/TestRegister.mjs";
const ALL_BYTES = [
"\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f",

View file

@ -7,7 +7,7 @@
* @copyright Crown Copyright 2017
* @license Apache-2.0
*/
import TestRegister from "../TestRegister";
import TestRegister from "../../lib/TestRegister.mjs";
TestRegister.addTests([
{

View file

@ -0,0 +1,22 @@
/**
* Index of Coincidence tests.
*
* @author George O [georgeomnet+cyberchef@gmail.com]
* @copyright Crown Copyright 2019
* @license Apache-2.0
*/
import TestRegister from "../../lib/TestRegister.mjs";
TestRegister.addTests([
{
name: "Index of Coincidence",
input: "Hello world, this is a test to determine the correct IC value.",
expectedMatch: /^Index of Coincidence: 0\.07142857142857142\nNormalized: 1\.857142857142857/,
recipeConfig: [
{
"op": "Index of Coincidence",
"args": []
},
],
},
]);

View file

@ -6,7 +6,7 @@
* @copyright Crown Copyright 2018
* @license Apache-2.0
*/
import TestRegister from "../TestRegister";
import TestRegister from "../../lib/TestRegister.mjs";
TestRegister.addTests([
{

View file

@ -6,7 +6,7 @@
* @copyright Crown Copyright 2018
* @license Apache-2.0
*/
import TestRegister from "../TestRegister";
import TestRegister from "../../lib/TestRegister.mjs";
TestRegister.addTests([
{

View file

@ -0,0 +1,93 @@
/**
* JSON to CSV tests.
*
* @author mshwed [m@ttshwed.com]
*
* @copyright Crown Copyright 2019
* @license Apache-2.0
*/
import TestRegister from "../../lib/TestRegister.mjs";
const EXPECTED_CSV_SINGLE = "a,b,c\r\n1,2,3\r\n";
const EXPECTED_CSV_MULTIPLE = "a,b,c\r\n1,2,3\r\n1,2,3\r\n";
const EXPECTED_CSV_EMPTY = "\r\n\r\n";
TestRegister.addTests([
{
name: "JSON to CSV: strings as values",
input: JSON.stringify({a: "1", b: "2", c: "3"}),
expectedOutput: EXPECTED_CSV_SINGLE,
recipeConfig: [
{
op: "JSON to CSV",
args: [",", "\\r\\n"]
},
],
},
{
name: "JSON to CSV: numbers as values",
input: JSON.stringify({a: 1, b: 2, c: 3}),
expectedOutput: EXPECTED_CSV_SINGLE,
recipeConfig: [
{
op: "JSON to CSV",
args: [",", "\\r\\n"]
},
],
},
{
name: "JSON to CSV: numbers and strings as values",
input: JSON.stringify({a: 1, b: "2", c: 3}),
expectedOutput: EXPECTED_CSV_SINGLE,
recipeConfig: [
{
op: "JSON to CSV",
args: [",", "\\r\\n"]
},
],
},
{
name: "JSON to CSV: JSON as an array",
input: JSON.stringify([{a: 1, b: "2", c: 3}]),
expectedOutput: EXPECTED_CSV_SINGLE,
recipeConfig: [
{
op: "JSON to CSV",
args: [",", "\\r\\n"]
},
],
},
{
name: "JSON to CSV: multiple JSON values in an array",
input: JSON.stringify([{a: 1, b: "2", c: 3}, {a: 1, b: "2", c: 3}]),
expectedOutput: EXPECTED_CSV_MULTIPLE,
recipeConfig: [
{
op: "JSON to CSV",
args: [",", "\\r\\n"]
},
],
},
{
name: "JSON to CSV: empty JSON",
input: JSON.stringify({}),
expectedOutput: EXPECTED_CSV_EMPTY,
recipeConfig: [
{
op: "JSON to CSV",
args: [",", "\\r\\n"]
},
],
},
{
name: "JSON to CSV: empty JSON in array",
input: JSON.stringify([{}]),
expectedOutput: EXPECTED_CSV_EMPTY,
recipeConfig: [
{
op: "JSON to CSV",
args: [",", "\\r\\n"]
},
],
}
]);

View file

@ -6,7 +6,7 @@
* @copyright Crown Copyright 2018
* @license Apache-2.0
*/
import TestRegister from "../TestRegister";
import TestRegister from "../../lib/TestRegister.mjs";
const outputObject = JSON.stringify({
String: "SomeString",

View file

@ -6,7 +6,7 @@
* @copyright Crown Copyright 2018
* @license Apache-2.0
*/
import TestRegister from "../TestRegister";
import TestRegister from "../../lib/TestRegister.mjs";
const inputObject = JSON.stringify({
String: "SomeString",

View file

@ -6,7 +6,7 @@
* @copyright Crown Copyright 2018
* @license Apache-2.0
*/
import TestRegister from "../TestRegister";
import TestRegister from "../../lib/TestRegister.mjs";
const outputObject = JSON.stringify({
String: "SomeString",

View file

@ -6,7 +6,7 @@
* @copyright Crown Copyright 2018
* @license Apache-2.0
*/
import TestRegister from "../TestRegister";
import TestRegister from "../../lib/TestRegister.mjs";
TestRegister.addTests([
{

View file

@ -5,7 +5,7 @@
* @copyright Crown Copyright 2017
* @license Apache-2.0
*/
import TestRegister from "../TestRegister";
import TestRegister from "../../lib/TestRegister.mjs";
TestRegister.addTests([
{

File diff suppressed because one or more lines are too long

View file

@ -4,7 +4,7 @@
* @copyright Crown Copyright 2018
* @license Apache-2.0
*/
import TestRegister from "../TestRegister";
import TestRegister from "../../lib/TestRegister.mjs";
TestRegister.addTests([
{

View file

@ -6,7 +6,7 @@
* @copyright Crown Copyright 2017
* @license Apache-2.0
*/
import TestRegister from "../TestRegister";
import TestRegister from "../../lib/TestRegister.mjs";
TestRegister.addTests([
{

View file

@ -4,7 +4,7 @@
* @copyright Crown Copyright 2019
* @license Apache-2.0
*/
import TestRegister from "../TestRegister";
import TestRegister from "../../lib/TestRegister.mjs";
TestRegister.addTests([
{

View file

@ -6,7 +6,7 @@
* @copyright Crown Copyright 2017
* @license Apache-2.0
*/
import TestRegister from "../TestRegister";
import TestRegister from "../../lib/TestRegister.mjs";
TestRegister.addTests([
{

View file

@ -6,7 +6,7 @@
* @copyright Crown Copyright 2017
* @license Apache-2.0
*/
import TestRegister from "../TestRegister";
import TestRegister from "../../lib/TestRegister.mjs";
TestRegister.addTests([
{

View file

@ -5,7 +5,7 @@
* @copyright Crown Copyright 2018
* @license Apache-2.0
*/
import TestRegister from "../TestRegister";
import TestRegister from "../../lib/TestRegister.mjs";
const ASCII_TEXT = "A common mistake that people make when trying to design something completely foolproof is to underestimate the ingenuity of complete fools.";
@ -248,7 +248,8 @@ IOE1W/Zqmqzq+4frwnzWwYv9/U1RwIs/qlFVnzliREOzW+om8EncSSd7fQ==
=fEAT
-----END PGP MESSAGE-----
`,
expectedOutput: `Signed by PGP fingerprint: e94e06dd0b3744a0e970de9d84246548df98e485
expectedOutput: `Signed by PGP key ID: DF98E485
PGP fingerprint: e94e06dd0b3744a0e970de9d84246548df98e485
Signed on Tue, 29 May 2018 15:44:52 GMT
----------------------------------
${UTF8_TEXT}`,
@ -282,4 +283,30 @@ H2qMY1O7hezH3fp+EZzCAccJMtK7VPk13WAgMRH22HirG4aK1i75IVOtjBgObzDh
}
]
},
{
name: "PGP Verify: ASCII, Alice",
input: `-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256
A common mistake that people make when trying to design something completely foolproof is to underestimate the ingenuity of complete fools.
-----BEGIN PGP SIGNATURE-----
iLMEAQEIAB0WIQRLbJy6MLpYOr9qojE+2VNAUiMLOgUCXRTsvwAKCRA+2VNAUiML
OuaHBADMMNtsuN92Fb+UrDimsv6TDQpbJhDkwp9kZdKYP5HAmSYAhXBG7N+YCMw+
v2FSpUu9jJiPBm1K1SEwLufQVexoRv6RsBNolRFB07sArau0s0DnIXUchCZWvyTP
1KsjBnDr84U2b11H58g4DlTT4gQrz30rFuHz9AGmPAtDHbSXIA==
=vnk/
-----END PGP SIGNATURE-----`,
expectedOutput: `Signed by PGP key ID: DF98E485
PGP fingerprint: e94e06dd0b3744a0e970de9d84246548df98e485
Signed on Thu, 27 Jun 2019 16:20:15 GMT
----------------------------------
A common mistake that people make when trying to design something completely foolproof is to underestimate the ingenuity of complete fools.`,
recipeConfig: [
{
"op": "PGP Verify",
"args": [ALICE_PUBLIC]
}
]
}
]);

View file

@ -7,7 +7,7 @@
* @license Apache-2.0
*/
import TestRegister from "../TestRegister";
import TestRegister from "../../lib/TestRegister.mjs";
TestRegister.addTests([
{

View file

@ -5,7 +5,7 @@
* @copyright Crown Copyright 2017
* @license Apache-2.0
*/
import TestRegister from "../TestRegister";
import TestRegister from "../../lib/TestRegister.mjs";
TestRegister.addTests([
{

View file

@ -5,7 +5,7 @@
* @copyright Crown Copyright 2018
* @license Apache-2.0
*/
import TestRegister from "../TestRegister";
import TestRegister from "../../lib/TestRegister.mjs";
TestRegister.addTests([
{

View file

@ -6,7 +6,7 @@
* @license Apache-2.0
*/
import TestRegister from "../TestRegister";
import TestRegister from "../../lib/TestRegister.mjs";
TestRegister.addTests([
{

View file

@ -6,7 +6,7 @@
* @copyright Crown Copyright 2018
* @license Apache-2.0
*/
import TestRegister from "../TestRegister";
import TestRegister from "../../lib/TestRegister.mjs";
TestRegister.addTests([
{

View file

@ -6,7 +6,7 @@
* @license Apache-2.0
*/
import TestRegister from "../TestRegister";
import TestRegister from "../../lib/TestRegister.mjs";
TestRegister.addTests([
{

View file

@ -5,7 +5,7 @@
* @copyright Crown Copyright 2017
* @license Apache-2.0
*/
import TestRegister from "../TestRegister";
import TestRegister from "../../lib/TestRegister.mjs";
TestRegister.addTests([
{

View file

@ -6,7 +6,7 @@
* @copyright Crown Copyright 2018
* @license Apache-2.0
*/
import TestRegister from "../TestRegister";
import TestRegister from "../../lib/TestRegister.mjs";
TestRegister.addTests([
{

View file

@ -5,7 +5,7 @@
* @copyright Crown Copyright 2017
* @license Apache-2.0
*/
import TestRegister from "../TestRegister";
import TestRegister from "../../lib/TestRegister.mjs";
TestRegister.addTests([
{

View file

@ -6,7 +6,7 @@
* @copyright Crown Copyright 2018
* @license Apache-2.0
*/
import TestRegister from "../TestRegister";
import TestRegister from "../../lib/TestRegister.mjs";
TestRegister.addTests([

View file

@ -5,7 +5,7 @@
* @copyright Copyright 2017
* @license Apache-2.0
*/
import TestRegister from "../TestRegister";
import TestRegister from "../../lib/TestRegister.mjs";
TestRegister.addTests([
{

View file

@ -6,7 +6,7 @@
* @copyright Crown Copyright 2018
* @license Apache-2.0
*/
import TestRegister from "../TestRegister";
import TestRegister from "../../lib/TestRegister.mjs";
TestRegister.addTests([
{

View file

@ -6,7 +6,7 @@
* @copyright Crown Copyright 2018
* @license Apache-2.0
*/
import TestRegister from "../TestRegister";
import TestRegister from "../../lib/TestRegister.mjs";
TestRegister.addTests([
{

View file

@ -6,7 +6,7 @@
* @copyright Crown Copyright 2018
* @license Apache-2.0
*/
import TestRegister from "../TestRegister";
import TestRegister from "../../lib/TestRegister.mjs";
TestRegister.addTests([
{

File diff suppressed because one or more lines are too long

View file

@ -5,7 +5,7 @@
* @copyright Crown Copyright 2017
* @license Apache-2.0
*/
import TestRegister from "../TestRegister";
import TestRegister from "../../lib/TestRegister.mjs";
TestRegister.addTests([
{

View file

@ -6,7 +6,7 @@
* @copyright Crown Copyright 2018
* @license Apache-2.0
*/
import TestRegister from "../TestRegister";
import TestRegister from "../../lib/TestRegister.mjs";
TestRegister.addTests([
{

View file

@ -6,7 +6,7 @@
* @copyright Crown Copyright 2018
* @license Apache-2.0
*/
import TestRegister from "../TestRegister";
import TestRegister from "../../lib/TestRegister.mjs";
TestRegister.addTests([
{

View file

@ -6,7 +6,7 @@
* @copyright Crown Copyright 2018
* @license Apache-2.0
*/
import TestRegister from "../TestRegister";
import TestRegister from "../../lib/TestRegister.mjs";
TestRegister.addTests([
{

View file

@ -0,0 +1,55 @@
/**
* To Geohash tests
*
* @author gchq77703
* @copyright Crown Copyright 2018
* @license Apache-2.0
*/
import TestRegister from "../../lib/TestRegister.mjs";
TestRegister.addTests([
{
name: "To Geohash",
input: "37.8324,112.5584",
expectedOutput: "ww8p1r4t8",
recipeConfig: [
{
op: "To Geohash",
args: [9],
},
],
},
{
name: "To Geohash",
input: "37.9324,-112.2584",
expectedOutput: "9w8pv3ruj",
recipeConfig: [
{
op: "To Geohash",
args: [9],
},
],
},
{
name: "To Geohash",
input: "37.8324,112.5584",
expectedOutput: "ww8",
recipeConfig: [
{
op: "To Geohash",
args: [3],
},
],
},
{
name: "To Geohash",
input: "37.9324,-112.2584",
expectedOutput: "9w8pv3rujxy5b99",
recipeConfig: [
{
op: "To Geohash",
args: [15],
},
],
},
]);

View file

@ -6,7 +6,7 @@
* @copyright Crown Copyright 2018
* @license Apache-2.0
*/
import TestRegister from "../TestRegister";
import TestRegister from "../../lib/TestRegister.mjs";
TestRegister.addTests([
{

View file

@ -4,7 +4,7 @@
* @copyright Crown Copyright 2019
* @license Apache-2.0
*/
import TestRegister from "../TestRegister";
import TestRegister from "../../lib/TestRegister.mjs";
TestRegister.addTests([
{

View file

@ -6,7 +6,7 @@
* @copyright Crown Copyright 2019
* @license Apache-2.0
*/
import TestRegister from "../TestRegister";
import TestRegister from "../../lib/TestRegister.mjs";
TestRegister.addTests([
{