mirror of
https://github.com/gchq/CyberChef.git
synced 2025-05-07 15:07:11 -04:00
Merge branch 'tlwr-feature-async-ops' into feature-async-ops
This commit is contained in:
commit
5b5412a902
3 changed files with 183 additions and 6 deletions
|
@ -201,7 +201,7 @@ var FlowControl = {
|
|||
* @returns {Object} The updated state of the recipe.
|
||||
*/
|
||||
runReturn: function(state) {
|
||||
state.progress = state.opList.length;
|
||||
state.progress = state.opList.length - 1;
|
||||
return state;
|
||||
},
|
||||
|
||||
|
|
|
@ -159,8 +159,7 @@ Recipe.prototype.execute = function(dish, currentStep, state) {
|
|||
return e;
|
||||
};
|
||||
|
||||
// Operations can be asynchronous so we have to return a Promise to a
|
||||
// future value.
|
||||
// Operations can be asynchronous so we have to return a Promise to a future value.
|
||||
return new Promise(function(resolve, reject) {
|
||||
// Helper function to clean up recursing to the next recipe step.
|
||||
// It is a closure to avoid having to pass in resolve and reject.
|
||||
|
@ -180,7 +179,7 @@ Recipe.prototype.execute = function(dish, currentStep, state) {
|
|||
|
||||
currentStep = currentStep || 0;
|
||||
|
||||
if (currentStep === recipe.opList.length) {
|
||||
if (currentStep >= recipe.opList.length) {
|
||||
resolve(currentStep);
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -54,7 +54,7 @@ TestRegister.addTests([
|
|||
},
|
||||
{
|
||||
name: "Fork, Conditional Jump, Encodings",
|
||||
input: "Some data with a 1 in it\nSome data with a 2 in it",
|
||||
input: "Some data with a 1 in it\nSome data with a 2 in it\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\n",
|
||||
recipeConfig: [
|
||||
{"op":"Fork", "args":["\\n", "\\n", false]},
|
||||
|
@ -64,6 +64,107 @@ 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: "Jump: skips negatively",
|
||||
input: [
|
||||
"should be changed",
|
||||
].join("\n"),
|
||||
expectedOutput: [
|
||||
"should be changed was changed",
|
||||
].join("\n"),
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "Jump",
|
||||
args: [2, 10],
|
||||
},
|
||||
{
|
||||
// Initially bypassed, until Jump(-3,_)
|
||||
op: "Find / Replace",
|
||||
args: [
|
||||
{
|
||||
"option": "Regex",
|
||||
"string": "should be changed"
|
||||
},
|
||||
"should be changed was changed",
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
],
|
||||
},
|
||||
{
|
||||
// Initially bypassed
|
||||
op: "Jump",
|
||||
args: [1, 10],
|
||||
},
|
||||
{
|
||||
op: "Jump",
|
||||
// -1 skips itself
|
||||
// -2 skips the one before
|
||||
// -3 skips the one before that
|
||||
args: [-3, 10],
|
||||
},
|
||||
{
|
||||
op: "Wait",
|
||||
args: [1],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "Conditional Jump: Skips 0",
|
||||
input: [
|
||||
|
@ -79,7 +180,7 @@ TestRegister.addTests([
|
|||
recipeConfig: [
|
||||
{
|
||||
op: "Conditional Jump",
|
||||
args: ["match", 0, 0],
|
||||
args: ["match", 0, 10],
|
||||
},
|
||||
{
|
||||
op: "Find / Replace",
|
||||
|
@ -109,4 +210,81 @@ TestRegister.addTests([
|
|||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
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