FunctionControlFlowTransformer tests: testing few items in controlFlowNode storage

This commit is contained in:
sanex3339
2016-12-27 18:15:25 +03:00
parent f4fd3d74b8
commit 725c26577e
2 changed files with 32 additions and 0 deletions
@@ -0,0 +1,4 @@
(function () {
var test1 = 1 + 2;
var test2 = 2 - 3;
})();
@@ -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);
});
});
});
});