Added additional test for eval transformer

This commit is contained in:
sanex3339
2018-01-11 00:33:02 +03:00
parent afe8832bbb
commit f3efba9e2a
9 changed files with 80 additions and 45 deletions
+4 -5
View File
@@ -7,12 +7,11 @@ import { NO_ADDITIONAL_NODES_PRESET } from '../../src/options/presets/NoCustomNo
let obfuscatedCode: string = JavaScriptObfuscator.obfuscate(
`
(function(){
function foo (a, b) {
return eval('var c = a + b; eval(\\'a + c\\');');
function foo () {
eval('var s = 1;');
}
console.log(foo(1, 2));
foo();
})();
`,
{
@@ -36,7 +36,6 @@ describe('BlockStatementControlFlowTransformer', function () {
);
obfuscatedCode = obfuscationResult.getObfuscatedCode();
console.log(obfuscatedCode);
});
describe('`console.log` statements', ()=> {
@@ -233,7 +233,29 @@ describe('AstToEvalCallExpressionTransformer', () => {
});
});
describe('variant #7: integration with control flow flattening', () => {
describe('variant #7: wrong eval string', () => {
const evalExpressionRegExp: RegExp = /eval *\('~'\);/;
let obfuscatedCode: string
before(() => {
const code: string = readFileAsString(__dirname + '/fixtures/wrong-eval-string.js');
const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
code,
{
...NO_ADDITIONAL_NODES_PRESET
}
);
obfuscatedCode = obfuscationResult.getObfuscatedCode();
});
it('should skip obfuscation of eval string', () => {
assert.match(obfuscatedCode, evalExpressionRegExp);
});
});
describe('variant #8: integration with control flow flattening', () => {
const variableMatch: string = '_0x([a-f0-9]){4,6}';
const controlFlowStorageNodeMatch: string = `` +
`var *${variableMatch} *= *\\{` +
@@ -0,0 +1,7 @@
(function(){
function foo () {
eval('~');
}
foo();
})();