started on full op test suite

This commit is contained in:
d98762625 2018-08-13 17:57:53 +01:00
parent a2f4e34866
commit f100356078
3 changed files with 442 additions and 4 deletions

View File

@ -18,4 +18,8 @@ export default [
"Untar",
"Unzip",
"Zip",
// Also uses files
"DetectFileType",
"ExtractEXIF",
];

View File

@ -52,7 +52,7 @@ const wrapRun = (run) => () => {
*/
export function it(name, run) {
return {
name,
name: `Node API: ${name}`,
run: wrapRun(run),
};
}

View File

@ -17,7 +17,6 @@ import assert from "assert";
import it from "../assertionHandler";
import {
ADD,
addLineNumbers,
adler32Checksum,
AESDecrypt,
@ -30,12 +29,13 @@ import {
toBase64,
toHex,
} from "../../../src/node/index";
import chef from "../../../src/node/index";
import TestRegister from "../../TestRegister";
TestRegister.addApiTests([
it("ADD: toggleString argument", () => {
const result = ADD("sample input", {
const result = chef.ADD("sample input", {
key: {
string: "some key",
option: "Hex"
@ -85,6 +85,63 @@ TestRegister.addApiTests([
assert.strictEqual(result.toString(), "weiy qtpsh");
}),
it("analyzeHash", () => {
const result = chef.analyseHash(chef.MD5("some input"));
const expected = `Hash length: 32
Byte length: 16
Bit length: 128
Based on the length, this hash could have been generated by one of the following hashing functions:
MD5
MD4
MD2
HAVAL-128
RIPEMD-128
Snefru
Tiger-128`;
assert.strictEqual(result.toString(), expected);
}),
it("AND", () => {
const result = chef.AND("Scot-free", {
key: "Raining Cats and Dogs",
});
assert.strictEqual(result.toString(), ".\"M$(D E.");
}),
it("atBash Cipher", () => {
const result = chef.atbashCipher("Happy as a Clam");
assert.strictEqual(result.toString(), "Szkkb zh z Xozn");
}),
it("Bcrypt", () => {
const result = chef.bcrypt("Put a Sock In It");
assert.strictEqual(result.toString(), "$2a$10$ODeP1.6fMsb.ENk2ngPUCO7qTGVPyHA9TqDVcyupyed8FjsiF65L6");
}),
it("bcryptCompare", () => {
const result = chef.bcryptCompare("Put a Sock In It", {
hash: "$2a$10$2rT4a3XnIecBsd1H33dMTuyYE1HJ1n9F.V2rjQtAH73rh1qvOf/ae",
});
assert.strictEqual(result.toString(), "Match: Put a Sock In It");
}),
it("Bcrypt Parse", () => {
const result = chef.bcryptParse("$2a$10$ODeP1.6fMsb.ENk2ngPUCO7qTGVPyHA9TqDVcyupyed8FjsiF65L6");
const expected = `Rounds: 10
Salt: $2a$10$ODeP1.6fMsb.ENk2ngPUCO
Password hash: 7qTGVPyHA9TqDVcyupyed8FjsiF65L6
Full hash: $2a$10$ODeP1.6fMsb.ENk2ngPUCO7qTGVPyHA9TqDVcyupyed8FjsiF65L6`;
assert.strictEqual(result.toString(), expected);
}),
it("bifid cipher decode", () => {
const result = chef.bifidCipherDecode("Vhef Qnte Ke Xfhz Mxon Bmgf", {
keyword: "Alpha",
});
assert.strictEqual(result.toString(), "What Goes Up Must Come Down");
}),
it("bifid cipher encode: string option", () => {
const result = bifidCipherEncode("some input", {
keyword: "mykeyword",
@ -92,6 +149,11 @@ TestRegister.addApiTests([
assert.strictEqual(result.toString(), "nmhs zmsdo");
}),
it("bit shift left", () => {
const result = chef.bitShiftLeft("Keep Your Eyes Peeled");
assert.strictEqual(result.toString(), ".ÊÊà@²Þêä@.òÊæ@ ÊÊØÊÈ");
}),
it("bitShiftRight: number and option", () => {
const result = bitShiftRight("some bits to shift", {
type: "Arithmetic shift",
@ -100,6 +162,49 @@ TestRegister.addApiTests([
assert.strictEqual(result.toString(), "9762\u001014:9\u0010:7\u00109443:");
}),
it("Blowfish encrypt", () => {
const result = chef.blowfishEncrypt("Fool's Gold", {
key: {
string: "One",
option: "hex",
},
iv: {
string: "Two",
option: "utf8"
}
});
assert.strictEqual(result.toString(), "8999b513bf2ff064b2977dea7e05f1b5");
}),
it("Blowfish decrypt", () => {
const result = chef.blowfishDecrypt("8999b513bf2ff064b2977dea7e05f1b5", {
key: {
string: "One",
option: "hex",
},
iv: {
string: "Two",
option: "utf8",
}
});
assert.strictEqual(result.toString(), "Fool's Gold");
}),
it("BSON Deserialise", () => {
const result = chef.BSONDeserialise("....phrase.....Mouth-watering..");
assert.strictEqual(result.toString(), "{\"phrase\": \"Mouth-watering\"}");
}),
it("BSON Serialise", () => {
const result = chef.BSONSerialise({"phrase": "Mouth-watering"});
assert.strictEqual(result.toString(), " ....phrase.....Mouth-watering..");
}),
it("Bzip2 Decompress", () => {
const result = chef.bzip2Decompress(chef.fromBase64("QlpoOTFBWSZTWUdQlt0AAAIVgEAAAQAmJAwAIAAxBkxA0A2pTL6U2CozxdyRThQkEdQlt0A="));
assert.strictEqual(result.toString(), "Fit as a Fiddle");
}),
it("cartesianProduct: binary string", () => {
const result = cartesianProduct("1:2\\n\\n3:4", {
itemDelimiter: ":",
@ -107,6 +212,99 @@ TestRegister.addApiTests([
assert.strictEqual(result.toString(), "(1,3):(1,4):(2,3):(2,4)");
}),
it("Change IP format", () => {
const result = chef.changeIPFormat("172.20.23.54", {
inputFormat: "Dotted Decimal",
outputFormat: "Hex",
});
assert.strictEqual(result.toString(), "ac141736");
}),
it("Chi square", () => {
const result = chef.chiSquare("Burst Your Bubble");
assert.strictEqual(result.toString(), "433.55399816176475");
}),
it("Compare CTPH Hashes", () => {
const result = chef.compareCTPHHashes("1234\n3456");
assert.strictEqual(result.toString(), "0");
}),
it("Compare SSDEEPHashes", () => {
const result = chef.compareCTPHHashes("1234\n3456");
assert.strictEqual(result.toString(), "0");
}),
it("Convert area", () => {
const result = chef.convertArea("12345", {
inputUnits: "Square metre (sq m)",
outputUnits: "Isle of Wight"
});
assert.strictEqual(result.toString(), "0.00003248684210526316");
}),
it("Convert data units", () => {
const result = chef.convertDataUnits("12345", {
inputUnits: "Bits (b)",
outputUnits: "Kilobytes (KB)",
});
assert.strictEqual(result.toString(), "1.543125");
}),
it("Convert distance", () => {
const result = chef.convertDistance("1234567", {
inputUnits: "Nanometres (nm)",
outputUnits: "Furlongs (fur)",
});
assert.strictEqual(result.toString(), "0.00000613699494949495");
}),
it("Convert mass", () => {
const result = chef.convertMass("123", {
inputUnits: "Earth mass (M⊕)",
outputUnits: "Great Pyramid of Giza (6,000,000 tonnes)",
});
assert.strictEqual(result.toString(), "122429895000000000");
}),
it("Convert speed", () => {
const result = chef.convertSpeed("123", {
inputUnits: "Lunar escape velocity",
outputUnits: "Jet airliner cruising speed",
});
assert.strictEqual(result.toString(), "1168.5");
}),
it("Count occurrences", () => {
const result = chef.countOccurrences("Talk the Talk", {
searchString: {
string: "Tal",
option: "Simple string",
}
});
assert.strictEqual(result.toString(), "2");
}),
it("CRC16 Checksum", () => {
const result = chef.CRC16Checksum("Rain on Your Parade");
assert.strictEqual(result.toString(), "db1c");
}),
it("CRC32 Checksum", () => {
const result = chef.CRC32Checksum("Rain on Your Parade");
assert.strictEqual(result.toString(), "e902f76c");
}),
it("CSS Beautify", () => {
const result = chef.CSSBeautify("header {color:black;padding:3rem;}");
const expected = `header {
\\tcolor:black;
\\tpadding:3rem;
}
`;
assert.strictEqual(result.toString(), expected);
}),
it("CSS minify: boolean", () => {
const input = `header {
// comment
@ -119,6 +317,242 @@ color: white;
assert.strictEqual(result.toString(), "header {// comment width: 100%;color: white;}");
}),
it("CSS Selector", () => {
const result = chef.CSSSelector("<html><header><h1>Hello</h1></header></html>", {
cssSelector: "h1",
});
assert.strictEqual(result.toString(), "<h1>Hello</h1>");
}),
it("CTPH", () => {
const result = chef.CTPH("If You Can't Stand the Heat, Get Out of the Kitchen");
assert.strictEqual(result.toString(), "A:+EgFgBKAA0V0UFfClEs6:+Qk0gUFse");
}),
it("Decode NetBIOS Name", () => {
assert.strictEqual(chef.decodeNetBIOSName("EBGMGMCAEHHCGFGFGLCAFEGPCAENGFCA").toString(), "All Greek To Me");
}),
it("Decode text", () => {
const encoded = chef.encodeText("Ugly Duckling", {
encoding: "UTF16LE (1200)",
});
const result = chef.decodeText(encoded, {
encoding: "UTF16LE (1200)",
});
assert.strictEqual(result.toString(), "Ugly Duckling");
}),
it("Derive EVP Key", () => {
const result = chef.deriveEVPKey("", {
passphrase: {
string: "46 6c 65 61 20 4d 61 72 6b 65 74",
option: "Hex",
},
salt: {
string: "Market",
option: "Hex",
},
});
assert.strictEqual(result.toString(), "7c21a9f5063a4d62fb1050068245c181");
}),
it("Derive PBKDF2 Key", () => {
const result = chef.derivePBKDF2Key("", {
passphrase: {
string: "Jack of All Trades Master of None",
option: "utf8",
},
keySize: 256,
iterations: 2,
hashingFunction: "md5",
salt: {
string: "fruit",
option: "utf8"
}
});
assert.strictEqual(result.toString(), "728a885b209e8b19cbd7430ca32608ff09190f7ccb7ded204e1d4c50f87c47bf");
}),
it("DES Decrypt", () => {
const result = chef.DESDecrypt("713081c66db781c323965ba8f166fd8c230c3bb48504a913", {
key: {
string: "onetwoth",
option: "utf8",
},
iv: {
string: "threetwo",
option: "Hex",
},
mode: "ECB",
});
assert.strictEqual(result.toString(), "Put a Sock In It");
}),
it("DES Encrypt", () => {
const result = chef.DESEncrypt("Put a Sock In It", {
key: {
string: "onetwoth",
option: "utf8",
},
iv: {
string: "threetwo",
option: "Hex",
},
mode: "ECB",
});
assert.strictEqual(result.toString(), "713081c66db781c323965ba8f166fd8c230c3bb48504a913");
}),
it("Diff", () => {
const result = chef.diff("one two\\n\\none two three");
assert.strictEqual(result.toString(), "one two three");
}),
it("Disassemble x86", () => {
const result = chef.disassembleX86(chef.toBase64("one two three"));
const expected = `0000000000000000 0000 ADD BYTE PTR [RAX],AL\r
0000000000000002 0B250000000B OR ESP,DWORD PTR [000000000B000008]\r
`;
assert.strictEqual(result.toString(), expected);
}),
it("Divide", () => {
assert.strictEqual(chef.divide("4\n7").toString(), "0.57142857142857142857");
}),
it("Drop bytes", () => {
assert.strictEqual(chef.dropBytes("There's No I in Team").toString(), "'s No I in Team");
}),
it("Entropy", () => {
const result = chef.entropy("Ride Him, Cowboy!");
assert.strictEqual(result.toString(), "3.734521664779752");
}),
it("Escape string", () => {
const result = chef.escapeString("Know the Ropes", {
escapeLevel: "Everything",
JSONCompatible: false,
ES6Compatible: true,
uppercaseHex: true,
});
assert.strictEqual(result.toString(), "\\x4B\\x6E\\x6F\\x77\\x20\\x74\\x68\\x65\\x20\\x52\\x6F\\x70\\x65\\x73");
}),
it("Escape unicode characters", () => {
assert.strictEqual(chef.escapeUnicodeCharacters("σου").toString(), "\\u03C3\\u03BF\\u03C5");
}),
it("Expand alphabet range", () => {
assert.strictEqual(
chef.expandAlphabetRange("Fight Fire With Fire", {delimiter: "t"}).toString(),
"Ftitgthttt tFtitrtet tWtitttht tFtitrte");
}),
it("Extract dates", () => {
assert.strictEqual(chef.extractDates("Don't Look a Gift Horse In The Mouth 01/02/1992").toString(), "01/02/1992\n");
}),
it("Filter", () => {
const result = chef.filter(
`I Smell a Rat
Every Cloud Has a Silver Lining
Top Drawer`, {
regex: "Every",
});
const expected = "Every Cloud Has a Silver Lining";
assert.strictEqual(result.toString(), expected);
}),
it("Find / Replace", () => {
assert.strictEqual(
chef.findReplace(
"Curiosity Killed The Cat",
{
find: {
string: "l",
option: "Regex",
},
replace: "s",
}).toString(),
"Curiosity Kissed The Cat");
}),
it("Fletcher8 Checksum", () => {
assert.strictEqual(chef.fletcher8Checksum("Keep Your Eyes Peeled").toString(), "48");
}),
it("Format MAC addresses", () => {
const result = chef.formatMACAddresses("00-01-02-03-04-05");
const expected = `000102030405
000102030405
00-01-02-03-04-05
00-01-02-03-04-05
00:01:02:03:04:05
00:01:02:03:04:05
`;
assert.strictEqual(result.toString(), expected);
}),
it("Frequency distribution", () => {
const result = chef.frequencyDistribution("Don't Count Your Chickens Before They Hatch");
const expected = "{\"dataLength\":43,\"percentages\":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,13.953488372093023,0,0,0,0,0,0,2.3255813953488373,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2.3255813953488373,4.651162790697675,2.3255813953488373,0,0,0,2.3255813953488373,0,0,0,0,0,0,0,0,0,0,0,2.3255813953488373,0,0,0,0,2.3255813953488373,0,0,0,0,0,0,0,2.3255813953488373,0,4.651162790697675,0,9.30232558139535,2.3255813953488373,0,6.976744186046512,2.3255813953488373,0,2.3255813953488373,0,0,6.976744186046512,9.30232558139535,0,0,4.651162790697675,2.3255813953488373,6.976744186046512,4.651162790697675,0,0,0,2.3255813953488373,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],\"distribution\":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,6,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,2,1,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,2,0,4,1,0,3,1,0,1,0,0,3,4,0,0,2,1,3,2,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],\"bytesRepresented\":22}";
assert.strictEqual(result.toString(), expected);
}),
it("From base", () => {
assert.strictEqual(chef.fromBase("11", {radix: 13}).toString(), "14");
}),
it("From BCD", () => {
assert.strictEqual(chef.fromBCD("1143", { inputFormat: "Raw", scheme: "7 4 2 1"}).toString(), "31313433");
}),
it("From binary", () => {
assert.strictEqual(chef.fromBinary("010101011100101101011010").toString(), "UËZ");
}),
it("From Charcode", () => {
assert.strictEqual(chef.fromCharcode("4c 6f 6e 67 20 49 6e 20 54 68 65 20 54 6f 6f 74 68 0a").toString(), "Long In The Tooth\n");
}),
it("From decimal", () => {
assert.strictEqual(chef.fromDecimal("72 101 108 108 111").toString(), "Hello");
}),
it("From hex", () => {
assert.strictEqual(chef.fromHex("52 69 6e 67 20 41 6e 79 20 42 65 6c 6c 73 3f").toString(), "Ring Any Bells?");
}),
it("From hex content", () => {
assert.strictEqual(chef.fromHexContent("foo|3d|bar").toString(), "foo=bar");
}),
it("To and From hex dump", () => {
assert.strictEqual(chef.fromHexdump(chef.toHexdump("Elephant in the Room")).toString(), "Elephant in the Room");
}),
it("From HTML entity", () => {
assert.strictEqual(chef.fromHTMLEntity("&amp;").toString(), "&");
}),
it("To and From morse code", () => {
assert.strictEqual(chef.fromMorseCode(chef.toMorseCode("Put a Sock In It")).toString(), "PUT A SOCK IN IT");
}),
it("From octal", () => {
assert.strictEqual(chef.fromOctal("113 156 157 167 40 164 150 145 40 122 157 160 145 163").toString(), "Know the Ropes");
}),
it("To, From punycode", () => {
assert.strictEqual(chef.fromPunycode(chef.toPunycode("münchen")).toString(), "münchen");
}),
it("From unix timestamp", () => {
assert.strictEqual(chef.fromUNIXTimestamp("978346800").toString(), "Mon 1 January 2001 11:00:00 UTC");
}),
it("toBase64: editableOption", () => {
const result = toBase64("some input", {
alphabet: {
@ -145,7 +579,7 @@ color: white;
delimiter: "Colon",
});
assert.strictEqual(result.toString(), "73:6f:6d:65:20:69:6e:70:75:74");
})
}),
]);