mirror of
https://github.com/gchq/CyberChef.git
synced 2025-04-22 07:46:16 -04:00
Merge branch 'master' into feature-ebcdic
This commit is contained in:
commit
6bf06a9629
73 changed files with 1481 additions and 1003 deletions
|
@ -38,17 +38,17 @@ import Chef from "../src/core/Chef.js";
|
|||
TestRegister.prototype.runTests = function() {
|
||||
return Promise.all(
|
||||
this.tests.map(function(test, i) {
|
||||
var chef = new Chef();
|
||||
const chef = new Chef();
|
||||
|
||||
return Promise.resolve(chef.bake(
|
||||
return chef.bake(
|
||||
test.input,
|
||||
test.recipeConfig,
|
||||
{},
|
||||
0,
|
||||
false
|
||||
))
|
||||
)
|
||||
.then(function(result) {
|
||||
var ret = {
|
||||
const ret = {
|
||||
test: test,
|
||||
status: null,
|
||||
output: null,
|
||||
|
|
|
@ -14,15 +14,16 @@ import TestRegister from "./TestRegister.js";
|
|||
import "./tests/operations/Base58.js";
|
||||
import "./tests/operations/ByteRepr.js";
|
||||
import "./tests/operations/CharEnc.js";
|
||||
import "./tests/operations/Code.js";
|
||||
import "./tests/operations/Compress.js";
|
||||
import "./tests/operations/FlowControl.js";
|
||||
import "./tests/operations/MorseCode.js";
|
||||
import "./tests/operations/StrUtils.js";
|
||||
|
||||
var allTestsPassing = true,
|
||||
testStatusCounts = {
|
||||
total: 0,
|
||||
};
|
||||
let allTestsPassing = true;
|
||||
const testStatusCounts = {
|
||||
total: 0,
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
|
@ -32,7 +33,7 @@ var allTestsPassing = true,
|
|||
* @returns {string}
|
||||
*/
|
||||
function statusToIcon(status) {
|
||||
var icons = {
|
||||
const icons = {
|
||||
erroring: "🔥",
|
||||
failing: "❌",
|
||||
passing: "✔️️",
|
||||
|
@ -48,7 +49,7 @@ function statusToIcon(status) {
|
|||
*/
|
||||
function handleTestResult(testResult) {
|
||||
allTestsPassing = allTestsPassing && testResult.status === "passing";
|
||||
var newCount = (testStatusCounts[testResult.status] || 0) + 1;
|
||||
const newCount = (testStatusCounts[testResult.status] || 0) + 1;
|
||||
testStatusCounts[testResult.status] = newCount;
|
||||
testStatusCounts.total += 1;
|
||||
|
||||
|
@ -83,8 +84,8 @@ TestRegister.runTests()
|
|||
|
||||
console.log("\n");
|
||||
|
||||
for (var testStatus in testStatusCounts) {
|
||||
var count = testStatusCounts[testStatus];
|
||||
for (const testStatus in testStatusCounts) {
|
||||
const count = testStatusCounts[testStatus];
|
||||
if (count > 0) {
|
||||
console.log(testStatus.toUpperCase(), count);
|
||||
}
|
||||
|
|
132
test/tests/operations/Code.js
Normal file
132
test/tests/operations/Code.js
Normal file
|
@ -0,0 +1,132 @@
|
|||
/**
|
||||
* Code tests.
|
||||
*
|
||||
* @author tlwr [toby@toby.codes]
|
||||
*
|
||||
* @copyright Crown Copyright 2017
|
||||
* @license Apache-2.0
|
||||
*/
|
||||
import TestRegister from "../../TestRegister.js";
|
||||
|
||||
TestRegister.addTests([
|
||||
{
|
||||
name: "To Camel case (dumb)",
|
||||
input: "hello world",
|
||||
expectedOutput: "helloWorld",
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "To Camel case",
|
||||
"args": [false]
|
||||
}
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "To Snake case (dumb)",
|
||||
input: "hello world",
|
||||
expectedOutput: "hello_world",
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "To Snake case",
|
||||
"args": [false]
|
||||
}
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "To Kebab case (dumb)",
|
||||
input: "hello world",
|
||||
expectedOutput: "hello-world",
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "To Kebab case",
|
||||
"args": [false]
|
||||
}
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "To Camel case (smart)",
|
||||
input: [
|
||||
"test='hello'",
|
||||
"echo $test",
|
||||
"a_camel_case_function",
|
||||
"$a_camel_case_variable;",
|
||||
"function function_name() {",
|
||||
" console.log('things inside quotes do not get broken');",
|
||||
" console.log(\"things inside quotes do not get broken\");",
|
||||
"}",
|
||||
].join("\n"),
|
||||
expectedOutput: [
|
||||
"test='hello'",
|
||||
"echo $test",
|
||||
"aCamelCaseFunction",
|
||||
"$aCamelCaseVariable;",
|
||||
"function functionName() {",
|
||||
" console.log('things inside quotes do not get broken');",
|
||||
" console.log(\"things inside quotes do not get broken\");",
|
||||
"}",
|
||||
].join("\n"),
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "To Camel case",
|
||||
"args": [true]
|
||||
}
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "To Snake case (smart)",
|
||||
input: [
|
||||
"test='hello'",
|
||||
"echo $test",
|
||||
"aSnakeCaseFunction",
|
||||
"$aSnakeCaseVariable;",
|
||||
"function functionName() {",
|
||||
" console.log('things inside quotes do not get broken');",
|
||||
" console.log(\"things inside quotes do not get broken\");",
|
||||
"}",
|
||||
].join("\n"),
|
||||
expectedOutput: [
|
||||
"test='hello'",
|
||||
"echo $test",
|
||||
"a_snake_case_function",
|
||||
"$a_snake_case_variable;",
|
||||
"function function_name() {",
|
||||
" console.log('things inside quotes do not get broken');",
|
||||
" console.log(\"things inside quotes do not get broken\");",
|
||||
"}",
|
||||
].join("\n"),
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "To Snake case",
|
||||
"args": [true]
|
||||
}
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "To Kebab case (smart)",
|
||||
input: [
|
||||
"test='hello'",
|
||||
"echo $test",
|
||||
"aKebabCaseFunction",
|
||||
"$aKebabCaseVariable;",
|
||||
"function functionName() {",
|
||||
" console.log('things inside quotes do not get broken');",
|
||||
" console.log(\"things inside quotes do not get broken\");",
|
||||
"}",
|
||||
].join("\n"),
|
||||
expectedOutput: [
|
||||
"test='hello'",
|
||||
"echo $test",
|
||||
"a-kebab-case-function",
|
||||
"$a-kebab-case-variable;",
|
||||
"function function-name() {",
|
||||
" console.log('things inside quotes do not get broken');",
|
||||
" console.log(\"things inside quotes do not get broken\");",
|
||||
"}",
|
||||
].join("\n"),
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "To Kebab case",
|
||||
"args": [true]
|
||||
}
|
||||
],
|
||||
},
|
||||
]);
|
|
@ -66,6 +66,62 @@ TestRegister.addTests([
|
|||
{"op":"To Base64", "args":["A-Za-z0-9+/="]}
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "Jump: skips 0",
|
||||
input: [
|
||||
"should be changed",
|
||||
].join("\n"),
|
||||
expectedOutput: [
|
||||
"should be changed was changed",
|
||||
].join("\n"),
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "Jump",
|
||||
args: [0, 10],
|
||||
},
|
||||
{
|
||||
op: "Find / Replace",
|
||||
args: [
|
||||
{
|
||||
"option": "Regex",
|
||||
"string": "should be changed"
|
||||
},
|
||||
"should be changed was changed",
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "Jump: skips 1",
|
||||
input: [
|
||||
"shouldnt be changed",
|
||||
].join("\n"),
|
||||
expectedOutput: [
|
||||
"shouldnt be changed",
|
||||
].join("\n"),
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "Jump",
|
||||
args: [1, 10],
|
||||
},
|
||||
{
|
||||
op: "Find / Replace",
|
||||
args: [
|
||||
{
|
||||
"option": "Regex",
|
||||
"string": "shouldnt be changed"
|
||||
},
|
||||
"shouldnt be changed was changed",
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "Conditional Jump: Skips 0",
|
||||
input: [
|
||||
|
@ -111,4 +167,111 @@ TestRegister.addTests([
|
|||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "Comment: nothing",
|
||||
input: "",
|
||||
expectedOutput: "",
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "Comment",
|
||||
"args": [""]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "Fork, Comment, Base64",
|
||||
input: "cat\nsat\nmat",
|
||||
expectedOutput: "Y2F0\nc2F0\nbWF0\n",
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "Fork",
|
||||
"args": ["\\n", "\\n", false]
|
||||
},
|
||||
{
|
||||
"op": "Comment",
|
||||
"args": ["Testing 123"]
|
||||
},
|
||||
{
|
||||
"op": "To Base64",
|
||||
"args": ["A-Za-z0-9+/="]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "Conditional Jump: Skips 1",
|
||||
input: [
|
||||
"match",
|
||||
"should not be changed",
|
||||
"should be changed",
|
||||
].join("\n"),
|
||||
expectedOutput: [
|
||||
"match",
|
||||
"should not be changed",
|
||||
"should be changed was changed"
|
||||
].join("\n"),
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "Conditional Jump",
|
||||
args: ["match", 1, 10],
|
||||
},
|
||||
{
|
||||
op: "Find / Replace",
|
||||
args: [
|
||||
{
|
||||
"option": "Regex",
|
||||
"string": "should not be changed"
|
||||
},
|
||||
"should not be changed was changed",
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
],
|
||||
},
|
||||
{
|
||||
op: "Find / Replace",
|
||||
args: [
|
||||
{
|
||||
"option": "Regex",
|
||||
"string": "should be changed"
|
||||
},
|
||||
"should be changed was changed",
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "Conditional Jump: Skips negatively",
|
||||
input: [
|
||||
"match",
|
||||
].join("\n"),
|
||||
expectedOutput: [
|
||||
"replaced",
|
||||
].join("\n"),
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "Jump",
|
||||
args: [1],
|
||||
},
|
||||
{
|
||||
op: "Find / Replace",
|
||||
args: [
|
||||
{
|
||||
"option": "Regex",
|
||||
"string": "match"
|
||||
},
|
||||
"replaced",
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
],
|
||||
},
|
||||
{
|
||||
op: "Conditional Jump",
|
||||
args: ["match", -2, 10],
|
||||
},
|
||||
],
|
||||
},
|
||||
]);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue