/** * 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", "gndg zoujg", [3, 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 { browser.end(); } }; /** @function * Clears the current recipe and bakes a new operation. * * @param {Browser} browser - Nightwatch client * @param {string|Array} opName - name of operation to be tested, array for multiple ops * @param {string} input - input text for test * @param {Array|Array>} 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} opName - name of operation to be tested, array for multiple ops * @param {string} input - input text * @param {string} output - expected output * @param {Array|Array>} args - arguments, nested if multiple ops */ function testOp(browser, opName, input, output, args=[]) { bakeOp(browser, opName, input, args); utils.expectOutput(browser, output, true); } /** @function * Clears the current recipe and tests a new operation with HTML output. * * @param {Browser} browser - Nightwatch client * @param {string|Array} 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|Array>} 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} opName - name of operation to be tested array for multiple ops * @param {string} filename - filename of image file from samples directory * @param {Array|Array>} 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} 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|Array>} 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); } }