mirror of
https://github.com/gchq/CyberChef.git
synced 2025-06-15 10:44:50 -04:00
Merge branch 'master' into fernet
This commit is contained in:
commit
bc82f590d4
782 changed files with 87846 additions and 21883 deletions
|
@ -5,6 +5,9 @@
|
|||
* @copyright Crown Copyright 2018
|
||||
* @license Apache-2.0
|
||||
*/
|
||||
|
||||
const utils = require("./browserUtils.js");
|
||||
|
||||
module.exports = {
|
||||
before: browser => {
|
||||
browser
|
||||
|
@ -70,25 +73,26 @@ module.exports = {
|
|||
.moveToElement(toHex, 10, 10)
|
||||
.useCss()
|
||||
.waitForElementVisible(".popover-body", 1000)
|
||||
.doubleClick();
|
||||
.doubleClick("xpath", toHex);
|
||||
|
||||
// Confirm that it has been added to the recipe
|
||||
browser
|
||||
.useCss()
|
||||
.waitForElementVisible(op)
|
||||
.waitForElementVisible(op, 100)
|
||||
.expect.element(op).text.to.contain("To Hex");
|
||||
|
||||
// Enter input
|
||||
browser
|
||||
.useCss()
|
||||
.setValue("#input-text", "Don't Panic.")
|
||||
.sendKeys("#input-text .cm-content", "Don't Panic.")
|
||||
.pause(1000)
|
||||
.click("#bake");
|
||||
|
||||
// Check output
|
||||
browser
|
||||
.useCss()
|
||||
.waitForElementNotVisible("#stale-indicator", 500)
|
||||
.expect.element("#output-text").to.have.value.that.equals("44 6f 6e 27 74 20 50 61 6e 69 63 2e");
|
||||
.waitForElementNotVisible("#stale-indicator", 1000)
|
||||
.expect.element("#output-text .cm-content").text.that.equals("44 6f 6e 27 74 20 50 61 6e 69 63 2e");
|
||||
|
||||
// Clear recipe
|
||||
browser
|
||||
|
@ -106,6 +110,10 @@ module.exports = {
|
|||
loadOp("BSON deserialise", browser)
|
||||
.waitForElementNotVisible("#output-loader", 5000);
|
||||
|
||||
// Charts
|
||||
loadOp("Entropy", browser)
|
||||
.waitForElementNotVisible("#output-loader", 5000);
|
||||
|
||||
// Ciphers
|
||||
loadOp("AES Encrypt", browser)
|
||||
.waitForElementNotVisible("#output-loader", 5000);
|
||||
|
@ -134,6 +142,10 @@ module.exports = {
|
|||
loadOp("Encode text", browser)
|
||||
.waitForElementNotVisible("#output-loader", 5000);
|
||||
|
||||
// Hashing
|
||||
loadOp("Streebog", browser)
|
||||
.waitForElementNotVisible("#output-loader", 5000);
|
||||
|
||||
// Image
|
||||
loadOp("Extract EXIF", browser)
|
||||
.waitForElementNotVisible("#output-loader", 5000);
|
||||
|
@ -161,6 +173,73 @@ module.exports = {
|
|||
// UserAgent
|
||||
loadOp("Parse User Agent", browser)
|
||||
.waitForElementNotVisible("#output-loader", 5000);
|
||||
|
||||
// YARA
|
||||
loadOp("YARA Rules", browser)
|
||||
.waitForElementNotVisible("#output-loader", 5000);
|
||||
|
||||
browser.click("#clr-recipe");
|
||||
},
|
||||
|
||||
"Move around the UI": browser => {
|
||||
const otherCat = "//a[contains(@class, 'category-title') and contains(@data-target, '#catOther')]",
|
||||
genUUID = "//li[contains(@class, 'operation') and text()='Generate UUID']";
|
||||
|
||||
browser.useXpath();
|
||||
|
||||
// Scroll to a lower category
|
||||
browser
|
||||
.getLocationInView(otherCat)
|
||||
.expect.element(otherCat).to.be.visible;
|
||||
|
||||
// Open category
|
||||
browser
|
||||
.click(otherCat)
|
||||
.expect.element(genUUID).to.be.visible;
|
||||
|
||||
// Add op to recipe
|
||||
/* mouseButtonUp drops wherever the actual cursor is, not necessarily in the right place,
|
||||
so we can't test Sortable.js properly using Nightwatch. html-dnd doesn't work either.
|
||||
Instead of relying on drag and drop, we double click on the op to load it. */
|
||||
browser
|
||||
.getLocationInView(genUUID)
|
||||
.moveToElement(genUUID, 10, 10)
|
||||
.doubleClick("xpath", genUUID)
|
||||
.useCss()
|
||||
.waitForElementVisible(".operation .op-title", 1000)
|
||||
.waitForElementNotVisible("#stale-indicator", 1000)
|
||||
.expect.element("#output-text .cm-content").text.which.matches(/[\da-f-]{36}/);
|
||||
|
||||
browser.click("#clr-recipe");
|
||||
},
|
||||
|
||||
"Search": browser => {
|
||||
// Search for an op
|
||||
browser
|
||||
.useCss()
|
||||
.clearValue("#search")
|
||||
.setValue("#search", "md5")
|
||||
.useXpath()
|
||||
.waitForElementVisible("//ul[@id='search-results']//b[text()='MD5']", 1000);
|
||||
},
|
||||
|
||||
"Alert bar": browser => {
|
||||
// Bake nothing to create an empty output which can be copied
|
||||
utils.clear(browser);
|
||||
utils.bake(browser);
|
||||
|
||||
// Alert bar shows and contains correct content
|
||||
browser
|
||||
.click("#copy-output")
|
||||
.waitForElementVisible("#snackbar-container")
|
||||
.waitForElementVisible("#snackbar-container .snackbar-content")
|
||||
.expect.element("#snackbar-container .snackbar-content").text.to.equal("Copied raw output successfully.");
|
||||
|
||||
// Alert bar disappears after the correct amount of time
|
||||
// Should disappear after 2000ms
|
||||
browser
|
||||
.waitForElementNotPresent("#snackbar-container .snackbar-content", 2500)
|
||||
.waitForElementNotVisible("#snackbar-container");
|
||||
},
|
||||
|
||||
after: browser => {
|
704
tests/browser/01_io.js
Normal file
704
tests/browser/01_io.js
Normal file
|
@ -0,0 +1,704 @@
|
|||
/**
|
||||
* Tests for input and output of various types to ensure the editors work as expected
|
||||
* and retain data integrity, especially when it comes to special characters.
|
||||
*
|
||||
* @author n1474335 [n1474335@gmail.com]
|
||||
* @copyright Crown Copyright 2023
|
||||
* @license Apache-2.0
|
||||
*/
|
||||
|
||||
// import {
|
||||
// clear,
|
||||
// utils.setInput,
|
||||
// bake,
|
||||
// setChrEnc,
|
||||
// setEOLSeq,
|
||||
// copy,
|
||||
// paste,
|
||||
// loadRecipe,
|
||||
// expectOutput,
|
||||
// uploadFile,
|
||||
// uploadFolder
|
||||
// } from "./browserUtils.js";
|
||||
|
||||
const utils = require("./browserUtils.js");
|
||||
|
||||
const SPECIAL_CHARS = [
|
||||
"\u0000\u0001\u0002\u0003\u0004\u0005\u0006\u0007\u0008\u0009\u000a\u000b\u000c\u000d\u000e\u000f",
|
||||
"\u0010\u0011\u0012\u0013\u0014\u0015\u0016\u0017\u0018\u0019\u001a\u001b\u001c\u001d\u001e\u001f",
|
||||
"\u007f",
|
||||
"\u0080\u0081\u0082\u0083\u0084\u0085\u0086\u0087\u0088\u0089\u008a\u008b\u008c\u008d\u008e\u008f",
|
||||
"\u0090\u0091\u0092\u0093\u0094\u0095\u0096\u0097\u0098\u0099\u009a\u009b\u009c\u009d\u009e\u009f",
|
||||
"\u00ad\u061c\u200b\u200e\u200f\u2028\u2029\u202d\u202e\u2066\u2067\u2069\ufeff\ufff9\ufffa\ufffb\ufffc"
|
||||
].join("");
|
||||
|
||||
const ALL_BYTES = [
|
||||
"\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f",
|
||||
"\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f",
|
||||
"\x20\x21\x22\x23\x24\x25\x26\x27\x28\x29\x2a\x2b\x2c\x2d\x2e\x2f",
|
||||
"\x30\x31\x32\x33\x34\x35\x36\x37\x38\x39\x3a\x3b\x3c\x3d\x3e\x3f",
|
||||
"\x40\x41\x42\x43\x44\x45\x46\x47\x48\x49\x4a\x4b\x4c\x4d\x4e\x4f",
|
||||
"\x50\x51\x52\x53\x54\x55\x56\x57\x58\x59\x5a\x5b\x5c\x5d\x5e\x5f",
|
||||
"\x60\x61\x62\x63\x64\x65\x66\x67\x68\x69\x6a\x6b\x6c\x6d\x6e\x6f",
|
||||
"\x70\x71\x72\x73\x74\x75\x76\x77\x78\x79\x7a\x7b\x7c\x7d\x7e\x7f",
|
||||
"\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f",
|
||||
"\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9a\x9b\x9c\x9d\x9e\x9f",
|
||||
"\xa0\xa1\xa2\xa3\xa4\xa5\xa6\xa7\xa8\xa9\xaa\xab\xac\xad\xae\xaf",
|
||||
"\xb0\xb1\xb2\xb3\xb4\xb5\xb6\xb7\xb8\xb9\xba\xbb\xbc\xbd\xbe\xbf",
|
||||
"\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf",
|
||||
"\xd0\xd1\xd2\xd3\xd4\xd5\xd6\xd7\xd8\xd9\xda\xdb\xdc\xdd\xde\xdf",
|
||||
"\xe0\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed\xee\xef",
|
||||
"\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff",
|
||||
].join("");
|
||||
|
||||
const PUA_CHARS = "\ue000\ue001\uf8fe\uf8ff";
|
||||
|
||||
const MULTI_LINE_STRING =`"You know," said Arthur, "it's at times like this, when I'm trapped in a Vogon airlock with a man from Betelgeuse, and about to die of asphyxiation in deep space that I really wish I'd listened to what my mother told me when I was young."
|
||||
"Why, what did she tell you?"
|
||||
"I don't know, I didn't listen."`;
|
||||
|
||||
const SELECTABLE_STRING = `ONE
|
||||
two
|
||||
ONE
|
||||
three
|
||||
ONE
|
||||
four
|
||||
ONE`;
|
||||
|
||||
// Descriptions for named control characters
|
||||
const CONTROL_CHAR_NAMES = {
|
||||
0: "null",
|
||||
7: "bell",
|
||||
8: "backspace",
|
||||
10: "line feed",
|
||||
11: "vertical tab",
|
||||
13: "carriage return",
|
||||
27: "escape",
|
||||
8203: "zero width space",
|
||||
8204: "zero width non-joiner",
|
||||
8205: "zero width joiner",
|
||||
8206: "left-to-right mark",
|
||||
8207: "right-to-left mark",
|
||||
8232: "line separator",
|
||||
8237: "left-to-right override",
|
||||
8238: "right-to-left override",
|
||||
8294: "left-to-right isolate",
|
||||
8295: "right-to-left isolate",
|
||||
8297: "pop directional isolate",
|
||||
8233: "paragraph separator",
|
||||
65279: "zero width no-break space",
|
||||
65532: "object replacement"
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
before: browser => {
|
||||
browser
|
||||
.resizeWindow(1280, 800)
|
||||
.url(browser.launchUrl)
|
||||
.useCss()
|
||||
.waitForElementNotPresent("#preloader", 10000)
|
||||
.click("#auto-bake-label");
|
||||
},
|
||||
|
||||
"CodeMirror has loaded correctly": browser => {
|
||||
/* Editor has initialised */
|
||||
browser
|
||||
.useCss()
|
||||
// Input
|
||||
.waitForElementVisible("#input-text")
|
||||
.waitForElementVisible("#input-text .cm-editor")
|
||||
.waitForElementVisible("#input-text .cm-editor .cm-scroller")
|
||||
.waitForElementVisible("#input-text .cm-editor .cm-scroller .cm-content")
|
||||
.waitForElementVisible("#input-text .cm-editor .cm-scroller .cm-content .cm-line")
|
||||
// Output
|
||||
.waitForElementVisible("#output-text")
|
||||
.waitForElementVisible("#output-text .cm-editor")
|
||||
.waitForElementVisible("#output-text .cm-editor .cm-scroller")
|
||||
.waitForElementVisible("#output-text .cm-editor .cm-scroller .cm-content")
|
||||
.waitForElementVisible("#output-text .cm-editor .cm-scroller .cm-content .cm-line");
|
||||
|
||||
/* Status bar is showing and has correct values */
|
||||
browser // Input
|
||||
.waitForElementVisible("#input-text .cm-status-bar")
|
||||
.waitForElementVisible("#input-text .cm-status-bar .stats-length-value")
|
||||
.expect.element("#input-text .cm-status-bar .stats-length-value").text.to.equal("0");
|
||||
browser.waitForElementVisible("#input-text .cm-status-bar .stats-lines-value")
|
||||
.expect.element("#input-text .cm-status-bar .stats-lines-value").text.to.equal("1");
|
||||
browser.waitForElementVisible("#input-text .cm-status-bar .chr-enc-value")
|
||||
.expect.element("#input-text .cm-status-bar .chr-enc-value").text.to.equal("Raw Bytes");
|
||||
browser.waitForElementVisible("#input-text .cm-status-bar .eol-value")
|
||||
.expect.element("#input-text .cm-status-bar .eol-value").text.to.equal("LF");
|
||||
|
||||
browser // Output
|
||||
.waitForElementVisible("#output-text .cm-status-bar")
|
||||
.waitForElementVisible("#output-text .cm-status-bar .stats-length-value")
|
||||
.expect.element("#output-text .cm-status-bar .stats-length-value").text.to.equal("0");
|
||||
browser.waitForElementVisible("#output-text .cm-status-bar .stats-lines-value")
|
||||
.expect.element("#output-text .cm-status-bar .stats-lines-value").text.to.equal("1");
|
||||
browser.waitForElementVisible("#output-text .cm-status-bar .baking-time-info")
|
||||
.expect.element("#output-text .cm-status-bar .baking-time-info").text.to.contain("ms");
|
||||
browser.waitForElementVisible("#output-text .cm-status-bar .chr-enc-value")
|
||||
.expect.element("#output-text .cm-status-bar .chr-enc-value").text.to.equal("Raw Bytes");
|
||||
browser.waitForElementVisible("#output-text .cm-status-bar .eol-value")
|
||||
.expect.element("#output-text .cm-status-bar .eol-value").text.to.equal("LF");
|
||||
},
|
||||
|
||||
"Adding content": browser => {
|
||||
/* Status bar updates correctly */
|
||||
utils.setInput(browser, MULTI_LINE_STRING);
|
||||
|
||||
browser.expect.element("#input-text .cm-status-bar .stats-length-value").text.to.equal("301");
|
||||
browser.expect.element("#input-text .cm-status-bar .stats-lines-value").text.to.equal("3");
|
||||
browser.expect.element("#input-text .cm-status-bar .chr-enc-value").text.to.equal("Raw Bytes");
|
||||
browser.expect.element("#input-text .cm-status-bar .eol-value").text.to.equal("LF");
|
||||
|
||||
browser.expect.element("#output-text .cm-status-bar .stats-length-value").text.to.equal("0");
|
||||
browser.expect.element("#output-text .cm-status-bar .stats-lines-value").text.to.equal("1");
|
||||
browser.expect.element("#output-text .cm-status-bar .baking-time-info").text.to.contain("ms");
|
||||
browser.expect.element("#output-text .cm-status-bar .chr-enc-value").text.to.equal("Raw Bytes");
|
||||
browser.expect.element("#output-text .cm-status-bar .eol-value").text.to.equal("LF");
|
||||
|
||||
/* Output updates correctly */
|
||||
utils.bake(browser);
|
||||
browser.expect.element("#output-text .cm-status-bar .stats-length-value").text.to.equal("301");
|
||||
browser.expect.element("#output-text .cm-status-bar .stats-lines-value").text.to.equal("3");
|
||||
browser.expect.element("#output-text .cm-status-bar .baking-time-info").text.to.contain("ms");
|
||||
browser.expect.element("#output-text .cm-status-bar .chr-enc-value").text.to.equal("Raw Bytes");
|
||||
browser.expect.element("#output-text .cm-status-bar .eol-value").text.to.equal("LF");
|
||||
},
|
||||
|
||||
"Special content": browser => {
|
||||
/* Special characters are rendered correctly */
|
||||
utils.setInput(browser, SPECIAL_CHARS, false);
|
||||
|
||||
// First line
|
||||
for (let i = 0x0; i <= 0x8; i++) {
|
||||
browser.expect.element(`#input-text .cm-line:nth-of-type(1) .cm-specialChar:nth-of-type(${i+1})`)
|
||||
.to.have.property("title").equals(`Control character ${CONTROL_CHAR_NAMES[i] || "0x" + i.toString(16)}`);
|
||||
browser.expect.element(`#input-text .cm-line:nth-of-type(1) .cm-specialChar:nth-of-type(${i+1})`)
|
||||
.text.to.equal(String.fromCharCode(0x2400 + i));
|
||||
}
|
||||
|
||||
// Tab \u0009
|
||||
browser.expect.element(`#input-text .cm-line:nth-of-type(1)`).to.have.property("textContent").match(/\u0009$/);
|
||||
|
||||
// Line feed \u000a
|
||||
browser.expect.element(`#input-text .cm-line:nth-of-type(1)`).to.have.property("textContent").match(/^.{10}$/);
|
||||
browser.expect.element("#input-text .cm-status-bar .stats-lines-value").text.to.equal("2");
|
||||
|
||||
// Second line
|
||||
for (let i = 0x0b; i < SPECIAL_CHARS.length; i++) {
|
||||
const index = SPECIAL_CHARS.charCodeAt(i);
|
||||
const name = CONTROL_CHAR_NAMES[index] || "0x" + index.toString(16);
|
||||
const value = index >= 32 ? "\u2022" : String.fromCharCode(0x2400 + index);
|
||||
|
||||
browser.expect.element(`#input-text .cm-line:nth-of-type(2) .cm-specialChar:nth-of-type(${i-10})`)
|
||||
.to.have.property("title").equals(`Control character ${name}`);
|
||||
browser.expect.element(`#input-text .cm-line:nth-of-type(2) .cm-specialChar:nth-of-type(${i-10})`)
|
||||
.text.to.equal(value);
|
||||
}
|
||||
|
||||
/* Output renders correctly */
|
||||
utils.setChrEnc(browser, "output", "UTF-8");
|
||||
utils.bake(browser);
|
||||
|
||||
// First line
|
||||
for (let i = 0x0; i <= 0x8; i++) {
|
||||
browser.expect.element(`#output-text .cm-line:nth-of-type(1) .cm-specialChar:nth-of-type(${i+1})`)
|
||||
.to.have.property("title").equals(`Control character ${CONTROL_CHAR_NAMES[i] || "0x" + i.toString(16)}`);
|
||||
browser.expect.element(`#output-text .cm-line:nth-of-type(1) .cm-specialChar:nth-of-type(${i+1})`)
|
||||
.text.to.equal(String.fromCharCode(0x2400 + i));
|
||||
}
|
||||
|
||||
// Tab \u0009
|
||||
browser.expect.element(`#output-text .cm-line:nth-of-type(1)`).to.have.property("textContent").match(/\u0009$/);
|
||||
|
||||
// Line feed \u000a
|
||||
browser.expect.element(`#output-text .cm-line:nth-of-type(1)`).to.have.property("textContent").match(/^.{10}$/);
|
||||
browser.expect.element("#output-text .cm-status-bar .stats-lines-value").text.to.equal("2");
|
||||
|
||||
// Second line
|
||||
for (let i = 0x0b; i < SPECIAL_CHARS.length; i++) {
|
||||
const index = SPECIAL_CHARS.charCodeAt(i);
|
||||
const name = CONTROL_CHAR_NAMES[index] || "0x" + index.toString(16);
|
||||
const value = index >= 32 ? "\u2022" : String.fromCharCode(0x2400 + index);
|
||||
|
||||
browser.expect.element(`#output-text .cm-content .cm-line:nth-of-type(2) .cm-specialChar:nth-of-type(${i-10})`)
|
||||
.to.have.property("title").equals(`Control character ${name}`);
|
||||
browser.expect.element(`#output-text .cm-content .cm-line:nth-of-type(2) .cm-specialChar:nth-of-type(${i-10})`)
|
||||
.text.to.equal(value);
|
||||
}
|
||||
|
||||
/* Bytes are rendered correctly */
|
||||
utils.setInput(browser, ALL_BYTES, false);
|
||||
// Expect length to be 255, since one character is creating a newline
|
||||
browser.expect.element(`#input-text .cm-content`).to.have.property("textContent").match(/^.{255}$/);
|
||||
browser.expect.element("#input-text .cm-status-bar .stats-length-value").text.to.equal("256");
|
||||
browser.expect.element("#input-text .cm-status-bar .stats-lines-value").text.to.equal("2");
|
||||
|
||||
|
||||
/* PUA \ue000-\uf8ff */
|
||||
utils.setInput(browser, PUA_CHARS, false);
|
||||
utils.setChrEnc(browser, "output", "UTF-8");
|
||||
utils.bake(browser);
|
||||
|
||||
// Confirm input and output as expected
|
||||
/* In order to render whitespace characters as control character pictures in the output, even
|
||||
when they are the designated line separator, CyberChef sometimes chooses to represent them
|
||||
internally using the Unicode Private Use Area (https://en.wikipedia.org/wiki/Private_Use_Areas).
|
||||
See `Utils.escapeWhitespace()` for an example of this.
|
||||
Therefore, PUA characters should be rendered normally in the Input but as control character
|
||||
pictures in the output.
|
||||
*/
|
||||
browser.expect.element(`#input-text .cm-content`).to.have.property("textContent").match(/^\ue000\ue001\uf8fe\uf8ff$/);
|
||||
browser.expect.element(`#output-text .cm-content`).to.have.property("textContent").match(/^\u2400\u2401\u3cfe\u3cff$/);
|
||||
|
||||
/* Can be copied */
|
||||
utils.setInput(browser, SPECIAL_CHARS, false);
|
||||
utils.setChrEnc(browser, "output", "UTF-8");
|
||||
utils.bake(browser);
|
||||
|
||||
// Manual copy
|
||||
browser
|
||||
.doubleClick("#output-text .cm-content .cm-line:nth-of-type(1) .cm-specialChar:nth-of-type(1)")
|
||||
.waitForElementVisible("#output-text .cm-selectionBackground");
|
||||
utils.copy(browser);
|
||||
utils.paste(browser, "#search"); // Paste into search box as this won't mess with the values
|
||||
|
||||
// Ensure that the values are as expected
|
||||
browser.expect.element("#search").to.have.value.that.equals("\u0000\u0001\u0002\u0003\u0004\u0005\u0006\u0007\u0008");
|
||||
browser.clearValue("#search");
|
||||
|
||||
// Raw copy
|
||||
browser
|
||||
.click("#copy-output")
|
||||
.pause(100);
|
||||
utils.paste(browser, "#search"); // Paste into search box as this won't mess with the values
|
||||
|
||||
// Ensure that the values are as expected
|
||||
browser.expect.element("#search").to.have.value.that.matches(/^\u0000\u0001\u0002\u0003\u0004\u0005\u0006\u0007\u0008\u0009/);
|
||||
browser.clearValue("#search");
|
||||
},
|
||||
|
||||
"HTML output": browser => {
|
||||
/* Displays correctly */
|
||||
utils.loadRecipe(browser, "Entropy", ALL_BYTES);
|
||||
utils.bake(browser);
|
||||
|
||||
browser
|
||||
.waitForElementVisible("#output-html")
|
||||
.waitForElementVisible("#output-html #chart-area");
|
||||
|
||||
/* Status bar widgets are disabled */
|
||||
browser.expect.element("#output-text .cm-status-bar .disabled .stats-length-value").to.be.visible;
|
||||
browser.expect.element("#output-text .cm-status-bar .disabled .stats-lines-value").to.be.visible;
|
||||
browser.expect.element("#output-text .cm-status-bar .disabled .chr-enc-value").to.be.visible;
|
||||
browser.expect.element("#output-text .cm-status-bar .disabled .eol-value").to.be.visible;
|
||||
|
||||
/* Displays special chars correctly */
|
||||
utils.loadRecipe(browser, "To Table", ",\u0000\u0001\u0002\u0003\u0004", [",", "\\r\\n", false, "HTML"]);
|
||||
utils.bake(browser);
|
||||
|
||||
for (let i = 0x0; i <= 0x4; i++) {
|
||||
browser.expect.element(`#output-html .cm-specialChar:nth-of-type(${i+1})`)
|
||||
.to.have.property("title").equals(`Control character ${CONTROL_CHAR_NAMES[i] || "0x" + i.toString(16)}`);
|
||||
browser.expect.element(`#output-html .cm-specialChar:nth-of-type(${i+1})`)
|
||||
.text.to.equal(String.fromCharCode(0x2400 + i));
|
||||
}
|
||||
|
||||
/* Can be copied */
|
||||
// Raw copy
|
||||
browser
|
||||
.click("#copy-output")
|
||||
.pause(100);
|
||||
utils.paste(browser, "#search"); // Paste into search box as this won't mess with the values
|
||||
|
||||
// Ensure that the values are as expected
|
||||
browser.expect.element("#search").to.have.value.that.matches(/\u0000\u0001\u0002\u0003\u0004/);
|
||||
browser.clearValue("#search");
|
||||
},
|
||||
|
||||
"Highlighting": browser => {
|
||||
utils.setInput(browser, SELECTABLE_STRING);
|
||||
utils.bake(browser);
|
||||
|
||||
/* Selecting input text also selects other instances in input and output */
|
||||
browser // Input
|
||||
.click("#auto-bake-label")
|
||||
.doubleClick("#input-text .cm-content .cm-line:nth-of-type(1)")
|
||||
.waitForElementVisible("#input-text .cm-selectionLayer .cm-selectionBackground")
|
||||
.waitForElementNotPresent("#input-text .cm-content .cm-line:nth-of-type(1) .cm-selectionMatch")
|
||||
.waitForElementNotPresent("#input-text .cm-content .cm-line:nth-of-type(2) .cm-selectionMatch")
|
||||
.waitForElementVisible("#input-text .cm-content .cm-line:nth-of-type(3) .cm-selectionMatch")
|
||||
.waitForElementNotPresent("#input-text .cm-content .cm-line:nth-of-type(4) .cm-selectionMatch")
|
||||
.waitForElementVisible("#input-text .cm-content .cm-line:nth-of-type(5) .cm-selectionMatch")
|
||||
.waitForElementNotPresent("#input-text .cm-content .cm-line:nth-of-type(6) .cm-selectionMatch")
|
||||
.waitForElementVisible("#input-text .cm-content .cm-line:nth-of-type(7) .cm-selectionMatch");
|
||||
|
||||
browser // Output
|
||||
.waitForElementVisible("#output-text .cm-selectionLayer .cm-selectionBackground")
|
||||
.waitForElementNotPresent("#output-text .cm-content .cm-line:nth-of-type(1) .cm-selectionMatch")
|
||||
.waitForElementNotPresent("#output-text .cm-content .cm-line:nth-of-type(2) .cm-selectionMatch")
|
||||
.waitForElementVisible("#output-text .cm-content .cm-line:nth-of-type(3) .cm-selectionMatch")
|
||||
.waitForElementNotPresent("#output-text .cm-content .cm-line:nth-of-type(4) .cm-selectionMatch")
|
||||
.waitForElementVisible("#output-text .cm-content .cm-line:nth-of-type(5) .cm-selectionMatch")
|
||||
.waitForElementNotPresent("#output-text .cm-content .cm-line:nth-of-type(6) .cm-selectionMatch")
|
||||
.waitForElementVisible("#output-text .cm-content .cm-line:nth-of-type(7) .cm-selectionMatch");
|
||||
|
||||
/* Selecting output text highlights in input */
|
||||
browser // Output
|
||||
.click("#output-text")
|
||||
.waitForElementNotPresent("#input-text .cm-selectionLayer .cm-selectionBackground")
|
||||
.waitForElementNotPresent("#output-text .cm-selectionLayer .cm-selectionBackground")
|
||||
.waitForElementNotPresent("#input-text .cm-content .cm-line .cm-selectionMatch")
|
||||
.waitForElementNotPresent("#output-text .cm-content .cm-line .cm-selectionMatch")
|
||||
.doubleClick("#output-text .cm-content .cm-line:nth-of-type(7)")
|
||||
.waitForElementVisible("#output-text .cm-selectionLayer .cm-selectionBackground")
|
||||
.waitForElementVisible("#output-text .cm-content .cm-line:nth-of-type(1) .cm-selectionMatch")
|
||||
.waitForElementNotPresent("#output-text .cm-content .cm-line:nth-of-type(2) .cm-selectionMatch")
|
||||
.waitForElementVisible("#output-text .cm-content .cm-line:nth-of-type(3) .cm-selectionMatch")
|
||||
.waitForElementNotPresent("#output-text .cm-content .cm-line:nth-of-type(4) .cm-selectionMatch")
|
||||
.waitForElementVisible("#output-text .cm-content .cm-line:nth-of-type(5) .cm-selectionMatch")
|
||||
.waitForElementNotPresent("#output-text .cm-content .cm-line:nth-of-type(6) .cm-selectionMatch")
|
||||
.waitForElementNotPresent("#output-text .cm-content .cm-line:nth-of-type(7) .cm-selectionMatch");
|
||||
|
||||
browser // Input
|
||||
.waitForElementVisible("#input-text .cm-selectionLayer .cm-selectionBackground")
|
||||
.waitForElementVisible("#input-text .cm-content .cm-line:nth-of-type(1) .cm-selectionMatch")
|
||||
.waitForElementNotPresent("#input-text .cm-content .cm-line:nth-of-type(2) .cm-selectionMatch")
|
||||
.waitForElementVisible("#input-text .cm-content .cm-line:nth-of-type(3) .cm-selectionMatch")
|
||||
.waitForElementNotPresent("#input-text .cm-content .cm-line:nth-of-type(4) .cm-selectionMatch")
|
||||
.waitForElementVisible("#input-text .cm-content .cm-line:nth-of-type(5) .cm-selectionMatch")
|
||||
.waitForElementNotPresent("#input-text .cm-content .cm-line:nth-of-type(6) .cm-selectionMatch")
|
||||
.waitForElementNotPresent("#input-text .cm-content .cm-line:nth-of-type(7) .cm-selectionMatch");
|
||||
|
||||
// Turn autobake off again
|
||||
browser.click("#auto-bake-label");
|
||||
},
|
||||
|
||||
"Character encoding": browser => {
|
||||
const CHINESE_CHARS = "不要恐慌。";
|
||||
/* Dropup works */
|
||||
/* Selecting changes output correctly */
|
||||
utils.setInput(browser, CHINESE_CHARS, false);
|
||||
utils.setChrEnc(browser, "input", "UTF-8");
|
||||
utils.bake(browser);
|
||||
utils.expectOutput(browser, "\u00E4\u00B8\u008D\u00E8\u00A6\u0081\u00E6\u0081\u0090\u00E6\u0085\u008C\u00E3\u0080\u0082");
|
||||
|
||||
/* Changing output to match input works as expected */
|
||||
utils.setChrEnc(browser, "output", "UTF-8");
|
||||
utils.bake(browser);
|
||||
utils.expectOutput(browser, CHINESE_CHARS);
|
||||
|
||||
/* Encodings appear in the URL */
|
||||
browser.assert.urlContains("ienc=65001");
|
||||
browser.assert.urlContains("oenc=65001");
|
||||
|
||||
/* Preserved when changing tabs */
|
||||
browser
|
||||
.click("#btn-new-tab")
|
||||
.waitForElementVisible("#input-tabs li:nth-of-type(2).active-input-tab");
|
||||
browser.expect.element("#input-text .chr-enc-value").text.that.equals("Raw Bytes");
|
||||
browser.expect.element("#output-text .chr-enc-value").text.that.equals("Raw Bytes");
|
||||
|
||||
utils.setChrEnc(browser, "input", "UTF-7");
|
||||
utils.setChrEnc(browser, "output", "UTF-7");
|
||||
|
||||
browser
|
||||
.click("#input-tabs li:nth-of-type(1)")
|
||||
.waitForElementVisible("#input-tabs li:nth-of-type(1).active-input-tab");
|
||||
browser.expect.element("#input-text .chr-enc-value").text.that.equals("UTF-8");
|
||||
browser.expect.element("#output-text .chr-enc-value").text.that.equals("UTF-8");
|
||||
|
||||
/* Try various encodings */
|
||||
// These are not meant to be realistic encodings for this data
|
||||
utils.setInput(browser, CHINESE_CHARS, false);
|
||||
utils.setChrEnc(browser, "input", "UTF-8");
|
||||
utils.setChrEnc(browser, "output", "UTF-16LE");
|
||||
utils.bake(browser);
|
||||
utils.expectOutput(browser, "\uB8E4\uE88D\u81A6\u81E6\uE690\u8C85\u80E3");
|
||||
|
||||
utils.setChrEnc(browser, "output", "Simplified Chinese GBK");
|
||||
utils.bake(browser);
|
||||
utils.expectOutput(browser, "\u6D93\u5D88\uFDFF\u93AD\u612D\u53A1\u9286\u0000");
|
||||
|
||||
utils.setChrEnc(browser, "input", "UTF-7");
|
||||
utils.bake(browser);
|
||||
utils.expectOutput(browser, "+Tg0-+iYE-+YFA-+YUw-");
|
||||
|
||||
utils.setChrEnc(browser, "input", "Traditional Chinese Big5");
|
||||
utils.bake(browser);
|
||||
utils.expectOutput(browser, "\u3043\u74B6\uFDFF\u7A3A\uFDFF");
|
||||
|
||||
utils.setChrEnc(browser, "output", "Windows-1251 Cyrillic");
|
||||
utils.bake(browser);
|
||||
utils.expectOutput(browser, "\u00A4\u0408\u00ADn\u00AE\u0408\u00B7W\u040EC");
|
||||
},
|
||||
|
||||
"Line endings": browser => {
|
||||
/* Dropup works */
|
||||
/* Selecting changes view in input */
|
||||
utils.setInput(browser, MULTI_LINE_STRING);
|
||||
|
||||
// Line endings: LF
|
||||
|
||||
// Input
|
||||
browser
|
||||
.waitForElementPresent("#input-text .cm-content .cm-line:nth-of-type(3)")
|
||||
.waitForElementNotPresent("#input-text .cm-content .cm-line:nth-of-type(4)")
|
||||
.waitForElementNotPresent("#input-text .cm-content .cm-specialChar");
|
||||
browser.expect.element("#input-text .cm-status-bar .stats-length-value").text.to.equal("301");
|
||||
browser.expect.element("#input-text .cm-status-bar .stats-lines-value").text.to.equal("3");
|
||||
|
||||
// Output
|
||||
utils.bake(browser);
|
||||
browser
|
||||
.waitForElementPresent("#output-text .cm-content .cm-line:nth-of-type(3)")
|
||||
.waitForElementNotPresent("#output-text .cm-content .cm-line:nth-of-type(4)")
|
||||
.waitForElementNotPresent("#output-text .cm-content .cm-specialChar");
|
||||
browser.expect.element("#output-text .cm-status-bar .stats-length-value").text.to.equal("301");
|
||||
browser.expect.element("#output-text .cm-status-bar .stats-lines-value").text.to.equal("3");
|
||||
|
||||
// Input EOL: VT
|
||||
utils.setEOLSeq(browser, "input", "VT");
|
||||
|
||||
// Input
|
||||
browser
|
||||
.waitForElementPresent("#input-text .cm-content .cm-line:nth-of-type(1)")
|
||||
.waitForElementNotPresent("#input-text .cm-content .cm-line:nth-of-type(2)")
|
||||
.waitForElementPresent("#input-text .cm-content .cm-specialChar");
|
||||
browser.expect.element("#input-text .cm-content .cm-specialChar").text.to.equal("␊");
|
||||
browser.expect.element("#input-text .cm-status-bar .stats-length-value").text.to.equal("301");
|
||||
browser.expect.element("#input-text .cm-status-bar .stats-lines-value").text.to.equal("1");
|
||||
|
||||
// Output
|
||||
utils.bake(browser);
|
||||
browser
|
||||
.waitForElementPresent("#output-text .cm-content .cm-line:nth-of-type(3)")
|
||||
.waitForElementNotPresent("#output-text .cm-content .cm-line:nth-of-type(4)")
|
||||
.waitForElementNotPresent("#output-text .cm-content .cm-specialChar");
|
||||
browser.expect.element("#output-text .cm-status-bar .stats-length-value").text.to.equal("301");
|
||||
browser.expect.element("#output-text .cm-status-bar .stats-lines-value").text.to.equal("3");
|
||||
|
||||
// Output EOL: VT
|
||||
utils.setEOLSeq(browser, "output", "VT");
|
||||
|
||||
// Input
|
||||
browser
|
||||
.waitForElementPresent("#input-text .cm-content .cm-line:nth-of-type(1)")
|
||||
.waitForElementNotPresent("#input-text .cm-content .cm-line:nth-of-type(2)")
|
||||
.waitForElementPresent("#input-text .cm-content .cm-specialChar");
|
||||
browser.expect.element("#input-text .cm-content .cm-specialChar").text.to.equal("␊");
|
||||
browser.expect.element("#input-text .cm-status-bar .stats-length-value").text.to.equal("301");
|
||||
browser.expect.element("#input-text .cm-status-bar .stats-lines-value").text.to.equal("1");
|
||||
|
||||
// Output
|
||||
browser
|
||||
.waitForElementPresent("#output-text .cm-content .cm-line:nth-of-type(1)")
|
||||
.waitForElementNotPresent("#output-text .cm-content .cm-line:nth-of-type(2)")
|
||||
.waitForElementPresent("#output-text .cm-content .cm-specialChar");
|
||||
browser.expect.element("#output-text .cm-content .cm-specialChar").text.to.equal("␊");
|
||||
browser.expect.element("#output-text .cm-status-bar .stats-length-value").text.to.equal("301");
|
||||
browser.expect.element("#output-text .cm-status-bar .stats-lines-value").text.to.equal("1");
|
||||
|
||||
/* Adding new line ending changes output correctly */
|
||||
browser.sendKeys("#input-text .cm-content", browser.Keys.RETURN);
|
||||
|
||||
// Input
|
||||
browser
|
||||
.waitForElementPresent("#input-text .cm-content .cm-line:nth-of-type(2)")
|
||||
.waitForElementNotPresent("#input-text .cm-content .cm-line:nth-of-type(3)");
|
||||
browser.expect.element("#input-text .cm-status-bar .stats-length-value").text.to.equal("302");
|
||||
browser.expect.element("#input-text .cm-status-bar .stats-lines-value").text.to.equal("2");
|
||||
|
||||
// Output
|
||||
utils.bake(browser);
|
||||
browser
|
||||
.waitForElementPresent("#output-text .cm-content .cm-line:nth-of-type(2)")
|
||||
.waitForElementNotPresent("#output-text .cm-content .cm-line:nth-of-type(3)");
|
||||
browser.expect.element("#output-text .cm-status-bar .stats-length-value").text.to.equal("302");
|
||||
browser.expect.element("#output-text .cm-status-bar .stats-lines-value").text.to.equal("2");
|
||||
|
||||
// Input EOL: CRLF
|
||||
utils.setEOLSeq(browser, "input", "CRLF");
|
||||
// Output EOL: CR
|
||||
utils.setEOLSeq(browser, "output", "CR");
|
||||
browser.sendKeys("#input-text .cm-content", browser.Keys.RETURN);
|
||||
|
||||
// Input
|
||||
browser
|
||||
.waitForElementPresent("#input-text .cm-content .cm-line:nth-of-type(2)")
|
||||
.waitForElementNotPresent("#input-text .cm-content .cm-line:nth-of-type(3)")
|
||||
.waitForElementPresent("#input-text .cm-content .cm-line:nth-of-type(1) .cm-specialChar:nth-of-type(3)");
|
||||
browser.expect.element("#input-text .cm-content .cm-line:nth-of-type(1) .cm-specialChar:nth-of-type(3)").text.to.equal("␋");
|
||||
browser.expect.element("#input-text .cm-status-bar .stats-length-value").text.to.equal("304");
|
||||
browser.expect.element("#input-text .cm-status-bar .stats-lines-value").text.to.equal("2");
|
||||
|
||||
// Output
|
||||
utils.bake(browser);
|
||||
browser
|
||||
.waitForElementPresent("#output-text .cm-content .cm-line:nth-of-type(2)")
|
||||
.waitForElementNotPresent("#output-text .cm-content .cm-line:nth-of-type(3)")
|
||||
.waitForElementPresent("#output-text .cm-content .cm-line:nth-of-type(2) .cm-specialChar");
|
||||
browser.expect.element("#output-text .cm-content .cm-line:nth-of-type(2) .cm-specialChar").text.to.equal("␊");
|
||||
browser.expect.element("#output-text .cm-status-bar .stats-length-value").text.to.equal("304");
|
||||
browser.expect.element("#output-text .cm-status-bar .stats-lines-value").text.to.equal("2");
|
||||
|
||||
/* Line endings appear in the URL */
|
||||
browser.assert.urlContains("ieol=%0D%0A");
|
||||
browser.assert.urlContains("oeol=%0D");
|
||||
|
||||
/* Preserved when changing tabs */
|
||||
browser
|
||||
.click("#btn-new-tab")
|
||||
.waitForElementVisible("#input-tabs li:nth-of-type(2).active-input-tab");
|
||||
browser.expect.element("#input-text .eol-value").text.that.equals("LF");
|
||||
browser.expect.element("#output-text .eol-value").text.that.equals("LF");
|
||||
|
||||
utils.setEOLSeq(browser, "input", "FF");
|
||||
utils.setEOLSeq(browser, "output", "LS");
|
||||
|
||||
browser
|
||||
.click("#input-tabs li:nth-of-type(1)")
|
||||
.waitForElementVisible("#input-tabs li:nth-of-type(1).active-input-tab");
|
||||
browser.expect.element("#input-text .eol-value").text.that.equals("CRLF");
|
||||
browser.expect.element("#output-text .eol-value").text.that.equals("CR");
|
||||
},
|
||||
|
||||
"File inputs": browser => {
|
||||
utils.clear(browser);
|
||||
|
||||
/* Side panel displays correct info */
|
||||
utils.uploadFile(browser, "files/TowelDay.jpeg");
|
||||
|
||||
browser
|
||||
.waitForElementVisible("#input-text .cm-file-details")
|
||||
.waitForElementVisible("#input-text .cm-file-details .file-details-toggle-shown")
|
||||
.waitForElementVisible("#input-text .cm-file-details .file-details-thumbnail")
|
||||
.waitForElementVisible("#input-text .cm-file-details .file-details-name")
|
||||
.waitForElementVisible("#input-text .cm-file-details .file-details-size")
|
||||
.waitForElementVisible("#input-text .cm-file-details .file-details-type")
|
||||
.waitForElementVisible("#input-text .cm-file-details .file-details-loaded");
|
||||
browser.expect.element("#input-text .cm-file-details .file-details-name").text.that.equals("TowelDay.jpeg");
|
||||
browser.expect.element("#input-text .cm-file-details .file-details-size").text.that.equals("61,379 bytes");
|
||||
browser.expect.element("#input-text .cm-file-details .file-details-type").text.that.equals("image/jpeg");
|
||||
browser.expect.element("#input-text .cm-file-details .file-details-loaded").text.that.equals("100%");
|
||||
|
||||
/* Side panel can be hidden */
|
||||
browser
|
||||
.click("#input-text .cm-file-details .file-details-toggle-shown")
|
||||
.waitForElementNotPresent("#input-text .cm-file-details .file-details-toggle-shown")
|
||||
.waitForElementVisible("#input-text .cm-file-details .file-details-toggle-hidden")
|
||||
.expect.element("#input-text .cm-file-details").to.have.css("width").which.equals("1px");
|
||||
|
||||
browser
|
||||
.click("#input-text .cm-file-details .file-details-toggle-hidden")
|
||||
.waitForElementNotPresent("#input-text .cm-file-details .file-details-toggle-hidden")
|
||||
.waitForElementVisible("#input-text .cm-file-details .file-details-toggle-shown")
|
||||
.expect.element("#input-text .cm-file-details").to.have.css("width").which.equals("200px");
|
||||
},
|
||||
|
||||
"Folder inputs": browser => {
|
||||
utils.clear(browser);
|
||||
|
||||
/* Side panel displays correct info */
|
||||
utils.uploadFolder(browser, "files");
|
||||
|
||||
// Loop through tabs
|
||||
for (let i = 1; i < 3; i++) {
|
||||
browser
|
||||
.click(`#input-tabs li:nth-of-type(${i})`)
|
||||
.waitForElementVisible(`#input-tabs li:nth-of-type(${i}).active-input-tab`);
|
||||
|
||||
browser
|
||||
.waitForElementVisible("#input-text .cm-file-details")
|
||||
.waitForElementVisible("#input-text .cm-file-details .file-details-toggle-shown")
|
||||
.waitForElementVisible("#input-text .cm-file-details .file-details-thumbnail")
|
||||
.waitForElementVisible("#input-text .cm-file-details .file-details-name")
|
||||
.waitForElementVisible("#input-text .cm-file-details .file-details-size")
|
||||
.waitForElementVisible("#input-text .cm-file-details .file-details-type")
|
||||
.waitForElementVisible("#input-text .cm-file-details .file-details-loaded");
|
||||
|
||||
browser.getText("#input-text .cm-file-details .file-details-name", function(result) {
|
||||
switch (result.value) {
|
||||
case "TowelDay.jpeg":
|
||||
browser.expect.element("#input-text .cm-file-details .file-details-name").text.that.equals("TowelDay.jpeg");
|
||||
browser.expect.element("#input-text .cm-file-details .file-details-size").text.that.equals("61,379 bytes");
|
||||
browser.expect.element("#input-text .cm-file-details .file-details-type").text.that.equals("image/jpeg");
|
||||
browser.expect.element("#input-text .cm-file-details .file-details-loaded").text.that.equals("100%");
|
||||
break;
|
||||
case "Hitchhikers_Guide.jpeg":
|
||||
browser.expect.element("#input-text .cm-file-details .file-details-name").text.that.equals("Hitchhikers_Guide.jpeg");
|
||||
browser.expect.element("#input-text .cm-file-details .file-details-size").text.that.equals("36,595 bytes");
|
||||
browser.expect.element("#input-text .cm-file-details .file-details-type").text.that.equals("image/jpeg");
|
||||
browser.expect.element("#input-text .cm-file-details .file-details-loaded").text.that.equals("100%");
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
"Loading from URL": browser => {
|
||||
/* Complex deep link populates the input correctly (encoding, eol, input) */
|
||||
browser
|
||||
.urlHash("recipe=To_Base64('A-Za-z0-9%2B/%3D')&input=VGhlIHNoaXBzIGh1bmcgaW4gdGhlIHNreSBpbiBtdWNoIHRoZSBzYW1lIHdheSB0aGF0IGJyaWNrcyBkb24ndC4M&ienc=21866&oenc=1201&ieol=%0C&oeol=%E2%80%A9")
|
||||
.waitForElementVisible("#rec-list li.operation");
|
||||
|
||||
browser.expect.element(`#input-text .cm-content`).to.have.property("textContent").match(/^.{65}$/);
|
||||
browser.expect.element("#input-text .cm-status-bar .stats-length-value").text.to.equal("66");
|
||||
browser.expect.element("#input-text .cm-status-bar .stats-lines-value").text.to.equal("2");
|
||||
|
||||
browser.expect.element("#input-text .chr-enc-value").text.that.equals("KOI8-U Ukrainian Cyrillic");
|
||||
browser.expect.element("#output-text .chr-enc-value").text.that.equals("UTF-16BE");
|
||||
|
||||
browser.expect.element("#input-text .eol-value").text.that.equals("FF");
|
||||
browser.expect.element("#output-text .eol-value").text.that.equals("PS");
|
||||
|
||||
utils.bake(browser);
|
||||
|
||||
browser.expect.element(`#output-text .cm-content`).to.have.property("textContent").match(/^.{44}$/);
|
||||
browser.expect.element("#output-text .cm-status-bar .stats-length-value").text.to.equal("44");
|
||||
browser.expect.element("#output-text .cm-status-bar .stats-lines-value").text.to.equal("1");
|
||||
},
|
||||
|
||||
"Replace input with output": browser => {
|
||||
/* Input is correctly populated */
|
||||
utils.loadRecipe(browser, "XOR", "The ships hung in the sky in much the same way that bricks don't.", [{ "option": "Hex", "string": "65" }, "Standard", false]);
|
||||
utils.setChrEnc(browser, "input", "UTF-32LE");
|
||||
utils.setChrEnc(browser, "output", "UTF-7");
|
||||
utils.setEOLSeq(browser, "input", "CRLF");
|
||||
utils.setEOLSeq(browser, "output", "LS");
|
||||
|
||||
browser
|
||||
.sendKeys("#input-text .cm-content", browser.Keys.RETURN)
|
||||
.expect.element("#input-text .cm-status-bar .stats-lines-value").text.to.equal("2");
|
||||
utils.bake(browser);
|
||||
|
||||
browser.expect.element("#input-text .cm-status-bar .stats-length-value").text.to.equal("67");
|
||||
browser.expect.element("#input-text .cm-status-bar .stats-lines-value").text.to.equal("2");
|
||||
browser.expect.element("#input-text .chr-enc-value").text.that.equals("UTF-32LE");
|
||||
browser.expect.element("#input-text .eol-value").text.that.equals("CRLF");
|
||||
browser.expect.element("#output-text .cm-status-bar .stats-length-value").text.to.equal("268");
|
||||
|
||||
browser
|
||||
.click("#switch")
|
||||
.waitForElementVisible("#stale-indicator");
|
||||
|
||||
browser.expect.element("#input-text .cm-status-bar .stats-length-value").text.to.equal("268");
|
||||
|
||||
/* Special characters, encodings and line endings all as expected */
|
||||
browser.expect.element("#input-text .cm-status-bar .stats-lines-value").text.to.equal("1");
|
||||
browser.expect.element("#input-text .chr-enc-value").text.that.equals("UTF-7");
|
||||
browser.expect.element("#input-text .eol-value").text.that.equals("LS");
|
||||
browser.expect.element("#input-text .cm-line:nth-of-type(1) .cm-specialChar:nth-of-type(1)").text.to.equal("␍");
|
||||
browser.expect.element("#input-text .cm-line:nth-of-type(1) .cm-specialChar:nth-of-type(49)").text.to.equal("␑");
|
||||
browser.waitForElementNotPresent("#input-text .cm-line:nth-of-type(1) .cm-specialChar:nth-of-type(50)");
|
||||
},
|
||||
|
||||
|
||||
after: browser => {
|
||||
browser.end();
|
||||
}
|
||||
};
|
502
tests/browser/02_ops.js
Normal file
502
tests/browser/02_ops.js
Normal file
|
@ -0,0 +1,502 @@
|
|||
/**
|
||||
* Tests for operations.
|
||||
* The primary purpose for these test is to ensure that the operations
|
||||
* output something vaguely expected (i.e. they aren't completely broken
|
||||
* after a dependency update or changes to the UI), rather than to confirm
|
||||
* that this output is actually accurate. Accuracy of output and testing
|
||||
* of edge cases should be carried out in the operations test suite found
|
||||
* in /tests/operations as this is much faster and easier to configure
|
||||
* than the UI tests found here.
|
||||
*
|
||||
* @author n1474335 [n1474335@gmail.com]
|
||||
* @copyright Crown Copyright 2021
|
||||
* @license Apache-2.0
|
||||
*/
|
||||
|
||||
const utils = require("./browserUtils.js");
|
||||
|
||||
module.exports = {
|
||||
before: browser => {
|
||||
browser
|
||||
.resizeWindow(1280, 800)
|
||||
.url(browser.launchUrl)
|
||||
.useCss()
|
||||
.waitForElementNotPresent("#preloader", 10000)
|
||||
.click("#auto-bake-label");
|
||||
},
|
||||
|
||||
"Sanity check operations": async browser => {
|
||||
const Images = await import("../samples/Images.mjs");
|
||||
testOp(browser, "A1Z26 Cipher Decode", "20 5 19 20 15 21 20 16 21 20", "testoutput");
|
||||
testOp(browser, "A1Z26 Cipher Encode", "test input", "20 5 19 20 9 14 16 21 20");
|
||||
testOp(browser, "ADD", "test input", "Ê»ÉÊv¿ÄÆËÊ", [{ "option": "Hex", "string": "56" }]);
|
||||
testOp(browser, "AES Decrypt", "b443f7f7c16ac5396a34273f6f639caa", "test output", [{ "option": "Hex", "string": "00112233445566778899aabbccddeeff" }, { "option": "Hex", "string": "00000000000000000000000000000000" }, "CBC", "Hex", "Raw", { "option": "Hex", "string": "" }]);
|
||||
testOp(browser, "AES Encrypt", "test input", "e42eb8fbfb7a98fff061cd2c1a794d92", [{"option": "Hex", "string": "00112233445566778899aabbccddeeff"}, {"option": "Hex", "string": "00000000000000000000000000000000"}, "CBC", "Raw", "Hex"]);
|
||||
testOp(browser, "AND", "test input", "4$04 $044", [{ "option": "Hex", "string": "34" }]);
|
||||
testOp(browser, "Add line numbers", "test input", "1 test input");
|
||||
testOp(browser, ["From Hex", "Add Text To Image", "To Base64"], Images.PNG_HEX, Images.PNG_CHEF_B64, [[], ["Chef", "Center", "Middle", 0, 0, 16], []]);
|
||||
testOp(browser, "Adler-32 Checksum", "test input", "16160411");
|
||||
testOp(browser, "Affine Cipher Decode", "test input", "rcqr glnsr", [1, 2]);
|
||||
testOp(browser, "Affine Cipher Encode", "test input", "njln rbfpn", [2, 1]);
|
||||
testOp(browser, "AMF Decode", "\u000A\u0013\u0001\u0003a\u0006\u0009test", /"\$value": "test"/);
|
||||
testOp(browser, "AMF Encode", '{"a": "test"}', "\u000A\u0013\u0001\u0003a\u0006\u0009test");
|
||||
testOp(browser, "Analyse hash", "0123456789abcdef", /CRC-64/);
|
||||
testOp(browser, "Atbash Cipher", "test input", "gvhg rmkfg");
|
||||
// testOp(browser, "Avro to JSON", "test input", "test_output");
|
||||
testOp(browser, "BLAKE2b", "test input", "33ebdc8f38177f3f3f334eeb117a84e11f061bbca4db6b8923e5cec85103f59f415551a5d5a933fdb6305dc7bf84671c2540b463dbfa08ee1895cfaa5bd780b5", ["512", "Hex", { "option": "UTF8", "string": "pass" }]);
|
||||
testOp(browser, "BLAKE2s", "test input", "defe73d61dfa6e5807e4f9643e159a09ccda6be3c26dcd65f8a9bb38bfc973a7", ["256", "Hex", { "option": "UTF8", "string": "pass" }]);
|
||||
testOp(browser, "BSON deserialise", "\u0011\u0000\u0000\u0000\u0002a\u0000\u0005\u0000\u0000\u0000test\u0000\u0000", '{\u000A "a": "test"\u000A}');
|
||||
testOp(browser, "BSON serialise", '{"a":"test"}', "\u0011\u0000\u0000\u0000\u0002a\u0000\u0005\u0000\u0000\u0000test\u0000\u0000");
|
||||
// testOp(browser, "Bacon Cipher Decode", "test input", "test_output");
|
||||
// testOp(browser, "Bacon Cipher Encode", "test input", "test_output");
|
||||
testOp(browser, "Bcrypt", "test input", /^\$2a\$06\$.{53}$/, [6]);
|
||||
testOp(browser, "Bcrypt compare", "test input", "Match: test input", ["$2a$05$FCfBSVX7OeRkK.9kQVFCiOYu9XtwtIbePqUiroD1lkASW9q5QClzG"]);
|
||||
testOp(browser, "Bcrypt parse", "$2a$05$kXWtAIGB/R8VEzInoM5ocOTBtyc0m2YTIwFiBU/0XoW032f9QrkWW", /Rounds: 5/);
|
||||
testOp(browser, "Bifid Cipher Decode", "qblb tfovy", "test input", ["pass"]);
|
||||
testOp(browser, "Bifid Cipher Encode", "test input", "qblb tfovy", ["pass"]);
|
||||
testOp(browser, "Bit shift left", "test input", "\u00E8\u00CA\u00E6\u00E8@\u00D2\u00DC\u00E0\u00EA\u00E8");
|
||||
testOp(browser, "Bit shift right", "test input", ":29:\u0010478::");
|
||||
testOp(browser, "Blowfish Decrypt", "10884e15427dd84ec35204e9c8e921ae", "test_output", [{"option": "Hex", "string": "1234567801234567"}, {"option": "Hex", "string": "0011223344556677"}, "CBC", "Hex", "Raw"]);
|
||||
testOp(browser, "Blowfish Encrypt", "test input", "f0fadbd1d90d774f714248cf26b96410", [{"option": "Hex", "string": "1234567801234567"}, {"option": "Hex", "string": "0011223344556677"}, "CBC", "Raw", "Hex"]);
|
||||
testOp(browser, ["From Hex", "Blur Image", "To Base64"], Images.PNG_HEX, Images.PNG_BLUR_B64);
|
||||
testOpHtml(browser, "Bombe", "XTSYN WAEUG EZALY NRQIM AMLZX MFUOD AWXLY LZCUZ QOQBQ JLCPK NDDRW F", "table tr:last-child td:first-child", "ECG", ["3-rotor", "LEYJVCNIXWPBQMDRTAKZGFUHOS", "BDFHJLCPRTXVZNYEIWGAKMUSQO<W", "AJDKSIRUXBLHWTMCQGZNPYFVOE<F", "ESOVPZJAYQUIRHXLNFTGKDCMWB<K", "AY BR CU DH EQ FS GL IP JX KN MO TZ VW", "HELLO CYBER CHEFU SER", 0, true]);
|
||||
testOp(browser, ["Bzip2 Compress", "To Hex"], "test input", "42 5a 68 39 31 41 59 26 53 59 cf 96 82 1d 00 00 03 91 80 40 00 02 21 4e 00 20 00 21 90 c2 10 c0 88 33 92 8e df 17 72 45 38 50 90 cf 96 82 1d");
|
||||
testOp(browser, ["From Hex", "Bzip2 Decompress"], "425a68393141592653597b0884b7000003038000008200ce00200021a647a4218013709517c5dc914e14241ec2212dc0", "test_output", [[], [true]]);
|
||||
// testOp(browser, "CBOR Decode", "test input", "test output");
|
||||
// testOp(browser, "CBOR Encode", "test input", "test output");
|
||||
testOp(browser, "CRC-16 Checksum", "test input", "77c7");
|
||||
testOp(browser, "CRC-32 Checksum", "test input", "29822bc8");
|
||||
testOp(browser, "CRC-8 Checksum", "test input", "9d");
|
||||
// testOp(browser, "CSS Beautify", "test input", "test_output");
|
||||
// testOp(browser, "CSS Minify", "test input", "test_output");
|
||||
// testOp(browser, "CSS selector", "test input", "test_output");
|
||||
// testOp(browser, "CSV to JSON", "test input", "test_output");
|
||||
// testOp(browser, "CTPH", "test input", "test_output");
|
||||
// testOp(browser, "Cartesian Product", "test input", "test_output");
|
||||
// testOp(browser, "Change IP format", "test input", "test_output");
|
||||
// testOp(browser, "Chi Square", "test input", "test_output");
|
||||
// testOp(browser, "CipherSaber2 Decrypt", "test input", "test_output");
|
||||
// testOp(browser, "CipherSaber2 Encrypt", "test input", "test_output");
|
||||
// testOp(browser, "Citrix CTX1 Decode", "test input", "test_output");
|
||||
// testOp(browser, "Citrix CTX1 Encode", "test input", "test_output");
|
||||
testOpHtml(browser, "Colossus", "CTBKJUVXHZ-H3L4QV+YEZUK+SXOZ/N", "table tr:last-child td:first-child", "30", ["", "KH Pattern", "Z", "", "", "None", "Select Program", "Letter Count", "", "", "", "", "", "", false, "", "", "", "", "", "", false, "", "", "", "", "", "", false, "", false, "", false, false, false, false, false, "", false, false, "", "", 0, "", "", 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]);
|
||||
// testOp(browser, "Comment", "test input", "test_output");
|
||||
// testOp(browser, "Compare CTPH hashes", "test input", "test_output");
|
||||
// testOp(browser, "Compare SSDEEP hashes", "test input", "test_output");
|
||||
// testOp(browser, "Conditional Jump", "test input", "test_output");
|
||||
testOpImage(browser, "Contain Image", "files/Hitchhikers_Guide.jpeg");
|
||||
// testOp(browser, "Convert area", "test input", "test_output");
|
||||
// testOp(browser, "Convert co-ordinate format", "test input", "test_output");
|
||||
// testOp(browser, "Convert data units", "test input", "test_output");
|
||||
// testOp(browser, "Convert distance", "test input", "test_output");
|
||||
testOpImage(browser, "Convert Image Format", "files/Hitchhikers_Guide.jpeg");
|
||||
// testOp(browser, "Convert mass", "test input", "test_output");
|
||||
// testOp(browser, "Convert speed", "test input", "test_output");
|
||||
// testOp(browser, "Convert to NATO alphabet", "test input", "test_output");
|
||||
// testOp(browser, "Count occurrences", "test input", "test_output");
|
||||
testOpImage(browser, "Cover Image", "files/Hitchhikers_Guide.jpeg");
|
||||
testOpImage(browser, "Crop Image", "files/Hitchhikers_Guide.jpeg");
|
||||
// testOp(browser, "CSS Selector", "test input", "test output");
|
||||
// testOp(browser, "DES Decrypt", "test input", "test_output");
|
||||
// testOp(browser, "DES Encrypt", "test input", "test_output");
|
||||
// testOp(browser, "DNS over HTTPS", "test input", "test_output");
|
||||
// testOp(browser, "Dechunk HTTP response", "test input", "test_output");
|
||||
// testOp(browser, "Decode NetBIOS Name", "test input", "test_output");
|
||||
// testOp(browser, "Decode text", "test input", "test_output");
|
||||
// testOp(browser, "Defang IP Addresses", "test input", "test_output");
|
||||
// testOp(browser, "Defang URL", "test input", "test_output");
|
||||
// testOp(browser, "Derive EVP key", "test input", "test_output");
|
||||
// testOp(browser, "Derive PBKDF2 key", "test input", "test_output");
|
||||
// testOp(browser, "Detect File Type", "test input", "test_output");
|
||||
testOpHtml(browser, "Diff", "The cat sat on the mat\n\nThe mat cat on the sat", "ins:first-child", "mat", ["\\n\\n", "Word", true, true, false, false]);
|
||||
// testOp(browser, "Disassemble x86", "test input", "test_output");
|
||||
testOpImage(browser, "Dither Image", "files/Hitchhikers_Guide.jpeg");
|
||||
// testOp(browser, "Divide", "test input", "test_output");
|
||||
// testOp(browser, "Drop bytes", "test input", "test_output");
|
||||
// testOp(browser, "Encode NetBIOS Name", "test input", "test_output");
|
||||
// testOp(browser, "Encode text", "test input", "test_output");
|
||||
// testOp(browser, "Enigma", "test input", "test_output");
|
||||
testOpHtml(browser, "Entropy", "test input", "", /Shannon entropy: 2.8464393446710154/);
|
||||
// testOp(browser, "Escape string", "test input", "test_output");
|
||||
// testOp(browser, "Escape Unicode Characters", "test input", "test_output");
|
||||
// testOp(browser, "Expand alphabet range", "test input", "test_output");
|
||||
// testOp(browser, "Extract dates", "test input", "test_output");
|
||||
// testOp(browser, "Extract domains", "test input", "test_output");
|
||||
// testOp(browser, "Extract EXIF", "test input", "test_output");
|
||||
// testOp(browser, "Extract email addresses", "test input", "test_output");
|
||||
// testOp(browser, "Extract file paths", "test input", "test_output");
|
||||
testOpFile(browser, "Extract Files", "files/Hitchhikers_Guide.jpeg", ".card:last-child .collapsed", "extracted_at_0x3d38.zlib");
|
||||
testOpFile(browser, "Extract ID3", "files/mp3example.mp3", "tr:last-child td:last-child", "Kevin MacLeod");
|
||||
// testOp(browser, "Extract IP addresses", "test input", "test_output");
|
||||
// testOp(browser, "Extract LSB", "test input", "test_output");
|
||||
// testOp(browser, "Extract MAC addresses", "test input", "test_output");
|
||||
// testOp(browser, "Extract RGBA", "test input", "test_output");
|
||||
// testOp(browser, "Extract URLs", "test input", "test_output");
|
||||
// testOp(browser, "Filter", "test input", "test_output");
|
||||
// testOp(browser, "Find / Replace", "test input", "test_output");
|
||||
// testOp(browser, "Fletcher-16 Checksum", "test input", "test_output");
|
||||
// testOp(browser, "Fletcher-32 Checksum", "test input", "test_output");
|
||||
// testOp(browser, "Fletcher-64 Checksum", "test input", "test_output");
|
||||
// testOp(browser, "Fletcher-8 Checksum", "test input", "test_output");
|
||||
testOpImage(browser, "Flip Image", "files/Hitchhikers_Guide.jpeg");
|
||||
// testOp(browser, "Fork", "test input", "test_output");
|
||||
// testOp(browser, "Format MAC addresses", "test input", "test_output");
|
||||
testOpHtml(browser, "Frequency distribution", "test input", "", /Number of bytes not represented: 248/);
|
||||
// testOp(browser, "From BCD", "test input", "test_output");
|
||||
// testOp(browser, "From Base", "test input", "test_output");
|
||||
// testOp(browser, "From Base32", "test input", "test_output");
|
||||
// testOp(browser, "From Base58", "test input", "test_output");
|
||||
// testOp(browser, "From Base62", "test input", "test_output");
|
||||
// testOp(browser, "From Base64", "test input", "test_output");
|
||||
// testOp(browser, "From Base85", "test input", "test_output");
|
||||
// testOp(browser, "From Binary", "test input", "test_output");
|
||||
// testOp(browser, "From Braille", "test input", "test_output");
|
||||
// testOp(browser, "From Case Insensitive Regex", "test input", "test_output");
|
||||
// testOp(browser, "From Charcode", "test input", "test_output");
|
||||
// testOp(browser, "From Decimal", "test input", "test_output");
|
||||
// testOp(browser, "From HTML Entity", "test input", "test_output");
|
||||
// testOp(browser, "From Hex", "test input", "test_output");
|
||||
// testOp(browser, "From Hex Content", "test input", "test_output");
|
||||
// testOp(browser, "From Hexdump", "test input", "test_output");
|
||||
// testOp(browser, "From MessagePack", "test input", "test_output");
|
||||
// testOp(browser, "From Morse Code", "test input", "test_output");
|
||||
// testOp(browser, "From Octal", "test input", "test_output");
|
||||
// testOp(browser, "From Punycode", "test input", "test_output");
|
||||
// testOp(browser, "From Quoted Printable", "test input", "test_output");
|
||||
// testOp(browser, "From UNIX Timestamp", "test input", "test_output");
|
||||
testOpHtml(browser, "Fuzzy Match", "test input", "b:last-child", "in", ["tein", 15, 30, 30, 15, -5, -15, -1]);
|
||||
// testOp(browser, "GOST hash", "test input", "test_output");
|
||||
// testOp(browser, "Generate all hashes", "test input", "test_output");
|
||||
// testOp(browser, "Generate HOTP", "test input", "test_output");
|
||||
testOpHtml(browser, "Generate Image", "test input", "img", "");
|
||||
// testOp(browser, "Generate Lorem Ipsum", "test input", "test_output");
|
||||
// testOp(browser, "Generate PGP Key Pair", "test input", "test_output");
|
||||
testOpHtml(browser, "Generate QR Code", "test input", "img", "");
|
||||
// testOp(browser, "Generate TOTP", "test input", "test_output");
|
||||
// testOp(browser, "Generate UUID", "test input", "test_output");
|
||||
// testOp(browser, "Generic Code Beautify", "test input", "test_output");
|
||||
// testOp(browser, "Group IP addresses", "test input", "test_output");
|
||||
// testOp(browser, "Gunzip", "test input", "test_output");
|
||||
// testOp(browser, "Gzip", "test input", "test_output");
|
||||
// testOp(browser, "HAS-160", "test input", "test_output");
|
||||
// testOp(browser, "HMAC", "test input", "test_output");
|
||||
// testOp(browser, "HTML To Text", "test input", "test_output");
|
||||
// testOp(browser, "HTTP request", "test input", "test_output");
|
||||
// testOp(browser, "Hamming Distance", "test input", "test_output");
|
||||
// testOp(browser, "Haversine distance", "test input", "test_output");
|
||||
// testOp(browser, "Head", "test input", "test_output");
|
||||
testOpHtml(browser, "Heatmap chart", "X Y\n0 1\n1 2", "svg", /X/);
|
||||
testOpHtml(browser, "Hex Density chart", "X Y\n0 1\n1 2", "svg", /X/);
|
||||
// testOp(browser, "Hex to Object Identifier", "test input", "test_output");
|
||||
// testOp(browser, "Hex to PEM", "test input", "test_output");
|
||||
testOpImage(browser, "Image Brightness / Contrast", "files/Hitchhikers_Guide.jpeg");
|
||||
testOpImage(browser, "Image Filter", "files/Hitchhikers_Guide.jpeg");
|
||||
testOpImage(browser, "Image Hue/Saturation/Lightness", "files/Hitchhikers_Guide.jpeg");
|
||||
testOpImage(browser, "Image Opacity", "files/Hitchhikers_Guide.jpeg");
|
||||
testOpHtml(browser, "Index of Coincidence", "test input", "", /Index of Coincidence: 0.08333333333333333/);
|
||||
testOpImage(browser, "Invert Image", "files/Hitchhikers_Guide.jpeg");
|
||||
// testOp(browser, "JPath expression", "test input", "test_output");
|
||||
testOpHtml(browser, "JSON Beautify", "{a:1}", ".json-dict .json-literal", "1");
|
||||
// testOp(browser, "JSON Minify", "test input", "test_output");
|
||||
// testOp(browser, "JSON to CSV", "test input", "test_output");
|
||||
// testOp(browser, "JWT Decode", "test input", "test_output");
|
||||
// testOp(browser, "JWT Sign", "test input", "test_output");
|
||||
// testOp(browser, "JWT Verify", "test input", "test_output");
|
||||
// testOp(browser, "JavaScript Beautify", "test input", "test_output");
|
||||
// testOp(browser, "JavaScript Minify", "test input", "test_output");
|
||||
// testOp(browser, "JavaScript Parser", "test input", "test_output");
|
||||
// testOp(browser, "Jump", "test input", "test_output");
|
||||
// testOp(browser, "Keccak", "test input", "test_output");
|
||||
// testOp(browser, "Label", "test input", "test_output");
|
||||
// testOp(browser, "LM Hash", "test input", "test output");
|
||||
// testOp(browser, "Lorenz", "test input", "test_output");
|
||||
// testOp(browser, "Luhn Checksum", "test input", "test_output");
|
||||
// testOp(browser, "LZ String", "test input", "test output");
|
||||
// testOp(browser, "LZ4 Compress", "test input", "test output");
|
||||
// testOp(browser, "LZ4 Decompress", "test input", "test output");
|
||||
// testOp(browser, "LZMA Compress", "test input", "test output");
|
||||
// testOp(browser, "LZMA Decompress", "test input", "test output");
|
||||
// testOp(browser, "MD2", "test input", "test_output");
|
||||
// testOp(browser, "MD4", "test input", "test_output");
|
||||
// testOp(browser, "MD5", "test input", "test_output");
|
||||
// testOp(browser, "MD6", "test input", "test_output");
|
||||
testOpHtml(browser, "Magic", "dGVzdF9vdXRwdXQ=", "tr:nth-of-type(1) th:nth-of-type(2)", "Result snippet");
|
||||
testOpHtml(browser, "Magic", "dGVzdF9vdXRwdXQ=", "tr:nth-of-type(2) td:nth-of-type(2)", "test_output");
|
||||
testOpHtml(browser, "Magic", "dGVzdF9vdXRwdXQ=", "tr:nth-of-type(2) td:nth-of-type(1)", /Base64/);
|
||||
// testOp(browser, "Mean", "test input", "test_output");
|
||||
// testOp(browser, "Median", "test input", "test_output");`
|
||||
// testOp(browser, "Merge", "test input", "test_output");`
|
||||
// testOp(browser, "Microsoft Script Decoder", "test input", "test_output");
|
||||
// testOp(browser, "Multiple Bombe", "test input", "test_output");
|
||||
// testOp(browser, "Multiply", "test input", "test_output");
|
||||
// testOp(browser, "NOT", "test input", "test_output");
|
||||
// testOp(browser, "Normalise Image", "test input", "test_output");
|
||||
// testOp(browser, "Normalise Unicode", "test input", "test_output");
|
||||
// testOp(browser, "Numberwang", "test input", "test_output");
|
||||
// testOp(browser, "OR", "test input", "test_output");
|
||||
// testOp(browser, "Object Identifier to Hex", "test input", "test_output");
|
||||
testOpHtml(browser, "Offset checker", "test input\n\nbest input", ".hl5", "est input");
|
||||
// testOp(browser, "Optical Character Recognition", "test input", "test_output");
|
||||
// testOp(browser, "PEM to Hex", "test input", "test_output");
|
||||
// testOp(browser, "PGP Decrypt", "test input", "test_output");
|
||||
// testOp(browser, "PGP Decrypt and Verify", "test input", "test_output");
|
||||
// testOp(browser, "PGP Encrypt", "test input", "test_output");
|
||||
// testOp(browser, "PGP Encrypt and Sign", "test input", "test_output");
|
||||
// testOp(browser, "PGP Verify", "test input", "test_output");
|
||||
// testOp(browser, "PHP Deserialize", "test input", "test_output");
|
||||
// testOp(browser, "Pad lines", "test input", "test_output");
|
||||
// testOp(browser, "Parse ASN.1 hex string", "test input", "test_output");
|
||||
testOpHtml(browser, "Parse colour code", "#000", ".colorpicker-preview", "rgb(0, 0, 0)");
|
||||
testOpHtml(browser, "Parse DateTime", "01/12/2000 13:00:00", "", /Date: Friday 1st December 2000/);
|
||||
// testOp(browser, "Parse IP range", "test input", "test_output");
|
||||
testOpHtml(browser, "Parse IPv4 header", "45 c0 00 c4 02 89 00 00 ff 11 1e 8c c0 a8 0c 01 c0 a8 0c 02", "tr:last-child td:last-child", "192.168.12.2");
|
||||
// testOp(browser, "Parse IPv6 address", "test input", "test_output");
|
||||
// testOp(browser, "Parse ObjectID timestamp", "test input", "test_output");
|
||||
// testOp(browser, "Parse QR Code", "test input", "test_output");
|
||||
// testOp(browser, "Parse SSH Host Key", "test input", "test_output");
|
||||
testOpHtml(browser, "Parse TCP", "c2eb0050a138132e70dc9fb9501804025ea70000", "tr:nth-of-type(2) td:last-child", "49899");
|
||||
// testOp(browser, "Parse TLV", "test input", "test_output");
|
||||
testOpHtml(browser, "Parse UDP", "04 89 00 35 00 2c 01 01", "tr:last-child td:last-child", "0x0101");
|
||||
// testOp(browser, "Parse UNIX file permissions", "test input", "test_output");
|
||||
// testOp(browser, "Parse URI", "test input", "test_output");
|
||||
// testOp(browser, "Parse User Agent", "test input", "test_output");
|
||||
// testOp(browser, "Parse X.509 certificate", "test input", "test_output");
|
||||
testOpFile(browser, "Play Media", "files/mp3example.mp3", "audio", "");
|
||||
// testOp(browser, "Power Set", "test input", "test_output");
|
||||
// testOp(browser, "Protobuf Decode", "test input", "test_output");
|
||||
// testOp(browser, "Pseudo-Random Number Generator", "test input", "test_output");
|
||||
// testOp(browser, "RC2 Decrypt", "test input", "test_output");
|
||||
// testOp(browser, "RC2 Encrypt", "test input", "test_output");
|
||||
// testOp(browser, "RC4", "test input", "test_output");
|
||||
// testOp(browser, "RC4 Drop", "test input", "test_output");
|
||||
// testOp(browser, "RIPEMD", "test input", "test_output");
|
||||
// testOp(browser, "ROT13", "test input", "test_output");
|
||||
// testOp(browser, "ROT47", "test input", "test_output");
|
||||
// testOp(browser, "ROT8000", "test input", "test_output");
|
||||
// testOp(browser, "Rail Fence Cipher Decode", "test input", "test_output");
|
||||
// testOp(browser, "Rail Fence Cipher Encode", "test input", "test_output");
|
||||
testOpImage(browser, "Randomize Colour Palette", "files/Hitchhikers_Guide.jpeg");
|
||||
// testOp(browser, "Raw Deflate", "test input", "test_output");
|
||||
// testOp(browser, "Raw Inflate", "test input", "test_output");
|
||||
// testOp(browser, "Register", "test input", "test_output");
|
||||
testOpHtml(browser, "Regular expression", "The cat sat on the mat", ".hl2:last-child", "mat", ["User defined", ".at", true, true, false, false, false, false, "Highlight matches"]);
|
||||
// testOp(browser, "Remove Diacritics", "test input", "test_output");
|
||||
// testOp(browser, "Remove EXIF", "test input", "test_output");
|
||||
// testOp(browser, "Remove line numbers", "test input", "test_output");
|
||||
// testOp(browser, "Remove null bytes", "test input", "test_output");
|
||||
// testOp(browser, "Remove whitespace", "test input", "test_output");
|
||||
testOpImage(browser, "Render Image", "files/Hitchhikers_Guide.jpeg");
|
||||
testOpHtml(browser, "Render Markdown", "# test input", "h1", "test input");
|
||||
testOpImage(browser, "Resize Image", "files/Hitchhikers_Guide.jpeg");
|
||||
// testOp(browser, "Return", "test input", "test_output");
|
||||
// testOp(browser, "Reverse", "test input", "test_output");
|
||||
testOpImage(browser, "Rotate Image", "files/Hitchhikers_Guide.jpeg");
|
||||
// testOp(browser, "Rotate left", "test input", "test_output");
|
||||
// testOp(browser, "Rotate right", "test input", "test_output");
|
||||
// testOp(browser, "Scrypt", "test input", "test output");
|
||||
// testOp(browser, "SHA0", "test input", "test_output");
|
||||
// testOp(browser, "SHA1", "test input", "test_output");
|
||||
// testOp(browser, "SHA2", "test input", "test_output");
|
||||
// testOp(browser, "SHA3", "test input", "test_output");
|
||||
// testOp(browser, "SQL Beautify", "test input", "test_output");
|
||||
// testOp(browser, "SQL Minify", "test input", "test_output");
|
||||
// testOp(browser, "SSDEEP", "test input", "test_output");
|
||||
// testOp(browser, "SUB", "test input", "test_output");
|
||||
// testOp(browser, "Scan for Embedded Files", "test input", "test_output");
|
||||
testOpHtml(browser, "Scatter chart", "a b\n1 2", "svg", /a/);
|
||||
// testOp(browser, "Scrypt", "test input", "test_output");
|
||||
testOpHtml(browser, "Series chart", "1 2 3\n4 5 6", "svg", /3/);
|
||||
// testOp(browser, "Set Difference", "test input", "test_output");
|
||||
// testOp(browser, "Set Intersection", "test input", "test_output");
|
||||
// testOp(browser, "Set Union", "test input", "test_output");
|
||||
// testOp(browser, "Shake", "test input", "test_output");
|
||||
testOpImage(browser, "Sharpen Image", "files/Hitchhikers_Guide.jpeg");
|
||||
testOpHtml(browser, "Show Base64 offsets", "test input", "span:nth-last-of-type(2)", "B");
|
||||
testOpHtml(browser, "Show on map", "51.5007° N, 0.1246° W", "#presentedMap .leaflet-popup-content", "51.5007,-0.1246");
|
||||
// testOp(browser, "Sleep", "test input", "test_output");
|
||||
// testOp(browser, "SM3", "test input", "test output");
|
||||
// testOp(browser, "Snefru", "test input", "test_output");
|
||||
// testOp(browser, "Sort", "test input", "test_output");
|
||||
// testOp(browser, "Split", "test input", "test_output");
|
||||
// testOpImage(browser, "Split Colour Channels", "files/Hitchhikers_Guide.jpeg");
|
||||
// testOp(browser, "Standard Deviation", "test input", "test_output");
|
||||
// testOp(browser, "Streebog", "test input", "test_output");
|
||||
// testOp(browser, "Strings", "test input", "test_output");
|
||||
// testOp(browser, "Strip HTML tags", "test input", "test_output");
|
||||
// testOp(browser, "Strip HTTP headers", "test input", "test_output");
|
||||
// testOp(browser, "Subsection", "test input", "test_output");
|
||||
// testOp(browser, "Substitute", "test input", "test_output");
|
||||
// testOp(browser, "Subtract", "test input", "test_output");
|
||||
// testOp(browser, "Sum", "test input", "test_output");
|
||||
// testOp(browser, "Swap endianness", "test input", "test_output");
|
||||
// testOp(browser, "Symmetric Difference", "test input", "test_output");
|
||||
testOpHtml(browser, "Syntax highlighter", "var a = [4,5,6]", ".hljs-selector-attr", "[4,5,6]");
|
||||
// testOp(browser, "TCP/IP Checksum", "test input", "test_output");
|
||||
// testOp(browser, "Tail", "test input", "test_output");
|
||||
// testOp(browser, "Take bytes", "test input", "test_output");
|
||||
testOp(browser, "Tar", "test input", /^file\.txt\x00{92}/);
|
||||
testOpHtml(browser, "Text Encoding Brute Force", "test input", "tr:nth-of-type(4) td:last-child", /t\u2400e\u2400s\u2400t\u2400/);
|
||||
// testOp(browser, "To BCD", "test input", "test_output");
|
||||
// testOp(browser, "To Base", "test input", "test_output");
|
||||
// testOp(browser, "To Base32", "test input", "test_output");
|
||||
// testOp(browser, "To Base58", "test input", "test_output");
|
||||
// testOp(browser, "To Base62", "test input", "test_output");
|
||||
// testOp(browser, "To Base64", "test input", "test_output");
|
||||
// testOp(browser, "To Base85", "test input", "test_output");
|
||||
// testOp(browser, "To Binary", "test input", "test_output");
|
||||
// testOp(browser, "To Braille", "test input", "test_output");
|
||||
// testOp(browser, "To Camel case", "test input", "test_output");
|
||||
// testOp(browser, "To Case Insensitive Regex", "test input", "test_output");
|
||||
// testOp(browser, "To Charcode", "test input", "test_output");
|
||||
// testOp(browser, "To Decimal", "test input", "test_output");
|
||||
// testOp(browser, "To HTML Entity", "test input", "test_output");
|
||||
// testOp(browser, "To Hex", "test input", "test_output");
|
||||
// testOp(browser, "To Hex Content", "test input", "test_output");
|
||||
// testOp(browser, "To Hexdump", "test input", "test_output");
|
||||
// testOp(browser, "To Kebab case", "test input", "test_output");
|
||||
// testOp(browser, "To Lower case", "test input", "test_output");
|
||||
// testOp(browser, "To MessagePack", "test input", "test_output");
|
||||
// testOp(browser, "To Morse Code", "test input", "test_output");
|
||||
// testOp(browser, "To Octal", "test input", "test_output");
|
||||
// testOp(browser, "To Punycode", "test input", "test_output");
|
||||
// testOp(browser, "To Quoted Printable", "test input", "test_output");
|
||||
// testOp(browser, "To Snake case", "test input", "test_output");
|
||||
testOpHtml(browser, "To Table", "a,b,c\n1,2,3", "", /| a | b | c |/);
|
||||
// testOp(browser, "To UNIX Timestamp", "test input", "test_output");
|
||||
// testOp(browser, "To Upper case", "test input", "test_output");
|
||||
// testOp(browser, "Translate DateTime Format", "test input", "test_output");
|
||||
// testOp(browser, "Triple DES Decrypt", "test input", "test_output");
|
||||
// testOp(browser, "Triple DES Encrypt", "test input", "test_output");
|
||||
// testOp(browser, "Typex", "test input", "test_output");
|
||||
// testOp(browser, "UNIX Timestamp to Windows Filetime", "test input", "test_output");
|
||||
// testOp(browser, "URL Decode", "test input", "test_output");
|
||||
// testOp(browser, "URL Encode", "test input", "test_output");
|
||||
// testOp(browser, "Unescape string", "test input", "test_output");
|
||||
// testOp(browser, "Unescape Unicode Characters", "test input", "test_output");
|
||||
// testOp(browser, "Unique", "test input", "test_output");
|
||||
testOpHtml(browser, ["Tar", "Untar"], "test input", ".float-right", /10 bytes/);
|
||||
testOpHtml(browser, ["Zip", "Unzip"], "test input", "#files span.float-right", /10 bytes/);
|
||||
// testOp(browser, "VarInt Decode", "test input", "test_output");
|
||||
// testOp(browser, "VarInt Encode", "test input", "test_output");
|
||||
testOpImage(browser, "View Bit Plane", "files/Hitchhikers_Guide.jpeg");
|
||||
// testOp(browser, "Vigenère Decode", "test input", "test_output");
|
||||
// testOp(browser, "Vigenère Encode", "test input", "test_output");
|
||||
testOp(browser, "Whirlpool", "test input", "8a0ee6885ba241353d17cbbe5f06538a7f04c8c955d376c20d6233fd4dd41aaffd13291447090ce781b5f940da266ed6d02cf8b79d4867065d10bdfc04166f38");
|
||||
// testOp(browser, "Windows Filetime to UNIX Timestamp", "test input", "test_output");
|
||||
testOp(browser, "XKCD Random Number", "test input", "4");
|
||||
// testOp(browser, "XML Beautify", "test input", "test_output");
|
||||
// testOp(browser, "XML Minify", "test input", "test_output");
|
||||
// testOp(browser, "XOR", "test input", "test_output");
|
||||
// testOp(browser, "XOR Brute Force", "test input", "test_output");
|
||||
// testOp(browser, "XPath expression", "test input", "test_output");
|
||||
// testOp(browser, "YARA Rules", "test input", "test_output");
|
||||
testOp(browser, "Zip", "test input", /^PK\u0003\u0004\u0014\u0000{3}/);
|
||||
// testOp(browser, "Zlib Deflate", "test input", "test_output");
|
||||
// testOp(browser, "Zlib Inflate", "test input", "test_output");
|
||||
},
|
||||
|
||||
|
||||
after: browser => {
|
||||
browser.end();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/** @function
|
||||
* Clears the current recipe and bakes a new operation.
|
||||
*
|
||||
* @param {Browser} browser - Nightwatch client
|
||||
* @param {string|Array<string>} opName - name of operation to be tested, array for multiple ops
|
||||
* @param {string} input - input text for test
|
||||
* @param {Array<string>|Array<Array<string>>} args - arguments, nested if multiple ops
|
||||
*/
|
||||
function bakeOp(browser, opName, input, args=[]) {
|
||||
browser.perform(function() {
|
||||
console.log(`Current test: ${opName}`);
|
||||
});
|
||||
utils.loadRecipe(browser, opName, input, args);
|
||||
browser.waitForElementVisible("#stale-indicator", 5000);
|
||||
utils.bake(browser);
|
||||
}
|
||||
|
||||
/** @function
|
||||
* Clears the current recipe and tests a new operation.
|
||||
*
|
||||
* @param {Browser} browser - Nightwatch client
|
||||
* @param {string|Array<string>} opName - name of operation to be tested, array for multiple ops
|
||||
* @param {string} input - input text
|
||||
* @param {string} output - expected output
|
||||
* @param {Array<string>|Array<Array<string>>} args - arguments, nested if multiple ops
|
||||
*/
|
||||
function testOp(browser, opName, input, output, args=[]) {
|
||||
bakeOp(browser, opName, input, args);
|
||||
utils.expectOutput(browser, output);
|
||||
}
|
||||
|
||||
/** @function
|
||||
* Clears the current recipe and tests a new operation with HTML output.
|
||||
*
|
||||
* @param {Browser} browser - Nightwatch client
|
||||
* @param {string|Array<string>} opName - name of operation to be tested array for multiple ops
|
||||
* @param {string} input - input text
|
||||
* @param {string} cssSelector - CSS selector for HTML output
|
||||
* @param {string} output - expected output
|
||||
* @param {Array<string>|Array<Array<string>>} args - arguments, nested if multiple ops
|
||||
*/
|
||||
function testOpHtml(browser, opName, input, cssSelector, output, args=[]) {
|
||||
bakeOp(browser, opName, input, args);
|
||||
|
||||
if (typeof output === "string") {
|
||||
browser.expect.element("#output-html " + cssSelector).text.that.equals(output);
|
||||
} else if (output instanceof RegExp) {
|
||||
browser.expect.element("#output-html " + cssSelector).text.that.matches(output);
|
||||
}
|
||||
}
|
||||
|
||||
/** @function
|
||||
* Clears the current recipe and tests a new Image-based operation.
|
||||
*
|
||||
* @param {Browser} browser - Nightwatch client
|
||||
* @param {string|Array<string>} opName - name of operation to be tested array for multiple ops
|
||||
* @param {string} filename - filename of image file from samples directory
|
||||
* @param {Array<string>|Array<Array<string>>} args - arguments, nested if multiple ops
|
||||
*/
|
||||
function testOpImage(browser, opName, filename, args) {
|
||||
browser.perform(function() {
|
||||
console.log(`Current test: ${opName}`);
|
||||
});
|
||||
utils.loadRecipe(browser, opName, "", args);
|
||||
utils.uploadFile(browser, filename);
|
||||
browser.waitForElementVisible("#stale-indicator", 5000);
|
||||
utils.bake(browser);
|
||||
|
||||
browser
|
||||
.waitForElementVisible("#output-html img")
|
||||
.expect.element("#output-html img").to.have.css("width").which.matches(/^[^0]\d*px/);
|
||||
}
|
||||
|
||||
/** @function
|
||||
* Clears the current recipe and tests a new File-based operation.
|
||||
*
|
||||
* @param {Browser} browser - Nightwatch client
|
||||
* @param {string|Array<string>} opName - name of operation to be tested array for multiple ops
|
||||
* @param {string} filename - filename of file from samples directory
|
||||
* @param {string} cssSelector - CSS selector for HTML output
|
||||
* @param {string} output - expected output
|
||||
* @param {Array<string>|Array<Array<string>>} args - arguments, nested if multiple ops
|
||||
*/
|
||||
function testOpFile(browser, opName, filename, cssSelector, output, args) {
|
||||
browser.perform(function() {
|
||||
console.log(`Current test: ${opName}`);
|
||||
});
|
||||
utils.loadRecipe(browser, opName, "", args);
|
||||
utils.uploadFile(browser, filename);
|
||||
browser.pause(100).waitForElementVisible("#stale-indicator", 5000);
|
||||
utils.bake(browser);
|
||||
|
||||
if (typeof output === "string") {
|
||||
browser.expect.element("#output-html " + cssSelector).text.that.equals(output);
|
||||
} else if (output instanceof RegExp) {
|
||||
browser.expect.element("#output-html " + cssSelector).text.that.matches(output);
|
||||
}
|
||||
}
|
247
tests/browser/browserUtils.js
Normal file
247
tests/browser/browserUtils.js
Normal file
|
@ -0,0 +1,247 @@
|
|||
/**
|
||||
* Utility functions for browser tests.
|
||||
*
|
||||
* @author n1474335 [n1474335@gmail.com]
|
||||
* @copyright Crown Copyright 2023
|
||||
* @license Apache-2.0
|
||||
*/
|
||||
|
||||
/** @function
|
||||
* Clears the recipe and input
|
||||
*
|
||||
* @param {Browser} browser - Nightwatch client
|
||||
*/
|
||||
function clear(browser) {
|
||||
browser
|
||||
.useCss()
|
||||
.click("#clr-recipe")
|
||||
.click("#clr-io")
|
||||
.waitForElementNotPresent("#rec-list li.operation")
|
||||
.expect.element("#input-text .cm-content").text.that.equals("");
|
||||
}
|
||||
|
||||
/** @function
|
||||
* Sets the input to the desired string
|
||||
*
|
||||
* @param {Browser} browser - Nightwatch client
|
||||
* @param {string} input - The text to populate the input with
|
||||
* @param {boolean} [type=true] - Whether to type the characters in by using sendKeys,
|
||||
* or to set the value of the editor directly (useful for special characters)
|
||||
*/
|
||||
function setInput(browser, input, type=true) {
|
||||
clear(browser);
|
||||
if (type) {
|
||||
browser
|
||||
.useCss()
|
||||
.sendKeys("#input-text .cm-content", input)
|
||||
.pause(100);
|
||||
} else {
|
||||
browser.execute(text => {
|
||||
window.app.setInput(text);
|
||||
}, [input]);
|
||||
}
|
||||
}
|
||||
|
||||
/** @function
|
||||
* Triggers a bake
|
||||
*
|
||||
* @param {Browser} browser - Nightwatch client
|
||||
*/
|
||||
function bake(browser) {
|
||||
browser
|
||||
.click("#bake")
|
||||
.waitForElementNotVisible("#stale-indicator", 5000)
|
||||
.waitForElementNotVisible("#output-loader", 5000);
|
||||
}
|
||||
|
||||
/** @function
|
||||
* Sets the character encoding in the input or output
|
||||
*
|
||||
* @param {Browser} browser - Nightwatch client
|
||||
* @param {string} io - Either "input" or "output"
|
||||
* @param {string} enc - The encoding to be set
|
||||
*/
|
||||
function setChrEnc(browser, io, enc) {
|
||||
io = `#${io}-text`;
|
||||
browser
|
||||
.useCss()
|
||||
.click(io + " .chr-enc-value")
|
||||
.waitForElementVisible(io + " .chr-enc-select .cm-status-bar-select-scroll")
|
||||
.click("link text", enc)
|
||||
.waitForElementNotVisible(io + " .chr-enc-select .cm-status-bar-select-scroll")
|
||||
.expect.element(io + " .chr-enc-value").text.that.equals(enc);
|
||||
}
|
||||
|
||||
/** @function
|
||||
* Sets the end of line sequence in the input or output
|
||||
*
|
||||
* @param {Browser} browser - Nightwatch client
|
||||
* @param {string} io - Either "input" or "output"
|
||||
* @param {string} eol - The sequence to set
|
||||
*/
|
||||
function setEOLSeq(browser, io, eol) {
|
||||
io = `#${io}-text`;
|
||||
browser
|
||||
.useCss()
|
||||
.click(io + " .eol-value")
|
||||
.waitForElementVisible(io + " .eol-select .cm-status-bar-select-content")
|
||||
.click(`${io} .cm-status-bar-select-content a[data-val=${eol}]`)
|
||||
.waitForElementNotVisible(io + " .eol-select .cm-status-bar-select-content")
|
||||
.expect.element(io + " .eol-value").text.that.equals(eol);
|
||||
}
|
||||
|
||||
/** @function
|
||||
* Copies whatever is currently selected
|
||||
*
|
||||
* @param {Browser} browser - Nightwatch client
|
||||
*/
|
||||
function copy(browser) {
|
||||
browser.perform(function() {
|
||||
const actions = this.actions({async: true});
|
||||
|
||||
// Ctrl + Ins used as this works on Windows, Linux and Mac
|
||||
return actions
|
||||
.keyDown(browser.Keys.CONTROL)
|
||||
.keyDown(browser.Keys.INSERT)
|
||||
.keyUp(browser.Keys.INSERT)
|
||||
.keyUp(browser.Keys.CONTROL);
|
||||
});
|
||||
}
|
||||
|
||||
/** @function
|
||||
* Pastes into the target element
|
||||
*
|
||||
* @param {Browser} browser - Nightwatch client
|
||||
* @param {string} el - Target element selector
|
||||
*/
|
||||
function paste(browser, el) {
|
||||
browser
|
||||
.click(el)
|
||||
.perform(function() {
|
||||
const actions = this.actions({async: true});
|
||||
|
||||
// Shift + Ins used as this works on Windows, Linux and Mac
|
||||
return actions
|
||||
.keyDown(browser.Keys.SHIFT)
|
||||
.keyDown(browser.Keys.INSERT)
|
||||
.keyUp(browser.Keys.INSERT)
|
||||
.keyUp(browser.Keys.SHIFT);
|
||||
})
|
||||
.pause(100);
|
||||
}
|
||||
|
||||
/** @function
|
||||
* Loads a recipe and input
|
||||
*
|
||||
* @param {Browser} browser - Nightwatch client
|
||||
* @param {string|Array<string>} opName - name of operation to be loaded, array for multiple ops
|
||||
* @param {string} input - input text for test
|
||||
* @param {Array<string>|Array<Array<string>>} args - arguments, nested if multiple ops
|
||||
*/
|
||||
function loadRecipe(browser, opName, input, args) {
|
||||
let recipeConfig;
|
||||
|
||||
if (typeof(opName) === "string") {
|
||||
recipeConfig = JSON.stringify([{
|
||||
"op": opName,
|
||||
"args": args
|
||||
}]);
|
||||
} else if (opName instanceof Array) {
|
||||
recipeConfig = JSON.stringify(
|
||||
opName.map((op, i) => {
|
||||
return {
|
||||
op: op,
|
||||
args: args.length ? args[i] : []
|
||||
};
|
||||
})
|
||||
);
|
||||
} else {
|
||||
throw new Error("Invalid operation type. Must be string or array of strings. Received: " + typeof(opName));
|
||||
}
|
||||
|
||||
clear(browser);
|
||||
setInput(browser, input, false);
|
||||
browser
|
||||
.urlHash("recipe=" + recipeConfig)
|
||||
.waitForElementPresent("#rec-list li.operation");
|
||||
}
|
||||
|
||||
/** @function
|
||||
* Tests whether the output matches a given value
|
||||
*
|
||||
* @param {Browser} browser - Nightwatch client
|
||||
* @param {string|RegExp} expected - The expected output value
|
||||
*/
|
||||
function expectOutput(browser, expected) {
|
||||
browser.execute(expected => {
|
||||
const output = window.app.manager.output.outputEditorView.state.doc.toString();
|
||||
if (expected instanceof RegExp) {
|
||||
return expected.test(output);
|
||||
} else {
|
||||
return expected === output;
|
||||
}
|
||||
}, [expected]);
|
||||
}
|
||||
|
||||
/** @function
|
||||
* Uploads a file using the #open-file input
|
||||
*
|
||||
* @param {Browser} browser - Nightwatch client
|
||||
* @param {string} filename - A path to a file in the samples directory
|
||||
*/
|
||||
function uploadFile(browser, filename) {
|
||||
const filepath = require("path").resolve(__dirname + "/../samples/" + filename);
|
||||
|
||||
// The file input cannot be interacted with by nightwatch while it is hidden,
|
||||
// so we temporarily expose it for the purposes of this test.
|
||||
browser.execute(() => {
|
||||
document.getElementById("open-file").style.display = "block";
|
||||
});
|
||||
browser
|
||||
.pause(100)
|
||||
.setValue("#open-file", filepath)
|
||||
.pause(100);
|
||||
browser.execute(() => {
|
||||
document.getElementById("open-file").style.display = "none";
|
||||
});
|
||||
browser.waitForElementVisible("#input-text .cm-file-details");
|
||||
}
|
||||
|
||||
/** @function
|
||||
* Uploads a folder using the #open-folder input
|
||||
*
|
||||
* @param {Browser} browser - Nightwatch client
|
||||
* @param {string} foldername - A path to a folder in the samples directory
|
||||
*/
|
||||
function uploadFolder(browser, foldername) {
|
||||
const folderpath = require("path").resolve(__dirname + "/../samples/" + foldername);
|
||||
|
||||
// The folder input cannot be interacted with by nightwatch while it is hidden,
|
||||
// so we temporarily expose it for the purposes of this test.
|
||||
browser.execute(() => {
|
||||
document.getElementById("open-folder").style.display = "block";
|
||||
});
|
||||
browser
|
||||
.pause(100)
|
||||
.setValue("#open-folder", folderpath)
|
||||
.pause(500);
|
||||
browser.execute(() => {
|
||||
document.getElementById("open-folder").style.display = "none";
|
||||
});
|
||||
browser.waitForElementVisible("#input-text .cm-file-details");
|
||||
}
|
||||
|
||||
|
||||
module.exports = {
|
||||
clear: clear,
|
||||
setInput: setInput,
|
||||
bake: bake,
|
||||
setChrEnc: setChrEnc,
|
||||
setEOLSeq: setEOLSeq,
|
||||
copy: copy,
|
||||
paste: paste,
|
||||
loadRecipe: loadRecipe,
|
||||
expectOutput: expectOutput,
|
||||
uploadFile: uploadFile,
|
||||
uploadFolder: uploadFolder
|
||||
};
|
205
tests/lib/TestRegister.mjs
Normal file
205
tests/lib/TestRegister.mjs
Normal file
|
@ -0,0 +1,205 @@
|
|||
/**
|
||||
* TestRegister.js
|
||||
*
|
||||
* This is so individual files can register their tests in one place, and
|
||||
* ensure that they will get run by the frontend.
|
||||
*
|
||||
* @author tlwr [toby@toby.codes]
|
||||
* @author d98762625 [d98762625@gmail.com]
|
||||
* @copyright Crown Copyright 2018
|
||||
* @license Apache-2.0
|
||||
*/
|
||||
import Chef from "../../src/core/Chef.mjs";
|
||||
import Utils from "../../src/core/Utils.mjs";
|
||||
import cliProgress from "cli-progress";
|
||||
import log from "loglevel";
|
||||
|
||||
/**
|
||||
* Object to store and run the list of tests.
|
||||
*
|
||||
* @class
|
||||
* @constructor
|
||||
*/
|
||||
class TestRegister {
|
||||
|
||||
/**
|
||||
* initialise with no tests
|
||||
*/
|
||||
constructor() {
|
||||
this.tests = [];
|
||||
this.apiTests = [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a list of tests to the register.
|
||||
*
|
||||
* @param {Object[]} 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.
|
||||
*/
|
||||
async runTests () {
|
||||
// Turn off logging to avoid messy errors
|
||||
log.setLevel("silent", false);
|
||||
|
||||
const progBar = new cliProgress.SingleBar({
|
||||
format: formatter,
|
||||
stopOnComplete: true
|
||||
}, cliProgress.Presets.shades_classic);
|
||||
const testResults = [];
|
||||
|
||||
console.log("Running operation tests...");
|
||||
progBar.start(this.tests.length, 0, {
|
||||
msg: "Setting up"
|
||||
});
|
||||
|
||||
for (const test of this.tests) {
|
||||
progBar.update(testResults.length, {
|
||||
msg: test.name
|
||||
});
|
||||
|
||||
const chef = new Chef();
|
||||
const result = await chef.bake(
|
||||
test.input,
|
||||
test.recipeConfig,
|
||||
{ returnType: "string" }
|
||||
);
|
||||
|
||||
const ret = {
|
||||
test: test,
|
||||
status: null,
|
||||
output: null,
|
||||
duration: result.duration
|
||||
};
|
||||
|
||||
if (result.error) {
|
||||
if (test.expectedError) {
|
||||
if (result.error.displayStr === test.expectedOutput) {
|
||||
ret.status = "passing";
|
||||
} else {
|
||||
ret.status = "failing";
|
||||
ret.output = [
|
||||
"Expected",
|
||||
"\t" + test.expectedOutput.replace(/\n/g, "\n\t"),
|
||||
"Received",
|
||||
"\t" + result.error.displayStr.replace(/\n/g, "\n\t"),
|
||||
].join("\n");
|
||||
}
|
||||
} else {
|
||||
ret.status = "erroring";
|
||||
ret.output = result.error.displayStr;
|
||||
}
|
||||
} else {
|
||||
if (test.expectedError) {
|
||||
ret.status = "failing";
|
||||
ret.output = "Expected an error but did not receive one.";
|
||||
} else if (result.result === test.expectedOutput) {
|
||||
ret.status = "passing";
|
||||
} else if ("expectedMatch" in test && test.expectedMatch.test(result.result)) {
|
||||
ret.status = "passing";
|
||||
} else if ("unexpectedMatch" in test && !test.unexpectedMatch.test(result.result)) {
|
||||
ret.status = "passing";
|
||||
} else {
|
||||
ret.status = "failing";
|
||||
const expected = test.expectedOutput ? test.expectedOutput :
|
||||
test.expectedMatch ? test.expectedMatch.toString() :
|
||||
test.unexpectedMatch ? "to not find " + test.unexpectedMatch.toString() :
|
||||
"unknown";
|
||||
ret.output = [
|
||||
"Expected",
|
||||
"\t" + expected.replace(/\n/g, "\n\t"),
|
||||
"Received",
|
||||
"\t" + result.result.replace(/\n/g, "\n\t"),
|
||||
].join("\n");
|
||||
}
|
||||
}
|
||||
|
||||
testResults.push(ret);
|
||||
progBar.increment();
|
||||
}
|
||||
|
||||
// Turn logging back on
|
||||
log.setLevel("info", false);
|
||||
|
||||
return testResults;
|
||||
}
|
||||
|
||||
/**
|
||||
* Run all api related tests and wrap results in report format
|
||||
*/
|
||||
async runApiTests() {
|
||||
const progBar = new cliProgress.SingleBar({
|
||||
format: formatter,
|
||||
stopOnComplete: true
|
||||
}, cliProgress.Presets.shades_classic);
|
||||
const testResults = [];
|
||||
|
||||
console.log("Running Node API tests...");
|
||||
progBar.start(this.apiTests.length, 0, {
|
||||
msg: "Setting up"
|
||||
});
|
||||
|
||||
global.TESTING = true;
|
||||
for (const test of this.apiTests) {
|
||||
progBar.update(testResults.length, {
|
||||
msg: test.name
|
||||
});
|
||||
|
||||
const result = {
|
||||
test: test,
|
||||
status: null,
|
||||
output: null
|
||||
};
|
||||
try {
|
||||
await test.run();
|
||||
result.status = "passing";
|
||||
} catch (e) {
|
||||
result.status = "erroring";
|
||||
result.output = `${e.message}\nError: ${e.stack}`;
|
||||
}
|
||||
|
||||
testResults.push(result);
|
||||
progBar.increment();
|
||||
}
|
||||
|
||||
return testResults;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Formatter for the progress bar
|
||||
*
|
||||
* @param {Object} options
|
||||
* @param {Object} params
|
||||
* @param {Object} payload
|
||||
* @returns {string}
|
||||
*/
|
||||
function formatter(options, params, payload) {
|
||||
const bar = options.barCompleteString.substr(0, Math.round(params.progress * options.barsize)) +
|
||||
options.barIncompleteString.substr(0, Math.round((1-params.progress) * options.barsize));
|
||||
|
||||
const percentage = Math.floor(params.progress * 100),
|
||||
duration = Math.floor((Date.now() - params.startTime) / 1000);
|
||||
|
||||
let testName = payload.msg ? payload.msg : "";
|
||||
if (params.value >= params.total) testName = "Tests completed";
|
||||
testName = Utils.truncate(testName, 25).padEnd(25, " ");
|
||||
|
||||
return `${testName} ${bar} ${params.value}/${params.total} | ${percentage}% | Duration: ${duration}s`;
|
||||
}
|
||||
|
||||
// Export an instance to make a singleton
|
||||
export default new TestRegister();
|
90
tests/lib/utils.mjs
Normal file
90
tests/lib/utils.mjs
Normal file
|
@ -0,0 +1,90 @@
|
|||
/**
|
||||
* 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}
|
||||
*/
|
||||
function statusToIcon(status) {
|
||||
return {
|
||||
erroring: "🔥",
|
||||
failing: "❌",
|
||||
passing: "✔️️",
|
||||
}[status] || "?";
|
||||
}
|
||||
|
||||
/**
|
||||
* Counts test statuses.
|
||||
*
|
||||
* @param {Object} testStatus
|
||||
* @param {Object} testResult
|
||||
*/
|
||||
function handleTestResult(testStatus, testResult) {
|
||||
testStatus.allTestsPassing = testStatus.allTestsPassing && testResult.status === "passing";
|
||||
testStatus.counts[testResult.status] = (testStatus.counts[testResult.status] || 0) + 1;
|
||||
testStatus.counts.total += 1;
|
||||
|
||||
if (testResult.duration > 2000) {
|
||||
console.log(`'${testResult.test.name}' took ${(testResult.duration / 1000).toFixed(1)}s to complete`);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Log each test result, count tests and failures.
|
||||
*
|
||||
* @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();
|
||||
for (const testStatusCount in testStatus.counts) {
|
||||
const count = testStatus.counts[testStatusCount];
|
||||
if (count > 0) {
|
||||
console.log(testStatusCount.toUpperCase() + "\t" + count);
|
||||
}
|
||||
}
|
||||
console.log();
|
||||
|
||||
// Print error messages for tests that didn't pass
|
||||
results.filter(res => res.status !== "passing").forEach(testResult => {
|
||||
console.log([
|
||||
statusToIcon(testResult.status),
|
||||
testResult.test.name
|
||||
].join(" "));
|
||||
|
||||
if (testResult.output) {
|
||||
console.log(
|
||||
testResult.output
|
||||
.trim()
|
||||
.replace(/^/, "\t")
|
||||
.replace(/\n/g, "\n\t")
|
||||
);
|
||||
}
|
||||
});
|
||||
console.log();
|
||||
|
||||
process.exit(testStatus.allTestsPassing ? 0 : 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fail if the process takes longer than 60 seconds.
|
||||
*/
|
||||
export function setLongTestFailure() {
|
||||
const timeLimit = 120;
|
||||
setTimeout(function() {
|
||||
console.log(`Tests took longer than ${timeLimit} seconds to run, returning.`);
|
||||
process.exit(1);
|
||||
}, timeLimit * 1000);
|
||||
}
|
60
tests/node/assertionHandler.mjs
Normal file
60
tests/node/assertionHandler.mjs
Normal 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) => async () => {
|
||||
try {
|
||||
await 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;
|
32
tests/node/consumers/cjs-consumer.js
Normal file
32
tests/node/consumers/cjs-consumer.js
Normal file
|
@ -0,0 +1,32 @@
|
|||
/**
|
||||
* 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 assert = require("assert");
|
||||
|
||||
require("cyberchef").then(chef => {
|
||||
|
||||
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");
|
||||
|
||||
});
|
48
tests/node/consumers/esm-consumer.mjs
Normal file
48
tests/node/consumers/esm-consumer.mjs
Normal file
|
@ -0,0 +1,48 @@
|
|||
/**
|
||||
* 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";
|
||||
import { bake, toHex, reverse, unique, multiply } from "cyberchef";
|
||||
|
||||
const a = bake("Testing, 1 2 3", [
|
||||
toHex,
|
||||
reverse,
|
||||
{
|
||||
op: unique,
|
||||
args: {
|
||||
delimiter: "Space",
|
||||
}
|
||||
},
|
||||
{
|
||||
op: multiply,
|
||||
args: {
|
||||
delimiter: "Space",
|
||||
}
|
||||
}
|
||||
]);
|
||||
|
||||
assert.equal(a.value, "630957449041920");
|
||||
|
||||
const b = chef.bake("Testing, 1 2 3", [
|
||||
chef.toHex,
|
||||
chef.reverse,
|
||||
{
|
||||
op: chef.unique,
|
||||
args: {
|
||||
delimiter: "Space",
|
||||
}
|
||||
},
|
||||
{
|
||||
op: chef.multiply,
|
||||
args: {
|
||||
delimiter: "Space",
|
||||
}
|
||||
}
|
||||
]);
|
||||
|
||||
assert.equal(b.value, "630957449041920");
|
41
tests/node/index.mjs
Normal file
41
tests/node/index.mjs
Normal file
|
@ -0,0 +1,41 @@
|
|||
/* 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.mjs";
|
||||
|
||||
import TestRegister from "../lib/TestRegister.mjs";
|
||||
import "./tests/nodeApi.mjs";
|
||||
import "./tests/operations.mjs";
|
||||
import "./tests/File.mjs";
|
||||
import "./tests/Dish.mjs";
|
||||
import "./tests/NodeDish.mjs";
|
||||
import "./tests/Utils.mjs";
|
||||
import "./tests/Categories.mjs";
|
||||
|
||||
const testStatus = {
|
||||
allTestsPassing: true,
|
||||
counts: {
|
||||
total: 0,
|
||||
}
|
||||
};
|
||||
|
||||
setLongTestFailure();
|
||||
|
||||
const logOpsTestReport = logTestReport.bind(null, testStatus);
|
||||
|
||||
(async function() {
|
||||
const results = await TestRegister.runApiTests();
|
||||
logOpsTestReport(results);
|
||||
})();
|
BIN
tests/node/sampleData/pic.jpg
Normal file
BIN
tests/node/sampleData/pic.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 4.6 KiB |
19
tests/node/tests/Categories.mjs
Normal file
19
tests/node/tests/Categories.mjs
Normal file
|
@ -0,0 +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 it from "../assertionHandler.mjs";
|
||||
import assert from "assert";
|
||||
|
||||
TestRegister.addApiTests([
|
||||
it("Categories: operations should be in a category", () => {
|
||||
const catOps = [];
|
||||
Categories.forEach(cat => {
|
||||
catOps.push(...cat.ops);
|
||||
});
|
||||
|
||||
for (const op in OperationConfig) {
|
||||
assert(catOps.includes(op), `'${op}' operation is not present in any category`);
|
||||
}
|
||||
}),
|
||||
|
||||
]);
|
12
tests/node/tests/Dish.mjs
Normal file
12
tests/node/tests/Dish.mjs
Normal 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);
|
||||
}),
|
||||
|
||||
]);
|
82
tests/node/tests/File.mjs
Normal file
82
tests/node/tests/File.mjs
Normal 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);
|
||||
}
|
||||
})
|
||||
|
||||
]);
|
199
tests/node/tests/NodeDish.mjs
Normal file
199
tests/node/tests/NodeDish.mjs
Normal 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]), 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("");
|
||||
assert.strictEqual(actual, "abcdefghijk");
|
||||
}),
|
||||
]);
|
23
tests/node/tests/Utils.mjs
Normal file
23
tests/node/tests/Utils.mjs
Normal file
|
@ -0,0 +1,23 @@
|
|||
import TestRegister from "../../lib/TestRegister.mjs";
|
||||
import Utils from "../../../src/core/Utils.mjs";
|
||||
import it from "../assertionHandler.mjs";
|
||||
import assert from "assert";
|
||||
|
||||
TestRegister.addApiTests([
|
||||
it("Utils: should parse six backslashes correctly", () => {
|
||||
assert.equal(Utils.parseEscapedChars("\\\\\\\\\\\\"), "\\\\\\");
|
||||
}),
|
||||
|
||||
it("Utils: should parse escaped quotes correctly", () => {
|
||||
assert.equal(Utils.parseEscapedChars("\\'"), "'");
|
||||
}),
|
||||
|
||||
it("Utils: should parse escaped quotes and backslashes correctly", () => {
|
||||
assert.equal(Utils.parseEscapedChars("\\\\'"), "\\'");
|
||||
}),
|
||||
|
||||
it("Utils: should parse escaped quotes and escaped backslashes correctly", () => {
|
||||
assert.equal(Utils.parseEscapedChars("\\\\\\'"), "\\'");
|
||||
}),
|
||||
|
||||
]);
|
413
tests/node/tests/nodeApi.mjs
Normal file
413
tests/node/tests/nodeApi.mjs
Normal file
|
@ -0,0 +1,413 @@
|
|||
/* 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, ExcludedOperationError } from "../../../src/core/errors/index.mjs";
|
||||
import NodeDish from "../../../src/node/NodeDish.mjs";
|
||||
|
||||
import { toBase32, magic} 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 as a default.");
|
||||
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, 11);
|
||||
}),
|
||||
|
||||
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", () => {
|
||||
assert.throws(() => chef.bake("some input", 3264), {
|
||||
name: "TypeError",
|
||||
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'."
|
||||
});
|
||||
}),
|
||||
|
||||
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", () => {
|
||||
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");
|
||||
}),
|
||||
|
||||
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", () => {
|
||||
assert.throws(() => chef.bake("something", [() => {}]), {
|
||||
name: "TypeError",
|
||||
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 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", () => {
|
||||
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", () => {
|
||||
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"]
|
||||
},
|
||||
{
|
||||
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 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", () => {
|
||||
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("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("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"
|
||||
});
|
||||
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"
|
||||
});
|
||||
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"
|
||||
});
|
||||
}),
|
||||
|
||||
it("Excluded operations: throw a sensible error when you try and call one", () => {
|
||||
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.");
|
||||
return true;
|
||||
},
|
||||
"Unexpected error type"
|
||||
);
|
||||
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.");
|
||||
return true;
|
||||
},
|
||||
"Unexpected error type"
|
||||
);
|
||||
}),
|
||||
|
||||
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");
|
||||
}),
|
||||
|
||||
]);
|
1137
tests/node/tests/operations.mjs
Normal file
1137
tests/node/tests/operations.mjs
Normal file
File diff suppressed because it is too large
Load diff
|
@ -1,96 +0,0 @@
|
|||
/**
|
||||
* TestRegister.js
|
||||
*
|
||||
* This is so individual files can register their tests in one place, and
|
||||
* ensure that they will get run by the frontend.
|
||||
*
|
||||
* @author tlwr [toby@toby.codes]
|
||||
* @copyright Crown Copyright 2017
|
||||
* @license Apache-2.0
|
||||
*/
|
||||
import Chef from "../../src/core/Chef";
|
||||
|
||||
(function() {
|
||||
/**
|
||||
* Object to store and run the list of tests.
|
||||
*
|
||||
* @class
|
||||
* @constructor
|
||||
*/
|
||||
function TestRegister() {
|
||||
this.tests = [];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Add a list of tests to the register.
|
||||
*
|
||||
* @param {Object[]} tests
|
||||
*/
|
||||
TestRegister.prototype.addTests = function(tests) {
|
||||
this.tests = this.tests.concat(tests);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Runs all the tests in the register.
|
||||
*/
|
||||
TestRegister.prototype.runTests = function() {
|
||||
return Promise.all(
|
||||
this.tests.map(function(test, i) {
|
||||
const chef = new Chef();
|
||||
|
||||
return chef.bake(
|
||||
test.input,
|
||||
test.recipeConfig,
|
||||
{},
|
||||
0,
|
||||
false
|
||||
).then(function(result) {
|
||||
const ret = {
|
||||
test: test,
|
||||
status: null,
|
||||
output: null,
|
||||
};
|
||||
|
||||
if (result.error) {
|
||||
if (test.expectedError) {
|
||||
ret.status = "passing";
|
||||
} else {
|
||||
ret.status = "erroring";
|
||||
ret.output = result.error.displayStr;
|
||||
}
|
||||
} else {
|
||||
if (test.expectedError) {
|
||||
ret.status = "failing";
|
||||
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)) {
|
||||
ret.status = "passing";
|
||||
} else {
|
||||
ret.status = "failing";
|
||||
const expected = test.expectedOutput ? test.expectedOutput :
|
||||
test.expectedMatch ? test.expectedMatch.toString() : "unknown";
|
||||
ret.output = [
|
||||
"Expected",
|
||||
"\t" + expected.replace(/\n/g, "\n\t"),
|
||||
"Received",
|
||||
"\t" + result.result.replace(/\n/g, "\n\t"),
|
||||
].join("\n");
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
});
|
||||
})
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
// Singleton TestRegister, keeping things simple and obvious.
|
||||
global.TestRegister = global.TestRegister || new TestRegister();
|
||||
})();
|
||||
|
||||
export default global.TestRegister;
|
||||
|
|
@ -10,158 +10,152 @@
|
|||
* @copyright Crown Copyright 2017
|
||||
* @license Apache-2.0
|
||||
*/
|
||||
import "babel-polyfill";
|
||||
|
||||
// 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.mjs";
|
||||
|
||||
import TestRegister from "./TestRegister";
|
||||
import "./tests/BCD";
|
||||
import "./tests/BSON";
|
||||
import "./tests/Base58";
|
||||
import "./tests/Base64";
|
||||
import "./tests/Base62";
|
||||
import "./tests/BitwiseOp";
|
||||
import "./tests/ByteRepr";
|
||||
import "./tests/CartesianProduct";
|
||||
import "./tests/CharEnc";
|
||||
import "./tests/Checksum";
|
||||
import "./tests/Ciphers";
|
||||
import "./tests/Code";
|
||||
import "./tests/Comment";
|
||||
import "./tests/Compress";
|
||||
import "./tests/ConditionalJump";
|
||||
import "./tests/Crypt";
|
||||
import "./tests/CSV";
|
||||
import "./tests/DateTime";
|
||||
import "./tests/ExtractEmailAddresses";
|
||||
import "./tests/Fork";
|
||||
import "./tests/FromDecimal";
|
||||
import "./tests/Hash";
|
||||
import "./tests/HaversineDistance";
|
||||
import "./tests/Hexdump";
|
||||
import "./tests/Image";
|
||||
import "./tests/Jump";
|
||||
import "./tests/JSONBeautify";
|
||||
import "./tests/JSONMinify";
|
||||
import "./tests/JWTDecode";
|
||||
import "./tests/JWTSign";
|
||||
import "./tests/JWTVerify";
|
||||
import "./tests/MS";
|
||||
import "./tests/Magic";
|
||||
import "./tests/MorseCode";
|
||||
import "./tests/NetBIOS";
|
||||
import "./tests/OTP";
|
||||
import "./tests/PGP";
|
||||
import "./tests/PHP";
|
||||
import "./tests/ParseIPRange";
|
||||
import "./tests/ParseQRCode";
|
||||
import "./tests/PowerSet";
|
||||
import "./tests/Regex";
|
||||
import "./tests/Register";
|
||||
import "./tests/RemoveDiacritics";
|
||||
import "./tests/Rotate";
|
||||
import "./tests/SeqUtils";
|
||||
import "./tests/SetDifference";
|
||||
import "./tests/SetIntersection";
|
||||
import "./tests/SetUnion";
|
||||
import "./tests/StrUtils";
|
||||
import "./tests/SymmetricDifference";
|
||||
import "./tests/TextEncodingBruteForce";
|
||||
import "./tests/TranslateDateTimeFormat";
|
||||
import "./tests/Magic";
|
||||
import "./tests/ParseTLV";
|
||||
import "./tests/Media";
|
||||
import "./tests/ToFromInsensitiveRegex";
|
||||
import TestRegister from "../lib/TestRegister.mjs";
|
||||
import "./tests/AESKeyWrap.mjs";
|
||||
import "./tests/AvroToJSON.mjs";
|
||||
import "./tests/BaconCipher.mjs";
|
||||
import "./tests/Base45.mjs";
|
||||
import "./tests/Base58.mjs";
|
||||
import "./tests/Base62.mjs";
|
||||
import "./tests/Base64.mjs";
|
||||
import "./tests/Base85.mjs";
|
||||
import "./tests/Base92.mjs";
|
||||
import "./tests/BCD.mjs";
|
||||
import "./tests/BitwiseOp.mjs";
|
||||
import "./tests/BLAKE2b.mjs";
|
||||
import "./tests/BLAKE2s.mjs";
|
||||
import "./tests/Bombe.mjs";
|
||||
import "./tests/BSON.mjs";
|
||||
import "./tests/ByteRepr.mjs";
|
||||
import "./tests/CaesarBoxCipher.mjs";
|
||||
import "./tests/CaretMdecode.mjs";
|
||||
import "./tests/CartesianProduct.mjs";
|
||||
import "./tests/CBORDecode.mjs";
|
||||
import "./tests/CBOREncode.mjs";
|
||||
import "./tests/CetaceanCipherDecode.mjs";
|
||||
import "./tests/CetaceanCipherEncode.mjs";
|
||||
import "./tests/ChaCha.mjs";
|
||||
import "./tests/ChangeIPFormat.mjs";
|
||||
import "./tests/CharEnc.mjs";
|
||||
import "./tests/Charts.mjs";
|
||||
import "./tests/Checksum.mjs";
|
||||
import "./tests/Ciphers.mjs";
|
||||
import "./tests/CipherSaber2.mjs";
|
||||
import "./tests/CMAC.mjs";
|
||||
import "./tests/Code.mjs";
|
||||
import "./tests/Colossus.mjs";
|
||||
import "./tests/Comment.mjs";
|
||||
import "./tests/Compress.mjs";
|
||||
import "./tests/ConditionalJump.mjs";
|
||||
import "./tests/ConvertCoordinateFormat.mjs";
|
||||
import "./tests/ConvertToNATOAlphabet.mjs";
|
||||
import "./tests/Crypt.mjs";
|
||||
import "./tests/CSV.mjs";
|
||||
import "./tests/DateTime.mjs";
|
||||
import "./tests/DefangIP.mjs";
|
||||
import "./tests/ELFInfo.mjs";
|
||||
import "./tests/Enigma.mjs";
|
||||
import "./tests/ExtractEmailAddresses.mjs";
|
||||
import "./tests/FileTree.mjs";
|
||||
import "./tests/FletcherChecksum.mjs";
|
||||
import "./tests/Fork.mjs";
|
||||
import "./tests/FromDecimal.mjs";
|
||||
import "./tests/GenerateAllHashes.mjs";
|
||||
import "./tests/GenerateDeBruijnSequence.mjs";
|
||||
import "./tests/GetAllCasings.mjs";
|
||||
import "./tests/GOST.mjs";
|
||||
import "./tests/Gunzip.mjs";
|
||||
import "./tests/Gzip.mjs";
|
||||
import "./tests/Hash.mjs";
|
||||
import "./tests/HASSH.mjs";
|
||||
import "./tests/HaversineDistance.mjs";
|
||||
import "./tests/Hex.mjs";
|
||||
import "./tests/Hexdump.mjs";
|
||||
import "./tests/HKDF.mjs";
|
||||
import "./tests/Image.mjs";
|
||||
import "./tests/IndexOfCoincidence.mjs";
|
||||
import "./tests/JA3Fingerprint.mjs";
|
||||
import "./tests/JA3SFingerprint.mjs";
|
||||
import "./tests/JSONBeautify.mjs";
|
||||
import "./tests/JSONMinify.mjs";
|
||||
import "./tests/JSONtoCSV.mjs";
|
||||
import "./tests/Jump.mjs";
|
||||
import "./tests/JWTDecode.mjs";
|
||||
import "./tests/JWTSign.mjs";
|
||||
import "./tests/JWTVerify.mjs";
|
||||
import "./tests/LevenshteinDistance.mjs";
|
||||
import "./tests/Lorenz.mjs";
|
||||
import "./tests/LS47.mjs";
|
||||
import "./tests/LuhnChecksum.mjs";
|
||||
import "./tests/LZNT1Decompress.mjs";
|
||||
import "./tests/LZString.mjs";
|
||||
import "./tests/Magic.mjs";
|
||||
import "./tests/Media.mjs";
|
||||
import "./tests/MorseCode.mjs";
|
||||
import "./tests/MS.mjs";
|
||||
import "./tests/MultipleBombe.mjs";
|
||||
import "./tests/MurmurHash3.mjs";
|
||||
import "./tests/NetBIOS.mjs";
|
||||
import "./tests/NormaliseUnicode.mjs";
|
||||
import "./tests/NTLM.mjs";
|
||||
import "./tests/OTP.mjs";
|
||||
import "./tests/ParseIPRange.mjs";
|
||||
import "./tests/ParseObjectIDTimestamp.mjs";
|
||||
import "./tests/ParseQRCode.mjs";
|
||||
import "./tests/ParseSSHHostKey.mjs";
|
||||
import "./tests/ParseTCP.mjs";
|
||||
import "./tests/ParseTLV.mjs";
|
||||
import "./tests/ParseUDP.mjs";
|
||||
import "./tests/PEMtoHex.mjs";
|
||||
import "./tests/PGP.mjs";
|
||||
import "./tests/PHP.mjs";
|
||||
import "./tests/PowerSet.mjs";
|
||||
import "./tests/Protobuf.mjs";
|
||||
import "./tests/Rabbit.mjs";
|
||||
import "./tests/RAKE.mjs";
|
||||
import "./tests/Regex.mjs";
|
||||
import "./tests/Register.mjs";
|
||||
import "./tests/RisonEncodeDecode.mjs";
|
||||
import "./tests/Rotate.mjs";
|
||||
import "./tests/RSA.mjs";
|
||||
import "./tests/SeqUtils.mjs";
|
||||
import "./tests/SetDifference.mjs";
|
||||
import "./tests/SetIntersection.mjs";
|
||||
import "./tests/SetUnion.mjs";
|
||||
import "./tests/Shuffle.mjs";
|
||||
import "./tests/SIGABA.mjs";
|
||||
import "./tests/SM4.mjs";
|
||||
// import "./tests/SplitColourChannels.mjs"; // Cannot test operations that use the File type yet
|
||||
import "./tests/StrUtils.mjs";
|
||||
import "./tests/Subsection.mjs";
|
||||
import "./tests/SwapCase.mjs";
|
||||
import "./tests/SymmetricDifference.mjs";
|
||||
import "./tests/TextEncodingBruteForce.mjs";
|
||||
import "./tests/ToFromInsensitiveRegex.mjs";
|
||||
import "./tests/TranslateDateTimeFormat.mjs";
|
||||
import "./tests/Typex.mjs";
|
||||
import "./tests/UnescapeString.mjs";
|
||||
import "./tests/Unicode.mjs";
|
||||
import "./tests/YARA.mjs";
|
||||
import "./tests/ConvertCoordinateFormat";
|
||||
|
||||
// Cannot test operations that use the File type yet
|
||||
//import "./tests/SplitColourChannels";
|
||||
|
||||
let allTestsPassing = true;
|
||||
const testStatusCounts = {
|
||||
total: 0,
|
||||
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] || "?";
|
||||
}
|
||||
const logOpsTestReport = logTestReport.bind(null, testStatus);
|
||||
|
||||
|
||||
/**
|
||||
* 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);
|
||||
|
||||
|
||||
TestRegister.runTests()
|
||||
.then(function(results) {
|
||||
results.forEach(handleTestResult);
|
||||
|
||||
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);
|
||||
});
|
||||
(async function() {
|
||||
const results = await TestRegister.runTests();
|
||||
logOpsTestReport(results);
|
||||
})();
|
||||
|
|
324
tests/operations/tests/AESKeyWrap.mjs
Normal file
324
tests/operations/tests/AESKeyWrap.mjs
Normal file
|
@ -0,0 +1,324 @@
|
|||
/**
|
||||
* @author mikecat
|
||||
* @copyright Crown Copyright 2022
|
||||
* @license Apache-2.0
|
||||
*/
|
||||
import TestRegister from "../../lib/TestRegister.mjs";
|
||||
|
||||
TestRegister.addTests([
|
||||
{
|
||||
"name": "AES Key Wrap: RFC Test Vector, 128-bit data, 128-bit KEK",
|
||||
"input": "00112233445566778899aabbccddeeff",
|
||||
"expectedOutput": "1fa68b0a8112b447aef34bd8fb5a7b829d3e862371d2cfe5",
|
||||
"recipeConfig": [
|
||||
{
|
||||
"op": "AES Key Wrap",
|
||||
"args": [
|
||||
{"option": "Hex", "string": "000102030405060708090a0b0c0d0e0f"},
|
||||
{"option": "Hex", "string": "a6a6a6a6a6a6a6a6"},
|
||||
"Hex", "Hex"
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
"name": "AES Key Wrap: RFC Test Vector, 128-bit data, 192-bit KEK",
|
||||
"input": "00112233445566778899aabbccddeeff",
|
||||
"expectedOutput": "96778b25ae6ca435f92b5b97c050aed2468ab8a17ad84e5d",
|
||||
"recipeConfig": [
|
||||
{
|
||||
"op": "AES Key Wrap",
|
||||
"args": [
|
||||
{"option": "Hex", "string": "000102030405060708090a0b0c0d0e0f1011121314151617"},
|
||||
{"option": "Hex", "string": "a6a6a6a6a6a6a6a6"},
|
||||
"Hex", "Hex"
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
"name": "AES Key Wrap: RFC Test Vector, 128-bit data, 256-bit KEK",
|
||||
"input": "00112233445566778899aabbccddeeff",
|
||||
"expectedOutput": "64e8c3f9ce0f5ba263e9777905818a2a93c8191e7d6e8ae7",
|
||||
"recipeConfig": [
|
||||
{
|
||||
"op": "AES Key Wrap",
|
||||
"args": [
|
||||
{"option": "Hex", "string": "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f"},
|
||||
{"option": "Hex", "string": "a6a6a6a6a6a6a6a6"},
|
||||
"Hex", "Hex"
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
"name": "AES Key Wrap: RFC Test Vector, 192-bit data, 192-bit KEK",
|
||||
"input": "00112233445566778899aabbccddeeff0001020304050607",
|
||||
"expectedOutput": "031d33264e15d33268f24ec260743edce1c6c7ddee725a936ba814915c6762d2",
|
||||
"recipeConfig": [
|
||||
{
|
||||
"op": "AES Key Wrap",
|
||||
"args": [
|
||||
{"option": "Hex", "string": "000102030405060708090a0b0c0d0e0f1011121314151617"},
|
||||
{"option": "Hex", "string": "a6a6a6a6a6a6a6a6"},
|
||||
"Hex", "Hex"
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
"name": "AES Key Wrap: RFC Test Vector, 192-bit data, 256-bit KEK",
|
||||
"input": "00112233445566778899aabbccddeeff0001020304050607",
|
||||
"expectedOutput": "a8f9bc1612c68b3ff6e6f4fbe30e71e4769c8b80a32cb8958cd5d17d6b254da1",
|
||||
"recipeConfig": [
|
||||
{
|
||||
"op": "AES Key Wrap",
|
||||
"args": [
|
||||
{"option": "Hex", "string": "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f"},
|
||||
{"option": "Hex", "string": "a6a6a6a6a6a6a6a6"},
|
||||
"Hex", "Hex"
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
"name": "AES Key Wrap: RFC Test Vector, 256-bit data, 256-bit KEK",
|
||||
"input": "00112233445566778899aabbccddeeff000102030405060708090a0b0c0d0e0f",
|
||||
"expectedOutput": "28c9f404c4b810f4cbccb35cfb87f8263f5786e2d80ed326cbc7f0e71a99f43bfb988b9b7a02dd21",
|
||||
"recipeConfig": [
|
||||
{
|
||||
"op": "AES Key Wrap",
|
||||
"args": [
|
||||
{"option": "Hex", "string": "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f"},
|
||||
{"option": "Hex", "string": "a6a6a6a6a6a6a6a6"},
|
||||
"Hex", "Hex"
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
"name": "AES Key Unwrap: RFC Test Vector, 128-bit data, 128-bit KEK",
|
||||
"input": "1fa68b0a8112b447aef34bd8fb5a7b829d3e862371d2cfe5",
|
||||
"expectedOutput": "00112233445566778899aabbccddeeff",
|
||||
"recipeConfig": [
|
||||
{
|
||||
"op": "AES Key Unwrap",
|
||||
"args": [
|
||||
{"option": "Hex", "string": "000102030405060708090a0b0c0d0e0f"},
|
||||
{"option": "Hex", "string": "a6a6a6a6a6a6a6a6"},
|
||||
"Hex", "Hex"
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
"name": "AES Key Unwrap: RFC Test Vector, 128-bit data, 192-bit KEK",
|
||||
"input": "96778b25ae6ca435f92b5b97c050aed2468ab8a17ad84e5d",
|
||||
"expectedOutput": "00112233445566778899aabbccddeeff",
|
||||
"recipeConfig": [
|
||||
{
|
||||
"op": "AES Key Unwrap",
|
||||
"args": [
|
||||
{"option": "Hex", "string": "000102030405060708090a0b0c0d0e0f1011121314151617"},
|
||||
{"option": "Hex", "string": "a6a6a6a6a6a6a6a6"},
|
||||
"Hex", "Hex"
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
"name": "AES Key Unwrap: RFC Test Vector, 128-bit data, 256-bit KEK",
|
||||
"input": "64e8c3f9ce0f5ba263e9777905818a2a93c8191e7d6e8ae7",
|
||||
"expectedOutput": "00112233445566778899aabbccddeeff",
|
||||
"recipeConfig": [
|
||||
{
|
||||
"op": "AES Key Unwrap",
|
||||
"args": [
|
||||
{"option": "Hex", "string": "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f"},
|
||||
{"option": "Hex", "string": "a6a6a6a6a6a6a6a6"},
|
||||
"Hex", "Hex"
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
"name": "AES Key Unwrap: RFC Test Vector, 192-bit data, 192-bit KEK",
|
||||
"input": "031d33264e15d33268f24ec260743edce1c6c7ddee725a936ba814915c6762d2",
|
||||
"expectedOutput": "00112233445566778899aabbccddeeff0001020304050607",
|
||||
"recipeConfig": [
|
||||
{
|
||||
"op": "AES Key Unwrap",
|
||||
"args": [
|
||||
{"option": "Hex", "string": "000102030405060708090a0b0c0d0e0f1011121314151617"},
|
||||
{"option": "Hex", "string": "a6a6a6a6a6a6a6a6"},
|
||||
"Hex", "Hex"
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
"name": "AES Key Unwrap: RFC Test Vector, 192-bit data, 256-bit KEK",
|
||||
"input": "a8f9bc1612c68b3ff6e6f4fbe30e71e4769c8b80a32cb8958cd5d17d6b254da1",
|
||||
"expectedOutput": "00112233445566778899aabbccddeeff0001020304050607",
|
||||
"recipeConfig": [
|
||||
{
|
||||
"op": "AES Key Unwrap",
|
||||
"args": [
|
||||
{"option": "Hex", "string": "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f"},
|
||||
{"option": "Hex", "string": "a6a6a6a6a6a6a6a6"},
|
||||
"Hex", "Hex"
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
"name": "AES Key Unwrap: RFC Test Vector, 256-bit data, 256-bit KEK",
|
||||
"input": "28c9f404c4b810f4cbccb35cfb87f8263f5786e2d80ed326cbc7f0e71a99f43bfb988b9b7a02dd21",
|
||||
"expectedOutput": "00112233445566778899aabbccddeeff000102030405060708090a0b0c0d0e0f",
|
||||
"recipeConfig": [
|
||||
{
|
||||
"op": "AES Key Unwrap",
|
||||
"args": [
|
||||
{"option": "Hex", "string": "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f"},
|
||||
{"option": "Hex", "string": "a6a6a6a6a6a6a6a6"},
|
||||
"Hex", "Hex"
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
"name": "AES Key Wrap: invalid KEK length",
|
||||
"input": "00112233445566778899aabbccddeeff",
|
||||
"expectedOutput": "KEK must be either 16, 24, or 32 bytes (currently 10 bytes)",
|
||||
"recipeConfig": [
|
||||
{
|
||||
"op": "AES Key Wrap",
|
||||
"args": [
|
||||
{"option": "Hex", "string": "00010203040506070809"},
|
||||
{"option": "Hex", "string": "a6a6a6a6a6a6a6a6"},
|
||||
"Hex", "Hex"
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
"name": "AES Key Wrap: invalid IV length",
|
||||
"input": "00112233445566778899aabbccddeeff",
|
||||
"expectedOutput": "IV must be 8 bytes (currently 6 bytes)",
|
||||
"recipeConfig": [
|
||||
{
|
||||
"op": "AES Key Wrap",
|
||||
"args": [
|
||||
{"option": "Hex", "string": "000102030405060708090a0b0c0d0e0f"},
|
||||
{"option": "Hex", "string": "a6a6a6a6a6a6"},
|
||||
"Hex", "Hex"
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
"name": "AES Key Wrap: input length not multiple of 8",
|
||||
"input": "00112233445566778899aabbccddeeff0102",
|
||||
"expectedOutput": "input must be 8n (n>=2) bytes (currently 18 bytes)",
|
||||
"recipeConfig": [
|
||||
{
|
||||
"op": "AES Key Wrap",
|
||||
"args": [
|
||||
{"option": "Hex", "string": "000102030405060708090a0b0c0d0e0f"},
|
||||
{"option": "Hex", "string": "a6a6a6a6a6a6a6a6"},
|
||||
"Hex", "Hex"
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
"name": "AES Key Wrap: input too short",
|
||||
"input": "0011223344556677",
|
||||
"expectedOutput": "input must be 8n (n>=2) bytes (currently 8 bytes)",
|
||||
"recipeConfig": [
|
||||
{
|
||||
"op": "AES Key Wrap",
|
||||
"args": [
|
||||
{"option": "Hex", "string": "000102030405060708090a0b0c0d0e0f"},
|
||||
{"option": "Hex", "string": "a6a6a6a6a6a6a6a6"},
|
||||
"Hex", "Hex"
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
"name": "AES Key Unwrap: invalid KEK length",
|
||||
"input": "1fa68b0a8112b447aef34bd8fb5a7b829d3e862371d2cfe5",
|
||||
"expectedOutput": "KEK must be either 16, 24, or 32 bytes (currently 10 bytes)",
|
||||
"recipeConfig": [
|
||||
{
|
||||
"op": "AES Key Unwrap",
|
||||
"args": [
|
||||
{"option": "Hex", "string": "00010203040506070809"},
|
||||
{"option": "Hex", "string": "a6a6a6a6a6a6a6a6"},
|
||||
"Hex", "Hex"
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
"name": "AES Key Unwrap: invalid IV length",
|
||||
"input": "1fa68b0a8112b447aef34bd8fb5a7b829d3e862371d2cfe5",
|
||||
"expectedOutput": "IV must be 8 bytes (currently 6 bytes)",
|
||||
"recipeConfig": [
|
||||
{
|
||||
"op": "AES Key Unwrap",
|
||||
"args": [
|
||||
{"option": "Hex", "string": "000102030405060708090a0b0c0d0e0f"},
|
||||
{"option": "Hex", "string": "a6a6a6a6a6a6"},
|
||||
"Hex", "Hex"
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
"name": "AES Key Unwrap: input length not multiple of 8",
|
||||
"input": "1fa68b0a8112b447aef34bd8fb5a7b829d3e862371d2cfe5e621",
|
||||
"expectedOutput": "input must be 8n (n>=3) bytes (currently 26 bytes)",
|
||||
"recipeConfig": [
|
||||
{
|
||||
"op": "AES Key Unwrap",
|
||||
"args": [
|
||||
{"option": "Hex", "string": "000102030405060708090a0b0c0d0e0f"},
|
||||
{"option": "Hex", "string": "a6a6a6a6a6a6a6a6"},
|
||||
"Hex", "Hex"
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
"name": "AES Key Unwrap: input too short",
|
||||
"input": "1fa68b0a8112b447aef34bd8fb5a7b82",
|
||||
"expectedOutput": "input must be 8n (n>=3) bytes (currently 16 bytes)",
|
||||
"recipeConfig": [
|
||||
{
|
||||
"op": "AES Key Unwrap",
|
||||
"args": [
|
||||
{"option": "Hex", "string": "000102030405060708090a0b0c0d0e0f"},
|
||||
{"option": "Hex", "string": "a6a6a6a6a6a6a6a6"},
|
||||
"Hex", "Hex"
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
"name": "AES Key Unwrap: corrupted input",
|
||||
"input": "1fa68b0a8112b447aef34bd8fb5a7b829d3e862371d2cfe6",
|
||||
"expectedOutput": "IV mismatch",
|
||||
"recipeConfig": [
|
||||
{
|
||||
"op": "AES Key Unwrap",
|
||||
"args": [
|
||||
{"option": "Hex", "string": "000102030405060708090a0b0c0d0e0f"},
|
||||
{"option": "Hex", "string": "a6a6a6a6a6a6a6a6"},
|
||||
"Hex", "Hex"
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
]);
|
66
tests/operations/tests/AvroToJSON.mjs
Normal file
66
tests/operations/tests/AvroToJSON.mjs
Normal file
|
@ -0,0 +1,66 @@
|
|||
/**
|
||||
* Avro to JSON tests.
|
||||
*
|
||||
* @author jarrodconnolly [jarrod@nestedquotes.ca]
|
||||
* @copyright Crown Copyright 2019
|
||||
* @license Apache-2.0
|
||||
*/
|
||||
|
||||
import TestRegister from "../../lib/TestRegister.mjs";
|
||||
|
||||
TestRegister.addTests([
|
||||
{
|
||||
name: "Avro to JSON: no input (force JSON true)",
|
||||
input: "",
|
||||
expectedOutput: "Please provide an input.",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "Avro to JSON",
|
||||
args: [true]
|
||||
}
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "Avro to JSON: no input (force JSON false)",
|
||||
input: "",
|
||||
expectedOutput: "Please provide an input.",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "Avro to JSON",
|
||||
args: [false]
|
||||
}
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "Avro to JSON: small (force JSON true)",
|
||||
input: "\x4f\x62\x6a\x01\x04\x16\x61\x76\x72\x6f\x2e\x73\x63\x68\x65\x6d\x61\x96\x01\x7b\x22\x74\x79\x70\x65\x22\x3a\x22\x72\x65" +
|
||||
"\x63\x6f\x72\x64\x22\x2c\x22\x6e\x61\x6d\x65\x22\x3a\x22\x73\x6d\x61\x6c\x6c\x22\x2c\x22\x66\x69\x65\x6c\x64\x73\x22\x3a" +
|
||||
"\x5b\x7b\x22\x6e\x61\x6d\x65\x22\x3a\x22\x6e\x61\x6d\x65\x22\x2c\x22\x74\x79\x70\x65\x22\x3a\x22\x73\x74\x72\x69\x6e\x67" +
|
||||
"\x22\x7d\x5d\x7d\x14\x61\x76\x72\x6f\x2e\x63\x6f\x64\x65\x63\x08\x6e\x75\x6c\x6c\x00\x4e\x02\x47\x63\x2e\x37\x02\xe5\xb7" +
|
||||
"\x5c\xda\xb9\xa6\x2f\x15\x41\x02\x0e\x0c\x6d\x79\x6e\x61\x6d\x65\x4e\x02\x47\x63\x2e\x37\x02\xe5\xb7\x5c\xda\xb9\xa6\x2f" +
|
||||
"\x15\x41",
|
||||
expectedOutput: "{\n \"name\": \"myname\"\n}",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "Avro to JSON",
|
||||
args: [true]
|
||||
}
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "Avro to JSON: small (force JSON false)",
|
||||
input: "\x4f\x62\x6a\x01\x04\x16\x61\x76\x72\x6f\x2e\x73\x63\x68\x65\x6d\x61\x96\x01\x7b\x22\x74\x79\x70\x65\x22\x3a\x22\x72\x65" +
|
||||
"\x63\x6f\x72\x64\x22\x2c\x22\x6e\x61\x6d\x65\x22\x3a\x22\x73\x6d\x61\x6c\x6c\x22\x2c\x22\x66\x69\x65\x6c\x64\x73\x22\x3a" +
|
||||
"\x5b\x7b\x22\x6e\x61\x6d\x65\x22\x3a\x22\x6e\x61\x6d\x65\x22\x2c\x22\x74\x79\x70\x65\x22\x3a\x22\x73\x74\x72\x69\x6e\x67" +
|
||||
"\x22\x7d\x5d\x7d\x14\x61\x76\x72\x6f\x2e\x63\x6f\x64\x65\x63\x08\x6e\x75\x6c\x6c\x00\x4e\x02\x47\x63\x2e\x37\x02\xe5\xb7" +
|
||||
"\x5c\xda\xb9\xa6\x2f\x15\x41\x02\x0e\x0c\x6d\x79\x6e\x61\x6d\x65\x4e\x02\x47\x63\x2e\x37\x02\xe5\xb7\x5c\xda\xb9\xa6\x2f" +
|
||||
"\x15\x41",
|
||||
expectedOutput: "{\"name\":\"myname\"}\n",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "Avro to JSON",
|
||||
args: [false]
|
||||
}
|
||||
],
|
||||
}
|
||||
]);
|
|
@ -5,7 +5,7 @@
|
|||
* @copyright Crown Copyright 2017
|
||||
* @license Apache-2.0
|
||||
*/
|
||||
import TestRegister from "../TestRegister";
|
||||
import TestRegister from "../../lib/TestRegister.mjs";
|
||||
|
||||
TestRegister.addTests([
|
||||
{
|
||||
|
|
56
tests/operations/tests/BLAKE2b.mjs
Normal file
56
tests/operations/tests/BLAKE2b.mjs
Normal file
|
@ -0,0 +1,56 @@
|
|||
/**
|
||||
* BitwiseOp tests
|
||||
*
|
||||
* @author h345983745
|
||||
* @copyright Crown Copyright 2019
|
||||
* @license Apache-2.0
|
||||
*/
|
||||
import TestRegister from "../../lib/TestRegister.mjs";
|
||||
|
||||
TestRegister.addTests([
|
||||
{
|
||||
name: "BLAKE2b: 512 - Hello World",
|
||||
input: "Hello World",
|
||||
expectedOutput: "4386a08a265111c9896f56456e2cb61a64239115c4784cf438e36cc851221972da3fb0115f73cd02486254001f878ab1fd126aac69844ef1c1ca152379d0a9bd",
|
||||
recipeConfig: [
|
||||
{ "op": "BLAKE2b",
|
||||
"args": ["512", "Hex", {string: "", option: "UTF8"}] }
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "BLAKE2b: 384 - Hello World",
|
||||
input: "Hello World",
|
||||
expectedOutput: "4d388e82ca8f866e606b6f6f0be910abd62ad6e98c0adfc27cf35acf948986d5c5b9c18b6f47261e1e679eb98edf8e2d",
|
||||
recipeConfig: [
|
||||
{ "op": "BLAKE2b",
|
||||
"args": ["384", "Hex", {string: "", option: "UTF8"}] }
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "BLAKE2b: 256 - Hello World",
|
||||
input: "Hello World",
|
||||
expectedOutput: "1dc01772ee0171f5f614c673e3c7fa1107a8cf727bdf5a6dadb379e93c0d1d00",
|
||||
recipeConfig: [
|
||||
{ "op": "BLAKE2b",
|
||||
"args": ["256", "Hex", {string: "", option: "UTF8"}] }
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "BLAKE2b: 160 - Hello World",
|
||||
input: "Hello World",
|
||||
expectedOutput: "6a8489e6fd6e51fae12ab271ec7fc8134dd5d737",
|
||||
recipeConfig: [
|
||||
{ "op": "BLAKE2b",
|
||||
"args": ["160", "Hex", {string: "", option: "UTF8"}] }
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "BLAKE2b: Key Test",
|
||||
input: "message data",
|
||||
expectedOutput: "3d363ff7401e02026f4a4687d4863ced",
|
||||
recipeConfig: [
|
||||
{ "op": "BLAKE2b",
|
||||
"args": ["128", "Hex", {string: "pseudorandom key", option: "UTF8"}] }
|
||||
]
|
||||
}
|
||||
]);
|
47
tests/operations/tests/BLAKE2s.mjs
Executable file
47
tests/operations/tests/BLAKE2s.mjs
Executable file
|
@ -0,0 +1,47 @@
|
|||
/**
|
||||
* BitwiseOp tests
|
||||
*
|
||||
* @author h345983745
|
||||
* @copyright Crown Copyright 2019
|
||||
* @license Apache-2.0
|
||||
*/
|
||||
import TestRegister from "../../lib/TestRegister.mjs";
|
||||
|
||||
TestRegister.addTests([
|
||||
{
|
||||
name: "BLAKE2s: 256 - Hello World",
|
||||
input: "Hello World",
|
||||
expectedOutput: "7706af019148849e516f95ba630307a2018bb7bf03803eca5ed7ed2c3c013513",
|
||||
recipeConfig: [
|
||||
{ "op": "BLAKE2s",
|
||||
"args": ["256", "Hex", {string: "", option: "UTF8"}] }
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "BLAKE2s: 160 - Hello World",
|
||||
input: "Hello World",
|
||||
expectedOutput: "0e4fcfc2ee0097ac1d72d70b595a39e09a3c7c7e",
|
||||
recipeConfig: [
|
||||
{ "op": "BLAKE2s",
|
||||
"args": ["160", "Hex", {string: "", option: "UTF8"}] }
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "BLAKE2s: 128 - Hello World",
|
||||
input: "Hello World",
|
||||
expectedOutput: "9964ee6f36126626bf864363edfa96f6",
|
||||
recipeConfig: [
|
||||
{ "op": "BLAKE2s",
|
||||
"args": ["128", "Hex", {string: "", option: "UTF8"}] }
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "BLAKE2s: Key Test",
|
||||
input: "Hello World",
|
||||
expectedOutput: "9964ee6f36126626bf864363edfa96f6",
|
||||
recipeConfig: [
|
||||
{ "op": "BLAKE2s",
|
||||
"args": ["128", "Hex", {string: "", option: "UTF8"}] }
|
||||
]
|
||||
}
|
||||
]);
|
|
@ -6,7 +6,7 @@
|
|||
* @copyright Crown Copyright 2018
|
||||
* @license Apache-2.0
|
||||
*/
|
||||
import TestRegister from "../TestRegister";
|
||||
import TestRegister from "../../lib/TestRegister.mjs";
|
||||
|
||||
TestRegister.addTests([
|
||||
{
|
||||
|
|
433
tests/operations/tests/BaconCipher.mjs
Normal file
433
tests/operations/tests/BaconCipher.mjs
Normal file
|
@ -0,0 +1,433 @@
|
|||
/**
|
||||
* Bacon Cipher tests.
|
||||
*
|
||||
* @author Karsten Silkenbäumer [github.com/kassi]
|
||||
* @copyright Karsten Silkenbäumer 2019
|
||||
* @license Apache-2.0
|
||||
*/
|
||||
import TestRegister from "../../lib/TestRegister.mjs";
|
||||
import { BACON_ALPHABETS, BACON_TRANSLATIONS } from "../../../src/core/lib/Bacon.mjs";
|
||||
|
||||
const alphabets = Object.keys(BACON_ALPHABETS);
|
||||
const translations = BACON_TRANSLATIONS;
|
||||
|
||||
TestRegister.addTests([
|
||||
{
|
||||
name: "Bacon Decode: no input",
|
||||
input: "",
|
||||
expectedOutput: "",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "Bacon Cipher Decode",
|
||||
args: [alphabets[0], translations[0], false]
|
||||
}
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "Bacon Decode: reduced alphabet 0/1",
|
||||
input: "00011 00100 00010 01101 00011 01000 01100 00110 00001 00000 00010 01101 01100 10100 01101 10000 01001 10001",
|
||||
expectedOutput: "DECODINGBACONWORKS",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "Bacon Cipher Decode",
|
||||
args: [alphabets[0], translations[0], false]
|
||||
}
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "Bacon Decode: reduced alphabet 0/1 inverse",
|
||||
input: "11100 11011 11101 10010 11100 10111 10011 11001 11110 11111 11101 10010 10011 01011 10010 01111 10110 01110",
|
||||
expectedOutput: "DECODINGBACONWORKS",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "Bacon Cipher Decode",
|
||||
args: [alphabets[0], translations[0], true]
|
||||
}
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "Bacon Decode: reduced alphabet A/B lower case",
|
||||
input: "aaabb aabaa aaaba abbab aaabb abaaa abbaa aabba aaaab aaaaa aaaba abbab abbaa babaa abbab baaaa abaab baaab",
|
||||
expectedOutput: "DECODINGBACONWORKS",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "Bacon Cipher Decode",
|
||||
args: [alphabets[0], translations[1], false]
|
||||
}
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "Bacon Decode: reduced alphabet A/B lower case inverse",
|
||||
input: "bbbaa bbabb bbbab baaba bbbaa babbb baabb bbaab bbbba bbbbb bbbab baaba baabb ababb baaba abbbb babba abbba",
|
||||
expectedOutput: "DECODINGBACONWORKS",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "Bacon Cipher Decode",
|
||||
args: [alphabets[0], translations[1], true]
|
||||
}
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "Bacon Decode: reduced alphabet A/B upper case",
|
||||
input: "AAABB AABAA AAABA ABBAB AAABB ABAAA ABBAA AABBA AAAAB AAAAA AAABA ABBAB ABBAA BABAA ABBAB BAAAA ABAAB BAAAB",
|
||||
expectedOutput: "DECODINGBACONWORKS",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "Bacon Cipher Decode",
|
||||
args: [alphabets[0], translations[1], false]
|
||||
}
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "Bacon Decode: reduced alphabet A/B upper case inverse",
|
||||
input: "BBBAA BBABB BBBAB BAABA BBBAA BABBB BAABB BBAAB BBBBA BBBBB BBBAB BAABA BAABB ABABB BAABA ABBBB BABBA ABBBA",
|
||||
expectedOutput: "DECODINGBACONWORKS",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "Bacon Cipher Decode",
|
||||
args: [alphabets[0], translations[1], true]
|
||||
}
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "Bacon Decode: reduced alphabet case code",
|
||||
input: "thiS IsaN exampLe oF ThE bacON cIpher WIth upPPercasE letters tRanSLaTiNG to OnEs anD LoWErcase To zERoes. KS",
|
||||
expectedOutput: "DECODINGBACONWORKS",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "Bacon Cipher Decode",
|
||||
args: [alphabets[0], translations[2], false]
|
||||
}
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "Bacon Decode: reduced alphabet case code inverse",
|
||||
input: "THIs iS An EXAMPlE Of tHe BACon CiPHER wiTH UPppERCASe LETTERS TrANslAtIng TO oNeS ANd lOweRCASE tO ZerOES. ks",
|
||||
expectedOutput: "DECODINGBACONWORKS",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "Bacon Cipher Decode",
|
||||
args: [alphabets[0], translations[2], true]
|
||||
}
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "Bacon Decode: reduced alphabet case code",
|
||||
input: "A little example of the Bacon Cipher to be decoded. It is a working example and shorter than my others, but it anyways works tremendously. And just that's important, correct?",
|
||||
expectedOutput: "DECODE",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "Bacon Cipher Decode",
|
||||
args: [alphabets[0], translations[3], false]
|
||||
}
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "Bacon Decode: reduced alphabet case code inverse",
|
||||
input: "Well, there's now another example which will be not only strange to read but sound weird for everyone not knowing what the thing is about. Nevertheless, works great out of the box.",
|
||||
expectedOutput: "DECODE",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "Bacon Cipher Decode",
|
||||
args: [alphabets[0], translations[3], true]
|
||||
}
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "Bacon Decode: complete alphabet 0/1",
|
||||
input: "00011 00100 00010 01110 00011 01000 01101 00110 00001 00000 00010 01110 01101 10110 01110 10001 01010 10010",
|
||||
expectedOutput: "DECODINGBACONWORKS",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "Bacon Cipher Decode",
|
||||
args: [alphabets[1], translations[0], false]
|
||||
}
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "Bacon Decode: complete alphabet 0/1 inverse",
|
||||
input: "11100 11011 11101 10001 11100 10111 10010 11001 11110 11111 11101 10001 10010 01001 10001 01110 10101 01101",
|
||||
expectedOutput: "DECODINGBACONWORKS",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "Bacon Cipher Decode",
|
||||
args: [alphabets[1], translations[0], true]
|
||||
}
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "Bacon Decode: complete alphabet A/B lower case",
|
||||
input: "aaabb aabaa aaaba abbba aaabb abaaa abbab aabba aaaab aaaaa aaaba abbba abbab babba abbba baaab ababa baaba",
|
||||
expectedOutput: "DECODINGBACONWORKS",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "Bacon Cipher Decode",
|
||||
args: [alphabets[1], translations[1], false]
|
||||
}
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "Bacon Decode: complete alphabet A/B lower case inverse",
|
||||
input: "bbbaa bbabb bbbab baaab bbbaa babbb baaba bbaab bbbba bbbbb bbbab baaab baaba abaab baaab abbba babab abbab",
|
||||
expectedOutput: "DECODINGBACONWORKS",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "Bacon Cipher Decode",
|
||||
args: [alphabets[1], translations[1], true]
|
||||
}
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "Bacon Decode: complete alphabet A/B upper case",
|
||||
input: "AAABB AABAA AAABA ABBBA AAABB ABAAA ABBAB AABBA AAAAB AAAAA AAABA ABBBA ABBAB BABBA ABBBA BAAAB ABABA BAABA",
|
||||
expectedOutput: "DECODINGBACONWORKS",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "Bacon Cipher Decode",
|
||||
args: [alphabets[1], translations[1], false]
|
||||
}
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "Bacon Decode: complete alphabet A/B upper case inverse",
|
||||
input: "BBBAA BBABB BBBAB BAAAB BBBAA BABBB BAABA BBAAB BBBBA BBBBB BBBAB BAAAB BAABA ABAAB BAAAB ABBBA BABAB ABBAB",
|
||||
expectedOutput: "DECODINGBACONWORKS",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "Bacon Cipher Decode",
|
||||
args: [alphabets[1], translations[1], true]
|
||||
}
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "Bacon Decode: complete alphabet case code",
|
||||
input: "thiS IsaN exampLe oF THe bacON cIpher WItH upPPercasE letters tRanSLAtiNG tO OnES anD LOwErcaSe To ZeRoeS. kS",
|
||||
expectedOutput: "DECODINGBACONWORKS",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "Bacon Cipher Decode",
|
||||
args: [alphabets[1], translations[2], false]
|
||||
}
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "Bacon Decode: complete alphabet case code inverse",
|
||||
input: "THIs iSAn EXAMPlE Of thE BACon CiPHER wiTh UPppERCASe LETTERS TrANslaTIng To zEroES and LoWERcAsE tO oNEs. Ks",
|
||||
expectedOutput: "DECODINGBACONWORKS",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "Bacon Cipher Decode",
|
||||
args: [alphabets[1], translations[2], true]
|
||||
}
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "Bacon Decode: complete alphabet case code",
|
||||
input: "A little example of the Bacon Cipher to be decoded. It is a working example and shorter than the first, but it anyways works tremendously. And just that's important, correct?",
|
||||
expectedOutput: "DECODE",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "Bacon Cipher Decode",
|
||||
args: [alphabets[1], translations[3], false]
|
||||
}
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "Bacon Decode: complete alphabet case code inverse",
|
||||
input: "Well, there's now another example which will be not only strange to read but sound weird for everyone knowing nothing what the thing is about. Nevertheless, works great out of the box. ",
|
||||
expectedOutput: "DECODE",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "Bacon Cipher Decode",
|
||||
args: [alphabets[1], translations[3], true]
|
||||
}
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "Bacon Encode: no input",
|
||||
input: "",
|
||||
expectedOutput: "",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "Bacon Cipher Encode",
|
||||
args: [alphabets[0], translations[0], false, false]
|
||||
}
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "Bacon Encode: reduced alphabet 0/1",
|
||||
input: "There's a fox, and it jumps over the fence.",
|
||||
expectedOutput: "10010 00111 00100 10000 00100 10001 00000 00101 01101 10101 00000 01100 00011 01000 10010 01000 10011 01011 01110 10001 01101 10011 00100 10000 10010 00111 00100 00101 00100 01100 00010 00100",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "Bacon Cipher Encode",
|
||||
args: [alphabets[0], translations[0], false, false]
|
||||
}
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "Bacon Encode: reduced alphabet 0/1 inverse",
|
||||
input: "There's a fox, and it jumps over the fence.",
|
||||
expectedOutput: "01101 11000 11011 01111 11011 01110 11111 11010 10010 01010 11111 10011 11100 10111 01101 10111 01100 10100 10001 01110 10010 01100 11011 01111 01101 11000 11011 11010 11011 10011 11101 11011",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "Bacon Cipher Encode",
|
||||
args: [alphabets[0], translations[0], false, true]
|
||||
}
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "Bacon Encode: reduced alphabet 0/1, keeping extra characters",
|
||||
input: "There's a fox, and it jumps over the fence.",
|
||||
expectedOutput: "1001000111001001000000100'10001 00000 001010110110101, 000000110000011 0100010010 0100010011010110111010001 01101100110010010000 100100011100100 0010100100011000001000100.",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "Bacon Cipher Encode",
|
||||
args: [alphabets[0], translations[0], true, false]
|
||||
}
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "Bacon Encode: reduced alphabet 0/1 inverse, keeping extra characters",
|
||||
input: "There's a fox, and it jumps over the fence.",
|
||||
expectedOutput: "0110111000110110111111011'01110 11111 110101001001010, 111111001111100 1011101101 1011101100101001000101110 10010011001101101111 011011100011011 1101011011100111110111011.",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "Bacon Cipher Encode",
|
||||
args: [alphabets[0], translations[0], true, true]
|
||||
}
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "Bacon Encode: reduced alphabet A/B",
|
||||
input: "There's a fox, and it jumps over the fence.",
|
||||
expectedOutput: "BAABA AABBB AABAA BAAAA AABAA BAAAB AAAAA AABAB ABBAB BABAB AAAAA ABBAA AAABB ABAAA BAABA ABAAA BAABB ABABB ABBBA BAAAB ABBAB BAABB AABAA BAAAA BAABA AABBB AABAA AABAB AABAA ABBAA AAABA AABAA",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "Bacon Cipher Encode",
|
||||
args: [alphabets[0], translations[1], false, false]
|
||||
}
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "Bacon Encode: reduced alphabet A/B inverse",
|
||||
input: "There's a fox, and it jumps over the fence.",
|
||||
expectedOutput: "ABBAB BBAAA BBABB ABBBB BBABB ABBBA BBBBB BBABA BAABA ABABA BBBBB BAABB BBBAA BABBB ABBAB BABBB ABBAA BABAA BAAAB ABBBA BAABA ABBAA BBABB ABBBB ABBAB BBAAA BBABB BBABA BBABB BAABB BBBAB BBABB",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "Bacon Cipher Encode",
|
||||
args: [alphabets[0], translations[1], false, true]
|
||||
}
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "Bacon Encode: reduced alphabet A/B, keeping extra characters",
|
||||
input: "There's a fox, and it jumps over the fence.",
|
||||
expectedOutput: "BAABAAABBBAABAABAAAAAABAA'BAAAB AAAAA AABABABBABBABAB, AAAAAABBAAAAABB ABAAABAABA ABAAABAABBABABBABBBABAAAB ABBABBAABBAABAABAAAA BAABAAABBBAABAA AABABAABAAABBAAAAABAAABAA.",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "Bacon Cipher Encode",
|
||||
args: [alphabets[0], translations[1], true, false]
|
||||
}
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "Bacon Encode: reduced alphabet A/B inverse, keeping extra characters",
|
||||
input: "There's a fox, and it jumps over the fence.",
|
||||
expectedOutput: "ABBABBBAAABBABBABBBBBBABB'ABBBA BBBBB BBABABAABAABABA, BBBBBBAABBBBBAA BABBBABBAB BABBBABBAABABAABAAABABBBA BAABAABBAABBABBABBBB ABBABBBAAABBABB BBABABBABBBAABBBBBABBBABB.",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "Bacon Cipher Encode",
|
||||
args: [alphabets[0], translations[1], true, true]
|
||||
}
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "Bacon Encode: complete alphabet 0/1",
|
||||
input: "There's a fox, and it jumps over the fence.",
|
||||
expectedOutput: "10011 00111 00100 10001 00100 10010 00000 00101 01110 10111 00000 01101 00011 01000 10011 01001 10100 01100 01111 10010 01110 10101 00100 10001 10011 00111 00100 00101 00100 01101 00010 00100",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "Bacon Cipher Encode",
|
||||
args: [alphabets[1], translations[0], false, false]
|
||||
}
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "Bacon Encode: complete alphabet 0/1 inverse",
|
||||
input: "There's a fox, and it jumps over the fence.",
|
||||
expectedOutput: "01100 11000 11011 01110 11011 01101 11111 11010 10001 01000 11111 10010 11100 10111 01100 10110 01011 10011 10000 01101 10001 01010 11011 01110 01100 11000 11011 11010 11011 10010 11101 11011",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "Bacon Cipher Encode",
|
||||
args: [alphabets[1], translations[0], false, true]
|
||||
}
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "Bacon Encode: complete alphabet 0/1, keeping extra characters",
|
||||
input: "There's a fox, and it jumps over the fence.",
|
||||
expectedOutput: "1001100111001001000100100'10010 00000 001010111010111, 000000110100011 0100010011 0100110100011000111110010 01110101010010010001 100110011100100 0010100100011010001000100.",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "Bacon Cipher Encode",
|
||||
args: [alphabets[1], translations[0], true, false]
|
||||
}
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "Bacon Encode: complete alphabet 0/1 inverse, keeping extra characters",
|
||||
input: "There's a fox, and it jumps over the fence.",
|
||||
expectedOutput: "0110011000110110111011011'01101 11111 110101000101000, 111111001011100 1011101100 1011001011100111000001101 10001010101101101110 011001100011011 1101011011100101110111011.",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "Bacon Cipher Encode",
|
||||
args: [alphabets[1], translations[0], true, true]
|
||||
}
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "Bacon Encode: complete alphabet A/B",
|
||||
input: "There's a fox, and it jumps over the fence.",
|
||||
expectedOutput: "BAABB AABBB AABAA BAAAB AABAA BAABA AAAAA AABAB ABBBA BABBB AAAAA ABBAB AAABB ABAAA BAABB ABAAB BABAA ABBAA ABBBB BAABA ABBBA BABAB AABAA BAAAB BAABB AABBB AABAA AABAB AABAA ABBAB AAABA AABAA",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "Bacon Cipher Encode",
|
||||
args: [alphabets[1], translations[1], false, false]
|
||||
}
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "Bacon Encode: complete alphabet A/B inverse",
|
||||
input: "There's a fox, and it jumps over the fence.",
|
||||
expectedOutput: "ABBAA BBAAA BBABB ABBBA BBABB ABBAB BBBBB BBABA BAAAB ABAAA BBBBB BAABA BBBAA BABBB ABBAA BABBA ABABB BAABB BAAAA ABBAB BAAAB ABABA BBABB ABBBA ABBAA BBAAA BBABB BBABA BBABB BAABA BBBAB BBABB",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "Bacon Cipher Encode",
|
||||
args: [alphabets[1], translations[1], false, true]
|
||||
}
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "Bacon Encode: complete alphabet A/B, keeping extra characters",
|
||||
input: "There's a fox, and it jumps over the fence.",
|
||||
expectedOutput: "BAABBAABBBAABAABAAABAABAA'BAABA AAAAA AABABABBBABABBB, AAAAAABBABAAABB ABAAABAABB ABAABBABAAABBAAABBBBBAABA ABBBABABABAABAABAAAB BAABBAABBBAABAA AABABAABAAABBABAAABAAABAA.",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "Bacon Cipher Encode",
|
||||
args: [alphabets[1], translations[1], true, false]
|
||||
}
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "Bacon Encode: complete alphabet A/B inverse, keeping extra characters",
|
||||
input: "There's a fox, and it jumps over the fence.",
|
||||
expectedOutput: "ABBAABBAAABBABBABBBABBABB'ABBAB BBBBB BBABABAAABABAAA, BBBBBBAABABBBAA BABBBABBAA BABBAABABBBAABBBAAAAABBAB BAAABABABABBABBABBBA ABBAABBAAABBABB BBABABBABBBAABABBBABBBABB.",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "Bacon Cipher Encode",
|
||||
args: [alphabets[1], translations[1], true, true]
|
||||
}
|
||||
],
|
||||
},
|
||||
]);
|
103
tests/operations/tests/Base45.mjs
Normal file
103
tests/operations/tests/Base45.mjs
Normal file
|
@ -0,0 +1,103 @@
|
|||
/**
|
||||
* Base45 tests.
|
||||
*
|
||||
* @author Thomas Weißschuh [thomas@t-8ch.de]
|
||||
*
|
||||
* @copyright Crown Copyright 2021
|
||||
* @license Apache-2.0
|
||||
*/
|
||||
|
||||
import TestRegister from "../../lib/TestRegister.mjs";
|
||||
|
||||
const defaultB45Alph = "0-9A-Z $%*+\\-./:";
|
||||
|
||||
TestRegister.addTests([
|
||||
{
|
||||
name: "To Base45: nothing",
|
||||
input: "",
|
||||
expectedOutput: "",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "To Base45",
|
||||
args: [defaultB45Alph],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "To Base45: Spec encoding example 1",
|
||||
input: "AB",
|
||||
expectedOutput: "BB8",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "To Base45",
|
||||
args: [defaultB45Alph],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "To Base45: Spec encoding example 2",
|
||||
input: "Hello!!",
|
||||
expectedOutput: "%69 VD92EX0",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "To Base45",
|
||||
args: [defaultB45Alph],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "To Base45: Spec encoding example 3",
|
||||
input: "base-45",
|
||||
expectedOutput: "UJCLQE7W581",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "To Base45",
|
||||
args: [defaultB45Alph],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "From Base45: nothing",
|
||||
input: "",
|
||||
expectedOutput: "",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "From Base45",
|
||||
args: [defaultB45Alph],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "From Base45: Spec decoding example 1",
|
||||
input: "QED8WEX0",
|
||||
expectedOutput: "ietf!",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "From Base45",
|
||||
args: [defaultB45Alph],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "From Base45: Invalid character",
|
||||
input: "!",
|
||||
expectedOutput: "Character not in alphabet: '!'",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "From Base45",
|
||||
args: [defaultB45Alph],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "From Base45: Invalid triplet value",
|
||||
input: "ZZZ",
|
||||
expectedOutput: "Triplet too large: 'ZZZ'",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "From Base45",
|
||||
args: [defaultB45Alph],
|
||||
},
|
||||
],
|
||||
},
|
||||
]);
|
|
@ -6,7 +6,7 @@
|
|||
* @copyright Crown Copyright 2017
|
||||
* @license Apache-2.0
|
||||
*/
|
||||
import TestRegister from "../TestRegister";
|
||||
import TestRegister from "../../lib/TestRegister.mjs";
|
||||
|
||||
TestRegister.addTests([
|
||||
{
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
* @license Apache-2.0
|
||||
*/
|
||||
|
||||
import TestRegister from "../TestRegister";
|
||||
import TestRegister from "../../lib/TestRegister.mjs";
|
||||
|
||||
TestRegister.addTests([
|
||||
{
|
||||
|
|
|
@ -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",
|
||||
|
|
70
tests/operations/tests/Base85.mjs
Normal file
70
tests/operations/tests/Base85.mjs
Normal file
|
@ -0,0 +1,70 @@
|
|||
/**
|
||||
* Base85 tests
|
||||
*
|
||||
* @author john19696
|
||||
* @copyright Crown Copyright 2019
|
||||
* @license Apache-2.0
|
||||
*/
|
||||
import TestRegister from "../../lib/TestRegister.mjs";
|
||||
|
||||
// Example from Wikipedia
|
||||
const wpExample = "Man is distinguished, not only by his reason, but by this singular passion from other animals, which is a lust of the mind, that by a perseverance of delight in the continued and indefatigable generation of knowledge, exceeds the short vehemence of any carnal pleasure.";
|
||||
// Escape newline, quote & backslash
|
||||
const wpOutput = "9jqo^BlbD-BleB1DJ+*+F(f,q/0JhKF<GL>Cj@.4Gp$d7F!,L7@<6@)/0JDEF<G%<+EV:2F!,O<\
|
||||
DJ+*.@<*K0@<6L(Df-\\0Ec5e;DffZ(EZee.Bl.9pF\"AGXBPCsi+DGm>@3BB/F*&OCAfu2/AKYi(\
|
||||
DIb:@FD,*)+C]U=@3BN#EcYf8ATD3s@q?d$AftVqCh[NqF<G:8+EV:.+Cf>-FD5W8ARlolDIal(\
|
||||
DId<j@<?3r@:F%a+D58'ATD4$Bl@l3De:,-DJs`8ARoFb/0JMK@qB4^F!,R<AKZ&-DfTqBG%G>u\
|
||||
D.RTpAKYo'+CT/5+Cei#DII?(E,9)oF*2M7/c";
|
||||
|
||||
const allZeroExample = "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f\x20\x21\x22\x23\x24\x25\x26\x27\x28\x29\x2a\x2b\x2c\x2d\x2e\x2f\x30\x31\x32\x33\x34\x35\x36\x37\x38\x39\x3a\x3b\x3c\x3d\x3e\x3f\x40\x41\x42\x43\x44\x45\x46\x47\x48\x49\x4a\x4b\x4c\x4d\x4e\x4f\x50\x51\x52\x53\x54\x55\x56\x57\x58\x59\x5a\x5b\x5c\x5d\x5e\x5f\x60\x61\x62\x63\x64\x65\x66\x67\x68\x69\x6a\x6b\x6c\x6d\x6e\x6f\x70\x71\x72\x73\x74\x75\x76\x77\x78\x79\x7a\x7b\x7c\x7d\x7e\x7f\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9a\x9b\x9c\x9d\x9e\x9f\xa0\xa1\xa2\xa3\xa4\xa5\xa6\xa7\xa8\xa9\xaa\xab\xac\xad\xae\xaf\xb0\xb1\xb2\xb3\xb4\xb5\xb6\xb7\xb8\xb9\xba\xbb\xbc\xbd\xbe\xbf\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf\xd0\xd1\xd2\xd3\xd4\xd5\xd6\xd7\xd8\xd9\xda\xdb\xdc\xdd\xde\xdf\xe0\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed\xee\xef\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff";
|
||||
|
||||
const allZeroOutput = "zz!!*-'\"9eu7#RLhG$k3[W&.oNg'GVB\"(`=52*$$(B+<_pR,UFcb-n-Vr/1iJ-0JP==1c70M3&s#]4?Ykm5X@_(6q'R884cEH9MJ8X:f1+h<)lt#=BSg3>[:ZC?t!MSA7]@cBPD3sCi+'.E,fo>FEMbNG^4U^I!pHnJ:W<)KS>/9Ll%\"IN/`jYOHG]iPa.Q$R$jD4S=Q7DTV8*TUnsrdW2ZetXKAY/Yd(L?['d?O\\@K2_]Y2%o^qmn*`5Ta:aN;TJbg\"GZd*^:jeCE.%f\\,!5gtgiEi8N\\UjQ5OekiqBum-X60nF?)@o_%qPq\"ad`r;HWp";
|
||||
|
||||
TestRegister.addTests([
|
||||
{
|
||||
name: "To Base85",
|
||||
input: wpExample,
|
||||
expectedOutput: wpOutput,
|
||||
recipeConfig: [
|
||||
{ "op": "To Base85",
|
||||
"args": ["!-u"] }
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "From Base85",
|
||||
input: wpOutput + "\n",
|
||||
expectedOutput: wpExample,
|
||||
recipeConfig: [
|
||||
{ "op": "From Base85",
|
||||
"args": ["!-u", true] }
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "From Base85",
|
||||
input: wpOutput + "v",
|
||||
expectedError: true,
|
||||
expectedOutput: "From Base85 - Invalid character 'v' at index 337",
|
||||
recipeConfig: [
|
||||
{ "op": "From Base85",
|
||||
"args": ["!-u", false] }
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "To Base85",
|
||||
input: allZeroExample,
|
||||
expectedOutput: allZeroOutput,
|
||||
recipeConfig: [
|
||||
{ "op": "To Base85",
|
||||
"args": ["!-u"] }
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "From Base85",
|
||||
input: allZeroOutput,
|
||||
expectedOutput: allZeroExample,
|
||||
recipeConfig: [
|
||||
{ "op": "From Base85",
|
||||
"args": ["!-u", true, "z"] }
|
||||
]
|
||||
},
|
||||
]);
|
89
tests/operations/tests/Base92.mjs
Normal file
89
tests/operations/tests/Base92.mjs
Normal file
|
@ -0,0 +1,89 @@
|
|||
/**
|
||||
* Base92 tests.
|
||||
*
|
||||
* @author sg5506844 [sg5506844@gmail.com]
|
||||
* @copyright Crown Copyright 2021
|
||||
* @license Apache-2.0
|
||||
*/
|
||||
|
||||
import TestRegister from "../../lib/TestRegister.mjs";
|
||||
|
||||
TestRegister.addTests([
|
||||
{
|
||||
name: "To Base92: nothing",
|
||||
input: "",
|
||||
expectedOutput: "",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "To Base92",
|
||||
args: [],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "To Base92: Spec encoding example 1",
|
||||
input: "AB",
|
||||
expectedOutput: "8y2",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "To Base92",
|
||||
args: [],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "To Base92: Spec encoding example 2",
|
||||
input: "Hello!!",
|
||||
expectedOutput: ";K_$aOTo&",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "To Base92",
|
||||
args: [],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "To Base92: Spec encoding example 3",
|
||||
input: "base-92",
|
||||
expectedOutput: "DX2?V<Y(*",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "To Base92",
|
||||
args: [],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "From Base92: nothing",
|
||||
input: "",
|
||||
expectedOutput: "",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "From Base92",
|
||||
args: [],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "From Base92: Spec decoding example 1",
|
||||
input: "G'_DW[B",
|
||||
expectedOutput: "ietf!",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "From Base92",
|
||||
args: [],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "From Base92: Invalid character",
|
||||
input: "~",
|
||||
expectedOutput: "~ is not a base92 character",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "From Base92",
|
||||
args: [],
|
||||
},
|
||||
],
|
||||
},
|
||||
]);
|
|
@ -5,7 +5,7 @@
|
|||
* @copyright Crown Copyright 2017
|
||||
* @license Apache-2.0
|
||||
*/
|
||||
import TestRegister from "../TestRegister";
|
||||
import TestRegister from "../../lib/TestRegister.mjs";
|
||||
|
||||
TestRegister.addTests([
|
||||
{
|
||||
|
|
242
tests/operations/tests/Bombe.mjs
Normal file
242
tests/operations/tests/Bombe.mjs
Normal file
|
@ -0,0 +1,242 @@
|
|||
/**
|
||||
* Bombe machine tests.
|
||||
* @author s2224834
|
||||
* @copyright Crown Copyright 2019
|
||||
* @license Apache-2.0
|
||||
*/
|
||||
import TestRegister from "../../lib/TestRegister.mjs";
|
||||
|
||||
TestRegister.addTests([
|
||||
{
|
||||
// Plugboard for this test is BO LC KE GA
|
||||
name: "Bombe: 3 rotor (self-stecker)",
|
||||
input: "BBYFLTHHYIJQAYBBYS",
|
||||
expectedMatch: /<td>LGA<\/td> {2}<td>SS<\/td> {2}<td>VFISUSGTKSTMPSUNAK<\/td>/,
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "Bombe",
|
||||
"args": [
|
||||
"3-rotor",
|
||||
"",
|
||||
"EKMFLGDQVZNTOWYHXUSPAIBRCJ<R", // I
|
||||
"AJDKSIRUXBLHWTMCQGZNPYFVOE<F", // II
|
||||
"BDFHJLCPRTXVZNYEIWGAKMUSQO<W", // III
|
||||
"AY BR CU DH EQ FS GL IP JX KN MO TZ VW", // B
|
||||
"THISISATESTMESSAGE", 0, false
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
// This test produces a menu that doesn't use the first letter, which is also a good test
|
||||
name: "Bombe: 3 rotor (other stecker)",
|
||||
input: "JBYALIHDYNUAAVKBYM",
|
||||
expectedMatch: /<td>LGA<\/td> {2}<td>AG<\/td> {2}<td>QFIMUMAFKMQSKMYNGW<\/td>/,
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "Bombe",
|
||||
"args": [
|
||||
"3-rotor",
|
||||
"",
|
||||
"EKMFLGDQVZNTOWYHXUSPAIBRCJ<R", // I
|
||||
"AJDKSIRUXBLHWTMCQGZNPYFVOE<F", // II
|
||||
"BDFHJLCPRTXVZNYEIWGAKMUSQO<W", // III
|
||||
"AY BR CU DH EQ FS GL IP JX KN MO TZ VW", // B
|
||||
"THISISATESTMESSAGE", 0, false
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "Bombe: crib offset",
|
||||
input: "AAABBYFLTHHYIJQAYBBYS", // first three chars here are faked
|
||||
expectedMatch: /<td>LGA<\/td> {2}<td>SS<\/td> {2}<td>VFISUSGTKSTMPSUNAK<\/td>/,
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "Bombe",
|
||||
"args": [
|
||||
"3-rotor",
|
||||
"",
|
||||
"EKMFLGDQVZNTOWYHXUSPAIBRCJ<R", // I
|
||||
"AJDKSIRUXBLHWTMCQGZNPYFVOE<F", // II
|
||||
"BDFHJLCPRTXVZNYEIWGAKMUSQO<W", // III
|
||||
"AY BR CU DH EQ FS GL IP JX KN MO TZ VW", // B
|
||||
"THISISATESTMESSAGE", 3, false
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "Bombe: multiple stops",
|
||||
input: "BBYFLTHHYIJQAYBBYS",
|
||||
expectedMatch: /<td>LGA<\/td> {2}<td>TT<\/td> {2}<td>VFISUSGTKSTMPSUNAK<\/td>/,
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "Bombe",
|
||||
"args": [
|
||||
"3-rotor",
|
||||
"",
|
||||
"EKMFLGDQVZNTOWYHXUSPAIBRCJ<R", // I
|
||||
"AJDKSIRUXBLHWTMCQGZNPYFVOE<F", // II
|
||||
"BDFHJLCPRTXVZNYEIWGAKMUSQO<W", // III
|
||||
"AY BR CU DH EQ FS GL IP JX KN MO TZ VW", // B
|
||||
"THISISATESTM", 0, false
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "Bombe: checking machine",
|
||||
input: "BBYFLTHHYIJQAYBBYS",
|
||||
expectedMatch: /<td>LGA<\/td> {2}<td>TT AG BO CL EK FF HH II JJ SS YY<\/td> {2}<td>THISISATESTMESSAGE<\/td>/,
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "Bombe",
|
||||
"args": [
|
||||
"3-rotor",
|
||||
"",
|
||||
"EKMFLGDQVZNTOWYHXUSPAIBRCJ<R", // I
|
||||
"AJDKSIRUXBLHWTMCQGZNPYFVOE<F", // II
|
||||
"BDFHJLCPRTXVZNYEIWGAKMUSQO<W", // III
|
||||
"AY BR CU DH EQ FS GL IP JX KN MO TZ VW", // B
|
||||
"THISISATESTM", 0, true
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
// Takes a while to run, so disabling for general purpose testing. Re-enable if modifying this operation.
|
||||
// {
|
||||
// name: "Bombe: 4 rotor",
|
||||
// input: "LUOXGJSHGEDSRDOQQX",
|
||||
// expectedMatch: /<td>LHSC<\/td> {2}<td>SS<\/td> {2}<td>HHHSSSGQUUQPKSEKWK<\/td>/,
|
||||
// recipeConfig: [
|
||||
// {
|
||||
// "op": "Bombe",
|
||||
// "args": [
|
||||
// "4-rotor",
|
||||
// "LEYJVCNIXWPBQMDRTAKZGFUHOS", // Beta
|
||||
// "EKMFLGDQVZNTOWYHXUSPAIBRCJ<R", // I
|
||||
// "AJDKSIRUXBLHWTMCQGZNPYFVOE<F", // II
|
||||
// "BDFHJLCPRTXVZNYEIWGAKMUSQO<W", // III
|
||||
// "AE BN CK DQ FU GY HW IJ LO MP RX SZ TV", // B thin
|
||||
// "THISISATESTMESSAGE", 0, false
|
||||
// ]
|
||||
// }
|
||||
// ]
|
||||
// },
|
||||
{
|
||||
name: "Bombe: no crib",
|
||||
input: "JBYALIHDYNUAAVKBYM",
|
||||
expectedMatch: /Crib cannot be empty/,
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "Bombe",
|
||||
"args": [
|
||||
"3-rotor",
|
||||
"",
|
||||
"EKMFLGDQVZNTOWYHXUSPAIBRCJ<R", // I
|
||||
"AJDKSIRUXBLHWTMCQGZNPYFVOE<F", // II
|
||||
"BDFHJLCPRTXVZNYEIWGAKMUSQO<W", // III
|
||||
"AY BR CU DH EQ FS GL IP JX KN MO TZ VW", // B
|
||||
"", 0, false
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "Bombe: short crib",
|
||||
input: "JBYALIHDYNUAAVKBYM",
|
||||
expectedMatch: /Crib is too short/,
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "Bombe",
|
||||
"args": [
|
||||
"3-rotor",
|
||||
"",
|
||||
"EKMFLGDQVZNTOWYHXUSPAIBRCJ<R", // I
|
||||
"AJDKSIRUXBLHWTMCQGZNPYFVOE<F", // II
|
||||
"BDFHJLCPRTXVZNYEIWGAKMUSQO<W", // III
|
||||
"AY BR CU DH EQ FS GL IP JX KN MO TZ VW", // B
|
||||
"A", 0, false
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "Bombe: invalid crib",
|
||||
input: "JBYALIHDYNUAAVKBYM",
|
||||
expectedMatch: /Invalid crib: .* in both ciphertext and crib/,
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "Bombe",
|
||||
"args": [
|
||||
"3-rotor",
|
||||
"",
|
||||
"EKMFLGDQVZNTOWYHXUSPAIBRCJ<R", // I
|
||||
"AJDKSIRUXBLHWTMCQGZNPYFVOE<F", // II
|
||||
"BDFHJLCPRTXVZNYEIWGAKMUSQO<W", // III
|
||||
"AY BR CU DH EQ FS GL IP JX KN MO TZ VW", // B
|
||||
"AAAAAAAA", 0, false
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "Bombe: long crib",
|
||||
input: "JBYALIHDYNUAAVKBYM",
|
||||
expectedMatch: /Crib overruns supplied ciphertext/,
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "Bombe",
|
||||
"args": [
|
||||
"3-rotor",
|
||||
"",
|
||||
"EKMFLGDQVZNTOWYHXUSPAIBRCJ<R", // I
|
||||
"AJDKSIRUXBLHWTMCQGZNPYFVOE<F", // II
|
||||
"BDFHJLCPRTXVZNYEIWGAKMUSQO<W", // III
|
||||
"AY BR CU DH EQ FS GL IP JX KN MO TZ VW", // B
|
||||
"CCCCCCCCCCCCCCCCCCCCCC", 0, false
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "Bombe: really long crib",
|
||||
input: "BBBBBBBBBBBBBBBBBBBBBBBBBB",
|
||||
expectedMatch: /Crib is too long/,
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "Bombe",
|
||||
"args": [
|
||||
"3-rotor",
|
||||
"",
|
||||
"EKMFLGDQVZNTOWYHXUSPAIBRCJ<R", // I
|
||||
"AJDKSIRUXBLHWTMCQGZNPYFVOE<F", // II
|
||||
"BDFHJLCPRTXVZNYEIWGAKMUSQO<W", // III
|
||||
"AY BR CU DH EQ FS GL IP JX KN MO TZ VW", // B
|
||||
"AAAAAAAAAAAAAAAAAAAAAAAAAA", 0, false
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "Bombe: negative offset",
|
||||
input: "AAAAA",
|
||||
expectedMatch: /Offset cannot be negative/,
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "Bombe",
|
||||
"args": [
|
||||
"3-rotor",
|
||||
"",
|
||||
"EKMFLGDQVZNTOWYHXUSPAIBRCJ<R", // I
|
||||
"AJDKSIRUXBLHWTMCQGZNPYFVOE<F", // II
|
||||
"BDFHJLCPRTXVZNYEIWGAKMUSQO<W", // III
|
||||
"AY BR CU DH EQ FS GL IP JX KN MO TZ VW", // B
|
||||
"BBBBB", -1, false
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
// Enigma tests cover validation of rotors and reflector
|
||||
]);
|
|
@ -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",
|
||||
|
@ -73,7 +73,7 @@ TestRegister.addTests([
|
|||
},
|
||||
{
|
||||
name: "To Octal: Γειά σου",
|
||||
input: "Γειά σου", //[206,147,206,181,206,185,206,172,32,207,131,206,191,207,133],
|
||||
input: "Γειά σου", // [206,147,206,181,206,185,206,172,32,207,131,206,191,207,133],
|
||||
expectedOutput: "316 223 316 265 316 271 316 254 40 317 203 316 277 317 205",
|
||||
recipeConfig: [
|
||||
{
|
||||
|
|
144
tests/operations/tests/CBORDecode.mjs
Normal file
144
tests/operations/tests/CBORDecode.mjs
Normal file
|
@ -0,0 +1,144 @@
|
|||
/**
|
||||
* CBOR Decode Tests
|
||||
*
|
||||
* @author Danh4 [dan.h4@ncsc.gov.uk]
|
||||
* @copyright Crown Copyright 2019
|
||||
* @license Apache-2.0
|
||||
*/
|
||||
|
||||
import TestRegister from "../../lib/TestRegister.mjs";
|
||||
|
||||
TestRegister.addTests([
|
||||
{
|
||||
name: "CBOR Decode: Can decode integer",
|
||||
input: "0f",
|
||||
expectedOutput: "15",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "From Hex",
|
||||
args: []
|
||||
},
|
||||
{
|
||||
op: "CBOR Decode",
|
||||
args: []
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "CBOR Decode: Can decode decimal",
|
||||
input: "f9 3e 00",
|
||||
expectedOutput: "1.5",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "From Hex",
|
||||
args: []
|
||||
},
|
||||
{
|
||||
op: "CBOR Decode",
|
||||
args: []
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "From Hex: Can decode text",
|
||||
input: "64 54 65 78 74",
|
||||
expectedOutput: "\"Text\"",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "From Hex",
|
||||
args: []
|
||||
},
|
||||
{
|
||||
op: "CBOR Decode",
|
||||
args: []
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "From Hex: Can decode boolean true",
|
||||
input: "f5",
|
||||
expectedOutput: "true",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "From Hex",
|
||||
args: []
|
||||
},
|
||||
{
|
||||
op: "CBOR Decode",
|
||||
args: []
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "From Hex: Can decode boolean false",
|
||||
input: "f4",
|
||||
expectedOutput: "false",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "From Hex",
|
||||
args: []
|
||||
},
|
||||
{
|
||||
op: "CBOR Decode",
|
||||
args: []
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "From Hex: Can decode map",
|
||||
input: "a3 61 61 01 61 62 02 61 63 03",
|
||||
expectedOutput: JSON.stringify({a: 1, b: 2, c: 3}),
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "From Hex",
|
||||
args: []
|
||||
},
|
||||
{
|
||||
op: "CBOR Decode",
|
||||
args: []
|
||||
},
|
||||
{
|
||||
op: "JSON Minify",
|
||||
args: []
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "From Hex: Can decode list",
|
||||
input: "83 00 01 02",
|
||||
expectedOutput: "[0,1,2]",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "From Hex",
|
||||
args: []
|
||||
},
|
||||
{
|
||||
op: "CBOR Decode",
|
||||
args: []
|
||||
},
|
||||
{
|
||||
op: "JSON Minify",
|
||||
args: []
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "From Hex: Can round trip with encode",
|
||||
input: JSON.stringify({a: 1, b: false, c: [1, 2, 3]}),
|
||||
expectedOutput: JSON.stringify({a: 1, b: false, c: [1, 2, 3]}),
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "CBOR Encode",
|
||||
args: []
|
||||
},
|
||||
{
|
||||
op: "CBOR Decode",
|
||||
args: []
|
||||
},
|
||||
{
|
||||
op: "JSON Minify",
|
||||
args: []
|
||||
}
|
||||
]
|
||||
}
|
||||
]);
|
117
tests/operations/tests/CBOREncode.mjs
Normal file
117
tests/operations/tests/CBOREncode.mjs
Normal file
|
@ -0,0 +1,117 @@
|
|||
/**
|
||||
* CBOR Encode Tests.
|
||||
*
|
||||
* @author Danh4 [dan.h4@ncsc.gov.uk]
|
||||
* @copyright Crown Copyright 2019
|
||||
* @license Apache-2.0
|
||||
*/
|
||||
|
||||
import TestRegister from "../../lib/TestRegister.mjs";
|
||||
|
||||
TestRegister.addTests([
|
||||
{
|
||||
name: "CBOR Encode: Can encode integer",
|
||||
input: "15",
|
||||
expectedOutput: "0f",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "CBOR Encode",
|
||||
args: []
|
||||
},
|
||||
{
|
||||
op: "To Hex",
|
||||
args: []
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "CBOR Decode: Can encode decimal",
|
||||
input: "1.5",
|
||||
expectedOutput: "f9 3e 00",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "CBOR Encode",
|
||||
args: []
|
||||
},
|
||||
{
|
||||
op: "To Hex",
|
||||
args: []
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "CBOR Encode: Can encode text",
|
||||
input: "\"Text\"",
|
||||
expectedOutput: "64 54 65 78 74",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "CBOR Encode",
|
||||
args: []
|
||||
},
|
||||
{
|
||||
op: "To Hex",
|
||||
args: []
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "CBOR Encode: Can encode boolean true",
|
||||
input: "true",
|
||||
expectedOutput: "f5",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "CBOR Encode",
|
||||
args: []
|
||||
},
|
||||
{
|
||||
op: "To Hex",
|
||||
args: []
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "CBOR Encode: Can encode boolean false",
|
||||
input: "false",
|
||||
expectedOutput: "f4",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "CBOR Encode",
|
||||
args: []
|
||||
},
|
||||
{
|
||||
op: "To Hex",
|
||||
args: []
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "CBOR Encode: Can encode map",
|
||||
input: JSON.stringify({a: 1, b: 2, c: 3}),
|
||||
expectedOutput: "a3 61 61 01 61 62 02 61 63 03",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "CBOR Encode",
|
||||
args: []
|
||||
},
|
||||
{
|
||||
op: "To Hex",
|
||||
args: []
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "CBOR Encode: Can encode list",
|
||||
input: "[0,1,2]",
|
||||
expectedOutput: "83 00 01 02",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "CBOR Encode",
|
||||
args: []
|
||||
},
|
||||
{
|
||||
op: "To Hex",
|
||||
args: []
|
||||
}
|
||||
]
|
||||
}
|
||||
]);
|
314
tests/operations/tests/CMAC.mjs
Normal file
314
tests/operations/tests/CMAC.mjs
Normal file
|
@ -0,0 +1,314 @@
|
|||
/**
|
||||
* @author mikecat
|
||||
* @copyright Crown Copyright 2022
|
||||
* @license Apache-2.0
|
||||
*/
|
||||
import TestRegister from "../../lib/TestRegister.mjs";
|
||||
|
||||
// values in "NIST's CSRC" testcases are taken from here:
|
||||
// https://csrc.nist.gov/projects/cryptographic-standards-and-guidelines/example-values
|
||||
|
||||
TestRegister.addTests([
|
||||
{
|
||||
"name": "CMAC-AES128 NIST's CSRC Example #1",
|
||||
"input": "",
|
||||
"expectedOutput": "bb1d6929e95937287fa37d129b756746",
|
||||
"recipeConfig": [
|
||||
{
|
||||
"op": "CMAC",
|
||||
"args": [{"option": "Hex", "string": "2b7e151628aed2a6abf7158809cf4f3c"}, "AES"]
|
||||
},
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "CMAC-AES128 NIST's CSRC Example #2",
|
||||
"input": "6bc1bee22e409f96e93d7e117393172a",
|
||||
"expectedOutput": "070a16b46b4d4144f79bdd9dd04a287c",
|
||||
"recipeConfig": [
|
||||
{
|
||||
"op": "From Hex",
|
||||
"args": ["None"]
|
||||
},
|
||||
{
|
||||
"op": "CMAC",
|
||||
"args": [{"option": "Hex", "string": "2b7e151628aed2a6abf7158809cf4f3c"}, "AES"]
|
||||
},
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "CMAC-AES128 NIST's CSRC Example #3",
|
||||
"input": "6bc1bee22e409f96e93d7e117393172aae2d8a57",
|
||||
"expectedOutput": "7d85449ea6ea19c823a7bf78837dfade",
|
||||
"recipeConfig": [
|
||||
{
|
||||
"op": "From Hex",
|
||||
"args": ["None"]
|
||||
},
|
||||
{
|
||||
"op": "CMAC",
|
||||
"args": [{"option": "Hex", "string": "2b7e151628aed2a6abf7158809cf4f3c"}, "AES"]
|
||||
},
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "CMAC-AES128 NIST's CSRC Example #4",
|
||||
"input": "6bc1bee22e409f96e93d7e117393172aae2d8a571e03ac9c9eb76fac45af8e5130c81c46a35ce411e5fbc1191a0a52eff69f2445df4f9b17ad2b417be66c3710",
|
||||
"expectedOutput": "51f0bebf7e3b9d92fc49741779363cfe",
|
||||
"recipeConfig": [
|
||||
{
|
||||
"op": "From Hex",
|
||||
"args": ["None"]
|
||||
},
|
||||
{
|
||||
"op": "CMAC",
|
||||
"args": [{"option": "Hex", "string": "2b7e151628aed2a6abf7158809cf4f3c"}, "AES"]
|
||||
},
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "CMAC-AES192 NIST's CSRC Example #1",
|
||||
"input": "",
|
||||
"expectedOutput": "d17ddf46adaacde531cac483de7a9367",
|
||||
"recipeConfig": [
|
||||
{
|
||||
"op": "CMAC",
|
||||
"args": [{"option": "Hex", "string": "8e73b0f7da0e6452c810f32b809079e562f8ead2522c6b7b"}, "AES"]
|
||||
},
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "CMAC-AES192 NIST's CSRC Example #2",
|
||||
"input": "6bc1bee22e409f96e93d7e117393172a",
|
||||
"expectedOutput": "9e99a7bf31e710900662f65e617c5184",
|
||||
"recipeConfig": [
|
||||
{
|
||||
"op": "From Hex",
|
||||
"args": ["None"]
|
||||
},
|
||||
{
|
||||
"op": "CMAC",
|
||||
"args": [{"option": "Hex", "string": "8e73b0f7da0e6452c810f32b809079e562f8ead2522c6b7b"}, "AES"]
|
||||
},
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "CMAC-AES192 NIST's CSRC Example #3",
|
||||
"input": "6bc1bee22e409f96e93d7e117393172aae2d8a57",
|
||||
"expectedOutput": "3d75c194ed96070444a9fa7ec740ecf8",
|
||||
"recipeConfig": [
|
||||
{
|
||||
"op": "From Hex",
|
||||
"args": ["None"]
|
||||
},
|
||||
{
|
||||
"op": "CMAC",
|
||||
"args": [{"option": "Hex", "string": "8e73b0f7da0e6452c810f32b809079e562f8ead2522c6b7b"}, "AES"]
|
||||
},
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "CMAC-AES192 NIST's CSRC Example #4",
|
||||
"input": "6bc1bee22e409f96e93d7e117393172aae2d8a571e03ac9c9eb76fac45af8e5130c81c46a35ce411e5fbc1191a0a52eff69f2445df4f9b17ad2b417be66c3710",
|
||||
"expectedOutput": "a1d5df0eed790f794d77589659f39a11",
|
||||
"recipeConfig": [
|
||||
{
|
||||
"op": "From Hex",
|
||||
"args": ["None"]
|
||||
},
|
||||
{
|
||||
"op": "CMAC",
|
||||
"args": [{"option": "Hex", "string": "8e73b0f7da0e6452c810f32b809079e562f8ead2522c6b7b"}, "AES"]
|
||||
},
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "CMAC-AES256 NIST's CSRC Example #1",
|
||||
"input": "",
|
||||
"expectedOutput": "028962f61b7bf89efc6b551f4667d983",
|
||||
"recipeConfig": [
|
||||
{
|
||||
"op": "CMAC",
|
||||
"args": [{"option": "Hex", "string": "603deb1015ca71be2b73aef0857d77811f352c073b6108d72d9810a30914dff4"}, "AES"]
|
||||
},
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "CMAC-AES256 NIST's CSRC Example #2",
|
||||
"input": "6bc1bee22e409f96e93d7e117393172a",
|
||||
"expectedOutput": "28a7023f452e8f82bd4bf28d8c37c35c",
|
||||
"recipeConfig": [
|
||||
{
|
||||
"op": "From Hex",
|
||||
"args": ["None"]
|
||||
},
|
||||
{
|
||||
"op": "CMAC",
|
||||
"args": [{"option": "Hex", "string": "603deb1015ca71be2b73aef0857d77811f352c073b6108d72d9810a30914dff4"}, "AES"]
|
||||
},
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "CMAC-AES256 NIST's CSRC Example #3",
|
||||
"input": "6bc1bee22e409f96e93d7e117393172aae2d8a57",
|
||||
"expectedOutput": "156727dc0878944a023c1fe03bad6d93",
|
||||
"recipeConfig": [
|
||||
{
|
||||
"op": "From Hex",
|
||||
"args": ["None"]
|
||||
},
|
||||
{
|
||||
"op": "CMAC",
|
||||
"args": [{"option": "Hex", "string": "603deb1015ca71be2b73aef0857d77811f352c073b6108d72d9810a30914dff4"}, "AES"]
|
||||
},
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "CMAC-AES256 NIST's CSRC Example #4",
|
||||
"input": "6bc1bee22e409f96e93d7e117393172aae2d8a571e03ac9c9eb76fac45af8e5130c81c46a35ce411e5fbc1191a0a52eff69f2445df4f9b17ad2b417be66c3710",
|
||||
"expectedOutput": "e1992190549f6ed5696a2c056c315410",
|
||||
"recipeConfig": [
|
||||
{
|
||||
"op": "From Hex",
|
||||
"args": ["None"]
|
||||
},
|
||||
{
|
||||
"op": "CMAC",
|
||||
"args": [{"option": "Hex", "string": "603deb1015ca71be2b73aef0857d77811f352c073b6108d72d9810a30914dff4"}, "AES"]
|
||||
},
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "CMAC-TDES (1) NIST's CSRC Sample #1",
|
||||
"input": "",
|
||||
"expectedOutput": "7db0d37df936c550",
|
||||
"recipeConfig": [
|
||||
{
|
||||
"op": "CMAC",
|
||||
"args": [{"option": "Hex", "string": "0123456789abcdef23456789abcdef01456789abcdef0123"}, "Triple DES"]
|
||||
},
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "CMAC-TDES (1) NIST's CSRC Sample #2",
|
||||
"input": "6bc1bee22e409f96e93d7e117393172a",
|
||||
"expectedOutput": "30239cf1f52e6609",
|
||||
"recipeConfig": [
|
||||
{
|
||||
"op": "From Hex",
|
||||
"args": ["None"]
|
||||
},
|
||||
{
|
||||
"op": "CMAC",
|
||||
"args": [{"option": "Hex", "string": "0123456789abcdef23456789abcdef01456789abcdef0123"}, "Triple DES"]
|
||||
},
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "CMAC-TDES (1) NIST's CSRC Sample #3",
|
||||
"input": "6bc1bee22e409f96e93d7e117393172aae2d8a57",
|
||||
"expectedOutput": "6c9f3ee4923f6be2",
|
||||
"recipeConfig": [
|
||||
{
|
||||
"op": "From Hex",
|
||||
"args": ["None"]
|
||||
},
|
||||
{
|
||||
"op": "CMAC",
|
||||
"args": [{"option": "Hex", "string": "0123456789abcdef23456789abcdef01456789abcdef0123"}, "Triple DES"]
|
||||
},
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "CMAC-TDES (1) NIST's CSRC Sample #4",
|
||||
"input": "6bc1bee22e409f96e93d7e117393172aae2d8a571e03ac9c9eb76fac45af8e51",
|
||||
"expectedOutput": "99429bd0bf7904e5",
|
||||
"recipeConfig": [
|
||||
{
|
||||
"op": "From Hex",
|
||||
"args": ["None"]
|
||||
},
|
||||
{
|
||||
"op": "CMAC",
|
||||
"args": [{"option": "Hex", "string": "0123456789abcdef23456789abcdef01456789abcdef0123"}, "Triple DES"]
|
||||
},
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "CMAC-TDES (2) NIST's CSRC Sample #1",
|
||||
"input": "",
|
||||
"expectedOutput": "79ce52a7f786a960",
|
||||
"recipeConfig": [
|
||||
{
|
||||
"op": "CMAC",
|
||||
"args": [{"option": "Hex", "string": "0123456789abcdef23456789abcdef010123456789abcdef"}, "Triple DES"]
|
||||
},
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "CMAC-TDES (2) NIST's CSRC Sample #2",
|
||||
"input": "6bc1bee22e409f96e93d7e117393172a",
|
||||
"expectedOutput": "cc18a0b79af2413b",
|
||||
"recipeConfig": [
|
||||
{
|
||||
"op": "From Hex",
|
||||
"args": ["None"]
|
||||
},
|
||||
{
|
||||
"op": "CMAC",
|
||||
"args": [{"option": "Hex", "string": "0123456789abcdef23456789abcdef010123456789abcdef"}, "Triple DES"]
|
||||
},
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "CMAC-TDES (2) NIST's CSRC Sample #3",
|
||||
"input": "6bc1bee22e409f96e93d7e117393172aae2d8a57",
|
||||
"expectedOutput": "c06d377ecd101969",
|
||||
"recipeConfig": [
|
||||
{
|
||||
"op": "From Hex",
|
||||
"args": ["None"]
|
||||
},
|
||||
{
|
||||
"op": "CMAC",
|
||||
"args": [{"option": "Hex", "string": "0123456789abcdef23456789abcdef010123456789abcdef"}, "Triple DES"]
|
||||
},
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "CMAC-TDES (2) NIST's CSRC Sample #4",
|
||||
"input": "6bc1bee22e409f96e93d7e117393172aae2d8a571e03ac9c9eb76fac45af8e51",
|
||||
"expectedOutput": "9cd33580f9b64dfb",
|
||||
"recipeConfig": [
|
||||
{
|
||||
"op": "From Hex",
|
||||
"args": ["None"]
|
||||
},
|
||||
{
|
||||
"op": "CMAC",
|
||||
"args": [{"option": "Hex", "string": "0123456789abcdef23456789abcdef010123456789abcdef"}, "Triple DES"]
|
||||
},
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "CMAC-AES: invalid key length",
|
||||
"input": "",
|
||||
"expectedOutput": "The key for AES must be either 16, 24, or 32 bytes (currently 20 bytes)",
|
||||
"recipeConfig": [
|
||||
{
|
||||
"op": "CMAC",
|
||||
"args": [{"option": "Hex", "string": "00112233445566778899aabbccddeeff01234567"}, "AES"]
|
||||
},
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "CMAC-TDES: invalid key length",
|
||||
"input": "",
|
||||
"expectedOutput": "The key for Triple DES must be 16 or 24 bytes (currently 20 bytes)",
|
||||
"recipeConfig": [
|
||||
{
|
||||
"op": "CMAC",
|
||||
"args": [{"option": "Hex", "string": "00112233445566778899aabbccddeeff01234567"}, "Triple DES"]
|
||||
},
|
||||
]
|
||||
},
|
||||
]);
|
|
@ -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
|
||||
|
|
45
tests/operations/tests/CaesarBoxCipher.mjs
Normal file
45
tests/operations/tests/CaesarBoxCipher.mjs
Normal file
|
@ -0,0 +1,45 @@
|
|||
/**
|
||||
* Caesar Box Cipher tests.
|
||||
*
|
||||
* @author n1073645 [n1073645@gmail.com]
|
||||
*
|
||||
* @copyright Crown Copyright 2020
|
||||
* @license Apache-2.0
|
||||
*/
|
||||
import TestRegister from "../../lib/TestRegister.mjs";
|
||||
|
||||
TestRegister.addTests([
|
||||
{
|
||||
name: "Caesar Box Cipher: nothing",
|
||||
input: "",
|
||||
expectedOutput: "",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "Caesar Box Cipher",
|
||||
args: ["1"],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "Caesar Box Cipher: Hello World!",
|
||||
input: "Hello World!",
|
||||
expectedOutput: "Hlodeor!lWl",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "Caesar Box Cipher",
|
||||
args: ["3"],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "Caesar Box Cipher: Hello World!",
|
||||
input: "Hlodeor!lWl",
|
||||
expectedOutput: "HelloWorld!",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "Caesar Box Cipher",
|
||||
args: ["4"],
|
||||
},
|
||||
],
|
||||
}
|
||||
]);
|
39
tests/operations/tests/CaretMdecode.mjs
Normal file
39
tests/operations/tests/CaretMdecode.mjs
Normal file
|
@ -0,0 +1,39 @@
|
|||
/**
|
||||
* Caesar Box Cipher tests.
|
||||
*
|
||||
* @author tedk [tedk@ted.do]
|
||||
*
|
||||
* @copyright Crown Copyright 2020
|
||||
* @license Apache-2.0
|
||||
*/
|
||||
import TestRegister from "../../lib/TestRegister.mjs";
|
||||
|
||||
TestRegister.addTests([
|
||||
{
|
||||
name: "Caret/M-decode: nothing",
|
||||
input: "",
|
||||
expectedOutput: "",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "Caret/M-decode",
|
||||
args: [],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
/*
|
||||
* Tests the full range.
|
||||
* Everything except "^_" (\x5e\x5f) will decode correctly.
|
||||
*/
|
||||
name: "Caret/M-decode: Full set",
|
||||
input: "^@^A^B^C^D^E^F^G^H^I^J^K^L^M^N^O^P^Q^R^S^T^U^V^W^X^Y^Z^[^\\^]^^^_ !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~^?M-^@M-^AM-^BM-^CM-^DM-^EM-^FM-^GM-^HM-^IM-^JM-^KM-^LM-^MM-^NM-^OM-^PM-^QM-^RM-^SM-^TM-^UM-^VM-^WM-^XM-^YM-^ZM-^[M-^\\M-^]M-^^M-^_M- M-!M-\"M-#M-$M-%M-&M-'M-(M-)M-*M-+M-,M--M-.M-/M-0M-1M-2M-3M-4M-5M-6M-7M-8M-9M-:M-;M-<M-=M->M-?M-@M-AM-BM-CM-DM-EM-FM-GM-HM-IM-JM-KM-LM-MM-NM-OM-PM-QM-RM-SM-TM-UM-VM-WM-XM-YM-ZM-[M-\\M-]M-^M-_M-`M-aM-bM-cM-dM-eM-fM-gM-hM-iM-jM-kM-lM-mM-nM-oM-pM-qM-rM-sM-tM-uM-vM-wM-xM-yM-zM-{M-|M-}M-~M-^?",
|
||||
expectedOutput: "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f\x20\x21\x22\x23\x24\x25\x26\x27\x28\x29\x2a\x2b\x2c\x2d\x2e\x2f\x30\x31\x32\x33\x34\x35\x36\x37\x38\x39\x3a\x3b\x3c\x3d\x3e\x3f\x40\x41\x42\x43\x44\x45\x46\x47\x48\x49\x4a\x4b\x4c\x4d\x4e\x4f\x50\x51\x52\x53\x54\x55\x56\x57\x58\x59\x5a\x5b\x5c\x5d\x1f\x60\x61\x62\x63\x64\x65\x66\x67\x68\x69\x6a\x6b\x6c\x6d\x6e\x6f\x70\x71\x72\x73\x74\x75\x76\x77\x78\x79\x7a\x7b\x7c\x7d\x7e\x7f\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9a\x9b\x9c\x9d\x9e\x9f\xa0\xa1\xa2\xa3\xa4\xa5\xa6\xa7\xa8\xa9\xaa\xab\xac\xad\xae\xaf\xb0\xb1\xb2\xb3\xb4\xb5\xb6\xb7\xb8\xb9\xba\xbb\xbc\xbd\xbe\xbf\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf\xd0\xd1\xd2\xd3\xd4\xd5\xd6\xd7\xd8\xd9\xda\xdb\xdc\xdd\x8d\x2d\x5f\xe0\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed\xee\xef\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "Caret/M-decode",
|
||||
args: [],
|
||||
},
|
||||
],
|
||||
},
|
||||
]);
|
||||
|
|
@ -6,7 +6,7 @@
|
|||
* @copyright Crown Copyright 2018
|
||||
* @license Apache-2.0
|
||||
*/
|
||||
import TestRegister from "../TestRegister";
|
||||
import TestRegister from "../../lib/TestRegister.mjs";
|
||||
|
||||
TestRegister.addTests([
|
||||
{
|
||||
|
|
22
tests/operations/tests/CetaceanCipherDecode.mjs
Normal file
22
tests/operations/tests/CetaceanCipherDecode.mjs
Normal file
|
@ -0,0 +1,22 @@
|
|||
/**
|
||||
* CetaceanCipher Encode tests
|
||||
*
|
||||
* @author dolphinOnKeys
|
||||
* @copyright Crown Copyright 2022
|
||||
* @licence Apache-2.0
|
||||
*/
|
||||
import TestRegister from "../../lib/TestRegister.mjs";
|
||||
|
||||
TestRegister.addTests([
|
||||
{
|
||||
name: "Cetacean Cipher Decode",
|
||||
input: "EEEEEEEEEeeEEEEe EEEEEEEEEeeEEEeE EEEEEEEEEeeEEEee EEeeEEEEEeeEEeee",
|
||||
expectedOutput: "a b c で",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "Cetacean Cipher Decode",
|
||||
args: []
|
||||
},
|
||||
],
|
||||
}
|
||||
]);
|
22
tests/operations/tests/CetaceanCipherEncode.mjs
Normal file
22
tests/operations/tests/CetaceanCipherEncode.mjs
Normal file
|
@ -0,0 +1,22 @@
|
|||
/**
|
||||
* CetaceanCipher Encode tests
|
||||
*
|
||||
* @author dolphinOnKeys
|
||||
* @copyright Crown Copyright 2022
|
||||
* @licence Apache-2.0
|
||||
*/
|
||||
import TestRegister from "../../lib/TestRegister.mjs";
|
||||
|
||||
TestRegister.addTests([
|
||||
{
|
||||
name: "Cetacean Cipher Encode",
|
||||
input: "a b c で",
|
||||
expectedOutput: "EEEEEEEEEeeEEEEe EEEEEEEEEeeEEEeE EEEEEEEEEeeEEEee EEeeEEEEEeeEEeee",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "Cetacean Cipher Encode",
|
||||
args: []
|
||||
},
|
||||
],
|
||||
}
|
||||
]);
|
151
tests/operations/tests/ChaCha.mjs
Normal file
151
tests/operations/tests/ChaCha.mjs
Normal file
|
@ -0,0 +1,151 @@
|
|||
/**
|
||||
* ChaCha tests.
|
||||
*
|
||||
* @author joostrijneveld [joost@joostrijneveld.nl]
|
||||
* @copyright Crown Copyright 2022
|
||||
* @license Apache-2.0
|
||||
*/
|
||||
|
||||
import TestRegister from "../../lib/TestRegister.mjs";
|
||||
|
||||
TestRegister.addTests([
|
||||
{
|
||||
name: "ChaCha: no key",
|
||||
input: "",
|
||||
expectedOutput: `Invalid key length: 0 bytes.
|
||||
|
||||
ChaCha uses a key of 16 or 32 bytes (128 or 256 bits).`,
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "ChaCha",
|
||||
"args": [
|
||||
{"option": "Hex", "string": ""},
|
||||
{"option": "Hex", "string": ""},
|
||||
0, "20", "Hex", "Hex",
|
||||
]
|
||||
}
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "ChaCha: no nonce",
|
||||
input: "",
|
||||
expectedOutput: `Invalid nonce length: 0 bytes.
|
||||
|
||||
ChaCha uses a nonce of 8 or 12 bytes (64 or 96 bits).`,
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "ChaCha",
|
||||
"args": [
|
||||
{"option": "Hex", "string": "00000000000000000000000000000000"},
|
||||
{"option": "Hex", "string": ""},
|
||||
0, "20", "Hex", "Hex",
|
||||
]
|
||||
}
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "ChaCha: RFC8439",
|
||||
input: "Ladies and Gentlemen of the class of '99: If I could offer you only one tip for the future, sunscreen would be it.",
|
||||
expectedOutput: "6e 2e 35 9a 25 68 f9 80 41 ba 07 28 dd 0d 69 81 e9 7e 7a ec 1d 43 60 c2 0a 27 af cc fd 9f ae 0b f9 1b 65 c5 52 47 33 ab 8f 59 3d ab cd 62 b3 57 16 39 d6 24 e6 51 52 ab 8f 53 0c 35 9f 08 61 d8 07 ca 0d bf 50 0d 6a 61 56 a3 8e 08 8a 22 b6 5e 52 bc 51 4d 16 cc f8 06 81 8c e9 1a b7 79 37 36 5a f9 0b bf 74 a3 5b e6 b4 0b 8e ed f2 78 5e 42 87 4d",
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "ChaCha",
|
||||
"args": [
|
||||
{"option": "Hex", "string": "00:01:02:03:04:05:06:07:08:09:0a:0b:0c:0d:0e:0f:10:11:12:13:14:15:16:17:18:19:1a:1b:1c:1d:1e:1f"},
|
||||
{"option": "Hex", "string": "00:00:00:00:00:00:00:4a:00:00:00:00"},
|
||||
1, "20", "Raw", "Hex",
|
||||
]
|
||||
}
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "ChaCha: draft-strombergson-chacha-test-vectors-01 TC7.1",
|
||||
input: "00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00",
|
||||
expectedOutput: "29 56 0d 28 0b 45 28 40 0a 8f 4b 79 53 69 fb 3a 01 10 55 99 e9 f1 ed 58 27 9c fc 9e ce 2d c5 f9 9f 1c 2e 52 c9 82 38 f5 42 a5 c0 a8 81 d8 50 b6 15 d3 ac d9 fb db 02 6e 93 68 56 5d a5 0e 0d 49 dd 5b e8 ef 74 24 8b 3e 25 1d 96 5d 8f cb 21 e7 cf e2 04 d4 00 78 06 fb ee 3c e9 4c 74 bf ba d2 c1 1c 62 1b a0 48 14 7c 5c aa 94 d1 82 cc ff 6f d5 cf 44 ad f9 6e 3d 68 28 1b b4 96 76 af 87 e7",
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "ChaCha",
|
||||
"args": [
|
||||
{"option": "Hex", "string": "00 11 22 33 44 55 66 77 88 99 aa bb cc dd ee ff"},
|
||||
{"option": "Hex", "string": "0f 1e 2d 3c 4b 5a 69 78"},
|
||||
0, "8", "Hex", "Hex",
|
||||
]
|
||||
}
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "ChaCha: draft-strombergson-chacha-test-vectors-01 TC7.2",
|
||||
input: "00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00",
|
||||
expectedOutput: "5e dd c2 d9 42 8f ce ee c5 0a 52 a9 64 ea e0 ff b0 4b 2d e0 06 a9 b0 4c ff 36 8f fa 92 11 16 b2 e8 e2 64 ba bd 2e fa 0d e4 3e f2 e3 b6 d0 65 e8 f7 c0 a1 78 37 b0 a4 0e b0 e2 c7 a3 74 2c 87 53 ed e5 f3 f6 d1 9b e5 54 67 5e 50 6a 77 5c 63 f0 94 d4 96 5c 31 93 19 dc d7 50 6f 45 7b 11 7b 84 b1 0b 24 6e 95 6c 2d a8 89 8a 65 6c ee f3 f7 b7 16 45 b1 9f 70 1d b8 44 85 ce 51 21 f0 f6 17 ef",
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "ChaCha",
|
||||
"args": [
|
||||
{"option": "Hex", "string": "00 11 22 33 44 55 66 77 88 99 aa bb cc dd ee ff"},
|
||||
{"option": "Hex", "string": "0f 1e 2d 3c 4b 5a 69 78"},
|
||||
0, "12", "Hex", "Hex",
|
||||
]
|
||||
}
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "ChaCha: draft-strombergson-chacha-test-vectors-01 TC7.3",
|
||||
input: "00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00",
|
||||
expectedOutput: "d1 ab f6 30 46 7e b4 f6 7f 1c fb 47 cd 62 6a ae 8a fe db be 4f f8 fc 5f e9 cf ae 30 7e 74 ed 45 1f 14 04 42 5a d2 b5 45 69 d5 f1 81 48 93 99 71 ab b8 fa fc 88 ce 4a c7 fe 1c 3d 1f 7a 1e b7 ca e7 6c a8 7b 61 a9 71 35 41 49 77 60 dd 9a e0 59 35 0c ad 0d ce df aa 80 a8 83 11 9a 1a 6f 98 7f d1 ce 91 fd 8e e0 82 80 34 b4 11 20 0a 97 45 a2 85 55 44 75 d1 2a fc 04 88 7f ef 35 16 d1 2a 2c",
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "ChaCha",
|
||||
"args": [
|
||||
{"option": "Hex", "string": "00 11 22 33 44 55 66 77 88 99 aa bb cc dd ee ff"},
|
||||
{"option": "Hex", "string": "0f 1e 2d 3c 4b 5a 69 78"},
|
||||
0, "20", "Hex", "Hex",
|
||||
]
|
||||
}
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "ChaCha: draft-strombergson-chacha-test-vectors-01 TC7.4",
|
||||
input: "00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00",
|
||||
expectedOutput: "db 43 ad 9d 1e 84 2d 12 72 e4 53 0e 27 6b 3f 56 8f 88 59 b3 f7 cf 6d 9d 2c 74 fa 53 80 8c b5 15 7a 8e bf 46 ad 3d cc 4b 6c 7d ad de 13 17 84 b0 12 0e 0e 22 f6 d5 f9 ff a7 40 7d 4a 21 b6 95 d9 c5 dd 30 bf 55 61 2f ab 9b dd 11 89 20 c1 98 16 47 0c 7f 5d cd 42 32 5d bb ed 8c 57 a5 62 81 c1 44 cb 0f 03 e8 1b 30 04 62 4e 06 50 a1 ce 5a fa f9 a7 cd 81 63 f6 db d7 26 02 25 7d d9 6e 47 1e",
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "ChaCha",
|
||||
"args": [
|
||||
{"option": "Hex", "string": "00 11 22 33 44 55 66 77 88 99 aa bb cc dd ee ff ff ee dd cc bb aa 99 88 77 66 55 44 33 22 11 00"},
|
||||
{"option": "Hex", "string": "0f 1e 2d 3c 4b 5a 69 78"},
|
||||
0, "8", "Hex", "Hex",
|
||||
]
|
||||
}
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "ChaCha: draft-strombergson-chacha-test-vectors-01 TC7.5",
|
||||
input: "00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00",
|
||||
expectedOutput: "7e d1 2a 3a 63 91 2a e9 41 ba 6d 4c 0d 5e 86 2e 56 8b 0e 55 89 34 69 35 50 5f 06 4b 8c 26 98 db f7 d8 50 66 7d 8e 67 be 63 9f 3b 4f 6a 16 f9 2e 65 ea 80 f6 c7 42 94 45 da 1f c2 c1 b9 36 50 40 e3 2e 50 c4 10 6f 3b 3d a1 ce 7c cb 1e 71 40 b1 53 49 3c 0f 3a d9 a9 bc ff 07 7e c4 59 6f 1d 0f 29 bf 9c ba a5 02 82 0f 73 2a f5 a9 3c 49 ee e3 3d 1c 4f 12 af 3b 42 97 af 91 fe 41 ea 9e 94 a2",
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "ChaCha",
|
||||
"args": [
|
||||
{"option": "Hex", "string": "00 11 22 33 44 55 66 77 88 99 aa bb cc dd ee ff ff ee dd cc bb aa 99 88 77 66 55 44 33 22 11 00"},
|
||||
{"option": "Hex", "string": "0f 1e 2d 3c 4b 5a 69 78"},
|
||||
0, "12", "Hex", "Hex",
|
||||
]
|
||||
}
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "ChaCha: draft-strombergson-chacha-test-vectors-01 TC7.6",
|
||||
input: "00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00",
|
||||
expectedOutput: "9f ad f4 09 c0 08 11 d0 04 31 d6 7e fb d8 8f ba 59 21 8d 5d 67 08 b1 d6 85 86 3f ab bb 0e 96 1e ea 48 0f d6 fb 53 2b fd 49 4b 21 51 01 50 57 42 3a b6 0a 63 fe 4f 55 f7 a2 12 e2 16 7c ca b9 31 fb fd 29 cf 7b c1 d2 79 ed df 25 dd 31 6b b8 84 3d 6e de e0 bd 1e f1 21 d1 2f a1 7c bc 2c 57 4c cc ab 5e 27 51 67 b0 8b d6 86 f8 a0 9d f8 7e c3 ff b3 53 61 b9 4e bf a1 3f ec 0e 48 89 d1 8d a5",
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "ChaCha",
|
||||
"args": [
|
||||
{"option": "Hex", "string": "00 11 22 33 44 55 66 77 88 99 aa bb cc dd ee ff ff ee dd cc bb aa 99 88 77 66 55 44 33 22 11 00"},
|
||||
{"option": "Hex", "string": "0f 1e 2d 3c 4b 5a 69 78"},
|
||||
0, "20", "Hex", "Hex",
|
||||
]
|
||||
}
|
||||
],
|
||||
},
|
||||
]);
|
52
tests/operations/tests/ChangeIPFormat.mjs
Normal file
52
tests/operations/tests/ChangeIPFormat.mjs
Normal file
|
@ -0,0 +1,52 @@
|
|||
/**
|
||||
* Change IP format tests.
|
||||
*
|
||||
* @author Chris Smith
|
||||
* @copyright Crown Copyright 2019
|
||||
* @license Apache-2.0
|
||||
*/
|
||||
import TestRegister from "../../lib/TestRegister.mjs";
|
||||
|
||||
TestRegister.addTests([
|
||||
{
|
||||
name: "Change IP format: Dotted Decimal to Hex",
|
||||
input: "192.168.1.1",
|
||||
expectedOutput: "c0a80101",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "Change IP format",
|
||||
args: ["Dotted Decimal", "Hex"],
|
||||
},
|
||||
],
|
||||
}, {
|
||||
name: "Change IP format: Decimal to Dotted Decimal",
|
||||
input: "3232235777",
|
||||
expectedOutput: "192.168.1.1",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "Change IP format",
|
||||
args: ["Decimal", "Dotted Decimal"],
|
||||
},
|
||||
],
|
||||
}, {
|
||||
name: "Change IP format: Hex to Octal",
|
||||
input: "c0a80101",
|
||||
expectedOutput: "030052000401",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "Change IP format",
|
||||
args: ["Hex", "Octal"],
|
||||
},
|
||||
],
|
||||
}, {
|
||||
name: "Change IP format: Octal to Decimal",
|
||||
input: "030052000401",
|
||||
expectedOutput: "3232235777",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "Change IP format",
|
||||
args: ["Octal", "Decimal"],
|
||||
},
|
||||
],
|
||||
},
|
||||
]);
|
|
@ -5,7 +5,7 @@
|
|||
* @copyright Crown Copyright 2017
|
||||
* @license Apache-2.0
|
||||
*/
|
||||
import TestRegister from "../TestRegister";
|
||||
import TestRegister from "../../lib/TestRegister.mjs";
|
||||
|
||||
TestRegister.addTests([
|
||||
{
|
||||
|
@ -69,7 +69,7 @@ TestRegister.addTests([
|
|||
],
|
||||
},
|
||||
{
|
||||
name: "Generate Base64 Windows Powershell",
|
||||
name: "Generate Base64 Windows PowerShell",
|
||||
input: "ZABpAHIAIAAiAGMAOgBcAHAAcgBvAGcAcgBhAG0AIABmAGkAbABlAHMAIgAgAA==",
|
||||
expectedOutput: "dir \"c:\\program files\" ",
|
||||
recipeConfig: [
|
||||
|
@ -79,7 +79,7 @@ TestRegister.addTests([
|
|||
},
|
||||
{
|
||||
"op": "Decode text",
|
||||
"args": ["UTF16LE (1200)"]
|
||||
"args": ["UTF-16LE (1200)"]
|
||||
},
|
||||
{
|
||||
"op": "Encode text",
|
||||
|
|
55
tests/operations/tests/Charts.mjs
Normal file
55
tests/operations/tests/Charts.mjs
Normal file
|
@ -0,0 +1,55 @@
|
|||
/**
|
||||
* Chart tests.
|
||||
*
|
||||
* @author Matt C [me@mitt.dev]
|
||||
* @copyright Crown Copyright 2019
|
||||
* @license Apache-2.0
|
||||
*/
|
||||
import TestRegister from "../../lib/TestRegister.mjs";
|
||||
|
||||
TestRegister.addTests([
|
||||
{
|
||||
name: "Scatter chart",
|
||||
input: "100 100\n200 200\n300 300\n400 400\n500 500",
|
||||
expectedMatch: /^<svg width/,
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "Scatter chart",
|
||||
"args": ["Line feed", "Space", false, "time", "stress", "black", 5, false]
|
||||
}
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "Hex density chart",
|
||||
input: "100 100\n200 200\n300 300\n400 400\n500 500",
|
||||
expectedMatch: /^<svg width/,
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "Hex Density chart",
|
||||
"args": ["Line feed", "Space", 25, 15, true, "", "", true, "white", "black", true]
|
||||
}
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "Series chart",
|
||||
input: "100 100 100\n200 200 200\n300 300 300\n400 400 400\n500 500 500",
|
||||
expectedMatch: /^<svg width/,
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "Series chart",
|
||||
"args": ["Line feed", "Space", "", 1, "mediumseagreen, dodgerblue, tomato"]
|
||||
}
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "Heatmap chart",
|
||||
input: "100 100\n200 200\n300 300\n400 400\n500 500",
|
||||
expectedMatch: /^<svg width/,
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "Heatmap chart",
|
||||
"args": ["Line feed", "Space", 25, 25, true, "", "", false, "white", "black"]
|
||||
}
|
||||
],
|
||||
},
|
||||
]);
|
|
@ -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": []
|
||||
}
|
||||
]
|
||||
},
|
||||
}
|
||||
]);
|
||||
|
|
45
tests/operations/tests/CipherSaber2.mjs
Normal file
45
tests/operations/tests/CipherSaber2.mjs
Normal file
|
@ -0,0 +1,45 @@
|
|||
/**
|
||||
* Ciphersaber2 tests.
|
||||
*
|
||||
* @author n1073645 [n1073645@gmail.com]
|
||||
*
|
||||
* @copyright Crown Copyright 2020
|
||||
* @license Apache-2.0
|
||||
*/
|
||||
import TestRegister from "../../lib/TestRegister.mjs";
|
||||
|
||||
TestRegister.addTests([
|
||||
{
|
||||
name: "CipherSaber2 Encrypt",
|
||||
input: "Hello World",
|
||||
expectedMatch: /.{21}/s,
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "CipherSaber2 Encrypt",
|
||||
args: [{ "option": "Latin1", "string": "test" }, 20],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "CipherSaber2 Decrypt",
|
||||
input: "\x5d\xd9\x7f\xeb\x77\x3c\x42\x9d\xfe\x9c\x3b\x21\x63\xbd\x53\x38\x18\x7c\x36\x37",
|
||||
expectedOutput: "helloworld",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "CipherSaber2 Decrypt",
|
||||
args: [{ "option": "Latin1", "string": "test" }, 20],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "CipherSaber2 Encrypt",
|
||||
input: "",
|
||||
expectedMatch: /.{10}/s,
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "CipherSaber2 Encrypt",
|
||||
args: [{ "option": "Latin1", "string": "" }, 20],
|
||||
},
|
||||
],
|
||||
},
|
||||
]);
|
|
@ -7,7 +7,7 @@
|
|||
* @copyright Crown Copyright 2018
|
||||
* @license Apache-2.0
|
||||
*/
|
||||
import TestRegister from "../TestRegister";
|
||||
import TestRegister from "../../lib/TestRegister.mjs";
|
||||
|
||||
|
||||
TestRegister.addTests([
|
||||
|
@ -418,4 +418,114 @@ TestRegister.addTests([
|
|||
}
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "Rail Fence Cipher Decode: normal",
|
||||
input: "Cytgah sTEAto rtn rsligcdsrporpyi H r fWiigo ovn oe",
|
||||
expectedOutput: "Cryptography is THE Art of Writing or solving codes",
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "Rail Fence Cipher Decode",
|
||||
"args": [2, 0]
|
||||
}
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "Rail Fence Cipher Decode: key has to be bigger than 2",
|
||||
input: "Cytgah sTEAto rtn rsligcdsrporpyi H r fWiigo ovn oe",
|
||||
expectedOutput: "Key has to be bigger than 2",
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "Rail Fence Cipher Decode",
|
||||
"args": [1, 0]
|
||||
}
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "Rail Fence Cipher Decode: key has to be smaller than input's length",
|
||||
input: "shortinput",
|
||||
expectedOutput: "Key should be smaller than the cipher's length",
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "Rail Fence Cipher Decode",
|
||||
"args": [22, 0]
|
||||
}
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "Rail Fence Cipher Decode: offset should be positive",
|
||||
input: "shortinput",
|
||||
expectedOutput: "Offset has to be a positive integer",
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "Rail Fence Cipher Decode",
|
||||
"args": [2, -1]
|
||||
}
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "Rail Fence Cipher Decode: Normal with Offset non-null",
|
||||
input: "51746026813793592840",
|
||||
expectedOutput: "12345678901234567890",
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "Rail Fence Cipher Decode",
|
||||
"args": [4, 2]
|
||||
}
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "Rail Fence Cipher Encode: normal",
|
||||
input: "Cryptography is THE Art of Writing or solving codes",
|
||||
expectedOutput: "Cytgah sTEAto rtn rsligcdsrporpyi H r fWiigo ovn oe",
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "Rail Fence Cipher Encode",
|
||||
"args": [2, 0]
|
||||
}
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "Rail Fence Cipher Encode: key has to be bigger than 2",
|
||||
input: "Cryptography is THE Art of Writing or solving codes",
|
||||
expectedOutput: "Key has to be bigger than 2",
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "Rail Fence Cipher Encode",
|
||||
"args": [1, 0]
|
||||
}
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "Rail Fence Cipher Encode: key has to be smaller than input's length",
|
||||
input: "shortinput",
|
||||
expectedOutput: "Key should be smaller than the plain text's length",
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "Rail Fence Cipher Encode",
|
||||
"args": [22, 0]
|
||||
}
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "Rail Fence Cipher Encode: offset should be positive",
|
||||
input: "shortinput",
|
||||
expectedOutput: "Offset has to be a positive integer",
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "Rail Fence Cipher Encode",
|
||||
"args": [2, -1]
|
||||
}
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "Rail Fence Cipher Encode: Normal with Offset non-null",
|
||||
input: "12345678901234567890",
|
||||
expectedOutput: "51746026813793592840",
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "Rail Fence Cipher Encode",
|
||||
"args": [4, 2]
|
||||
}
|
||||
],
|
||||
},
|
||||
]);
|
||||
|
|
|
@ -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": {
|
||||
|
@ -185,11 +185,11 @@ TestRegister.addTests([
|
|||
{
|
||||
name: "JPath Expression: Empty expression",
|
||||
input: JSON.stringify(JSON_TEST_DATA),
|
||||
expectedOutput: "Invalid JPath expression: we need a path",
|
||||
expectedOutput: "",
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "JPath expression",
|
||||
"args": ["", "\n"]
|
||||
"args": ["", "\n", true]
|
||||
}
|
||||
],
|
||||
},
|
||||
|
@ -205,7 +205,7 @@ TestRegister.addTests([
|
|||
recipeConfig: [
|
||||
{
|
||||
"op": "JPath expression",
|
||||
"args": ["$.store.book[*].author", "\n"]
|
||||
"args": ["$.store.book[*].author", "\n", true]
|
||||
}
|
||||
],
|
||||
},
|
||||
|
@ -223,7 +223,7 @@ TestRegister.addTests([
|
|||
recipeConfig: [
|
||||
{
|
||||
"op": "JPath expression",
|
||||
"args": ["$..title", "\n"]
|
||||
"args": ["$..title", "\n", true]
|
||||
}
|
||||
],
|
||||
},
|
||||
|
@ -238,7 +238,7 @@ TestRegister.addTests([
|
|||
recipeConfig: [
|
||||
{
|
||||
"op": "JPath expression",
|
||||
"args": ["$.store.*", "\n"]
|
||||
"args": ["$.store.*", "\n", true]
|
||||
}
|
||||
],
|
||||
},
|
||||
|
@ -249,7 +249,7 @@ TestRegister.addTests([
|
|||
recipeConfig: [
|
||||
{
|
||||
"op": "JPath expression",
|
||||
"args": ["$..book[-1:]", "\n"]
|
||||
"args": ["$..book[-1:]", "\n", true]
|
||||
}
|
||||
],
|
||||
},
|
||||
|
@ -263,7 +263,7 @@ TestRegister.addTests([
|
|||
recipeConfig: [
|
||||
{
|
||||
"op": "JPath expression",
|
||||
"args": ["$..book[:2]", "\n"]
|
||||
"args": ["$..book[:2]", "\n", true]
|
||||
}
|
||||
],
|
||||
},
|
||||
|
@ -277,7 +277,7 @@ TestRegister.addTests([
|
|||
recipeConfig: [
|
||||
{
|
||||
"op": "JPath expression",
|
||||
"args": ["$..book[?(@.isbn)]", "\n"]
|
||||
"args": ["$..book[?(@.isbn)]", "\n", false]
|
||||
}
|
||||
],
|
||||
},
|
||||
|
@ -292,7 +292,7 @@ TestRegister.addTests([
|
|||
recipeConfig: [
|
||||
{
|
||||
"op": "JPath expression",
|
||||
"args": ["$..book[?(@.price<30 && @.category==\"fiction\")]", "\n"]
|
||||
"args": ["$..book[?(@.price<30 && @.category==\"fiction\")]", "\n", false]
|
||||
}
|
||||
],
|
||||
},
|
||||
|
@ -306,10 +306,25 @@ TestRegister.addTests([
|
|||
recipeConfig: [
|
||||
{
|
||||
"op": "JPath expression",
|
||||
"args": ["$..book[?(@.price<10)]", "\n"]
|
||||
"args": ["$..book[?(@.price<10)]", "\n", false]
|
||||
}
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "JPath Expression: Script-based expression",
|
||||
input: "[{}]",
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "JPath expression",
|
||||
"args": [
|
||||
"$..[?(({__proto__:[].constructor}).constructor(\"self.postMessage({action:'bakeComplete',data:{bakeId:1,dish:{type:1,value:''},duration:1,error:false,id:undefined,inputNum:2,progress:1,result:'<iframe/onload=debugger>',type: 'html'}});\")();)]",
|
||||
"\n",
|
||||
true
|
||||
]
|
||||
}
|
||||
],
|
||||
expectedOutput: "Invalid JPath expression: Eval [?(expr)] prevented in JSONPath expression."
|
||||
},
|
||||
{
|
||||
name: "CSS selector",
|
||||
input: '<div id="test">\n<p class="a">hello</p>\n<p>world</p>\n<p class="a">again</p>\n</div>',
|
||||
|
|
92
tests/operations/tests/Colossus.mjs
Normal file
92
tests/operations/tests/Colossus.mjs
Normal file
File diff suppressed because one or more lines are too long
|
@ -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",
|
||||
|
@ -42,7 +42,7 @@ TestRegister.addTests([
|
|||
{
|
||||
name: "Fork, Comment, Base64",
|
||||
input: "cat\nsat\nmat",
|
||||
expectedOutput: "Y2F0\nc2F0\nbWF0\n",
|
||||
expectedOutput: "Y2F0\nc2F0\nbWF0",
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "Fork",
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
* @copyright Crown Copyright 2017
|
||||
* @license Apache-2.0
|
||||
*/
|
||||
import TestRegister from "../TestRegister";
|
||||
import TestRegister from "../../lib/TestRegister.mjs";
|
||||
|
||||
TestRegister.addTests([
|
||||
{
|
||||
|
@ -23,4 +23,86 @@ TestRegister.addTests([
|
|||
}
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "LZMA compress & decompress",
|
||||
input: "The cat sat on the mat.",
|
||||
// Generated using command `echo -n "The cat sat on the mat." | lzma -z -6 | xxd -p`
|
||||
expectedOutput: "The cat sat on the mat.",
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "LZMA Compress",
|
||||
"args": ["6"]
|
||||
},
|
||||
{
|
||||
"op": "LZMA Decompress",
|
||||
"args": []
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "LZMA decompress: binary",
|
||||
// Generated using command `echo "00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f 10" | xxd -r -p | lzma -z -6 | xxd -p`
|
||||
input: "5d00008000ffffffffffffffff00000052500a84f99bb28021a969d627e03e8a922effffbd160000",
|
||||
expectedOutput: "00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f 10",
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "From Hex",
|
||||
"args": ["Space"]
|
||||
},
|
||||
{
|
||||
"op": "LZMA Decompress",
|
||||
"args": []
|
||||
},
|
||||
{
|
||||
"op": "To Hex",
|
||||
"args": ["Space", 0]
|
||||
}
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "LZMA decompress: string",
|
||||
// Generated using command `echo -n "The cat sat on the mat." | lzma -z -6 | xxd -p`
|
||||
input: "5d00008000ffffffffffffffff002a1a08a202b1a4b814b912c94c4152e1641907d3fd8cd903ffff4fec0000",
|
||||
expectedOutput: "The cat sat on the mat.",
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "From Hex",
|
||||
"args": ["Space"]
|
||||
},
|
||||
{
|
||||
"op": "LZMA Decompress",
|
||||
"args": []
|
||||
}
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "LZ4 Compress",
|
||||
input: "The cat sat on the mat.",
|
||||
expectedOutput: "04224d184070df170000805468652063617420736174206f6e20746865206d61742e00000000",
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "LZ4 Compress",
|
||||
"args": []
|
||||
},
|
||||
{
|
||||
"op": "To Hex",
|
||||
"args": ["None", 0]
|
||||
}
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "LZ4 Decompress",
|
||||
input: "04224d184070df170000805468652063617420736174206f6e20746865206d61742e00000000",
|
||||
expectedOutput: "The cat sat on the mat.",
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "From Hex",
|
||||
"args": ["None"]
|
||||
},
|
||||
{
|
||||
"op": "LZ4 Decompress",
|
||||
"args": []
|
||||
}
|
||||
],
|
||||
},
|
||||
]);
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
* @copyright Crown Copyright 2018
|
||||
* @license Apache-2.0
|
||||
*/
|
||||
import TestRegister from "../TestRegister";
|
||||
import TestRegister from "../../lib/TestRegister.mjs";
|
||||
|
||||
TestRegister.addTests([
|
||||
{
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
* UTM: 30N 699456 5709791,
|
||||
*/
|
||||
|
||||
import TestRegister from "../TestRegister";
|
||||
import TestRegister from "../../lib/TestRegister.mjs";
|
||||
|
||||
TestRegister.addTests([
|
||||
{
|
||||
|
|
32
tests/operations/tests/ConvertToNATOAlphabet.mjs
Normal file
32
tests/operations/tests/ConvertToNATOAlphabet.mjs
Normal file
|
@ -0,0 +1,32 @@
|
|||
/**
|
||||
* @author MarvinJWendt [git@marvinjwendt.com]
|
||||
* @copyright Crown Copyright 2019
|
||||
* @license Apache-2.0
|
||||
*/
|
||||
|
||||
import TestRegister from "../../lib/TestRegister.mjs";
|
||||
|
||||
TestRegister.addTests([
|
||||
{
|
||||
name: "Convert to NATO alphabet: nothing",
|
||||
input: "",
|
||||
expectedOutput: "",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "Convert to NATO alphabet",
|
||||
args: []
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "Convert to NATO alphabet: full alphabet with numbers",
|
||||
input: "abcdefghijklmnopqrstuvwxyz0123456789,/.",
|
||||
expectedOutput: "Alfa Bravo Charlie Delta Echo Foxtrot Golf Hotel India Juliett Kilo Lima Mike November Oscar Papa Quebec Romeo Sierra Tango Uniform Victor Whiskey X-ray Yankee Zulu Zero One Two Three Four Five Six Seven Eight Nine Comma Fraction bar Full stop ",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "Convert to NATO alphabet",
|
||||
args: []
|
||||
}
|
||||
]
|
||||
}
|
||||
]);
|
File diff suppressed because it is too large
Load diff
|
@ -6,7 +6,7 @@
|
|||
* @copyright Crown Copyright 2017
|
||||
* @license Apache-2.0
|
||||
*/
|
||||
import TestRegister from "../TestRegister";
|
||||
import TestRegister from "../../lib/TestRegister.mjs";
|
||||
|
||||
TestRegister.addTests([
|
||||
{
|
||||
|
|
43
tests/operations/tests/DefangIP.mjs
Normal file
43
tests/operations/tests/DefangIP.mjs
Normal file
|
@ -0,0 +1,43 @@
|
|||
/**
|
||||
* DefangIP tests.
|
||||
*
|
||||
* @author h345983745
|
||||
*
|
||||
* @copyright Crown Copyright 2019
|
||||
* @license Apache-2.0
|
||||
*/
|
||||
import TestRegister from "../../lib/TestRegister.mjs";
|
||||
|
||||
TestRegister.addTests([
|
||||
{
|
||||
name: "Defang IP: Valid IPV4",
|
||||
input: "192.168.1.1",
|
||||
expectedOutput: "192[.]168[.]1[.]1",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "Defang IP Addresses",
|
||||
args: [],
|
||||
},
|
||||
],
|
||||
}, {
|
||||
name: "Defang IP: Valid IPV6",
|
||||
input: "2001:0db8:85a3:0000:0000:8a2e:0370:7343",
|
||||
expectedOutput: "2001[:]0db8[:]85a3[:]0000[:]0000[:]8a2e[:]0370[:]7343",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "Defang IP Addresses",
|
||||
args: [],
|
||||
},
|
||||
],
|
||||
}, {
|
||||
name: "Defang IP: Valid IPV6 Shorthand",
|
||||
input: "2001:db8:3c4d:15::1a2f:1a2b",
|
||||
expectedOutput: "2001[:]db8[:]3c4d[:]15[:][:]1a2f[:]1a2b",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "Defang IP Addresses",
|
||||
args: [],
|
||||
},
|
||||
],
|
||||
},
|
||||
]);
|
86
tests/operations/tests/ELFInfo.mjs
Normal file
86
tests/operations/tests/ELFInfo.mjs
Normal file
|
@ -0,0 +1,86 @@
|
|||
/**
|
||||
* @author n1073645 [n1073645@gmail.com]
|
||||
* @copyright Crown Copyright 2022
|
||||
* @license Apache-2.0
|
||||
*/
|
||||
import TestRegister from "../../lib/TestRegister.mjs";
|
||||
import {ELF32_LE, ELF32_BE, ELF64_LE, ELF64_BE} from "../../samples/Executables.mjs";
|
||||
|
||||
const ELF32_LE_OUTPUT = "============================== ELF Header ==============================\nMagic: \x7fELF\nFormat: 32-bit\nEndianness: Little\nVersion: 1\nABI: System V\nABI Version: 0\nType: Executable File\nInstruction Set Architecture: x86\nELF Version: 1\nEntry Point: 0x8062150\nEntry PHOFF: 0x34\nEntry SHOFF: 0x54\nFlags: 00000000\nELF Header Size: 52 bytes\nProgram Header Size: 32 bytes\nProgram Header Entries: 1\nSection Header Size: 40 bytes\nSection Header Entries: 3\nSection Header Names: 0\n\n============================== Program Header ==============================\nProgram Header Type: Program Header Table\nOffset Of Segment: 52\nVirtual Address of Segment: 134512692\nPhysical Address of Segment: 134512692\nSize of Segment: 256 bytes\nSize of Segment in Memory: 256 bytes\nFlags: Execute,Read\n\n============================== Section Header ==============================\nType: String Table\nSection Name: .shstrab\nFlags: \nSection Vaddr in memory: 0\nOffset of the section: 204\nSection Size: 28\nAssociated Section: 0\nSection Extra Information: 0\n\nType: Symbol Table\nSection Name: .symtab\nFlags: \nSection Vaddr in memory: 0\nOffset of the section: 230\nSection Size: 16\nAssociated Section: 0\nSection Extra Information: 0\n\nType: String Table\nSection Name: .strtab\nFlags: \nSection Vaddr in memory: 0\nOffset of the section: 245\nSection Size: 4\nAssociated Section: 0\nSection Extra Information: 0\n\n============================== Symbol Table ==============================\nSymbol Name: test";
|
||||
const ELF32_BE_OUTPUT = "============================== ELF Header ==============================\nMagic: \x7fELF\nFormat: 32-bit\nEndianness: Big\nVersion: 1\nABI: System V\nABI Version: 0\nType: Executable File\nInstruction Set Architecture: x86\nELF Version: 1\nEntry Point: 0x8062150\nEntry PHOFF: 0x34\nEntry SHOFF: 0x54\nFlags: 00000000\nELF Header Size: 52 bytes\nProgram Header Size: 32 bytes\nProgram Header Entries: 1\nSection Header Size: 40 bytes\nSection Header Entries: 3\nSection Header Names: 0\n\n============================== Program Header ==============================\nProgram Header Type: Program Header Table\nOffset Of Segment: 52\nVirtual Address of Segment: 134512692\nPhysical Address of Segment: 134512692\nSize of Segment: 256 bytes\nSize of Segment in Memory: 256 bytes\nFlags: Execute,Read\n\n============================== Section Header ==============================\nType: String Table\nSection Name: .shstrab\nFlags: \nSection Vaddr in memory: 0\nOffset of the section: 204\nSection Size: 28\nAssociated Section: 0\nSection Extra Information: 0\n\nType: Symbol Table\nSection Name: .symtab\nFlags: \nSection Vaddr in memory: 0\nOffset of the section: 230\nSection Size: 16\nAssociated Section: 0\nSection Extra Information: 0\n\nType: String Table\nSection Name: .strtab\nFlags: \nSection Vaddr in memory: 0\nOffset of the section: 245\nSection Size: 4\nAssociated Section: 0\nSection Extra Information: 0\n\n============================== Symbol Table ==============================\nSymbol Name: test";
|
||||
const ELF64_LE_OUTPUT = "============================== ELF Header ==============================\nMagic: \x7fELF\nFormat: 64-bit\nEndianness: Little\nVersion: 1\nABI: System V\nABI Version: 0\nType: Executable File\nInstruction Set Architecture: AMD x86-64\nELF Version: 1\nEntry Point: 0x8062150\nEntry PHOFF: 0x40\nEntry SHOFF: 0x78\nFlags: 00000000\nELF Header Size: 64 bytes\nProgram Header Size: 56 bytes\nProgram Header Entries: 1\nSection Header Size: 64 bytes\nSection Header Entries: 3\nSection Header Names: 0\n\n============================== Program Header ==============================\nProgram Header Type: Program Header Table\nFlags: Execute,Read\nOffset Of Segment: 52\nVirtual Address of Segment: 134512692\nPhysical Address of Segment: 134512692\nSize of Segment: 256 bytes\nSize of Segment in Memory: 256 bytes\n\n============================== Section Header ==============================\nType: String Table\nSection Name: .shstrab\nFlags: \nSection Vaddr in memory: 0\nOffset of the section: 312\nSection Size: 28\nAssociated Section: 0\nSection Extra Information: 0\n\nType: Symbol Table\nSection Name: .symtab\nFlags: \nSection Vaddr in memory: 0\nOffset of the section: 336\nSection Size: 16\nAssociated Section: 0\nSection Extra Information: 0\n\nType: String Table\nSection Name: .strtab\nFlags: \nSection Vaddr in memory: 0\nOffset of the section: 361\nSection Size: 4\nAssociated Section: 0\nSection Extra Information: 0\n\n============================== Symbol Table ==============================\nSymbol Name: test";
|
||||
const ELF64_BE_OUTPUT = "============================== ELF Header ==============================\nMagic: \x7fELF\nFormat: 64-bit\nEndianness: Big\nVersion: 1\nABI: System V\nABI Version: 0\nType: Executable File\nInstruction Set Architecture: AMD x86-64\nELF Version: 1\nEntry Point: 0x8062150\nEntry PHOFF: 0x40\nEntry SHOFF: 0x78\nFlags: 00000000\nELF Header Size: 64 bytes\nProgram Header Size: 56 bytes\nProgram Header Entries: 1\nSection Header Size: 64 bytes\nSection Header Entries: 3\nSection Header Names: 0\n\n============================== Program Header ==============================\nProgram Header Type: Program Header Table\nFlags: Execute,Read\nOffset Of Segment: 52\nVirtual Address of Segment: 134512692\nPhysical Address of Segment: 134512692\nSize of Segment: 256 bytes\nSize of Segment in Memory: 256 bytes\n\n============================== Section Header ==============================\nType: String Table\nSection Name: .shstrab\nFlags: \nSection Vaddr in memory: 0\nOffset of the section: 312\nSection Size: 28\nAssociated Section: 0\nSection Extra Information: 0\n\nType: Symbol Table\nSection Name: .symtab\nFlags: \nSection Vaddr in memory: 0\nOffset of the section: 336\nSection Size: 16\nAssociated Section: 0\nSection Extra Information: 0\n\nType: String Table\nSection Name: .strtab\nFlags: \nSection Vaddr in memory: 0\nOffset of the section: 361\nSection Size: 4\nAssociated Section: 0\nSection Extra Information: 0\n\n============================== Symbol Table ==============================\nSymbol Name: test";
|
||||
|
||||
TestRegister.addTests([
|
||||
{
|
||||
name: "ELF Info invalid ELF.",
|
||||
input: "\x7f\x00\x00\x00",
|
||||
expectedOutput: "Invalid ELF",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "ELF Info",
|
||||
args: [],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "ELF Info 32-bit ELF Little Endian.",
|
||||
input: ELF32_LE,
|
||||
expectedOutput: ELF32_LE_OUTPUT,
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "From Hex",
|
||||
args: ["None"],
|
||||
},
|
||||
{
|
||||
op: "ELF Info",
|
||||
args: [],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "ELF Info 32-bit ELF Big Endian.",
|
||||
input: ELF32_BE,
|
||||
expectedOutput: ELF32_BE_OUTPUT,
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "From Hex",
|
||||
args: ["None"],
|
||||
},
|
||||
{
|
||||
op: "ELF Info",
|
||||
args: [],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "ELF Info 64-bit ELF Little Endian.",
|
||||
input: ELF64_LE,
|
||||
expectedOutput: ELF64_LE_OUTPUT,
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "From Hex",
|
||||
args: ["None"],
|
||||
},
|
||||
{
|
||||
op: "ELF Info",
|
||||
args: [],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "ELF Info 64-bit ELF Big Endian.",
|
||||
input: ELF64_BE,
|
||||
expectedOutput: ELF64_BE_OUTPUT,
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "From Hex",
|
||||
args: ["None"],
|
||||
},
|
||||
{
|
||||
op: "ELF Info",
|
||||
args: [],
|
||||
},
|
||||
],
|
||||
},
|
||||
]);
|
565
tests/operations/tests/Enigma.mjs
Normal file
565
tests/operations/tests/Enigma.mjs
Normal file
|
@ -0,0 +1,565 @@
|
|||
/**
|
||||
* Enigma machine tests.
|
||||
* @author s2224834
|
||||
* @copyright Crown Copyright 2019
|
||||
* @license Apache-2.0
|
||||
*/
|
||||
import TestRegister from "../../lib/TestRegister.mjs";
|
||||
|
||||
TestRegister.addTests([
|
||||
{
|
||||
// Simplest test: A single keypress in the default position on a basic
|
||||
// Enigma.
|
||||
name: "Enigma: basic wiring",
|
||||
input: "G",
|
||||
expectedOutput: "P",
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "Enigma",
|
||||
"args": [
|
||||
"3-rotor",
|
||||
"", "A", "A",
|
||||
// Note: start on Z because it steps when the key is pressed
|
||||
"EKMFLGDQVZNTOWYHXUSPAIBRCJ<R", "A", "A", // I
|
||||
"AJDKSIRUXBLHWTMCQGZNPYFVOE<F", "A", "A", // II
|
||||
"BDFHJLCPRTXVZNYEIWGAKMUSQO<W", "A", "Z", // III
|
||||
"AY BR CU DH EQ FS GL IP JX KN MO TZ VW", // B
|
||||
""
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
// Rotor position test: single keypress, basic rotors, random start
|
||||
// positions, no advancement of other rotors.
|
||||
name: "Enigma: rotor position",
|
||||
input: "A",
|
||||
expectedOutput: "T",
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "Enigma",
|
||||
"args": [
|
||||
"3-rotor",
|
||||
"", "A", "A",
|
||||
"EKMFLGDQVZNTOWYHXUSPAIBRCJ<R", "A", "N",
|
||||
"AJDKSIRUXBLHWTMCQGZNPYFVOE<F", "A", "F",
|
||||
"BDFHJLCPRTXVZNYEIWGAKMUSQO<W", "A", "W",
|
||||
"AY BR CU DH EQ FS GL IP JX KN MO TZ VW",
|
||||
""
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
// Rotor ring setting test: single keypress, basic rotors, one rotor
|
||||
// ring offset by one, basic start position, no advancement of other
|
||||
// rotors.
|
||||
name: "Enigma: rotor ring setting",
|
||||
input: "A",
|
||||
expectedOutput: "O",
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "Enigma",
|
||||
"args": [
|
||||
"3-rotor",
|
||||
"", "A", "A",
|
||||
"EKMFLGDQVZNTOWYHXUSPAIBRCJ<R", "A", "A",
|
||||
"AJDKSIRUXBLHWTMCQGZNPYFVOE<F", "A", "A",
|
||||
"BDFHJLCPRTXVZNYEIWGAKMUSQO<W", "B", "Z",
|
||||
"AY BR CU DH EQ FS GL IP JX KN MO TZ VW",
|
||||
""
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
// Rotor ring setting test: single keypress, basic rotors, random ring
|
||||
// settings, basic start position, no advancement of other rotors.
|
||||
name: "Enigma: rotor ring setting 2",
|
||||
input: "A",
|
||||
expectedOutput: "F",
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "Enigma",
|
||||
"args": [
|
||||
"3-rotor",
|
||||
"", "A", "A",
|
||||
"EKMFLGDQVZNTOWYHXUSPAIBRCJ<R", "N", "A",
|
||||
"AJDKSIRUXBLHWTMCQGZNPYFVOE<F", "F", "A",
|
||||
"BDFHJLCPRTXVZNYEIWGAKMUSQO<W", "W", "Z",
|
||||
"AY BR CU DH EQ FS GL IP JX KN MO TZ VW",
|
||||
""
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
// Stepping: basic configuration, enough input to cause middle rotor to
|
||||
// step
|
||||
name: "Enigma: stepping",
|
||||
input: "AAAAA AAAAA AAAAA AAAAA AAAAA A",
|
||||
expectedOutput: "UBDZG OWCXL TKSBT MCDLP BMUQO F",
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "Enigma",
|
||||
"args": [
|
||||
"3-rotor",
|
||||
"", "A", "A",
|
||||
"EKMFLGDQVZNTOWYHXUSPAIBRCJ<R", "A", "A",
|
||||
"AJDKSIRUXBLHWTMCQGZNPYFVOE<F", "A", "A",
|
||||
"BDFHJLCPRTXVZNYEIWGAKMUSQO<W", "A", "Z",
|
||||
"AY BR CU DH EQ FS GL IP JX KN MO TZ VW",
|
||||
""
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
// Ensure that we can decrypt an encrypted message.
|
||||
name: "Enigma: reflectivity",
|
||||
input: "AAAAA AAAAA AAAAA AAAAA AAAAA A",
|
||||
expectedOutput: "AAAAA AAAAA AAAAA AAAAA AAAAA A",
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "Enigma",
|
||||
"args": [
|
||||
"3-rotor",
|
||||
"", "A", "A",
|
||||
"EKMFLGDQVZNTOWYHXUSPAIBRCJ<R", "A", "A",
|
||||
"AJDKSIRUXBLHWTMCQGZNPYFVOE<F", "A", "A",
|
||||
"BDFHJLCPRTXVZNYEIWGAKMUSQO<W", "A", "Z",
|
||||
"AY BR CU DH EQ FS GL IP JX KN MO TZ VW",
|
||||
""
|
||||
]
|
||||
},
|
||||
{
|
||||
"op": "Enigma",
|
||||
"args": [
|
||||
"3-rotor",
|
||||
"", "A", "A",
|
||||
"EKMFLGDQVZNTOWYHXUSPAIBRCJ<R", "A", "A",
|
||||
"AJDKSIRUXBLHWTMCQGZNPYFVOE<F", "A", "A",
|
||||
"BDFHJLCPRTXVZNYEIWGAKMUSQO<W", "A", "Z",
|
||||
"AY BR CU DH EQ FS GL IP JX KN MO TZ VW",
|
||||
""
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
// Stepping: with rotors set so we're about to trigger the double step
|
||||
// anomaly
|
||||
name: "Enigma: double step anomaly",
|
||||
input: "AAAAA",
|
||||
expectedOutput: "EQIBM",
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "Enigma",
|
||||
"args": [
|
||||
"3-rotor",
|
||||
"", "A", "A",
|
||||
"EKMFLGDQVZNTOWYHXUSPAIBRCJ<R", "A", "A",
|
||||
"AJDKSIRUXBLHWTMCQGZNPYFVOE<F", "A", "D",
|
||||
"BDFHJLCPRTXVZNYEIWGAKMUSQO<W", "A", "U",
|
||||
"AY BR CU DH EQ FS GL IP JX KN MO TZ VW",
|
||||
""
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
// Stepping: with rotors set so we're about to trigger the double step
|
||||
// anomaly
|
||||
name: "Enigma: double step anomaly 2",
|
||||
input: "AAAA",
|
||||
expectedOutput: "BRNC",
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "Enigma",
|
||||
"args": [
|
||||
"3-rotor",
|
||||
"", "A", "A",
|
||||
"EKMFLGDQVZNTOWYHXUSPAIBRCJ<R", "A", "A",
|
||||
"AJDKSIRUXBLHWTMCQGZNPYFVOE<F", "A", "E",
|
||||
"BDFHJLCPRTXVZNYEIWGAKMUSQO<W", "A", "U",
|
||||
"AY BR CU DH EQ FS GL IP JX KN MO TZ VW",
|
||||
""
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
// Stepping: with rotors set so we're about to trigger the double step
|
||||
// anomaly
|
||||
name: "Enigma: double step anomaly 3",
|
||||
input: "AAAAA AAA",
|
||||
expectedOutput: "ZEEQI BMG",
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "Enigma",
|
||||
"args": [
|
||||
"3-rotor",
|
||||
"", "A", "A",
|
||||
"EKMFLGDQVZNTOWYHXUSPAIBRCJ<R", "A", "A",
|
||||
"AJDKSIRUXBLHWTMCQGZNPYFVOE<F", "A", "D",
|
||||
"BDFHJLCPRTXVZNYEIWGAKMUSQO<W", "A", "S",
|
||||
"AY BR CU DH EQ FS GL IP JX KN MO TZ VW",
|
||||
""
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
// Stepping: with a ring setting
|
||||
name: "Enigma: ring setting stepping",
|
||||
input: "AAAAA AAAAA AAAAA AAAAA AAAAA A",
|
||||
expectedOutput: "PBMFE BOUBD ZGOWC XLTKS BTXSH I",
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "Enigma",
|
||||
"args": [
|
||||
"3-rotor",
|
||||
"", "A", "A",
|
||||
"EKMFLGDQVZNTOWYHXUSPAIBRCJ<R", "A", "A",
|
||||
"AJDKSIRUXBLHWTMCQGZNPYFVOE<F", "A", "A",
|
||||
"BDFHJLCPRTXVZNYEIWGAKMUSQO<W", "H", "Z",
|
||||
"AY BR CU DH EQ FS GL IP JX KN MO TZ VW",
|
||||
""
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
// Stepping: with a ring setting and double step
|
||||
name: "Enigma: ring setting double step",
|
||||
input: "AAAAA AAAAA AAAAA AAAAA AAAAA A",
|
||||
expectedOutput: "TEVFK UTIIW EDWVI JPMVP GDEZS P",
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "Enigma",
|
||||
"args": [
|
||||
"3-rotor",
|
||||
"", "A", "A",
|
||||
"EKMFLGDQVZNTOWYHXUSPAIBRCJ<R", "Q", "A",
|
||||
"AJDKSIRUXBLHWTMCQGZNPYFVOE<F", "C", "D",
|
||||
"BDFHJLCPRTXVZNYEIWGAKMUSQO<W", "H", "F",
|
||||
"AY BR CU DH EQ FS GL IP JX KN MO TZ VW",
|
||||
""
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
// Four-rotor Enigma, random settings, no plugboard
|
||||
name: "Enigma: four rotor",
|
||||
input: "AAAAA AAAAA AAAAA AAAAA AAAAA A",
|
||||
expectedOutput: "GZXGX QUSUW JPWVI GVBTU DQZNZ J",
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "Enigma",
|
||||
"args": [
|
||||
"4-rotor",
|
||||
"LEYJVCNIXWPBQMDRTAKZGFUHOS", "A", "X", // Beta
|
||||
"EKMFLGDQVZNTOWYHXUSPAIBRCJ<R", "O", "E",
|
||||
"AJDKSIRUXBLHWTMCQGZNPYFVOE<F", "P", "F",
|
||||
"BDFHJLCPRTXVZNYEIWGAKMUSQO<W", "D", "Q",
|
||||
"AE BN CK DQ FU GY HW IJ LO MP RX SZ TV", // B thin
|
||||
""
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
// Four-rotor Enigma, different wheel set, no plugboard
|
||||
name: "Enigma: four rotor 2",
|
||||
input: "AAAAA AAAAA AAAAA AAAAA AAAAA A",
|
||||
expectedOutput: "HZJLP IKWBZ XNCWF FIHWL EROOZ C",
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "Enigma",
|
||||
"args": [
|
||||
"4-rotor",
|
||||
"FSOKANUERHMBTIYCWLQPZXVGJD", "A", "L", // Gamma
|
||||
"JPGVOUMFYQBENHZRDKASXLICTW<AN", "A", "J", // VI
|
||||
"VZBRGITYUPSDNHLXAWMJQOFECK<A", "M", "G", // V
|
||||
"ESOVPZJAYQUIRHXLNFTGKDCMWB<K", "W", "U", // IV
|
||||
"AR BD CO EJ FN GT HK IV LM PW QZ SX UY", // C thin
|
||||
""
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
// Four-rotor Enigma, different wheel set, random plugboard
|
||||
name: "Enigma: plugboard",
|
||||
input: "AAAAA AAAAA AAAAA AAAAA AAAAA A",
|
||||
expectedOutput: "GHLIM OJIUW DKLWM JGNJK DYJVD K",
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "Enigma",
|
||||
"args": [
|
||||
"4-rotor",
|
||||
"FSOKANUERHMBTIYCWLQPZXVGJD", "A", "I", // Gamma
|
||||
"NZJHGRCXMYSWBOUFAIVLPEKQDT<AN", "I", "V", // VII
|
||||
"ESOVPZJAYQUIRHXLNFTGKDCMWB<K", "O", "O", // IV
|
||||
"FKQHTLXOCBJSPDZRAMEWNIUYGV<AN", "U", "Z", // VIII
|
||||
"AE BN CK DQ FU GY HW IJ LO MP RX SZ TV", // B thin
|
||||
"WN MJ LX YB FP QD US IH CE GR"
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
// Decryption test on above input
|
||||
name: "Enigma: decryption",
|
||||
input: "GHLIM OJIUW DKLWM JGNJK DYJVD K",
|
||||
expectedOutput: "AAAAA AAAAA AAAAA AAAAA AAAAA A",
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "Enigma",
|
||||
"args": [
|
||||
"4-rotor",
|
||||
"FSOKANUERHMBTIYCWLQPZXVGJD", "A", "I", // Gamma
|
||||
"NZJHGRCXMYSWBOUFAIVLPEKQDT<AN", "I", "V", // VII
|
||||
"ESOVPZJAYQUIRHXLNFTGKDCMWB<K", "O", "O", // IV
|
||||
"FKQHTLXOCBJSPDZRAMEWNIUYGV<AN", "U", "Z", // VIII
|
||||
"AE BN CK DQ FU GY HW IJ LO MP RX SZ TV", // B thin
|
||||
"WN MJ LX YB FP QD US IH CE GR"
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
// Decryption test on real message
|
||||
name: "Enigma: decryption 2",
|
||||
input: "LANOTCTOUARBBFPMHPHGCZXTDYGAHGUFXGEWKBLKGJWLQXXTGPJJAVTOCKZFSLPPQIHZFXOEBWIIEKFZLCLOAQJULJOYHSSMBBGWHZANVOIIPYRBRTDJQDJJOQKCXWDNBBTYVXLYTAPGVEATXSONPNYNQFUDBBHHVWEPYEYDOHNLXKZDNWRHDUWUJUMWWVIIWZXIVIUQDRHYMNCYEFUAPNHOTKHKGDNPSAKNUAGHJZSMJBMHVTREQEDGXHLZWIFUSKDQVELNMIMITHBHDBWVHDFYHJOQIHORTDJDBWXEMEAYXGYQXOHFDMYUXXNOJAZRSGHPLWMLRECWWUTLRTTVLBHYOORGLGOWUXNXHMHYFAACQEKTHSJW",
|
||||
expectedOutput: "KRKRALLEXXFOLGENDESISTSOFORTBEKANNTZUGEBENXXICHHABEFOLGELNBEBEFEHLERHALTENXXJANSTERLEDESBISHERIGXNREICHSMARSCHALLSJGOERINGJSETZTDERFUEHRERSIEYHVRRGRZSSADMIRALYALSSEINENNACHFOLGEREINXSCHRIFTLSCHEVOLLMACHTUNTERWEGSXABSOFORTSOLLENSIESAEMTLICHEMASSNAHMENVERFUEGENYDIESICHAUSDERGEGENWAERTIGENLAGEERGEBENXGEZXREICHSLEITEIKKTULPEKKJBORMANNJXXOBXDXMMMDURNHFKSTXKOMXADMXUUUBOOIEXKP",
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "Enigma",
|
||||
"args": [
|
||||
"4-rotor",
|
||||
"LEYJVCNIXWPBQMDRTAKZGFUHOS", "E", "C", // Beta
|
||||
"VZBRGITYUPSDNHLXAWMJQOFECK<A", "P", "D", // V
|
||||
"JPGVOUMFYQBENHZRDKASXLICTW<AN", "E", "S", // VI
|
||||
"FKQHTLXOCBJSPDZRAMEWNIUYGV<AN", "L", "Z", // VIII
|
||||
"AR BD CO EJ FN GT HK IV LM PW QZ SX UY", // C thin
|
||||
"AE BF CM DQ HU JN LX PR SZ VW"
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
// Non-alphabet characters drop test
|
||||
name: "Enigma: non-alphabet drop",
|
||||
input: "Hello, world. This is a test.",
|
||||
expectedOutput: "ILBDA AMTAZ MORNZ DDIOT U",
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "Enigma",
|
||||
"args": [
|
||||
"3-rotor",
|
||||
"", "A", "A",
|
||||
"EKMFLGDQVZNTOWYHXUSPAIBRCJ<R", "A", "A", // I
|
||||
"AJDKSIRUXBLHWTMCQGZNPYFVOE<F", "A", "A", // II
|
||||
"BDFHJLCPRTXVZNYEIWGAKMUSQO<W", "A", "A", // III
|
||||
"AY BR CU DH EQ FS GL IP JX KN MO TZ VW", // B
|
||||
"", true
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
// Non-alphabet characters passthrough test
|
||||
name: "Enigma: non-alphabet passthrough",
|
||||
input: "Hello, world. This is a test.",
|
||||
expectedOutput: "ILBDA, AMTAZ. MORN ZD D IOTU.",
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "Enigma",
|
||||
"args": [
|
||||
"3-rotor",
|
||||
"", "A", "A",
|
||||
"EKMFLGDQVZNTOWYHXUSPAIBRCJ<R", "A", "A", // I
|
||||
"AJDKSIRUXBLHWTMCQGZNPYFVOE<F", "A", "A", // II
|
||||
"BDFHJLCPRTXVZNYEIWGAKMUSQO<W", "A", "A", // III
|
||||
"AY BR CU DH EQ FS GL IP JX KN MO TZ VW", // B
|
||||
"", false
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "Enigma: rotor validation 1",
|
||||
input: "Hello, world. This is a test.",
|
||||
expectedOutput: "Rotor wiring must be 26 unique uppercase letters",
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "Enigma",
|
||||
"args": [
|
||||
"3-rotor",
|
||||
"", "A", "A",
|
||||
"EKMFLGDQVZNTOWYHXUSPAIBRCJ<R", "A", "A", // I
|
||||
"AJDKSIRUXBLHWTMCQGZNPYFVOE<F", "A", "A", // II
|
||||
"BDFHJLCPRTXVZNYEIWGAKMUSQ", "A", "A", // III
|
||||
"AY BR CU DH EQ FS GL IP JX KN MO TZ VW", // B
|
||||
""
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "Enigma: rotor validation 2",
|
||||
input: "Hello, world. This is a test.",
|
||||
expectedOutput: "Rotor wiring must be 26 unique uppercase letters",
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "Enigma",
|
||||
"args": [
|
||||
"3-rotor",
|
||||
"", "A", "A",
|
||||
"EKMFLGDQVZNTOWYHXUSPAIBRCJ<R", "A", "A", // I
|
||||
"AJDKSIRUXBLHWTMCQGZNPYFVOE<F", "A", "A", // II
|
||||
"BDFHJLCPRTXVZNYEIWGAKMUSQo", "A", "A", // III
|
||||
"AY BR CU DH EQ FS GL IP JX KN MO TZ VW", // B
|
||||
""
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "Enigma: rotor validation 3",
|
||||
input: "Hello, world. This is a test.",
|
||||
expectedOutput: "Rotor wiring must have each letter exactly once",
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "Enigma",
|
||||
"args": [
|
||||
"3-rotor",
|
||||
"", "A", "A",
|
||||
"EKMFLGDQVZNTOWYHXUSPAIBRCJ<R", "A", "A", // I
|
||||
"AJDKSIRUXBLHWTMCQGZNPYFVOE<F", "A", "A", // II
|
||||
"BDFHJLCPRTXVZNYEIWGAKMUSQA", "A", "A", // III
|
||||
"AY BR CU DH EQ FS GL IP JX KN MO TZ VW", // B
|
||||
""
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "Enigma: rotor validation 4",
|
||||
input: "Hello, world. This is a test.",
|
||||
expectedOutput: "Rotor steps must be unique",
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "Enigma",
|
||||
"args": [
|
||||
"3-rotor",
|
||||
"", "A", "A",
|
||||
"EKMFLGDQVZNTOWYHXUSPAIBRCJ<R", "A", "A", // I
|
||||
"AJDKSIRUXBLHWTMCQGZNPYFVOE<F", "A", "A", // II
|
||||
"BDFHJLCPRTXVZNYEIWGAKMUSQO<RR", "A", "A", // III
|
||||
"AY BR CU DH EQ FS GL IP JX KN MO TZ VW", // B
|
||||
""
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "Enigma: rotor validation 5",
|
||||
input: "Hello, world. This is a test.",
|
||||
expectedOutput: "Rotor steps must be 0-26 unique uppercase letters",
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "Enigma",
|
||||
"args": [
|
||||
"3-rotor",
|
||||
"", "A", "A",
|
||||
"EKMFLGDQVZNTOWYHXUSPAIBRCJ<R", "A", "A", // I
|
||||
"AJDKSIRUXBLHWTMCQGZNPYFVOE<F", "A", "A", // II
|
||||
"BDFHJLCPRTXVZNYEIWGAKMUSQO<a", "A", "A", // III
|
||||
"AY BR CU DH EQ FS GL IP JX KN MO TZ VW", // B
|
||||
""
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
// The ring setting and positions are dropdowns in the interface so not
|
||||
// gonna bother testing them
|
||||
{
|
||||
name: "Enigma: reflector validation 1",
|
||||
input: "Hello, world. This is a test.",
|
||||
expectedOutput: "Reflector must have exactly 13 pairs covering every letter",
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "Enigma",
|
||||
"args": [
|
||||
"3-rotor",
|
||||
"", "A", "A",
|
||||
"EKMFLGDQVZNTOWYHXUSPAIBRCJ<R", "A", "A", // I
|
||||
"AJDKSIRUXBLHWTMCQGZNPYFVOE<F", "A", "A", // II
|
||||
"BDFHJLCPRTXVZNYEIWGAKMUSQO<W", "A", "A", // III
|
||||
"AY BR CU DH EQ FS GL IP JX KN MO", // B
|
||||
""
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "Enigma: reflector validation 2",
|
||||
input: "Hello, world. This is a test.",
|
||||
expectedOutput: "Reflector must have exactly 13 pairs covering every letter",
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "Enigma",
|
||||
"args": [
|
||||
"3-rotor",
|
||||
"", "A", "A",
|
||||
"EKMFLGDQVZNTOWYHXUSPAIBRCJ<R", "A", "A", // I
|
||||
"AJDKSIRUXBLHWTMCQGZNPYFVOE<F", "A", "A", // II
|
||||
"BDFHJLCPRTXVZNYEIWGAKMUSQO<W", "A", "A", // III
|
||||
"AA BR CU DH EQ FS GL IP JX KN MO TZ VV WY", // B
|
||||
""
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "Enigma: reflector validation 3",
|
||||
input: "Hello, world. This is a test.",
|
||||
expectedOutput: "Reflector connects A more than once",
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "Enigma",
|
||||
"args": [
|
||||
"3-rotor",
|
||||
"", "A", "A",
|
||||
"EKMFLGDQVZNTOWYHXUSPAIBRCJ<R", "A", "A", // I
|
||||
"AJDKSIRUXBLHWTMCQGZNPYFVOE<F", "A", "A", // II
|
||||
"BDFHJLCPRTXVZNYEIWGAKMUSQO<W", "A", "A", // III
|
||||
"AY AR CU DH EQ FS GL IP JX KN MO TZ", // B
|
||||
""
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "Enigma: reflector validation 4",
|
||||
input: "Hello, world. This is a test.",
|
||||
expectedOutput: "Reflector must be a whitespace-separated list of uppercase letter pairs",
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "Enigma",
|
||||
"args": [
|
||||
"3-rotor",
|
||||
"", "A", "A",
|
||||
"EKMFLGDQVZNTOWYHXUSPAIBRCJ<R", "A", "A", // I
|
||||
"AJDKSIRUXBLHWTMCQGZNPYFVOE<F", "A", "A", // II
|
||||
"BDFHJLCPRTXVZNYEIWGAKMUSQO<W", "A", "A", // III
|
||||
"AYBR CU DH EQ FS GL IP JX KN MO TZ", // B
|
||||
""
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
]);
|
|
@ -5,13 +5,13 @@
|
|||
* @copyright Crown Copyright 2017
|
||||
* @license Apache-2.0
|
||||
*/
|
||||
import TestRegister from "../TestRegister";
|
||||
import TestRegister from "../../lib/TestRegister.mjs";
|
||||
|
||||
TestRegister.addTests([
|
||||
{
|
||||
name: "Extract email address",
|
||||
input: "email@example.com\nfirstname.lastname@example.com\nemail@subdomain.example.com\nfirstname+lastname@example.com\n1234567890@example.com\nemail@example-one.com\n_______@example.com email@example.name\nemail@example.museum email@example.co.jp firstname-lastname@example.com",
|
||||
expectedOutput: "email@example.com\nfirstname.lastname@example.com\nemail@subdomain.example.com\nfirstname+lastname@example.com\n1234567890@example.com\nemail@example-one.com\n_______@example.com\nemail@example.name\nemail@example.museum\nemail@example.co.jp\nfirstname-lastname@example.com\n",
|
||||
expectedOutput: "email@example.com\nfirstname.lastname@example.com\nemail@subdomain.example.com\nfirstname+lastname@example.com\n1234567890@example.com\nemail@example-one.com\n_______@example.com\nemail@example.name\nemail@example.museum\nemail@example.co.jp\nfirstname-lastname@example.com",
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "Extract email addresses",
|
||||
|
@ -22,7 +22,7 @@ TestRegister.addTests([
|
|||
{
|
||||
name: "Extract email address - Display total",
|
||||
input: "email@example.com\nfirstname.lastname@example.com\nemail@subdomain.example.com\nfirstname+lastname@example.com\n1234567890@example.com\nemail@example-one.com\n_______@example.com email@example.name\nemail@example.museum email@example.co.jp firstname-lastname@example.com",
|
||||
expectedOutput: "Total found: 11\n\nemail@example.com\nfirstname.lastname@example.com\nemail@subdomain.example.com\nfirstname+lastname@example.com\n1234567890@example.com\nemail@example-one.com\n_______@example.com\nemail@example.name\nemail@example.museum\nemail@example.co.jp\nfirstname-lastname@example.com\n",
|
||||
expectedOutput: "Total found: 11\n\nemail@example.com\nfirstname.lastname@example.com\nemail@subdomain.example.com\nfirstname+lastname@example.com\n1234567890@example.com\nemail@example-one.com\n_______@example.com\nemail@example.name\nemail@example.museum\nemail@example.co.jp\nfirstname-lastname@example.com",
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "Extract email addresses",
|
||||
|
@ -33,7 +33,7 @@ TestRegister.addTests([
|
|||
{
|
||||
name: "Extract email address (Internationalized)",
|
||||
input: "\u4f0a\u662d\u5091@\u90f5\u4ef6.\u5546\u52d9 \u093e\u092e@\u092e\u094b\u0939\u0928.\u0908\u0928\u094d\u092b\u094b\n\u044e\u0437\u0435\u0440@\u0435\u043a\u0437\u0430\u043c\u043f\u043b.\u043a\u043e\u043c \u03b8\u03c3\u03b5\u03c1@\u03b5\u03c7\u03b1\u03bc\u03c0\u03bb\u03b5.\u03c8\u03bf\u03bc Jos\u1ec5Silv\u1ec5@googl\u1ec5.com\nJos\u1ec5Silv\u1ec5@google.com and Jos\u1ec5Silva@google.com\nFoO@BaR.CoM, john@192.168.10.100\ng\xf3mez@junk.br and Abc.123@example.com.\nuser+mailbox/department=shipping@example.com\n\u7528\u6237@\u4f8b\u5b50.\u5e7f\u544a\n\u0909\u092a\u092f\u094b\u0917\u0915\u0930\u094d\u0924\u093e@\u0909\u0926\u093e\u0939\u0930\u0923.\u0915\u0949\u092e\n\u044e\u0437\u0435\u0440@\u0435\u043a\u0437\u0430\u043c\u043f\u043b.\u043a\u043e\u043c\n\u03b8\u03c3\u03b5\u03c1@\u03b5\u03c7\u03b1\u03bc\u03c0\u03bb\u03b5.\u03c8\u03bf\u03bc\nD\xf6rte@S\xf6rensen.example.com\n\u0430\u0434\u0436\u0430\u0439@\u044d\u043a\u0437\u0430\u043c\u043f\u043b.\u0440\u0443\u0441\ntest@xn--bcher-kva.com",
|
||||
expectedOutput: "\u4f0a\u662d\u5091@\u90f5\u4ef6.\u5546\u52d9\n\u093e\u092e@\u092e\u094b\u0939\u0928.\u0908\u0928\u094d\u092b\u094b\n\u044e\u0437\u0435\u0440@\u0435\u043a\u0437\u0430\u043c\u043f\u043b.\u043a\u043e\u043c\n\u03b8\u03c3\u03b5\u03c1@\u03b5\u03c7\u03b1\u03bc\u03c0\u03bb\u03b5.\u03c8\u03bf\u03bc\nJos\u1ec5Silv\u1ec5@googl\u1ec5.com\nJos\u1ec5Silv\u1ec5@google.com\nJos\u1ec5Silva@google.com\nFoO@BaR.CoM\njohn@192.168.10.100\ng\xf3mez@junk.br\nAbc.123@example.com\nuser+mailbox/department=shipping@example.com\n\u7528\u6237@\u4f8b\u5b50.\u5e7f\u544a\n\u0909\u092a\u092f\u094b\u0917\u0915\u0930\u094d\u0924\u093e@\u0909\u0926\u093e\u0939\u0930\u0923.\u0915\u0949\u092e\n\u044e\u0437\u0435\u0440@\u0435\u043a\u0437\u0430\u043c\u043f\u043b.\u043a\u043e\u043c\n\u03b8\u03c3\u03b5\u03c1@\u03b5\u03c7\u03b1\u03bc\u03c0\u03bb\u03b5.\u03c8\u03bf\u03bc\nD\xf6rte@S\xf6rensen.example.com\n\u0430\u0434\u0436\u0430\u0439@\u044d\u043a\u0437\u0430\u043c\u043f\u043b.\u0440\u0443\u0441\ntest@xn--bcher-kva.com\n",
|
||||
expectedOutput: "\u4f0a\u662d\u5091@\u90f5\u4ef6.\u5546\u52d9\n\u093e\u092e@\u092e\u094b\u0939\u0928.\u0908\u0928\u094d\u092b\u094b\n\u044e\u0437\u0435\u0440@\u0435\u043a\u0437\u0430\u043c\u043f\u043b.\u043a\u043e\u043c\n\u03b8\u03c3\u03b5\u03c1@\u03b5\u03c7\u03b1\u03bc\u03c0\u03bb\u03b5.\u03c8\u03bf\u03bc\nJos\u1ec5Silv\u1ec5@googl\u1ec5.com\nJos\u1ec5Silv\u1ec5@google.com\nJos\u1ec5Silva@google.com\nFoO@BaR.CoM\njohn@192.168.10.100\ng\xf3mez@junk.br\nAbc.123@example.com\nuser+mailbox/department=shipping@example.com\n\u7528\u6237@\u4f8b\u5b50.\u5e7f\u544a\n\u0909\u092a\u092f\u094b\u0917\u0915\u0930\u094d\u0924\u093e@\u0909\u0926\u093e\u0939\u0930\u0923.\u0915\u0949\u092e\n\u044e\u0437\u0435\u0440@\u0435\u043a\u0437\u0430\u043c\u043f\u043b.\u043a\u043e\u043c\n\u03b8\u03c3\u03b5\u03c1@\u03b5\u03c7\u03b1\u03bc\u03c0\u03bb\u03b5.\u03c8\u03bf\u03bc\nD\xf6rte@S\xf6rensen.example.com\n\u0430\u0434\u0436\u0430\u0439@\u044d\u043a\u0437\u0430\u043c\u043f\u043b.\u0440\u0443\u0441\ntest@xn--bcher-kva.com",
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "Extract email addresses",
|
||||
|
@ -44,7 +44,7 @@ TestRegister.addTests([
|
|||
{
|
||||
name: "Extract email address - Display total (Internationalized)",
|
||||
input: "\u4f0a\u662d\u5091@\u90f5\u4ef6.\u5546\u52d9 \u093e\u092e@\u092e\u094b\u0939\u0928.\u0908\u0928\u094d\u092b\u094b\n\u044e\u0437\u0435\u0440@\u0435\u043a\u0437\u0430\u043c\u043f\u043b.\u043a\u043e\u043c \u03b8\u03c3\u03b5\u03c1@\u03b5\u03c7\u03b1\u03bc\u03c0\u03bb\u03b5.\u03c8\u03bf\u03bc Jos\u1ec5Silv\u1ec5@googl\u1ec5.com\nJos\u1ec5Silv\u1ec5@google.com and Jos\u1ec5Silva@google.com\nFoO@BaR.CoM, john@192.168.10.100\ng\xf3mez@junk.br and Abc.123@example.com.\nuser+mailbox/department=shipping@example.com\n\u7528\u6237@\u4f8b\u5b50.\u5e7f\u544a\n\u0909\u092a\u092f\u094b\u0917\u0915\u0930\u094d\u0924\u093e@\u0909\u0926\u093e\u0939\u0930\u0923.\u0915\u0949\u092e\n\u044e\u0437\u0435\u0440@\u0435\u043a\u0437\u0430\u043c\u043f\u043b.\u043a\u043e\u043c\n\u03b8\u03c3\u03b5\u03c1@\u03b5\u03c7\u03b1\u03bc\u03c0\u03bb\u03b5.\u03c8\u03bf\u03bc\nD\xf6rte@S\xf6rensen.example.com\n\u0430\u0434\u0436\u0430\u0439@\u044d\u043a\u0437\u0430\u043c\u043f\u043b.\u0440\u0443\u0441\ntest@xn--bcher-kva.com",
|
||||
expectedOutput: "Total found: 19\n\n\u4f0a\u662d\u5091@\u90f5\u4ef6.\u5546\u52d9\n\u093e\u092e@\u092e\u094b\u0939\u0928.\u0908\u0928\u094d\u092b\u094b\n\u044e\u0437\u0435\u0440@\u0435\u043a\u0437\u0430\u043c\u043f\u043b.\u043a\u043e\u043c\n\u03b8\u03c3\u03b5\u03c1@\u03b5\u03c7\u03b1\u03bc\u03c0\u03bb\u03b5.\u03c8\u03bf\u03bc\nJos\u1ec5Silv\u1ec5@googl\u1ec5.com\nJos\u1ec5Silv\u1ec5@google.com\nJos\u1ec5Silva@google.com\nFoO@BaR.CoM\njohn@192.168.10.100\ng\xf3mez@junk.br\nAbc.123@example.com\nuser+mailbox/department=shipping@example.com\n\u7528\u6237@\u4f8b\u5b50.\u5e7f\u544a\n\u0909\u092a\u092f\u094b\u0917\u0915\u0930\u094d\u0924\u093e@\u0909\u0926\u093e\u0939\u0930\u0923.\u0915\u0949\u092e\n\u044e\u0437\u0435\u0440@\u0435\u043a\u0437\u0430\u043c\u043f\u043b.\u043a\u043e\u043c\n\u03b8\u03c3\u03b5\u03c1@\u03b5\u03c7\u03b1\u03bc\u03c0\u03bb\u03b5.\u03c8\u03bf\u03bc\nD\xf6rte@S\xf6rensen.example.com\n\u0430\u0434\u0436\u0430\u0439@\u044d\u043a\u0437\u0430\u043c\u043f\u043b.\u0440\u0443\u0441\ntest@xn--bcher-kva.com\n",
|
||||
expectedOutput: "Total found: 19\n\n\u4f0a\u662d\u5091@\u90f5\u4ef6.\u5546\u52d9\n\u093e\u092e@\u092e\u094b\u0939\u0928.\u0908\u0928\u094d\u092b\u094b\n\u044e\u0437\u0435\u0440@\u0435\u043a\u0437\u0430\u043c\u043f\u043b.\u043a\u043e\u043c\n\u03b8\u03c3\u03b5\u03c1@\u03b5\u03c7\u03b1\u03bc\u03c0\u03bb\u03b5.\u03c8\u03bf\u03bc\nJos\u1ec5Silv\u1ec5@googl\u1ec5.com\nJos\u1ec5Silv\u1ec5@google.com\nJos\u1ec5Silva@google.com\nFoO@BaR.CoM\njohn@192.168.10.100\ng\xf3mez@junk.br\nAbc.123@example.com\nuser+mailbox/department=shipping@example.com\n\u7528\u6237@\u4f8b\u5b50.\u5e7f\u544a\n\u0909\u092a\u092f\u094b\u0917\u0915\u0930\u094d\u0924\u093e@\u0909\u0926\u093e\u0939\u0930\u0923.\u0915\u0949\u092e\n\u044e\u0437\u0435\u0440@\u0435\u043a\u0437\u0430\u043c\u043f\u043b.\u043a\u043e\u043c\n\u03b8\u03c3\u03b5\u03c1@\u03b5\u03c7\u03b1\u03bc\u03c0\u03bb\u03b5.\u03c8\u03bf\u03bc\nD\xf6rte@S\xf6rensen.example.com\n\u0430\u0434\u0436\u0430\u0439@\u044d\u043a\u0437\u0430\u043c\u043f\u043b.\u0440\u0443\u0441\ntest@xn--bcher-kva.com",
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "Extract email addresses",
|
||||
|
|
22
tests/operations/tests/FileTree.mjs
Normal file
22
tests/operations/tests/FileTree.mjs
Normal file
|
@ -0,0 +1,22 @@
|
|||
/**
|
||||
* File tree tests.
|
||||
*
|
||||
* @author sw5678
|
||||
* @copyright Crown Copyright 2023
|
||||
* @license Apache-2.0
|
||||
*/
|
||||
import TestRegister from "../../lib/TestRegister.mjs";
|
||||
|
||||
TestRegister.addTests([
|
||||
{
|
||||
"name": "File Tree: basic example",
|
||||
"input": "/test_dir1/test_file1.txt\n/test_dir1/test_file2.txt\n/test_dir2/test_file1.txt",
|
||||
"expectedOutput": "test_dir1\n|---test_file1.txt\n|---test_file2.txt\ntest_dir2\n|---test_file1.txt",
|
||||
"recipeConfig": [
|
||||
{
|
||||
"op": "File Tree",
|
||||
"args": ["/", "Line feed"],
|
||||
},
|
||||
],
|
||||
}
|
||||
]);
|
108
tests/operations/tests/FletcherChecksum.mjs
Normal file
108
tests/operations/tests/FletcherChecksum.mjs
Normal file
|
@ -0,0 +1,108 @@
|
|||
/**
|
||||
* @author mikecat
|
||||
* @copyright Crown Copyright 2022
|
||||
* @license Apache-2.0
|
||||
*/
|
||||
import TestRegister from "../../lib/TestRegister.mjs";
|
||||
|
||||
TestRegister.addTests([
|
||||
{
|
||||
name: "Fletcher-16 Checksum: abcde",
|
||||
input: "abcde",
|
||||
expectedOutput: "c8f0",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "Fletcher-16 Checksum",
|
||||
args: [],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "Fletcher-16 Checksum: abcdef",
|
||||
input: "abcdef",
|
||||
expectedOutput: "2057",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "Fletcher-16 Checksum",
|
||||
args: [],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "Fletcher-16 Checksum: abcdefgh",
|
||||
input: "abcdefgh",
|
||||
expectedOutput: "0627",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "Fletcher-16 Checksum",
|
||||
args: [],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "Fletcher-32 Checksum: abcde",
|
||||
input: "abcde",
|
||||
expectedOutput: "f04fc729",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "Fletcher-32 Checksum",
|
||||
args: [],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "Fletcher-32 Checksum: abcdef",
|
||||
input: "abcdef",
|
||||
expectedOutput: "56502d2a",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "Fletcher-32 Checksum",
|
||||
args: [],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "Fletcher-32 Checksum: abcdefgh",
|
||||
input: "abcdefgh",
|
||||
expectedOutput: "ebe19591",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "Fletcher-32 Checksum",
|
||||
args: [],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "Fletcher-64 Checksum: abcde",
|
||||
input: "abcde",
|
||||
expectedOutput: "c8c6c527646362c6",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "Fletcher-64 Checksum",
|
||||
args: [],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "Fletcher-64 Checksum: abcdef",
|
||||
input: "abcdef",
|
||||
expectedOutput: "c8c72b276463c8c6",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "Fletcher-64 Checksum",
|
||||
args: [],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "Fletcher-64 Checksum: abcdefgh",
|
||||
input: "abcdefgh",
|
||||
expectedOutput: "312e2b28cccac8c6",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "Fletcher-64 Checksum",
|
||||
args: [],
|
||||
},
|
||||
],
|
||||
},
|
||||
]);
|
|
@ -6,7 +6,7 @@
|
|||
* @copyright Crown Copyright 2018
|
||||
* @license Apache-2.0
|
||||
*/
|
||||
import TestRegister from "../TestRegister";
|
||||
import TestRegister from "../../lib/TestRegister.mjs";
|
||||
|
||||
TestRegister.addTests([
|
||||
{
|
||||
|
@ -31,7 +31,7 @@ TestRegister.addTests([
|
|||
},
|
||||
{
|
||||
op: "Merge",
|
||||
args: [],
|
||||
args: [true],
|
||||
},
|
||||
],
|
||||
},
|
||||
|
@ -50,14 +50,14 @@ TestRegister.addTests([
|
|||
},
|
||||
{
|
||||
op: "Merge",
|
||||
args: [],
|
||||
args: [true],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "Fork, Conditional Jump, Encodings",
|
||||
input: "Some data with a 1 in it\nSome data with a 2 in it",
|
||||
expectedOutput: "U29tZSBkYXRhIHdpdGggYSAxIGluIGl0\n53 6f 6d 65 20 64 61 74 61 20 77 69 74 68 20 61 20 32 20 69 6e 20 69 74\n",
|
||||
expectedOutput: "U29tZSBkYXRhIHdpdGggYSAxIGluIGl0\n53 6f 6d 65 20 64 61 74 61 20 77 69 74 68 20 61 20 32 20 69 6e 20 69 74",
|
||||
recipeConfig: [
|
||||
{"op": "Fork", "args": ["\\n", "\\n", false]},
|
||||
{"op": "Conditional Jump", "args": ["1", false, "skipReturn", "10"]},
|
||||
|
@ -66,5 +66,16 @@ TestRegister.addTests([
|
|||
{"op": "Label", "args": ["skipReturn"]},
|
||||
{"op": "To Base64", "args": ["A-Za-z0-9+/="]}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
name: "Fork, Partial Merge",
|
||||
input: "Hello World",
|
||||
expectedOutput: "48656c6c6f 576f726c64",
|
||||
recipeConfig: [
|
||||
{ "op": "Fork", "args": [" ", " ", false] },
|
||||
{ "op": "Fork", "args": ["l", "l", false] },
|
||||
{ "op": "Merge", "args": [false] },
|
||||
{ "op": "To Hex", "args": ["None", 0] },
|
||||
]
|
||||
},
|
||||
]);
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
* @copyright Crown Copyright 2018
|
||||
* @licence Apache-2.0
|
||||
*/
|
||||
import TestRegister from "../TestRegister";
|
||||
import TestRegister from "../../lib/TestRegister.mjs";
|
||||
|
||||
TestRegister.addTests([
|
||||
{
|
||||
|
|
183
tests/operations/tests/GOST.mjs
Normal file
183
tests/operations/tests/GOST.mjs
Normal file
|
@ -0,0 +1,183 @@
|
|||
/**
|
||||
* GOST tests.
|
||||
*
|
||||
* The GOST library already includes a range of tests for the correctness of
|
||||
* the algorithms. These tests are intended only to confirm that the library
|
||||
* has been correctly integrated into CyberChef.
|
||||
*
|
||||
* @author n1474335 [n1474335@gmail.com]
|
||||
*
|
||||
* @copyright Crown Copyright 2023
|
||||
* @license Apache-2.0
|
||||
*/
|
||||
import TestRegister from "../../lib/TestRegister.mjs";
|
||||
|
||||
TestRegister.addTests([
|
||||
{
|
||||
name: "GOST Encrypt: Magma",
|
||||
input: "Hello, World!",
|
||||
expectedOutput: "f124ac5c0853870906dbaf9b56",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "GOST Encrypt",
|
||||
args: [
|
||||
{ "option": "Hex", "string": "00112233" },
|
||||
{ "option": "Hex", "string": "0011223344556677" },
|
||||
"Raw",
|
||||
"Hex",
|
||||
"GOST 28147 (Magma, 1989)",
|
||||
"64",
|
||||
"E-SC",
|
||||
"OFB",
|
||||
"CP",
|
||||
"ZERO"
|
||||
]
|
||||
}
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "GOST Encrypt: Kuznyechik",
|
||||
input: "Hello, World!",
|
||||
expectedOutput: "8673d490dfa4a66d5e3ff00ba316724f",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "GOST Encrypt",
|
||||
args: [
|
||||
{ "option": "Hex", "string": "00112233" },
|
||||
{ "option": "Hex", "string": "00112233445566778899aabbccddeeff" },
|
||||
"Raw",
|
||||
"Hex",
|
||||
"GOST R 34.12 (Kuznyechik, 2015)",
|
||||
"128",
|
||||
"E-SC",
|
||||
"CBC",
|
||||
"CP",
|
||||
"PKCS5"
|
||||
]
|
||||
}
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "GOST Decrypt: Magma",
|
||||
input: "f124ac5c0853870906dbaf9b56",
|
||||
expectedOutput: "Hello, World!",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "GOST Decrypt",
|
||||
args: [
|
||||
{ "option": "Hex", "string": "00112233" },
|
||||
{ "option": "Hex", "string": "0011223344556677" },
|
||||
"Hex",
|
||||
"Raw",
|
||||
"GOST 28147 (Magma, 1989)",
|
||||
"128",
|
||||
"E-SC",
|
||||
"OFB",
|
||||
"CP",
|
||||
"ZERO"
|
||||
]
|
||||
}
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "GOST Decrypt: Kuznyechik",
|
||||
input: "8673d490dfa4a66d5e3ff00ba316724f",
|
||||
expectedOutput: "Hello, World!\0\0\0",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "GOST Decrypt",
|
||||
args: [
|
||||
{ "option": "Hex", "string": "00112233" },
|
||||
{ "option": "Hex", "string": "00112233445566778899aabbccddeeff" },
|
||||
"Hex",
|
||||
"Raw",
|
||||
"GOST R 34.12 (Kuznyechik, 2015)",
|
||||
"128",
|
||||
"E-TEST",
|
||||
"CBC",
|
||||
"CP",
|
||||
"PKCS5"
|
||||
]
|
||||
}
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "GOST Sign",
|
||||
input: "Hello, World!",
|
||||
expectedOutput: "810d0c40e965",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "GOST Sign",
|
||||
args: [
|
||||
{ "option": "Hex", "string": "00112233" },
|
||||
{ "option": "Hex", "string": "0011223344556677" },
|
||||
"Raw",
|
||||
"Hex",
|
||||
"GOST 28147 (Magma, 1989)",
|
||||
"64",
|
||||
"E-C",
|
||||
48
|
||||
]
|
||||
}
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "GOST Verify",
|
||||
input: "Hello, World!",
|
||||
expectedOutput: "The signature matches",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "GOST Verify",
|
||||
args: [
|
||||
{ "option": "Hex", "string": "00112233" },
|
||||
{ "option": "Hex", "string": "00112233445566778899aabbccddeeff" },
|
||||
{ "option": "Hex", "string": "42b77fb3d6f6bf04" },
|
||||
"Raw",
|
||||
"GOST R 34.12 (Kuznyechik, 2015)",
|
||||
"128",
|
||||
"E-TEST"
|
||||
]
|
||||
}
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "GOST Key Wrap",
|
||||
input: "Hello, World!123",
|
||||
expectedOutput: "0bb706e92487fceef97589911faeb28200000000000000000000000000000000\r\n6b7bfd16",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "GOST Key Wrap",
|
||||
args: [
|
||||
{ "option": "Hex", "string": "00112233" },
|
||||
{ "option": "Hex", "string": "0011223344556677" },
|
||||
"Raw",
|
||||
"Hex",
|
||||
"GOST R 34.12 (Kuznyechik, 2015)",
|
||||
"64",
|
||||
"E-TEST",
|
||||
"CP"
|
||||
]
|
||||
}
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "GOST Key Unwrap",
|
||||
input: "c8e58458a42d21974d50103d59b469f2c8e58458a42d21974d50103d59b469f2\r\na32a1575",
|
||||
expectedOutput: "0123456789abcdef0123456789abcdef",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "GOST Key Unwrap",
|
||||
args: [
|
||||
{ "option": "Hex", "string": "" },
|
||||
{ "option": "Latin1", "string": "00112233" },
|
||||
"Hex",
|
||||
"Raw",
|
||||
"GOST 28147 (Magma, 1989)",
|
||||
"64",
|
||||
"E-Z",
|
||||
"CP"
|
||||
]
|
||||
}
|
||||
],
|
||||
},
|
||||
]);
|
115
tests/operations/tests/GenerateAllHashes.mjs
Normal file
115
tests/operations/tests/GenerateAllHashes.mjs
Normal file
|
@ -0,0 +1,115 @@
|
|||
/**
|
||||
* GenerateAllHashes tests.
|
||||
*
|
||||
* @author john19696 [john19696@protonmail.com]
|
||||
* @copyright Crown Copyright 2022
|
||||
* @license Apache-2.0
|
||||
*/
|
||||
import TestRegister from "../../lib/TestRegister.mjs";
|
||||
|
||||
TestRegister.addTests([
|
||||
{
|
||||
name: "Full generate all hashes",
|
||||
input: "test",
|
||||
expectedOutput: `MD2: dd34716876364a02d0195e2fb9ae2d1b
|
||||
MD4: db346d691d7acc4dc2625db19f9e3f52
|
||||
MD5: 098f6bcd4621d373cade4e832627b4f6
|
||||
MD6: 93c8a7d0ff132f325138a82b2baa98c12a7c9ac982feb6c5b310a1ca713615bd
|
||||
SHA0: f8d3b312442a67706057aeb45b983221afb4f035
|
||||
SHA1: a94a8fe5ccb19ba61c4c0873d391e987982fbbd3
|
||||
SHA2 224: 90a3ed9e32b2aaf4c61c410eb925426119e1a9dc53d4286ade99a809
|
||||
SHA2 256: 9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08
|
||||
SHA2 384: 768412320f7b0aa5812fce428dc4706b3cae50e02a64caa16a782249bfe8efc4b7ef1ccb126255d196047dfedf17a0a9
|
||||
SHA2 512: ee26b0dd4af7e749aa1a8ee3c10ae9923f618980772e473f8819a5d4940e0db27ac185f8a0e1d5f84f88bc887fd67b143732c304cc5fa9ad8e6f57f50028a8ff
|
||||
SHA3 224: 3797bf0afbbfca4a7bbba7602a2b552746876517a7f9b7ce2db0ae7b
|
||||
SHA3 256: 36f028580bb02cc8272a9a020f4200e346e276ae664e45ee80745574e2f5ab80
|
||||
SHA3 384: e516dabb23b6e30026863543282780a3ae0dccf05551cf0295178d7ff0f1b41eecb9db3ff219007c4e097260d58621bd
|
||||
SHA3 512: 9ece086e9bac491fac5c1d1046ca11d737b92a2b2ebd93f005d7b710110c0a678288166e7fbe796883a4f2e9b3ca9f484f521d0ce464345cc1aec96779149c14
|
||||
Keccak 224: 3be30a9ff64f34a5861116c5198987ad780165f8366e67aff4760b5e
|
||||
Keccak 256: 9c22ff5f21f0b81b113e63f7db6da94fedef11b2119b4088b89664fb9a3cb658
|
||||
Keccak 384: 53d0ba137307d4c2f9b6674c83edbd58b70c0f4340133ed0adc6fba1d2478a6a03b7788229e775d2de8ae8c0759d0527
|
||||
Keccak 512: 1e2e9fc2002b002d75198b7503210c05a1baac4560916a3c6d93bcce3a50d7f00fd395bf1647b9abb8d1afcc9c76c289b0c9383ba386a956da4b38934417789e
|
||||
Shake 128: d3b0aa9cd8b7255622cebc631e867d4093d6f6010191a53973c45fec9b07c774
|
||||
Shake 256: b54ff7255705a71ee2925e4a3e30e41aed489a579d5595e0df13e32e1e4dd202a7c7f68b31d6418d9845eb4d757adda6ab189e1bb340db818e5b3bc725d992fa
|
||||
RIPEMD-128: f1abb5083c9ff8a9dbbca9cd2b11fead
|
||||
RIPEMD-160: 5e52fee47e6b070565f74372468cdc699de89107
|
||||
RIPEMD-256: fe0289110d07daeee9d9500e14c57787d9083f6ba10e6bcb256f86bb4fe7b981
|
||||
RIPEMD-320: 3b0a2e841e589cf583634a5dd265d2b5d497c4cc44b241e34e0f62d03e98c1b9dc72970b9bc20eb5
|
||||
HAS-160: cb15e491eec6e769771d1f811315139c93071084
|
||||
Whirlpool-0: d50ff71342b521974bae166539871922669afcfc7181250ebbae015c317ebb797173a69e7a05afd11099a9f0918159cd5bc88434d3ca44513d7263caea9244fe
|
||||
Whirlpool-T: e6b4aa087751b4428171777f1893ba585404c7e0171787720eba0d8bccd710dc2c42f874c572bfae4cedabf50f2c80bf923805d4e31c504b86ca3bc59265e7dd
|
||||
Whirlpool: b913d5bbb8e461c2c5961cbe0edcdadfd29f068225ceb37da6defcf89849368f8c6c2eb6a4c4ac75775d032a0ecfdfe8550573062b653fe92fc7b8fb3b7be8d6
|
||||
BLAKE2b-128: 44a8995dd50b6657a037a7839304535b
|
||||
BLAKE2b-160: a34fc3b6d2cce8beb3216c2bbb5e55739e8121ed
|
||||
BLAKE2b-256: 928b20366943e2afd11ebc0eae2e53a93bf177a4fcf35bcc64d503704e65e202
|
||||
BLAKE2b-384: 8a84b8666c8fcfb69f2ec41f578d7c85fbdb504ea6510fb05b50fcbf7ed8153c77943bc2da73abb136834e1a0d4f22cb
|
||||
BLAKE2b-512: a71079d42853dea26e453004338670a53814b78137ffbed07603a41d76a483aa9bc33b582f77d30a65e6f29a896c0411f38312e1d66e0bf16386c86a89bea572
|
||||
BLAKE2s-128: e9ddd9926b9dcb382e09be39ba403d2c
|
||||
BLAKE2s-160: d6197dabec2bd6f4ff303b8e519e8f15d42a453d
|
||||
BLAKE2s-256: f308fc02ce9172ad02a7d75800ecfc027109bc67987ea32aba9b8dcc7b10150e
|
||||
Streebog-256: 12a50838191b5504f1e5f2fd078714cf6b592b9d29af99d0b10d8d02881c3857
|
||||
Streebog-512: 7200bf5dea560f0d7960d07fdc8874ad9f3b86ece2e45f5502ae2e176f2c928e0e581152281f5aee818318bed7cbe6aa69999589234723ceb33175598365b5c8
|
||||
GOST: ee67303696d205ddd2b2363e8e01b4b7199a80957d94d7678eaad3fc834c5a27
|
||||
LM Hash: 01FC5A6BE7BC6929AAD3B435B51404EE
|
||||
NT Hash: 0CB6948805F797BF2A82807973B89537
|
||||
SSDEEP: 3:Hn:Hn
|
||||
CTPH: A:E:E
|
||||
|
||||
Checksums:
|
||||
Fletcher-8: 3d
|
||||
Fletcher-16: 5dc1
|
||||
Fletcher-32: 3f5cd9e7
|
||||
Fletcher-64: 7473657474736574
|
||||
Adler-32: 045d01c1
|
||||
CRC-8: b9
|
||||
CRC-16: f82e
|
||||
CRC-32: d87f7e0c
|
||||
`,
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "Generate all hashes",
|
||||
"args": ["All", true]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "Hashes with length 32",
|
||||
input: "test",
|
||||
expectedOutput: `MD2: dd34716876364a02d0195e2fb9ae2d1b
|
||||
MD4: db346d691d7acc4dc2625db19f9e3f52
|
||||
MD5: 098f6bcd4621d373cade4e832627b4f6
|
||||
RIPEMD-128: f1abb5083c9ff8a9dbbca9cd2b11fead
|
||||
BLAKE2b-128: 44a8995dd50b6657a037a7839304535b
|
||||
BLAKE2s-128: e9ddd9926b9dcb382e09be39ba403d2c
|
||||
LM Hash: 01FC5A6BE7BC6929AAD3B435B51404EE
|
||||
NT Hash: 0CB6948805F797BF2A82807973B89537
|
||||
`,
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "Generate all hashes",
|
||||
"args": ["128", true]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "Hashes without names",
|
||||
input: "test",
|
||||
expectedOutput: `93c8a7d0ff132f325138a82b2baa98c12a7c9ac982feb6c5b310a1ca713615bd
|
||||
9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08
|
||||
36f028580bb02cc8272a9a020f4200e346e276ae664e45ee80745574e2f5ab80
|
||||
9c22ff5f21f0b81b113e63f7db6da94fedef11b2119b4088b89664fb9a3cb658
|
||||
d3b0aa9cd8b7255622cebc631e867d4093d6f6010191a53973c45fec9b07c774
|
||||
fe0289110d07daeee9d9500e14c57787d9083f6ba10e6bcb256f86bb4fe7b981
|
||||
928b20366943e2afd11ebc0eae2e53a93bf177a4fcf35bcc64d503704e65e202
|
||||
f308fc02ce9172ad02a7d75800ecfc027109bc67987ea32aba9b8dcc7b10150e
|
||||
12a50838191b5504f1e5f2fd078714cf6b592b9d29af99d0b10d8d02881c3857
|
||||
ee67303696d205ddd2b2363e8e01b4b7199a80957d94d7678eaad3fc834c5a27
|
||||
`,
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "Generate all hashes",
|
||||
"args": ["256", false]
|
||||
}
|
||||
]
|
||||
}
|
||||
]);
|
33
tests/operations/tests/GenerateDeBruijnSequence.mjs
Normal file
33
tests/operations/tests/GenerateDeBruijnSequence.mjs
Normal file
|
@ -0,0 +1,33 @@
|
|||
/**
|
||||
* De Brujin Sequence tests.
|
||||
*
|
||||
* @author gchq77703 [gchq77703@gchq.gov.uk]
|
||||
* @copyright Crown Copyright 2017
|
||||
* @license Apache-2.0
|
||||
*/
|
||||
import TestRegister from "../../lib/TestRegister.mjs";
|
||||
|
||||
TestRegister.addTests([
|
||||
{
|
||||
name: "Generate De Bruijn Sequence: Small Sequence",
|
||||
input: "",
|
||||
expectedOutput: "00010111",
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "Generate De Bruijn Sequence",
|
||||
"args": [2, 3]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "Generate De Bruijn Sequence: Long Sequence",
|
||||
input: "",
|
||||
expectedOutput: "0000010000200003000110001200013000210002200023000310003200033001010010200103001110011200113001210012200123001310013200133002010020200203002110021200213002210022200223002310023200233003010030200303003110031200313003210032200323003310033200333010110101201013010210102201023010310103201033011020110301111011120111301121011220112301131011320113301202012030121101212012130122101222012230123101232012330130201303013110131201313013210132201323013310133201333020210202202023020310203202033021030211102112021130212102122021230213102132021330220302211022120221302221022220222302231022320223302303023110231202313023210232202323023310233202333030310303203033031110311203113031210312203123031310313203133032110321203213032210322203223032310323203233033110331203313033210332203323033310333203333111112111131112211123111321113311212112131122211223112321123311312113131132211323113321133312122121231213212133122131222212223122321223312313123221232312332123331313213133132221322313232132331332213323133321333322222322233223232233323233233333",
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "Generate De Bruijn Sequence",
|
||||
"args": [4, 5]
|
||||
}
|
||||
]
|
||||
}
|
||||
]);
|
44
tests/operations/tests/GetAllCasings.mjs
Normal file
44
tests/operations/tests/GetAllCasings.mjs
Normal file
|
@ -0,0 +1,44 @@
|
|||
/**
|
||||
* GetAllCasings tests.
|
||||
*
|
||||
* @author n1073645 [n1073645@gmail.com]
|
||||
* @copyright Crown Copyright 2020
|
||||
* @license Apache-2.0
|
||||
*/
|
||||
import TestRegister from "../../lib/TestRegister.mjs";
|
||||
|
||||
TestRegister.addTests([
|
||||
{
|
||||
name: "All casings of test",
|
||||
input: "test",
|
||||
expectedOutput: "test\nTest\ntEst\nTEst\nteSt\nTeSt\ntESt\nTESt\ntesT\nTesT\ntEsT\nTEsT\nteST\nTeST\ntEST\nTEST",
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "Get All Casings",
|
||||
"args": []
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "All casings of t",
|
||||
input: "t",
|
||||
expectedOutput: "t\nT",
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "Get All Casings",
|
||||
"args": []
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "All casings of null",
|
||||
input: "",
|
||||
expectedOutput: "",
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "Get All Casings",
|
||||
"args": []
|
||||
}
|
||||
]
|
||||
}
|
||||
]);
|
58
tests/operations/tests/Gunzip.mjs
Normal file
58
tests/operations/tests/Gunzip.mjs
Normal file
|
@ -0,0 +1,58 @@
|
|||
/**
|
||||
* Gunzip Tests.
|
||||
*
|
||||
* @author n1073645 [n1073645@gmail.com]
|
||||
*
|
||||
* @copyright Crown Copyright 2019
|
||||
* @license Apache-2.0
|
||||
*/
|
||||
|
||||
import TestRegister from "../../lib/TestRegister.mjs";
|
||||
|
||||
TestRegister.addTests([
|
||||
{
|
||||
name: "Gunzip: No comment, no checksum and no filename",
|
||||
input: "1f8b0800f7c8f85d00ff0dc9dd0180200804e0556ea8262848fb3dc588c6a7e76faa8aeedb726036c68d951f76bf9a0af8aae1f97d9c0c084b02509cbf8c2c000000",
|
||||
expectedOutput: "The quick brown fox jumped over the slow dog",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "From Hex",
|
||||
args: ["None"]
|
||||
},
|
||||
{
|
||||
op: "Gunzip",
|
||||
args: []
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "Gunzip: No comment, no checksum and filename",
|
||||
input: "1f8b080843c9f85d00ff66696c656e616d65000dc9dd0180200804e0556ea8262848fb3dc588c6a7e76faa8aeedb726036c68d951f76bf9a0af8aae1f97d9c0c084b02509cbf8c2c000000",
|
||||
expectedOutput: "The quick brown fox jumped over the slow dog",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "From Hex",
|
||||
args: ["None"]
|
||||
},
|
||||
{
|
||||
op: "Gunzip",
|
||||
args: []
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "Gunzip: Has a comment, no checksum and has a filename",
|
||||
input: "1f8b08186fc9f85d00ff66696c656e616d6500636f6d6d656e74000dc9dd0180200804e0556ea8262848fb3dc588c6a7e76faa8aeedb726036c68d951f76bf9a0af8aae1f97d9c0c084b02509cbf8c2c000000",
|
||||
expectedOutput: "The quick brown fox jumped over the slow dog",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "From Hex",
|
||||
args: ["None"]
|
||||
},
|
||||
{
|
||||
op: "Gunzip",
|
||||
args: []
|
||||
}
|
||||
]
|
||||
}
|
||||
]);
|
89
tests/operations/tests/Gzip.mjs
Normal file
89
tests/operations/tests/Gzip.mjs
Normal file
|
@ -0,0 +1,89 @@
|
|||
/**
|
||||
* Gzip Tests.
|
||||
*
|
||||
* @author n1073645 [n1073645@gmail.com]
|
||||
*
|
||||
* @copyright Crown Copyright 2019
|
||||
* @license Apache-2.0
|
||||
*/
|
||||
|
||||
import TestRegister from "../../lib/TestRegister.mjs";
|
||||
|
||||
TestRegister.addTests([
|
||||
{
|
||||
name: "Gzip: No comment, no checksum and no filename",
|
||||
input: "The quick brown fox jumped over the slow dog",
|
||||
expectedOutput: "0dc9dd0180200804e0556ea8262848fb3dc588c6a7e76faa8aeedb726036c68d951f76bf9a0af8aae1f97d9c0c084b02509cbf8c2c000000",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "Gzip",
|
||||
args: ["Dynamic Huffman Coding", "", "", false]
|
||||
},
|
||||
{
|
||||
op: "Drop bytes",
|
||||
args: [0, 10, false]
|
||||
},
|
||||
{
|
||||
op: "To Hex",
|
||||
args: ["None"]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "Gzip: No comment, no checksum and has a filename",
|
||||
input: "The quick brown fox jumped over the slow dog",
|
||||
expectedOutput: "636f6d6d656e74000dc9dd0180200804e0556ea8262848fb3dc588c6a7e76faa8aeedb726036c68d951f76bf9a0af8aae1f97d9c0c084b02509cbf8c2c000000",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "Gzip",
|
||||
args: ["Dynamic Huffman Coding", "comment", "", false]
|
||||
},
|
||||
{
|
||||
op: "Drop bytes",
|
||||
args: [0, 10, false]
|
||||
},
|
||||
{
|
||||
op: "To Hex",
|
||||
args: ["None"]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "Gzip: Has a comment, no checksum and no filename",
|
||||
input: "The quick brown fox jumped over the slow dog",
|
||||
expectedOutput: "636f6d6d656e74000dc9dd0180200804e0556ea8262848fb3dc588c6a7e76faa8aeedb726036c68d951f76bf9a0af8aae1f97d9c0c084b02509cbf8c2c000000",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "Gzip",
|
||||
args: ["Dynamic Huffman Coding", "", "comment", false]
|
||||
},
|
||||
{
|
||||
op: "Drop bytes",
|
||||
args: [0, 10, false]
|
||||
},
|
||||
{
|
||||
op: "To Hex",
|
||||
args: ["None"]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "Gzip: Has a comment, no checksum and has a filename",
|
||||
input: "The quick brown fox jumped over the slow dog",
|
||||
expectedOutput: "66696c656e616d6500636f6d6d656e74000dc9dd0180200804e0556ea8262848fb3dc588c6a7e76faa8aeedb726036c68d951f76bf9a0af8aae1f97d9c0c084b02509cbf8c2c000000",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "Gzip",
|
||||
args: ["Dynamic Huffman Coding", "filename", "comment", false]
|
||||
},
|
||||
{
|
||||
op: "Drop bytes",
|
||||
args: [0, 10, false]
|
||||
},
|
||||
{
|
||||
op: "To Hex",
|
||||
args: ["None"]
|
||||
}
|
||||
]
|
||||
},
|
||||
]);
|
33
tests/operations/tests/HASSH.mjs
Normal file
33
tests/operations/tests/HASSH.mjs
Normal file
|
@ -0,0 +1,33 @@
|
|||
/**
|
||||
* HASSH tests.
|
||||
*
|
||||
* @author n1474335 [n1474335@gmail.com]
|
||||
* @copyright Crown Copyright 2021
|
||||
* @license Apache-2.0
|
||||
*/
|
||||
import TestRegister from "../../lib/TestRegister.mjs";
|
||||
|
||||
TestRegister.addTests([
|
||||
{
|
||||
name: "HASSH Client Fingerprint",
|
||||
input: "000003140814c639665f5425dcb80bf9f0a048380a410000007e6469666669652d68656c6c6d616e2d67726f75702d65786368616e67652d7368613235362c6469666669652d68656c6c6d616e2d67726f75702d65786368616e67652d736861312c6469666669652d68656c6c6d616e2d67726f757031342d736861312c6469666669652d68656c6c6d616e2d67726f7570312d736861310000000f7373682d7273612c7373682d6473730000009d6165733132382d6374722c6165733139322d6374722c6165733235362d6374722c617263666f75723235362c617263666f75723132382c6165733132382d6362632c336465732d6362632c626c6f77666973682d6362632c636173743132382d6362632c6165733139322d6362632c6165733235362d6362632c617263666f75722c72696a6e6461656c2d636263406c797361746f722e6c69752e73650000009d6165733132382d6374722c6165733139322d6374722c6165733235362d6374722c617263666f75723235362c617263666f75723132382c6165733132382d6362632c336465732d6362632c626c6f77666973682d6362632c636173743132382d6362632c6165733139322d6362632c6165733235362d6362632c617263666f75722c72696a6e6461656c2d636263406c797361746f722e6c69752e736500000069686d61632d6d64352c686d61632d736861312c756d61632d3634406f70656e7373682e636f6d2c686d61632d726970656d643136302c686d61632d726970656d64313630406f70656e7373682e636f6d2c686d61632d736861312d39362c686d61632d6d64352d393600000069686d61632d6d64352c686d61632d736861312c756d61632d3634406f70656e7373682e636f6d2c686d61632d726970656d643136302c686d61632d726970656d64313630406f70656e7373682e636f6d2c686d61632d736861312d39362c686d61632d6d64352d39360000001a6e6f6e652c7a6c6962406f70656e7373682e636f6d2c7a6c69620000001a6e6f6e652c7a6c6962406f70656e7373682e636f6d2c7a6c6962000000000000000000000000000000000000000000",
|
||||
expectedOutput: "21b457a327ce7a2d4fce5ef2c42400bd",
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "HASSH Client Fingerprint",
|
||||
"args": ["Hex", "Hash digest"]
|
||||
}
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "HASSH Server Fingerprint",
|
||||
input: "0000027c0b142c7bb93a1da21c9e54f5862e60a5597c000000596469666669652d68656c6c6d616e2d67726f75702d65786368616e67652d736861312c6469666669652d68656c6c6d616e2d67726f757031342d736861312c6469666669652d68656c6c6d616e2d67726f7570312d736861310000000f7373682d7273612c7373682d647373000000876165733132382d6362632c336465732d6362632c626c6f77666973682d6362632c636173743132382d6362632c617263666f75722c6165733139322d6362632c6165733235362d6362632c72696a6e6461656c2d636263406c797361746f722e6c69752e73652c6165733132382d6374722c6165733139322d6374722c6165733235362d637472000000876165733132382d6362632c336465732d6362632c626c6f77666973682d6362632c636173743132382d6362632c617263666f75722c6165733139322d6362632c6165733235362d6362632c72696a6e6461656c2d636263406c797361746f722e6c69752e73652c6165733132382d6374722c6165733139322d6374722c6165733235362d63747200000055686d61632d6d64352c686d61632d736861312c686d61632d726970656d643136302c686d61632d726970656d64313630406f70656e7373682e636f6d2c686d61632d736861312d39362c686d61632d6d64352d393600000055686d61632d6d64352c686d61632d736861312c686d61632d726970656d643136302c686d61632d726970656d64313630406f70656e7373682e636f6d2c686d61632d736861312d39362c686d61632d6d64352d3936000000096e6f6e652c7a6c6962000000096e6f6e652c7a6c6962000000000000000000000000000000000000000000000000",
|
||||
expectedOutput: "f430cd6761697a6a658ee1d45ed22e49",
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "HASSH Server Fingerprint",
|
||||
"args": ["Hex", "Hash digest"]
|
||||
}
|
||||
],
|
||||
}
|
||||
]);
|
180
tests/operations/tests/HKDF.mjs
Normal file
180
tests/operations/tests/HKDF.mjs
Normal file
|
@ -0,0 +1,180 @@
|
|||
/**
|
||||
* @author mikecat
|
||||
* @copyright Crown Copyright 2023
|
||||
* @license Apache-2.0
|
||||
*/
|
||||
import TestRegister from "../../lib/TestRegister.mjs";
|
||||
|
||||
TestRegister.addTests([
|
||||
{
|
||||
"name": "HKDF: RFC5869 Test Case 1",
|
||||
"input": "0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b",
|
||||
"expectedOutput": "3cb25f25faacd57a90434f64d0362f2a2d2d0a90cf1a5a4c5db02d56ecc4c5bf34007208d5b887185865",
|
||||
"recipeConfig": [
|
||||
{
|
||||
"op": "From Hex",
|
||||
"args": ["None"],
|
||||
},
|
||||
{
|
||||
"op": "Derive HKDF key",
|
||||
"args": [
|
||||
{"option": "Hex", "string": "000102030405060708090a0b0c"},
|
||||
{"option": "Hex", "string": "f0f1f2f3f4f5f6f7f8f9"},
|
||||
"SHA256", "with salt", 42,
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
"name": "HKDF: RFC5869 Test Case 2",
|
||||
"input": "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f",
|
||||
"expectedOutput": "b11e398dc80327a1c8e7f78c596a49344f012eda2d4efad8a050cc4c19afa97c59045a99cac7827271cb41c65e590e09da3275600c2f09b8367793a9aca3db71cc30c58179ec3e87c14c01d5c1f3434f1d87",
|
||||
"recipeConfig": [
|
||||
{
|
||||
"op": "From Hex",
|
||||
"args": ["None"],
|
||||
},
|
||||
{
|
||||
"op": "Derive HKDF key",
|
||||
"args": [
|
||||
{"option": "Hex", "string": "606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeaf"},
|
||||
{"option": "Hex", "string": "b0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff"},
|
||||
"SHA256", "with salt", 82,
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
"name": "HKDF: RFC5869 Test Case 3",
|
||||
"input": "0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b",
|
||||
"expectedOutput": "8da4e775a563c18f715f802a063c5a31b8a11f5c5ee1879ec3454e5f3c738d2d9d201395faa4b61a96c8",
|
||||
"recipeConfig": [
|
||||
{
|
||||
"op": "From Hex",
|
||||
"args": ["None"],
|
||||
},
|
||||
{
|
||||
"op": "Derive HKDF key",
|
||||
"args": [
|
||||
{"option": "Hex", "string": ""},
|
||||
{"option": "Hex", "string": ""},
|
||||
"SHA256", "with salt", 42,
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
"name": "HKDF: RFC5869 Test Case 4",
|
||||
"input": "0b0b0b0b0b0b0b0b0b0b0b",
|
||||
"expectedOutput": "085a01ea1b10f36933068b56efa5ad81a4f14b822f5b091568a9cdd4f155fda2c22e422478d305f3f896",
|
||||
"recipeConfig": [
|
||||
{
|
||||
"op": "From Hex",
|
||||
"args": ["None"],
|
||||
},
|
||||
{
|
||||
"op": "Derive HKDF key",
|
||||
"args": [
|
||||
{"option": "Hex", "string": "000102030405060708090a0b0c"},
|
||||
{"option": "Hex", "string": "f0f1f2f3f4f5f6f7f8f9"},
|
||||
"SHA1", "with salt", 42,
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
"name": "HKDF: RFC5869 Test Case 5",
|
||||
"input": "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f",
|
||||
"expectedOutput": "0bd770a74d1160f7c9f12cd5912a06ebff6adcae899d92191fe4305673ba2ffe8fa3f1a4e5ad79f3f334b3b202b2173c486ea37ce3d397ed034c7f9dfeb15c5e927336d0441f4c4300e2cff0d0900b52d3b4",
|
||||
"recipeConfig": [
|
||||
{
|
||||
"op": "From Hex",
|
||||
"args": ["None"],
|
||||
},
|
||||
{
|
||||
"op": "Derive HKDF key",
|
||||
"args": [
|
||||
{"option": "Hex", "string": "606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeaf"},
|
||||
{"option": "Hex", "string": "b0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff"},
|
||||
"SHA1", "with salt", 82,
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
"name": "HKDF: RFC5869 Test Case 6",
|
||||
"input": "0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b",
|
||||
"expectedOutput": "0ac1af7002b3d761d1e55298da9d0506b9ae52057220a306e07b6b87e8df21d0ea00033de03984d34918",
|
||||
"recipeConfig": [
|
||||
{
|
||||
"op": "From Hex",
|
||||
"args": ["None"],
|
||||
},
|
||||
{
|
||||
"op": "Derive HKDF key",
|
||||
"args": [
|
||||
{"option": "Hex", "string": ""},
|
||||
{"option": "Hex", "string": ""},
|
||||
"SHA1", "with salt", 42,
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
"name": "HKDF: RFC5869 Test Case 7",
|
||||
"input": "0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c",
|
||||
"expectedOutput": "2c91117204d745f3500d636a62f64f0ab3bae548aa53d423b0d1f27ebba6f5e5673a081d70cce7acfc48",
|
||||
"recipeConfig": [
|
||||
{
|
||||
"op": "From Hex",
|
||||
"args": ["None"],
|
||||
},
|
||||
{
|
||||
"op": "Derive HKDF key",
|
||||
"args": [
|
||||
{"option": "Hex", "string": ""},
|
||||
{"option": "Hex", "string": ""},
|
||||
"SHA1", "no salt", 42,
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
"name": "HKDF: RFC5869 Test Case 1 with skip extract",
|
||||
"input": "077709362c2e32df0ddc3f0dc47bba6390b6c73bb50f9c3122ec844ad7c2b3e5",
|
||||
"expectedOutput": "3cb25f25faacd57a90434f64d0362f2a2d2d0a90cf1a5a4c5db02d56ecc4c5bf34007208d5b887185865",
|
||||
"recipeConfig": [
|
||||
{
|
||||
"op": "From Hex",
|
||||
"args": ["None"],
|
||||
},
|
||||
{
|
||||
"op": "Derive HKDF key",
|
||||
"args": [
|
||||
{"option": "Hex", "string": ""},
|
||||
{"option": "Hex", "string": "f0f1f2f3f4f5f6f7f8f9"},
|
||||
"SHA256", "skip", 42,
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
"name": "HKDF: too large L",
|
||||
"input": "0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b",
|
||||
"expectedOutput": "L too large (maximum length for SHA256 is 8160)",
|
||||
"recipeConfig": [
|
||||
{
|
||||
"op": "From Hex",
|
||||
"args": ["None"],
|
||||
},
|
||||
{
|
||||
"op": "Derive HKDF key",
|
||||
"args": [
|
||||
{"option": "Hex", "string": "000102030405060708090a0b0c"},
|
||||
{"option": "Hex", "string": "f0f1f2f3f4f5f6f7f8f9"},
|
||||
"SHA256", "with salt", 8161,
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
]);
|
|
@ -5,7 +5,7 @@
|
|||
* @copyright Crown Copyright 2017
|
||||
* @license Apache-2.0
|
||||
*/
|
||||
import TestRegister from "../TestRegister";
|
||||
import TestRegister from "../../lib/TestRegister.mjs";
|
||||
|
||||
TestRegister.addTests([
|
||||
{
|
||||
|
@ -345,7 +345,7 @@ TestRegister.addTests([
|
|||
recipeConfig: [
|
||||
{
|
||||
"op": "Snefru",
|
||||
"args": ["2", "128"]
|
||||
"args": ["128", "2"]
|
||||
}
|
||||
]
|
||||
},
|
||||
|
@ -356,7 +356,7 @@ TestRegister.addTests([
|
|||
recipeConfig: [
|
||||
{
|
||||
"op": "Snefru",
|
||||
"args": ["4", "128"]
|
||||
"args": ["128", "4"]
|
||||
}
|
||||
]
|
||||
},
|
||||
|
@ -367,7 +367,7 @@ TestRegister.addTests([
|
|||
recipeConfig: [
|
||||
{
|
||||
"op": "Snefru",
|
||||
"args": ["8", "128"]
|
||||
"args": ["128", "8"]
|
||||
}
|
||||
]
|
||||
},
|
||||
|
@ -378,7 +378,7 @@ TestRegister.addTests([
|
|||
recipeConfig: [
|
||||
{
|
||||
"op": "Snefru",
|
||||
"args": ["2", "256"]
|
||||
"args": ["256", "2"]
|
||||
}
|
||||
]
|
||||
},
|
||||
|
@ -389,7 +389,7 @@ TestRegister.addTests([
|
|||
recipeConfig: [
|
||||
{
|
||||
"op": "Snefru",
|
||||
"args": ["4", "256"]
|
||||
"args": ["256", "4"]
|
||||
}
|
||||
]
|
||||
},
|
||||
|
@ -400,7 +400,18 @@ TestRegister.addTests([
|
|||
recipeConfig: [
|
||||
{
|
||||
"op": "Snefru",
|
||||
"args": ["8", "256"]
|
||||
"args": ["256", "8"]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "SM3 256 64",
|
||||
input: "Hello, World!",
|
||||
expectedOutput: "7ed26cbf0bee4ca7d55c1e64714c4aa7d1f163089ef5ceb603cd102c81fbcbc5",
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "SM3",
|
||||
"args": ["256", "64"]
|
||||
}
|
||||
]
|
||||
},
|
||||
|
@ -1033,7 +1044,73 @@ TestRegister.addTests([
|
|||
}
|
||||
]
|
||||
},
|
||||
/*{ // This takes a LONG time to run (over a minute usually).
|
||||
{
|
||||
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: ["GOST 28147 (1994)", "256", "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: ["GOST 28147 (1994)", "256", "D-A"]
|
||||
}
|
||||
]
|
||||
},
|
||||
/* { // This takes a LONG time to run (over a minute usually).
|
||||
name: "Scrypt: RFC test vector 4",
|
||||
input: "pleaseletmein",
|
||||
expectedOutput: "2101cb9b6a511aaeaddbbe09cf70f881ec568d574a2ffd4dabe5ee9820adaa478e56fd8f4ba5d09ffa1c6d927c40f4c337304049e8a952fbcbf45c6fa77a41a4",
|
||||
|
@ -1049,5 +1126,37 @@ TestRegister.addTests([
|
|||
]
|
||||
}
|
||||
]
|
||||
},*/
|
||||
}, */
|
||||
{
|
||||
name: "Argon2",
|
||||
input: "argon2password",
|
||||
expectedOutput: "$argon2i$v=19$m=4096,t=3,p=1$c29tZXNhbHQ$s43my9eBljQADuF/LWCG8vGqwAJzOorKQ0Yog8jFvbw",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "Argon2",
|
||||
args: [
|
||||
{"option": "UTF8", "string": "somesalt"},
|
||||
3,
|
||||
4096,
|
||||
1,
|
||||
32,
|
||||
"Argon2i",
|
||||
"Encoded hash"
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "Argon2 compare",
|
||||
input: "argon2password",
|
||||
expectedOutput: "Match: argon2password",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "Argon2 compare",
|
||||
args: [
|
||||
"$argon2i$v=19$m=4096,t=3,p=1$c29tZXNhbHQ$s43my9eBljQADuF/LWCG8vGqwAJzOorKQ0Yog8jFvbw"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]);
|
||||
|
|
|
@ -5,13 +5,24 @@
|
|||
* @copyright Crown Copyright 2018
|
||||
* @license Apache-2.0
|
||||
*/
|
||||
import TestRegister from "../TestRegister";
|
||||
import TestRegister from "../../lib/TestRegister.mjs";
|
||||
|
||||
TestRegister.addTests([
|
||||
{
|
||||
name: "Haversine distance",
|
||||
input: "51.487263,-0.124323, 38.9517,-77.1467",
|
||||
expectedOutput: "5619355.701829259",
|
||||
expectedOutput: "5902542.836307819",
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "Haversine distance",
|
||||
"args": []
|
||||
}
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "Haversine distance, zero distance",
|
||||
input: "51.487263,-0.124323, 51.487263,-0.124323",
|
||||
expectedOutput: "0",
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "Haversine distance",
|
||||
|
|
110
tests/operations/tests/Hex.mjs
Normal file
110
tests/operations/tests/Hex.mjs
Normal file
|
@ -0,0 +1,110 @@
|
|||
import TestRegister from "../../lib/TestRegister.mjs";
|
||||
|
||||
TestRegister.addTests([
|
||||
{
|
||||
name: "ASCII to Hex stream",
|
||||
input: "aberystwyth",
|
||||
expectedOutput: "6162657279737477797468",
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "To Hex",
|
||||
"args": [
|
||||
"None",
|
||||
0
|
||||
]
|
||||
},
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "ASCII to Hex with colon deliminator ",
|
||||
input: "aberystwyth",
|
||||
expectedOutput: "61:62:65:72:79:73:74:77:79:74:68",
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "To Hex",
|
||||
"args": [
|
||||
"Colon",
|
||||
0
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "ASCII to 0x Hex with comma",
|
||||
input: "aberystwyth",
|
||||
expectedOutput: "0x61,0x62,0x65,0x72,0x79,0x73,0x74,0x77,0x79,0x74,0x68",
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "To Hex",
|
||||
"args": [
|
||||
"0x with comma",
|
||||
0
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "ASCII to 0x Hex with comma and line breaks",
|
||||
input: "aberystwyth",
|
||||
expectedOutput: "0x61,0x62,0x65,0x72,\n0x79,0x73,0x74,0x77,\n0x79,0x74,0x68",
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "To Hex",
|
||||
"args": [
|
||||
"0x with comma",
|
||||
4
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "Hex stream to UTF-8",
|
||||
input: "e69591e69591e5ada9e5ad90",
|
||||
expectedOutput: "救救孩子",
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "From Hex",
|
||||
"args": [
|
||||
"Auto"
|
||||
]
|
||||
}
|
||||
]
|
||||
|
||||
},
|
||||
{
|
||||
name: "Multiline 0x hex to ASCII",
|
||||
input: "0x49,0x20,0x73,0x61,0x77,0x20,0x6d,0x79,0x73,0x65,0x6c,0x66,0x20,0x73,0x69,\
|
||||
0x74,0x74,0x69,0x6e,0x67,0x20,0x69,0x6e,0x20,0x74,0x68,0x65,0x20,0x63,0x72,\
|
||||
0x6f,0x74,0x63,0x68,0x20,0x6f,0x66,0x20,0x74,0x68,0x65,0x20,0x74,0x68,0x69,\
|
||||
0x73,0x20,0x66,0x69,0x67,0x20,0x74,0x72,0x65,0x65,0x2c,0x20,0x73,0x74,0x61,\
|
||||
0x72,0x76,0x69,0x6e,0x67,0x20,0x74,0x6f,0x20,0x64,0x65,0x61,0x74,0x68,0x2c,\
|
||||
0x20,0x6a,0x75,0x73,0x74,0x20,0x62,0x65,0x63,0x61,0x75,0x73,0x65,0x20,0x49,\
|
||||
0x20,0x63,0x6f,0x75,0x6c,0x64,0x6e,0x27,0x74,0x20,0x6d,0x61,0x6b,0x65,0x20,\
|
||||
0x75,0x70,0x20,0x6d,0x79,0x20,0x6d,0x69,0x6e,0x64,0x20,0x77,0x68,0x69,0x63,\
|
||||
0x68,0x20,0x6f,0x66,0x20,0x74,0x68,0x65,0x20,0x66,0x69,0x67,0x73,0x20,0x49,\
|
||||
0x20,0x77,0x6f,0x75,0x6c,0x64,0x20,0x63,0x68,0x6f,0x6f,0x73,0x65,0x2e",
|
||||
expectedOutput: "I saw myself sitting in the crotch of the this fig tree, starving to death, just because I couldn't make up my mind which of the figs I would choose.",
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "From Hex",
|
||||
"args": [
|
||||
"Auto"
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "0x with Comma to Ascii",
|
||||
input: "0x74,0x65,0x73,0x74,0x20,0x73,0x74,0x72,0x69,0x6e,0x67",
|
||||
expectedOutput: "test string",
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "From Hex",
|
||||
"args": [
|
||||
"0x with comma"
|
||||
]
|
||||
}
|
||||
]
|
||||
|
||||
},
|
||||
]);
|
|
@ -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",
|
||||
|
|
File diff suppressed because one or more lines are too long
22
tests/operations/tests/IndexOfCoincidence.mjs
Normal file
22
tests/operations/tests/IndexOfCoincidence.mjs
Normal 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": []
|
||||
},
|
||||
],
|
||||
},
|
||||
]);
|
55
tests/operations/tests/JA3Fingerprint.mjs
Normal file
55
tests/operations/tests/JA3Fingerprint.mjs
Normal file
|
@ -0,0 +1,55 @@
|
|||
/**
|
||||
* JA3Fingerprint tests.
|
||||
*
|
||||
* @author n1474335 [n1474335@gmail.com]
|
||||
* @copyright Crown Copyright 2021
|
||||
* @license Apache-2.0
|
||||
*/
|
||||
import TestRegister from "../../lib/TestRegister.mjs";
|
||||
|
||||
TestRegister.addTests([
|
||||
{
|
||||
name: "JA3 Fingerprint: TLS 1.0",
|
||||
input: "16030100a4010000a00301543dd2dd48f517ca9a93b1e599f019fdece704a23e86c1dcac588427abbaddf200005cc014c00a0039003800880087c00fc00500350084c012c00800160013c00dc003000ac013c00900330032009a009900450044c00ec004002f009600410007c011c007c00cc002000500040015001200090014001100080006000300ff0100001b000b000403000102000a000600040018001700230000000f000101",
|
||||
expectedOutput: "503053a0c5b2bd9b9334bf7f3d3b8852",
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "JA3 Fingerprint",
|
||||
"args": ["Hex", "Hash digest"]
|
||||
}
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "JA3 Fingerprint: TLS 1.1",
|
||||
input: "16030100a4010000a00302543dd2ed907e47d0086f34bee2c52dd6ccd8de63ba9387f5e810b09d9d49b38000005cc014c00a0039003800880087c00fc00500350084c012c00800160013c00dc003000ac013c00900330032009a009900450044c00ec004002f009600410007c011c007c00cc002000500040015001200090014001100080006000300ff0100001b000b000403000102000a000600040018001700230000000f000101",
|
||||
expectedOutput: "a314eb64cee6cb832aaaa372c8295bab",
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "JA3 Fingerprint",
|
||||
"args": ["Hex", "Hash digest"]
|
||||
}
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "JA3 Fingerprint: TLS 1.2",
|
||||
input: "1603010102010000fe0303543dd3283283692d85f9416b5ccc65d2aafca45c6530b3c6eafbf6d371b6a015000094c030c02cc028c024c014c00a00a3009f006b006a0039003800880087c032c02ec02ac026c00fc005009d003d00350084c012c00800160013c00dc003000ac02fc02bc027c023c013c00900a2009e0067004000330032009a009900450044c031c02dc029c025c00ec004009c003c002f009600410007c011c007c00cc002000500040015001200090014001100080006000300ff01000041000b000403000102000a000600040018001700230000000d002200200601060206030501050205030401040204030301030203030201020202030101000f000101",
|
||||
expectedOutput: "c1a36e1a870786cc75edddc0009eaf3a",
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "JA3 Fingerprint",
|
||||
"args": ["Hex", "Hash digest"]
|
||||
}
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "JA3 Fingerprint: TLS 1.3",
|
||||
input: "1603010200010001fc03034355d402c132771a9386b6e9994ae37069e0621af504c26673b1343843c21d8d0000264a4a130113021303c02bc02fc02cc030cca9cca8cc14cc13c013c014009c009d002f0035000a010001addada0000ff01000100000000180016000013626c6f672e636c6f7564666c6172652e636f6d0017000000230000000d00140012040308040401050308050501080606010201000500050100000000001200000010000e000c02683208687474702f312e3175500000000b000201000028002b00295a5a000100001d0020cf78b9167af054b922a96752b43973107b2a57766357dd288b2b42ab5df30e08002d00020101002b000b0acaca7f12030303020301000a000a00085a5a001d001700180a0a000100001500e4000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
|
||||
expectedOutput: "4826a90ec2daf4f7b4b64cc1c8bd343b",
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "JA3 Fingerprint",
|
||||
"args": ["Hex", "Hash digest"]
|
||||
}
|
||||
],
|
||||
},
|
||||
]);
|
57
tests/operations/tests/JA3SFingerprint.mjs
Normal file
57
tests/operations/tests/JA3SFingerprint.mjs
Normal file
|
@ -0,0 +1,57 @@
|
|||
/**
|
||||
* JA3SFingerprint tests.
|
||||
*
|
||||
* @author n1474335 [n1474335@gmail.com]
|
||||
* @copyright Crown Copyright 2021
|
||||
* @license Apache-2.0
|
||||
*/
|
||||
import TestRegister from "../../lib/TestRegister.mjs";
|
||||
|
||||
TestRegister.addTests([
|
||||
{
|
||||
name: "JA3S Fingerprint: TLS 1.0",
|
||||
input: "160301003d020000390301543dd2ddedbfe33895bd6bc676a3fa6b9fe5773a6e04d5476d1af3bcbc1dcbbb00c011000011ff01000100000b00040300010200230000",
|
||||
expectedOutput: "bed95e1b525d2f41db3a6d68fac5b566",
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "JA3S Fingerprint",
|
||||
"args": ["Hex", "Hash digest"]
|
||||
}
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "JA3S Fingerprint: TLS 1.1",
|
||||
input: "160302003d020000390302543dd2ed88131999a0120d36c14a4139671d75aae3d7d7779081d3cf7dd7725a00c013000011ff01000100000b00040300010200230000",
|
||||
expectedOutput: "130fac2dc19b142500acb0abc63b6379",
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "JA3S Fingerprint",
|
||||
"args": ["Hex", "Hash digest"]
|
||||
}
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "JA3S Fingerprint: TLS 1.2",
|
||||
input: "160303003d020000390303543dd328b38b445686739d58fab733fa23838f575e0e5ad9a1b9baace6cc3b4100c02f000011ff01000100000b00040300010200230000",
|
||||
expectedOutput: "ccc514751b175866924439bdbb5bba34",
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "JA3S Fingerprint",
|
||||
"args": ["Hex", "Hash digest"]
|
||||
}
|
||||
],
|
||||
},
|
||||
// This Server Hello was based on draft 18 of the TLS1.3 spec which does not include a Session ID field, leading it to fail.
|
||||
// The published version of TLS1.3 does require a legacy Session ID field (even if it is empty).
|
||||
// {
|
||||
// name: "JA3S Fingerprint: TLS 1.3",
|
||||
// input: "16030100520200004e7f123ef1609fd3f4fa8668aac5822d500fb0639b22671d0fb7258597355795511bf61301002800280024001d0020ae0e282a3b7a463e71064ecbaf671586e979b0edbebf7a4735c31678c70f660c",
|
||||
// expectedOutput: "986ae432c402479fe7a0c6fbe02164c1",
|
||||
// recipeConfig: [
|
||||
// {
|
||||
// "op": "JA3S Fingerprint",
|
||||
// "args": ["Hex", "Hash digest"]
|
||||
// }
|
||||
// ],
|
||||
// },
|
||||
]);
|
|
@ -6,7 +6,7 @@
|
|||
* @copyright Crown Copyright 2018
|
||||
* @license Apache-2.0
|
||||
*/
|
||||
import TestRegister from "../TestRegister";
|
||||
import TestRegister from "../../lib/TestRegister.mjs";
|
||||
|
||||
TestRegister.addTests([
|
||||
{
|
||||
|
@ -16,7 +16,7 @@ TestRegister.addTests([
|
|||
recipeConfig: [
|
||||
{
|
||||
op: "JSON Beautify",
|
||||
args: [" ", false],
|
||||
args: [" ", false, false],
|
||||
},
|
||||
],
|
||||
},
|
||||
|
@ -27,7 +27,7 @@ TestRegister.addTests([
|
|||
recipeConfig: [
|
||||
{
|
||||
op: "JSON Beautify",
|
||||
args: [" ", false],
|
||||
args: [" ", false, false],
|
||||
},
|
||||
],
|
||||
},
|
||||
|
@ -38,8 +38,12 @@ TestRegister.addTests([
|
|||
recipeConfig: [
|
||||
{
|
||||
op: "JSON Beautify",
|
||||
args: [" ", false],
|
||||
args: [" ", false, false],
|
||||
},
|
||||
{
|
||||
op: "HTML To Text",
|
||||
args: []
|
||||
}
|
||||
],
|
||||
},
|
||||
{
|
||||
|
@ -49,7 +53,7 @@ TestRegister.addTests([
|
|||
recipeConfig: [
|
||||
{
|
||||
op: "JSON Beautify",
|
||||
args: [" ", false],
|
||||
args: [" ", false, false],
|
||||
},
|
||||
],
|
||||
},
|
||||
|
@ -60,7 +64,7 @@ TestRegister.addTests([
|
|||
recipeConfig: [
|
||||
{
|
||||
op: "JSON Beautify",
|
||||
args: [" ", false],
|
||||
args: [" ", false, false],
|
||||
},
|
||||
],
|
||||
},
|
||||
|
@ -71,7 +75,7 @@ TestRegister.addTests([
|
|||
recipeConfig: [
|
||||
{
|
||||
op: "JSON Beautify",
|
||||
args: [" ", false],
|
||||
args: [" ", false, false],
|
||||
},
|
||||
],
|
||||
},
|
||||
|
@ -82,7 +86,7 @@ TestRegister.addTests([
|
|||
recipeConfig: [
|
||||
{
|
||||
op: "JSON Beautify",
|
||||
args: ["\t", false],
|
||||
args: ["\t", false, false],
|
||||
},
|
||||
],
|
||||
},
|
||||
|
@ -93,8 +97,12 @@ TestRegister.addTests([
|
|||
recipeConfig: [
|
||||
{
|
||||
op: "JSON Beautify",
|
||||
args: [" ", false],
|
||||
args: [" ", false, false],
|
||||
},
|
||||
{
|
||||
op: "HTML To Text",
|
||||
args: []
|
||||
}
|
||||
],
|
||||
},
|
||||
{
|
||||
|
@ -104,8 +112,12 @@ TestRegister.addTests([
|
|||
recipeConfig: [
|
||||
{
|
||||
op: "JSON Beautify",
|
||||
args: ["\t", false],
|
||||
args: ["\t", false, false],
|
||||
},
|
||||
{
|
||||
op: "HTML To Text",
|
||||
args: []
|
||||
}
|
||||
],
|
||||
},
|
||||
{
|
||||
|
@ -115,8 +127,12 @@ TestRegister.addTests([
|
|||
recipeConfig: [
|
||||
{
|
||||
op: "JSON Beautify",
|
||||
args: ["\t", true],
|
||||
args: ["\t", true, false],
|
||||
},
|
||||
{
|
||||
op: "HTML To Text",
|
||||
args: []
|
||||
}
|
||||
],
|
||||
},
|
||||
]);
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
* @copyright Crown Copyright 2018
|
||||
* @license Apache-2.0
|
||||
*/
|
||||
import TestRegister from "../TestRegister";
|
||||
import TestRegister from "../../lib/TestRegister.mjs";
|
||||
|
||||
TestRegister.addTests([
|
||||
{
|
||||
|
|
170
tests/operations/tests/JSONtoCSV.mjs
Normal file
170
tests/operations/tests/JSONtoCSV.mjs
Normal file
|
@ -0,0 +1,170 @@
|
|||
/**
|
||||
* 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: boolean and null as values",
|
||||
input: JSON.stringify({a: false, b: null, c: 3}),
|
||||
expectedOutput: "a,b,c\r\nfalse,null,3\r\n",
|
||||
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"]
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "JSON to CSV: nested JSON",
|
||||
input: JSON.stringify({a: 1, b: {c: 2, d: 3}}),
|
||||
expectedOutput: "a,b.c,b.d\r\n1,2,3\r\n",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "JSON to CSV",
|
||||
args: [",", "\\r\\n"]
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "JSON to CSV: nested array",
|
||||
input: JSON.stringify({a: 1, b: [2, 3]}),
|
||||
expectedOutput: "a,b.0,b.1\r\n1,2,3\r\n",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "JSON to CSV",
|
||||
args: [",", "\\r\\n"]
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "JSON to CSV: nested JSON, nested array",
|
||||
input: JSON.stringify({a: 1, b: {c: [2, 3], d: 4}}),
|
||||
expectedOutput: "a,b.c.0,b.c.1,b.d\r\n1,2,3,4\r\n",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "JSON to CSV",
|
||||
args: [",", "\\r\\n"]
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "JSON to CSV: nested array, nested JSON",
|
||||
input: JSON.stringify({a: 1, b: [{c: 3, d: 4}]}),
|
||||
expectedOutput: "a,b.0.c,b.0.d\r\n1,3,4\r\n",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "JSON to CSV",
|
||||
args: [",", "\\r\\n"]
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "JSON to CSV: nested array, nested array",
|
||||
input: JSON.stringify({a: 1, b: [[2, 3]]}),
|
||||
expectedOutput: "a,b.0.0,b.0.1\r\n1,2,3\r\n",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "JSON to CSV",
|
||||
args: [",", "\\r\\n"]
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "JSON to CSV: nested JSON, nested JSON",
|
||||
input: JSON.stringify({a: 1, b: { c: { d: 2, e: 3}}}),
|
||||
expectedOutput: "a,b.c.d,b.c.e\r\n1,2,3\r\n",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "JSON to CSV",
|
||||
args: [",", "\\r\\n"]
|
||||
},
|
||||
],
|
||||
}
|
||||
]);
|
|
@ -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",
|
||||
|
|
|
@ -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",
|
||||
|
|
|
@ -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",
|
||||
|
@ -14,10 +14,9 @@ const outputObject = JSON.stringify({
|
|||
iat: 1
|
||||
}, null, 4);
|
||||
|
||||
const invalidAlgorithm = "JsonWebTokenError: invalid algorithm";
|
||||
|
||||
const hsKey = "secret_cat";
|
||||
const rsKey = `-----BEGIN RSA PRIVATE KEY-----
|
||||
/* Retaining private key as a comment
|
||||
const rsPriv = `-----BEGIN RSA PRIVATE KEY-----
|
||||
MIICWwIBAAKBgQDdlatRjRjogo3WojgGHFHYLugdUWAY9iR3fy4arWNA1KoS8kVw
|
||||
33cJibXr8bvwUAUparCwlvdbH6dvEOfou0/gCFQsHUfQrSDv+MuSUMAe8jzKE4qW
|
||||
+jK+xQU9a03GUnKHkkle+Q0pX/g6jXZ7r1/xAK5Do2kQ+X5xK9cipRgEKwIDAQAB
|
||||
|
@ -32,11 +31,24 @@ fSSjAkLRi54PKJ8TFUeOP15h9sQzydI8zJU+upvDEKZsZc/UhT/SySDOxQ4G/523
|
|||
Y0sz/OZtSWcol/UMgQJALesy++GdvoIDLfJX5GBQpuFgFenRiRDabxrE9MNUZ2aP
|
||||
FaFp+DyAe+b4nDwuJaW2LURbr8AEZga7oQj0uYxcYw==
|
||||
-----END RSA PRIVATE KEY-----`;
|
||||
const esKey = `-----BEGIN PRIVATE KEY-----
|
||||
*/
|
||||
const rsPub = `-----BEGIN PUBLIC KEY-----
|
||||
MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDdlatRjRjogo3WojgGHFHYLugd
|
||||
UWAY9iR3fy4arWNA1KoS8kVw33cJibXr8bvwUAUparCwlvdbH6dvEOfou0/gCFQs
|
||||
HUfQrSDv+MuSUMAe8jzKE4qW+jK+xQU9a03GUnKHkkle+Q0pX/g6jXZ7r1/xAK5D
|
||||
o2kQ+X5xK9cipRgEKwIDAQAB
|
||||
-----END PUBLIC KEY-----`;
|
||||
/* Retaining private key as a comment
|
||||
const esPriv = `-----BEGIN PRIVATE KEY-----
|
||||
MIGHAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBG0wawIBAQQgevZzL1gdAFr88hb2
|
||||
OF/2NxApJCzGCEDdfSp6VQO30hyhRANCAAQRWz+jn65BtOMvdyHKcvjBeBSDZH2r
|
||||
1RTwjmYSi9R/zpBnuQ4EiMnCqfMPWiZqB4QdbAd0E7oH50VpuZ1P087G
|
||||
-----END PRIVATE KEY-----`;
|
||||
*/
|
||||
const esPub = `-----BEGIN PUBLIC KEY-----
|
||||
MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEEVs/o5+uQbTjL3chynL4wXgUg2R9
|
||||
q9UU8I5mEovUf86QZ7kOBIjJwqnzD1omageEHWwHdBO6B+dFabmdT9POxg==
|
||||
-----END PUBLIC KEY-----`;
|
||||
|
||||
TestRegister.addTests([
|
||||
{
|
||||
|
@ -53,22 +65,22 @@ TestRegister.addTests([
|
|||
{
|
||||
name: "JWT Verify: RS",
|
||||
input: "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJTdHJpbmciOiJTb21lU3RyaW5nIiwiTnVtYmVyIjo0MiwiaWF0IjoxfQ.MjEJhtZk2nXzigi24piMzANmrj3mILHJcDl0xOjl5a8EgdKVL1oaMEjTkMQp5RA8YrqeRBFaX-BGGCKOXn5zPY1DJwWsBUyN9C-wGR2Qye0eogH_3b4M9EW00TPCUPXm2rx8URFj7Wg9VlsmrGzLV2oKkPgkVxuFSxnpO3yjn1Y",
|
||||
expectedOutput: invalidAlgorithm,
|
||||
expectedOutput: outputObject,
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "JWT Verify",
|
||||
args: [rsKey],
|
||||
args: [rsPub],
|
||||
}
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "JWT Verify: ES",
|
||||
input: "eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCJ9.eyJTdHJpbmciOiJTb21lU3RyaW5nIiwiTnVtYmVyIjo0MiwiaWF0IjoxfQ.WkECT51jSfpRkcpQ4x0h5Dwe7CFBI6u6Et2gWp91HC7mpN_qCFadRpsvJLtKubm6cJTLa68xtei0YrDD8fxIUA",
|
||||
expectedOutput: invalidAlgorithm,
|
||||
expectedOutput: outputObject,
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "JWT Verify",
|
||||
args: [esKey],
|
||||
args: [esPub],
|
||||
}
|
||||
],
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
* @copyright Crown Copyright 2018
|
||||
* @license Apache-2.0
|
||||
*/
|
||||
import TestRegister from "../TestRegister";
|
||||
import TestRegister from "../../lib/TestRegister.mjs";
|
||||
|
||||
TestRegister.addTests([
|
||||
{
|
||||
|
|
45
tests/operations/tests/LS47.mjs
Normal file
45
tests/operations/tests/LS47.mjs
Normal file
|
@ -0,0 +1,45 @@
|
|||
/**
|
||||
* LS47 tests.
|
||||
*
|
||||
* @author n1073645 [n1073645@gmail.com]
|
||||
*
|
||||
* @copyright Crown Copyright 2020
|
||||
* @license Apache-2.0
|
||||
*/
|
||||
import TestRegister from "../../lib/TestRegister.mjs";
|
||||
|
||||
TestRegister.addTests([
|
||||
{
|
||||
name: "LS47 Encrypt",
|
||||
input: "thequickbrownfoxjumped",
|
||||
expectedOutput: "(,t74ci78cp/8trx*yesu:alp1wqy",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "LS47 Encrypt",
|
||||
args: ["helloworld", 0, "test"],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "LS47 Decrypt",
|
||||
input: "(,t74ci78cp/8trx*yesu:alp1wqy",
|
||||
expectedOutput: "thequickbrownfoxjumped---test",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "LS47 Decrypt",
|
||||
args: ["helloworld", 0],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "LS47 Encrypt",
|
||||
input: "thequickbrownfoxjumped",
|
||||
expectedOutput: "Letter H is not included in LS47",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "LS47 Encrypt",
|
||||
args: ["Helloworld", 0, "test"],
|
||||
},
|
||||
],
|
||||
}
|
||||
]);
|
22
tests/operations/tests/LZNT1Decompress.mjs
Normal file
22
tests/operations/tests/LZNT1Decompress.mjs
Normal file
|
@ -0,0 +1,22 @@
|
|||
/**
|
||||
* LZNT1 Decompress tests.
|
||||
*
|
||||
* @author 0xThiebaut [thiebaut.dev]
|
||||
* @copyright Crown Copyright 2023
|
||||
* @license Apache-2.0
|
||||
*/
|
||||
import TestRegister from "../../lib/TestRegister.mjs";
|
||||
|
||||
TestRegister.addTests([
|
||||
{
|
||||
name: "LZNT1 Decompress",
|
||||
input: "\x1a\xb0\x00compress\x00edtestda\x04ta\x07\x88alot",
|
||||
expectedOutput: "compressedtestdatacompressedalot",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "LZNT1 Decompress",
|
||||
args: []
|
||||
}
|
||||
],
|
||||
}
|
||||
]);
|
33
tests/operations/tests/LZString.mjs
Normal file
33
tests/operations/tests/LZString.mjs
Normal file
|
@ -0,0 +1,33 @@
|
|||
/**
|
||||
* LZString tests.
|
||||
*
|
||||
* @author crespyl [peter@crespyl.net]
|
||||
* @copyright Peter Jacobs 2021
|
||||
* @license Apache-2.0
|
||||
*/
|
||||
import TestRegister from "../../lib/TestRegister.mjs";
|
||||
|
||||
TestRegister.addTests([
|
||||
{
|
||||
name: "LZString Compress To Base64",
|
||||
input: "hello world",
|
||||
expectedOutput: "BYUwNmD2AEDukCcwBMg=",
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "LZString Compress",
|
||||
"args": ["Base64"]
|
||||
}
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "LZString Decompress From Base64",
|
||||
input: "BYUwNmD2AEDukCcwBMg=",
|
||||
expectedOutput: "hello world",
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "LZString Decompress",
|
||||
"args": ["Base64"]
|
||||
}
|
||||
],
|
||||
}
|
||||
]);
|
165
tests/operations/tests/LevenshteinDistance.mjs
Normal file
165
tests/operations/tests/LevenshteinDistance.mjs
Normal file
|
@ -0,0 +1,165 @@
|
|||
/**
|
||||
* @author mikecat
|
||||
* @copyright Crown Copyright 2023
|
||||
* @license Apache-2.0
|
||||
*/
|
||||
import TestRegister from "../../lib/TestRegister.mjs";
|
||||
|
||||
TestRegister.addTests([
|
||||
{
|
||||
"name": "Levenshtein Distance: Wikipedia example 1",
|
||||
"input": "kitten\nsitting",
|
||||
"expectedOutput": "3",
|
||||
"recipeConfig": [
|
||||
{
|
||||
"op": "Levenshtein Distance",
|
||||
"args": [
|
||||
"\\n", 1, 1, 1,
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
"name": "Levenshtein Distance: Wikipedia example 2",
|
||||
"input": "saturday\nsunday",
|
||||
"expectedOutput": "3",
|
||||
"recipeConfig": [
|
||||
{
|
||||
"op": "Levenshtein Distance",
|
||||
"args": [
|
||||
"\\n", 1, 1, 1,
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
"name": "Levenshtein Distance: Wikipedia example 1 with substitution cost 2",
|
||||
"input": "kitten\nsitting",
|
||||
"expectedOutput": "5",
|
||||
"recipeConfig": [
|
||||
{
|
||||
"op": "Levenshtein Distance",
|
||||
"args": [
|
||||
"\\n", 1, 1, 2,
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
"name": "Levenshtein Distance: varied costs 1",
|
||||
"input": "kitten\nsitting",
|
||||
"expectedOutput": "230",
|
||||
"recipeConfig": [
|
||||
{
|
||||
"op": "Levenshtein Distance",
|
||||
"args": [
|
||||
"\\n", 10, 100, 1000,
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
"name": "Levenshtein Distance: varied costs 2",
|
||||
"input": "kitten\nsitting",
|
||||
"expectedOutput": "1020",
|
||||
"recipeConfig": [
|
||||
{
|
||||
"op": "Levenshtein Distance",
|
||||
"args": [
|
||||
"\\n", 1000, 100, 10,
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
"name": "Levenshtein Distance: another delimiter",
|
||||
"input": "kitten sitting",
|
||||
"expectedOutput": "3",
|
||||
"recipeConfig": [
|
||||
{
|
||||
"op": "Levenshtein Distance",
|
||||
"args": [
|
||||
" ", 1, 1, 1,
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
"name": "Levenshtein Distance: too few samples",
|
||||
"input": "kitten",
|
||||
"expectedOutput": "Incorrect number of samples. Check your input and/or delimiter.",
|
||||
"recipeConfig": [
|
||||
{
|
||||
"op": "Levenshtein Distance",
|
||||
"args": [
|
||||
"\\n", 1, 1, 1,
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
"name": "Levenshtein Distance: too many samples",
|
||||
"input": "kitten\nsitting\nkitchen",
|
||||
"expectedOutput": "Incorrect number of samples. Check your input and/or delimiter.",
|
||||
"recipeConfig": [
|
||||
{
|
||||
"op": "Levenshtein Distance",
|
||||
"args": [
|
||||
"\\n", 1, 1, 1,
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
"name": "Levenshtein Distance: negative insertion cost",
|
||||
"input": "kitten\nsitting",
|
||||
"expectedOutput": "Negative costs are not allowed.",
|
||||
"recipeConfig": [
|
||||
{
|
||||
"op": "Levenshtein Distance",
|
||||
"args": [
|
||||
"\\n", -1, 1, 1,
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
"name": "Levenshtein Distance: negative deletion cost",
|
||||
"input": "kitten\nsitting",
|
||||
"expectedOutput": "Negative costs are not allowed.",
|
||||
"recipeConfig": [
|
||||
{
|
||||
"op": "Levenshtein Distance",
|
||||
"args": [
|
||||
"\\n", 1, -1, 1,
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
"name": "Levenshtein Distance: negative substitution cost",
|
||||
"input": "kitten\nsitting",
|
||||
"expectedOutput": "Negative costs are not allowed.",
|
||||
"recipeConfig": [
|
||||
{
|
||||
"op": "Levenshtein Distance",
|
||||
"args": [
|
||||
"\\n", 1, 1, -1,
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
"name": "Levenshtein Distance: cost zero",
|
||||
"input": "kitten\nsitting",
|
||||
"expectedOutput": "0",
|
||||
"recipeConfig": [
|
||||
{
|
||||
"op": "Levenshtein Distance",
|
||||
"args": [
|
||||
"\\n", 0, 0, 0,
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
]);
|
108
tests/operations/tests/Lorenz.mjs
Normal file
108
tests/operations/tests/Lorenz.mjs
Normal file
File diff suppressed because one or more lines are too long
66
tests/operations/tests/LuhnChecksum.mjs
Normal file
66
tests/operations/tests/LuhnChecksum.mjs
Normal file
|
@ -0,0 +1,66 @@
|
|||
/**
|
||||
* From Decimal tests
|
||||
*
|
||||
* @author n1073645 [n1073645@gmail.com]
|
||||
* @copyright Crown Copyright 2020
|
||||
* @licence Apache-2.0
|
||||
*/
|
||||
import TestRegister from "../../lib/TestRegister.mjs";
|
||||
|
||||
TestRegister.addTests([
|
||||
{
|
||||
name: "Luhn Checksum on standard data",
|
||||
input: "35641709012469",
|
||||
expectedOutput: "Checksum: 7\nCheckdigit: 0\nLuhn Validated String: 356417090124690",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "Luhn Checksum",
|
||||
args: []
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "Luhn Checksum on standard data 2",
|
||||
input: "896101950123440000",
|
||||
expectedOutput: "Checksum: 5\nCheckdigit: 1\nLuhn Validated String: 8961019501234400001",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "Luhn Checksum",
|
||||
args: []
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "Luhn Checksum on standard data 3",
|
||||
input: "35726908971331",
|
||||
expectedOutput: "Checksum: 6\nCheckdigit: 7\nLuhn Validated String: 357269089713317",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "Luhn Checksum",
|
||||
args: []
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "Luhn Checksum on invalid data",
|
||||
input: "35641709b012469",
|
||||
expectedOutput: "Character: b is not a digit.",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "Luhn Checksum",
|
||||
args: []
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "Luhn Checksum on empty data",
|
||||
input: "",
|
||||
expectedOutput: "",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "Luhn Checksum",
|
||||
args: []
|
||||
},
|
||||
],
|
||||
}
|
||||
]);
|
|
@ -5,7 +5,7 @@
|
|||
* @copyright Crown Copyright 2017
|
||||
* @license Apache-2.0
|
||||
*/
|
||||
import TestRegister from "../TestRegister";
|
||||
import TestRegister from "../../lib/TestRegister.mjs";
|
||||
|
||||
TestRegister.addTests([
|
||||
{
|
||||
|
|
|
@ -6,8 +6,8 @@
|
|||
* @copyright Crown Copyright 2018
|
||||
* @license Apache-2.0
|
||||
*/
|
||||
import TestRegister from "../TestRegister";
|
||||
|
||||
import TestRegister from "../../lib/TestRegister.mjs";
|
||||
import { JPG_RAW } from "../../samples/Images.mjs";
|
||||
|
||||
TestRegister.addTests([
|
||||
{
|
||||
|
@ -22,9 +22,9 @@ TestRegister.addTests([
|
|||
],
|
||||
},
|
||||
{
|
||||
name: "Magic: hex",
|
||||
name: "Magic: hex, correct rank",
|
||||
input: "41 42 43 44 45",
|
||||
expectedMatch: /"#recipe=From_Hex\('Space'\)"/,
|
||||
expectedMatch: /Properties[^#]+?#recipe=From_Hex\('Space'\)"/,
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "Magic",
|
||||
|
@ -33,8 +33,8 @@ TestRegister.addTests([
|
|||
],
|
||||
},
|
||||
{
|
||||
name: "Magic: jpeg",
|
||||
input: "\xFF\xD8\xFF",
|
||||
name: "Magic: jpeg render",
|
||||
input: JPG_RAW,
|
||||
expectedMatch: /Render_Image\('Raw'\)/,
|
||||
recipeConfig: [
|
||||
{
|
||||
|
@ -45,13 +45,112 @@ TestRegister.addTests([
|
|||
},
|
||||
{
|
||||
name: "Magic: mojibake",
|
||||
input: "d091d18bd100d182d180d0b0d10020d0bad0bed180d0b8d187d0bdd0b5d0b2d0b0d10020d0bbd0b8d100d0b020d0bfd180d18bd0b3d0b0d0b5d18220d187d0b5d180d0b5d0b720d0bbd0b5d0bdd0b8d0b2d183d18e20d100d0bed0b1d0b0d0bad1832e",
|
||||
input: "\xd0\x91\xd1\x8b\xd1\0\xd1\x82\xd1\x80\xd0\xb0\xd1\0\x20\xd0\xba\xd0\xbe\xd1\x80\xd0\xb8\xd1\x87\xd0\xbd\xd0\xb5\xd0\xb2\xd0\xb0\xd1\0\x20\xd0\xbb\xd0\xb8\xd1\0\xd0\xb0\x20\xd0\xbf\xd1\x80\xd1\x8b\xd0\xb3\xd0\xb0\xd0\xb5\xd1\x82\x20\xd1\x87\xd0\xb5\xd1\x80\xd0\xb5\xd0\xb7\x20\xd0\xbb\xd0\xb5\xd0\xbd\xd0\xb8\xd0\xb2\xd1\x83\xd1\x8e\x20\xd1\0\xd0\xbe\xd0\xb1\xd0\xb0\xd0\xba\xd1\x83\x2e",
|
||||
expectedMatch: /Быртрар коричневар лира прыгает через ленивую робаку./,
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "Magic",
|
||||
args: [3, true, false]
|
||||
args: [1, true, false]
|
||||
}
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "Magic: extensive language support, Yiddish",
|
||||
input: "די שנעל ברוין פאָקס דזשאַמפּס איבער די פויל הונט.",
|
||||
expectedMatch: /Yiddish/,
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "Magic",
|
||||
args: [1, false, true]
|
||||
}
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "Magic Chain: Base64",
|
||||
input: "WkVkV2VtUkRRbnBrU0Vwd1ltMWpQUT09",
|
||||
expectedMatch: /From_Base64\('A-Za-z0-9\+\/=',true,false\)\nFrom_Base64\('A-Za-z0-9\+\/=',true,false\)\nFrom_Base64\('A-Za-z0-9\+\/=',true,false\)/,
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "Magic",
|
||||
args: [3, false, false]
|
||||
}
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "Magic Chain: Hex -> Hexdump -> Base64",
|
||||
input: "MDAwMDAwMDAgIDM3IDM0IDIwIDM2IDM1IDIwIDM3IDMzIDIwIDM3IDM0IDIwIDMyIDMwIDIwIDM3ICB8NzQgNjUgNzMgNzQgMjAgN3wKMDAwMDAwMTAgIDMzIDIwIDM3IDM0IDIwIDM3IDMyIDIwIDM2IDM5IDIwIDM2IDY1IDIwIDM2IDM3ICB8MyA3NCA3MiA2OSA2ZSA2N3w=",
|
||||
expectedMatch: /From_Base64\('A-Za-z0-9\+\/=',true,false\)\nFrom_Hexdump\(\)\nFrom_Hex\('Space'\)/,
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "Magic",
|
||||
args: [3, false, false]
|
||||
}
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "Magic Chain: Charcode -> Octal -> Base32",
|
||||
input: "GY3SANRUEA2DAIBWGYQDMNJAGQYCANRXEA3DGIBUGAQDMNZAGY2CANBQEA3DEIBWGAQDIMBAGY3SANRTEA2DAIBWG4QDMNBAGQYCANRXEA3DEIBUGAQDMNRAG4YSANBQEA3DMIBRGQ2SANBQEA3DMIBWG4======",
|
||||
expectedMatch: /From_Base32\('A-Z2-7=',false\)\nFrom_Octal\('Space'\)\nFrom_Hex\('Space'\)/,
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "Magic",
|
||||
args: [3, false, false]
|
||||
}
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "Magic Chain: Base64 output",
|
||||
input: "WkVkV2VtUkRRbnBrU0Vwd1ltMWpQUT09",
|
||||
expectedMatch: /test string/,
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "Magic",
|
||||
args: [3, false, false]
|
||||
}
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "Magic Chain: Decimal -> Base32 -> Base32",
|
||||
input: "I5CVSVCNJFBFER2BLFJUCTKKKJDVKUKEINGUUV2FIFNFIRKJIJJEORJSKNAU2SSSI5MVCRCDJVFFKRKBLFKECTSKIFDUKWKUIFEUEUSHIFNFCPJ5HU6Q====",
|
||||
expectedMatch: /test string/,
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "Magic",
|
||||
args: [3, false, false]
|
||||
}
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "Magic: Raw Inflate",
|
||||
input: "\x4d\x52\xb1\x6e\xdc\x30\x0c\xdd\xf3\x15\x44\x80\x6e\xae\x91\x02\x4d\x80\x8e\x4d\x9a\x21\x53\x8b\xa6\x43\x56\x5a\xe2\x9d\x84\x93\x25\x43\x94\xed\xf8\xef\xf3\xe8\x6b\x0e\xb7\x1c\xce\xd4\x7b\x8f\x8f\x7c\x7c\xda\x06\xa9\x4f\x41\x0e\x14\x95\x98\x34\x8e\x53\x92\x8e\x62\x6e\x73\x6c\x71\x11\x5a\x65\x20\x9e\x26\x3a\x94\x4a\x8e\x6b\xdd\x62\x3e\x52\x99\x1b\x71\x4a\x34\x72\xce\x52\xa9\x1c\xe8\xd6\x99\xd0\x2d\x95\x49\x2a\xb7\x58\xb2\xd2\x1a\x5b\x88\x19\xa2\x26\x31\xd4\xb2\xaa\xd4\x9e\xfe\x05\x51\xb9\x86\xc5\xec\xd2\xec\xe5\x7f\x6b\x92\xec\x8a\xb7\x1e\x29\x9e\x84\xde\x7e\xff\x25\x34\x7e\x64\x95\x87\xef\x1d\x8d\xa5\x0a\xb9\x62\xc0\x77\x43\xd6\x6d\x32\x91\x33\xf6\xe7\xf3\x6b\x47\xbf\x9e\x5f\x89\xb3\xa7\xc7\x54\xd6\x43\xd4\xd0\x91\xab\x82\x4e\x10\x1c\x62\xe6\xba\xed\xaf\x41\xde\xfd\x3c\x4e\x8a\x57\x88\x55\x51\x35\x15\x7b\xf1\x72\x5d\xc1\x60\x9e\x1b\x03\xc6\xc9\xcd\xe9\xac\x13\x58\x31\xc3\x8e\x76\x41\xdc\x49\xe7\x11\x42\x2f\x7f\x96\x87\xbd\xf6\xd6\xdf\xdf\xfd\xa0\x89\xab\x02\x0c\x66\xe0\x7c\x34\x1a\xfe\x54\x76\x0d\xeb\xfa\x1c\x11\x2c\x23\x8c\xb3\x0b\xfb\x64\xfd\xcd\x0d\xb6\x43\xad\x94\x64\x69\x78\xd1\x78\xcc\xe2\x51\x00\x85\x07\x2c\x67\x28\x2d\x50\x13\x17\x72\x84\xa3\x9d\x9d\x4b\xfe\x7a\x5d\xe1\xb4\x69\x53\xe3\x20\x9c\x38\x99\x69\xd9\x87\xc0\xa2\x2f\xab\x5b\x79\x3b\xe7\x63\x41\x06\x5e\xcc\x1f\x18\x5e\x20\x61\xe5\x0b\xd0\xbc\xa8\x25\xc0\xe9\x58\x2a\x5e\x46\xed\xe9\xa5\x41\x40\x81\xc9\x4e\x70\x22\xbe\xbb\x58\xed\x68\x98\x63\xc2\x6d\xc0\x18\x72\xad\x32\x4a\x6e\x38\x94\x8d\x10\x6e\x2d\xc0\xd2\x60\x09\x7c\xfa\x34\x4f\x2d\x48\xac\xf4\xed\xee\x0b\x3e\x72\x59\xf6\xab\xa0\x16\x47\x1c\xc9\x82\x65\xa9\xe0\x17\xb6\x36\xc1\x46\xfb\x0f",
|
||||
expectedMatch: /#recipe=Raw_Inflate(.|\n)+CyberChef is a simple, intuitive web app for carrying out all manner of /,
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "Magic",
|
||||
args: [1, false, false]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "Magic: Defang IP Address, valid",
|
||||
input: "192.168.0.1",
|
||||
expectedMatch: /Properties[^#]+?#recipe=Defang_IP_Addresses\(\)"/,
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "Magic",
|
||||
args: [1, false, false]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "Magic: Defang IP Address, invalid",
|
||||
input: "192.168.0.1.0",
|
||||
unexpectedMatch: /Defang_IP_Addresses/,
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "Magic",
|
||||
args: [1, false, false]
|
||||
}
|
||||
]
|
||||
}
|
||||
]);
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue