Added failing test for custom nodes identifier names collision

This commit is contained in:
sanex3339
2020-01-01 15:53:44 +03:00
parent 3d4a7f9a52
commit f39d16370b
8 changed files with 22848 additions and 50 deletions
+10 -7
View File
@@ -1,20 +1,23 @@
'use strict';
import { NO_ADDITIONAL_NODES_PRESET } from '../../src/options/presets/NoCustomNodes';
import { IdentifierNamesGenerator } from '../../src/enums/generators/identifier-names-generators/IdentifierNamesGenerator';
(function () {
const JavaScriptObfuscator: any = require('../../index');
let obfuscatedCode: string = JavaScriptObfuscator.obfuscate(
`
var abc = 1;
var cde = 1;
var fg = 1;
var sss = 1;
// Paste your JavaScript code here
function hi() {
console.log("Hello World!");
}
hi();
`,
{
...NO_ADDITIONAL_NODES_PRESET,
compact: false,
renameGlobals: true
renameGlobals: true,
identifierNamesGenerator: IdentifierNamesGenerator.HexadecimalIdentifierNamesGenerator,
stringArray: true,
rotateStringArray: false
}
).getObfuscatedCode();
@@ -666,5 +666,46 @@ describe('JavaScriptObfuscator', () => {
assert.equal(result, expectedValue);
});
});
describe('Identifier names collision between base code and appended custom nodes', () => {
const samplesCount: number = 30;
let areCollisionsExists: boolean = false;
let obfuscateFunc: (identifierNamesGenerator: IdentifierNamesGenerator) => string;
before(() => {
const code: string = readFileAsString(__dirname + '/fixtures/custom-nodes-identifier-names-collision.js');
obfuscateFunc = (identifierNamesGenerator: IdentifierNamesGenerator) => JavaScriptObfuscator.obfuscate(
code,
{
identifierNamesGenerator,
compact: false,
renameGlobals: true,
identifiersDictionary: ['foo', 'bar', 'baz', 'bark', 'hawk', 'foozmos', 'cow', 'chikago'],
stringArray: true
}
).getObfuscatedCode();
[
IdentifierNamesGenerator.DictionaryIdentifierNamesGenerator,
IdentifierNamesGenerator.MangledIdentifierNamesGenerator
].forEach((identifierNamesGenerator: IdentifierNamesGenerator) => {
for (let i = 0; i < samplesCount; i++) {
try {
eval(obfuscateFunc(identifierNamesGenerator));
} catch {
areCollisionsExists = true;
break;
}
}
});
});
it('It does not create identifier names collision', () => {
assert.equal(areCollisionsExists, false);
});
});
});
});
@@ -0,0 +1,4 @@
function hi() {
console.log("Hello World!");
}
hi();