Added more tests for object keys transformation

This commit is contained in:
sanex3339
2018-01-05 13:27:59 +03:00
parent 21641cd0dd
commit 8ba6eaf04d
4 changed files with 67 additions and 6 deletions
+1 -1
View File
@@ -46,7 +46,7 @@
"@types/estree": "0.0.38",
"@types/md5": "2.1.32",
"@types/mkdirp": "0.5.2",
"@types/mocha": "2.2.45",
"@types/mocha": "2.2.46",
"@types/node": "8.5.5",
"@types/rimraf": "^2.0.2",
"@types/sinon": "4.1.2",
@@ -102,6 +102,38 @@ describe('ObjectExpressionKeysTransformer', () => {
assert.match(obfuscatedCode, regExp);
});
});
describe('variant #4: correct integration with control flow flattening object', () => {
const match: string = `` +
`var *${variableMatch} *= *{};` +
`${variableMatch}\\['\\w{5}'] *= *function *${variableMatch} *\\(${variableMatch}, *${variableMatch}\\) *{` +
`return *${variableMatch} *\\+ *${variableMatch};` +
`};` +
`var *${variableMatch} *= *${variableMatch}\\['\\w{5}']\\(0x1, *0x2\\);` +
``;
const regExp: RegExp = new RegExp(match);
let obfuscatedCode: string;
before(() => {
const code: string = readFileAsString(__dirname + '/fixtures/integration-with-control-flow-flattening.js');
const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
code,
{
...NO_ADDITIONAL_NODES_PRESET,
controlFlowFlattening: true,
controlFlowFlatteningThreshold: 1,
transformObjectKeys: true
}
);
obfuscatedCode = obfuscationResult.getObfuscatedCode();
});
it('should correctly transform object keys', () => {
assert.match(obfuscatedCode, regExp);
});
});
});
describe('correct placement of expression statements', () => {
@@ -226,6 +258,34 @@ describe('ObjectExpressionKeysTransformer', () => {
});
describe('Ignore transformation', () => {
describe('variant #1: disabled option', () => {
const match: string = `` +
`var *${variableMatch} *= *{` +
`'foo': *'bar',` +
`'baz': *'bark'` +
`}` +
``;
const regExp: RegExp = new RegExp(match);
let obfuscatedCode: string;
before(() => {
const code: string = readFileAsString(__dirname + '/fixtures/simple.js');
const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
code,
{
...NO_ADDITIONAL_NODES_PRESET
}
);
obfuscatedCode = obfuscationResult.getObfuscatedCode();
});
it('shouldn\'t transform object keys', () => {
assert.match(obfuscatedCode, regExp);
});
});
describe('variant #2: variable declaration without initialization', () => {
const match: string = `` +
`var *${variableMatch};` +
+3 -5
View File
@@ -64,11 +64,9 @@
dependencies:
"@types/node" "*"
"@types/mocha@2.2.45":
version "2.2.45"
resolved "https://registry.yarnpkg.com/@types/mocha/-/mocha-2.2.45.tgz#816572b6e45164526a36d4faa123e8267d6d5d0a"
dependencies:
"@types/node" "*"
"@types/mocha@2.2.46":
version "2.2.46"
resolved "https://registry.yarnpkg.com/@types/mocha/-/mocha-2.2.46.tgz#b04713f7759d1cf752effdaae7b3969e285ebc16"
"@types/node@*":
version "8.0.53"