mirror of
https://github.com/javascript-obfuscator/javascript-obfuscator
synced 2026-08-09 12:42:29 +00:00
Added more tests for object keys transformation
This commit is contained in:
+1
-1
@@ -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",
|
||||
|
||||
+60
@@ -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
@@ -0,0 +1,3 @@
|
||||
(function () {
|
||||
var variable = 1 + 2;
|
||||
})();
|
||||
@@ -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"
|
||||
|
||||
Reference in New Issue
Block a user