From 725c26577e57a7390b7cbd356c69f38001f97018 Mon Sep 17 00:00:00 2001 From: sanex3339 Date: Tue, 27 Dec 2016 18:15:25 +0300 Subject: [PATCH] FunctionControlFlowTransformer tests: testing few items in controlFlowNode storage --- ...ntrol-flow-transformer-multiple-items-1.js | 4 +++ .../FunctionControlFlowTransformer.spec.ts | 28 +++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 test/fixtures/node-transformers/node-control-flow-transformers/function-control-flow-transformer-multiple-items-1.js diff --git a/test/fixtures/node-transformers/node-control-flow-transformers/function-control-flow-transformer-multiple-items-1.js b/test/fixtures/node-transformers/node-control-flow-transformers/function-control-flow-transformer-multiple-items-1.js new file mode 100644 index 00000000..a303fe82 --- /dev/null +++ b/test/fixtures/node-transformers/node-control-flow-transformers/function-control-flow-transformer-multiple-items-1.js @@ -0,0 +1,4 @@ +(function () { + var test1 = 1 + 2; + var test2 = 2 - 3; +})(); diff --git a/test/functional-tests/node-transformers/node-control-flow-transformers/FunctionControlFlowTransformer.spec.ts b/test/functional-tests/node-transformers/node-control-flow-transformers/FunctionControlFlowTransformer.spec.ts index 8181dcb6..c5785fc1 100644 --- a/test/functional-tests/node-transformers/node-control-flow-transformers/FunctionControlFlowTransformer.spec.ts +++ b/test/functional-tests/node-transformers/node-control-flow-transformers/FunctionControlFlowTransformer.spec.ts @@ -86,5 +86,33 @@ describe('FunctionControlFlowTransformer', () => { assert.closeTo((totalValue - samplesCount) / samplesCount, expectedValue, delta); }); }); + + describe('variant #3 - single `control flow storage` node with multiple items', () => { + const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate( + readFileAsString( + './test/fixtures/node-transformers/node-control-flow-transformers/function-control-flow-transformer-multiple-items-1.js' + ), + { + ...NO_CUSTOM_NODES_PRESET, + controlFlowFlattening: true, + controlFlowFlatteningThreshold: 1 + } + ); + const obfuscatedCode: string = obfuscationResult.getObfuscatedCode(); + const regexp: RegExp = new RegExp( + `var *${variableMatch} *= *\\{` + + `'(\\\\x[a-f0-9]*){3}' *: *function *${variableMatch} *\\(${variableMatch}, *${variableMatch}\\) *\\{` + + `return *${variableMatch} *\\+ *${variableMatch};` + + `\\}, *` + + `'(\\\\x[a-f0-9]*){3}' *: *function *${variableMatch} *\\(${variableMatch}, *${variableMatch}\\) *\\{` + + `return *${variableMatch} *- *${variableMatch};` + + `\\}` + + `\\};` + ); + + it('should add `control flow storage` node with multiple items to the obfuscated code', () => { + assert.match(obfuscatedCode, regexp); + }); + }); }); });