mirror of
https://github.com/javascript-obfuscator/javascript-obfuscator
synced 2026-08-09 12:42:29 +00:00
Added failing test for custom nodes identifier names collision
This commit is contained in:
+10
-7
@@ -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);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
function hi() {
|
||||
console.log("Hello World!");
|
||||
}
|
||||
hi();
|
||||
Reference in New Issue
Block a user