mirror of
https://github.com/javascript-obfuscator/javascript-obfuscator
synced 2026-08-09 12:42:29 +00:00
Removed random internal random generation of identifiers prefix
This commit is contained in:
@@ -176,134 +176,6 @@ describe('OptionsNormalizer', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('identifiersPrefixRule', () => {
|
||||
describe('variant #1: string option value', () => {
|
||||
before(() => {
|
||||
optionsPreset = getNormalizedOptions({
|
||||
...DEFAULT_PRESET,
|
||||
identifiersPrefix: 'foo',
|
||||
});
|
||||
|
||||
expectedOptionsPreset = {
|
||||
...DEFAULT_PRESET,
|
||||
identifiersPrefix: 'foo',
|
||||
};
|
||||
});
|
||||
|
||||
it('should normalize options preset', () => {
|
||||
assert.deepEqual(optionsPreset, expectedOptionsPreset);
|
||||
});
|
||||
});
|
||||
|
||||
describe('variant #2: empty string option value', () => {
|
||||
before(() => {
|
||||
optionsPreset = getNormalizedOptions({
|
||||
...DEFAULT_PRESET,
|
||||
identifiersPrefix: '',
|
||||
});
|
||||
|
||||
expectedOptionsPreset = {
|
||||
...DEFAULT_PRESET,
|
||||
identifiersPrefix: false,
|
||||
};
|
||||
});
|
||||
|
||||
it('should normalize options preset', () => {
|
||||
assert.deepEqual(optionsPreset, expectedOptionsPreset);
|
||||
});
|
||||
});
|
||||
|
||||
describe('variant #3: option value is `true`', () => {
|
||||
before(() => {
|
||||
optionsPreset = getNormalizedOptions({
|
||||
...DEFAULT_PRESET,
|
||||
identifiersPrefix: true,
|
||||
});
|
||||
|
||||
expectedOptionsPreset = {
|
||||
...DEFAULT_PRESET,
|
||||
identifiersPrefix: true,
|
||||
};
|
||||
});
|
||||
|
||||
it('should normalize options preset', () => {
|
||||
assert.deepEqual(optionsPreset, expectedOptionsPreset);
|
||||
});
|
||||
});
|
||||
|
||||
describe('variant #4: option value is `false`', () => {
|
||||
before(() => {
|
||||
optionsPreset = getNormalizedOptions({
|
||||
...DEFAULT_PRESET,
|
||||
identifiersPrefix: false,
|
||||
});
|
||||
|
||||
expectedOptionsPreset = {
|
||||
...DEFAULT_PRESET,
|
||||
identifiersPrefix: false,
|
||||
};
|
||||
});
|
||||
|
||||
it('should normalize options preset', () => {
|
||||
assert.deepEqual(optionsPreset, expectedOptionsPreset);
|
||||
});
|
||||
});
|
||||
|
||||
describe('variant #5: option value is object', () => {
|
||||
before(() => {
|
||||
optionsPreset = getNormalizedOptions({
|
||||
...DEFAULT_PRESET,
|
||||
identifiersPrefix: <any>{},
|
||||
});
|
||||
|
||||
expectedOptionsPreset = {
|
||||
...DEFAULT_PRESET,
|
||||
identifiersPrefix: false,
|
||||
};
|
||||
});
|
||||
|
||||
it('should normalize options preset', () => {
|
||||
assert.deepEqual(optionsPreset, expectedOptionsPreset);
|
||||
});
|
||||
});
|
||||
|
||||
describe('variant #6: option value is function', () => {
|
||||
before(() => {
|
||||
optionsPreset = getNormalizedOptions({
|
||||
...DEFAULT_PRESET,
|
||||
identifiersPrefix: <any>{},
|
||||
});
|
||||
|
||||
expectedOptionsPreset = {
|
||||
...DEFAULT_PRESET,
|
||||
identifiersPrefix: false,
|
||||
};
|
||||
});
|
||||
|
||||
it('should normalize options preset', () => {
|
||||
assert.deepEqual(optionsPreset, expectedOptionsPreset);
|
||||
});
|
||||
});
|
||||
|
||||
describe('variant #7: option value is number', () => {
|
||||
before(() => {
|
||||
optionsPreset = getNormalizedOptions({
|
||||
...DEFAULT_PRESET,
|
||||
identifiersPrefix: <any>123,
|
||||
});
|
||||
|
||||
expectedOptionsPreset = {
|
||||
...DEFAULT_PRESET,
|
||||
identifiersPrefix: '123',
|
||||
};
|
||||
});
|
||||
|
||||
it('should normalize options preset', () => {
|
||||
assert.deepEqual(optionsPreset, expectedOptionsPreset);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('selfDefendingRule', () => {
|
||||
before(() => {
|
||||
optionsPreset = getNormalizedOptions({
|
||||
|
||||
@@ -9,7 +9,6 @@ import './unit-tests/analyzers/stack-trace-analyzer/StackTraceAnalyzer.spec';
|
||||
import './unit-tests/cli/sanitizers/ArraySanitizer.spec';
|
||||
import './unit-tests/cli/sanitizers/BooleanSanitizer.spec';
|
||||
import './unit-tests/cli/sanitizers/IdentifierNamesGeneratorSanitizer.spec';
|
||||
import './unit-tests/cli/sanitizers/IdentifiersPrefixSanitizer.spec';
|
||||
import './unit-tests/cli/sanitizers/ObfuscationTargetSanitizer.spec';
|
||||
import './unit-tests/cli/sanitizers/SourceMapModeSanitizer.spec';
|
||||
import './unit-tests/cli/sanitizers/StringArrayEncodingSanitizer.spec';
|
||||
|
||||
@@ -1,82 +0,0 @@
|
||||
import { assert } from 'chai';
|
||||
|
||||
import { IdentifiersPrefixSanitizer } from '../../../../src/cli/sanitizers/IdentifiersPrefixSanitizer';
|
||||
|
||||
describe('IdentifiersPrefixSanitizer', () => {
|
||||
describe('IdentifiersPrefixSanitizer: TCLISanitizer = (value: string): string | boolean', () => {
|
||||
describe('variant #1: identifiers prefix `true`', () => {
|
||||
const inputValue: string = 'true';
|
||||
const expectedValue: boolean = true;
|
||||
|
||||
let value: boolean | string;
|
||||
|
||||
before(() => {
|
||||
value = IdentifiersPrefixSanitizer(inputValue);
|
||||
});
|
||||
|
||||
it('should sanitize value', () => {
|
||||
assert.equal(value, expectedValue);
|
||||
});
|
||||
});
|
||||
|
||||
describe('variant #2: identifiers prefix `1`', () => {
|
||||
const inputValue: string = '1';
|
||||
const expectedValue: boolean = true;
|
||||
|
||||
let value: boolean | string;
|
||||
|
||||
before(() => {
|
||||
value = IdentifiersPrefixSanitizer(inputValue);
|
||||
});
|
||||
|
||||
it('should sanitize value', () => {
|
||||
assert.equal(value, expectedValue);
|
||||
});
|
||||
});
|
||||
|
||||
describe('variant #3: identifiers prefix `false`', () => {
|
||||
const inputValue: string = 'false';
|
||||
const expectedValue: boolean = false;
|
||||
|
||||
let value: boolean | string;
|
||||
|
||||
before(() => {
|
||||
value = IdentifiersPrefixSanitizer(inputValue);
|
||||
});
|
||||
|
||||
it('should sanitize value', () => {
|
||||
assert.equal(value, expectedValue);
|
||||
});
|
||||
});
|
||||
|
||||
describe('variant #4: identifiers prefix `0`', () => {
|
||||
const inputValue: string = '0';
|
||||
const expectedValue: boolean = false;
|
||||
|
||||
let value: boolean | string;
|
||||
|
||||
before(() => {
|
||||
value = IdentifiersPrefixSanitizer(inputValue);
|
||||
});
|
||||
|
||||
it('should sanitize value', () => {
|
||||
assert.equal(value, expectedValue);
|
||||
});
|
||||
});
|
||||
|
||||
describe('variant #5: string identifiers prefix', () => {
|
||||
const inputValue: string = 'foo';
|
||||
const expectedValue: string = 'foo';
|
||||
|
||||
let value: boolean | string;
|
||||
|
||||
before(() => {
|
||||
value = IdentifiersPrefixSanitizer(inputValue);
|
||||
});
|
||||
|
||||
it('should sanitize value', () => {
|
||||
assert.equal(value, expectedValue);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
+5
-57
@@ -36,62 +36,10 @@ describe('HexadecimalIdentifierNamesGenerator', () => {
|
||||
});
|
||||
|
||||
describe('generateWithPrefix (): string', () => {
|
||||
describe('Hexadecimal name with prefix', () => {
|
||||
const regExp: RegExp = /^foo_0x(\w){4,6}$/;
|
||||
|
||||
let identifierNamesGenerator: IIdentifierNamesGenerator,
|
||||
hexadecimalIdentifierName: string;
|
||||
|
||||
before(() => {
|
||||
const inversifyContainerFacade: IInversifyContainerFacade = new InversifyContainerFacade();
|
||||
|
||||
inversifyContainerFacade.load('', {
|
||||
identifiersPrefix: 'foo'
|
||||
});
|
||||
identifierNamesGenerator = inversifyContainerFacade.getNamed<IIdentifierNamesGenerator>(
|
||||
ServiceIdentifiers.IIdentifierNamesGenerator,
|
||||
IdentifierNamesGenerator.HexadecimalIdentifierNamesGenerator
|
||||
);
|
||||
|
||||
hexadecimalIdentifierName = identifierNamesGenerator.generateWithPrefix();
|
||||
});
|
||||
|
||||
it('should return hexadecimal name with prefix', () => {
|
||||
assert.match(hexadecimalIdentifierName, regExp);
|
||||
})
|
||||
});
|
||||
|
||||
describe('Hexadecimal name with random prefix', () => {
|
||||
const regExp: RegExp = /^(\w){6}_0x(\w){4,6}$/;
|
||||
|
||||
let identifierNamesGenerator: IIdentifierNamesGenerator,
|
||||
hexadecimalIdentifierName: string;
|
||||
|
||||
before(() => {
|
||||
const inversifyContainerFacade: IInversifyContainerFacade = new InversifyContainerFacade();
|
||||
|
||||
inversifyContainerFacade.load('', {
|
||||
identifiersPrefix: true
|
||||
});
|
||||
identifierNamesGenerator = inversifyContainerFacade.getNamed<IIdentifierNamesGenerator>(
|
||||
ServiceIdentifiers.IIdentifierNamesGenerator,
|
||||
IdentifierNamesGenerator.HexadecimalIdentifierNamesGenerator
|
||||
);
|
||||
|
||||
hexadecimalIdentifierName = identifierNamesGenerator.generateWithPrefix();
|
||||
});
|
||||
|
||||
it('should return hexadecimal name with prefix', () => {
|
||||
assert.match(hexadecimalIdentifierName, regExp);
|
||||
})
|
||||
});
|
||||
});
|
||||
|
||||
describe('getPrefix (): string', () => {
|
||||
const expectedIdentifierPrefix: string = 'foo';
|
||||
const regExp: RegExp = /^foo_0x(\w){4,6}$/;
|
||||
|
||||
let identifierNamesGenerator: IIdentifierNamesGenerator,
|
||||
identifierPrefix: string;
|
||||
hexadecimalIdentifierName: string;
|
||||
|
||||
before(() => {
|
||||
const inversifyContainerFacade: IInversifyContainerFacade = new InversifyContainerFacade();
|
||||
@@ -104,11 +52,11 @@ describe('HexadecimalIdentifierNamesGenerator', () => {
|
||||
IdentifierNamesGenerator.HexadecimalIdentifierNamesGenerator
|
||||
);
|
||||
|
||||
identifierPrefix = identifierNamesGenerator.getPrefix();
|
||||
hexadecimalIdentifierName = identifierNamesGenerator.generateWithPrefix();
|
||||
});
|
||||
|
||||
it('should return prefix', () => {
|
||||
assert.equal(identifierPrefix, expectedIdentifierPrefix);
|
||||
it('should return hexadecimal name with prefix', () => {
|
||||
assert.match(hexadecimalIdentifierName, regExp);
|
||||
})
|
||||
});
|
||||
});
|
||||
|
||||
+24
-92
@@ -130,94 +130,8 @@ describe('MangledIdentifierNamesGenerator', () => {
|
||||
});
|
||||
|
||||
describe('generateWithPrefix (): string', () => {
|
||||
describe('Mangled name with prefix', () => {
|
||||
let identifierNamesGenerator: IIdentifierNamesGenerator,
|
||||
mangledIdentifierName: string;
|
||||
|
||||
before(() => {
|
||||
const inversifyContainerFacade: IInversifyContainerFacade = new InversifyContainerFacade();
|
||||
|
||||
inversifyContainerFacade.load('', {
|
||||
identifiersPrefix: 'foo'
|
||||
});
|
||||
identifierNamesGenerator = inversifyContainerFacade.getNamed<IIdentifierNamesGenerator>(
|
||||
ServiceIdentifiers.IIdentifierNamesGenerator,
|
||||
IdentifierNamesGenerator.MangledIdentifierNamesGenerator
|
||||
);
|
||||
});
|
||||
|
||||
describe('variant #1: initial mangled name', () => {
|
||||
const expectedMangledIdentifierName: string = 'foo_a';
|
||||
|
||||
beforeEach(() => {
|
||||
mangledIdentifierName = identifierNamesGenerator.generateWithPrefix();
|
||||
});
|
||||
|
||||
it('should return mangled name with prefix', () => {
|
||||
assert.equal(mangledIdentifierName, expectedMangledIdentifierName);
|
||||
});
|
||||
});
|
||||
|
||||
describe('variant #2: second mangled name', () => {
|
||||
const expectedMangledIdentifierName: string = 'foo_b';
|
||||
|
||||
beforeEach(() => {
|
||||
mangledIdentifierName = identifierNamesGenerator.generateWithPrefix();
|
||||
});
|
||||
|
||||
it('should return mangled name with prefix', () => {
|
||||
assert.equal(mangledIdentifierName, expectedMangledIdentifierName);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('Mangled name with random prefix', () => {
|
||||
let identifierNamesGenerator: IIdentifierNamesGenerator,
|
||||
mangledIdentifierName: string;
|
||||
|
||||
before(() => {
|
||||
const inversifyContainerFacade: IInversifyContainerFacade = new InversifyContainerFacade();
|
||||
|
||||
inversifyContainerFacade.load('', {
|
||||
identifiersPrefix: true
|
||||
});
|
||||
identifierNamesGenerator = inversifyContainerFacade.getNamed<IIdentifierNamesGenerator>(
|
||||
ServiceIdentifiers.IIdentifierNamesGenerator,
|
||||
IdentifierNamesGenerator.MangledIdentifierNamesGenerator
|
||||
);
|
||||
});
|
||||
|
||||
describe('variant #1: initial mangled name', () => {
|
||||
const expectedMangledIdentifierNameRegExp: RegExp = /(\w){6}_a/;
|
||||
|
||||
beforeEach(() => {
|
||||
mangledIdentifierName = identifierNamesGenerator.generateWithPrefix();
|
||||
});
|
||||
|
||||
it('should return mangled name with prefix', () => {
|
||||
assert.match(mangledIdentifierName, expectedMangledIdentifierNameRegExp);
|
||||
});
|
||||
});
|
||||
|
||||
describe('variant #2: second mangled name', () => {
|
||||
const expectedMangledIdentifierNameRegExp: RegExp = /(\w){6}_b/;
|
||||
|
||||
beforeEach(() => {
|
||||
mangledIdentifierName = identifierNamesGenerator.generateWithPrefix();
|
||||
});
|
||||
|
||||
it('should return mangled name with prefix', () => {
|
||||
assert.match(mangledIdentifierName, expectedMangledIdentifierNameRegExp);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('getPrefix (): string', () => {
|
||||
const expectedIdentifierPrefix: string = 'foo';
|
||||
|
||||
let identifierNamesGenerator: IIdentifierNamesGenerator,
|
||||
identifierPrefix: string;
|
||||
mangledIdentifierName: string;
|
||||
|
||||
before(() => {
|
||||
const inversifyContainerFacade: IInversifyContainerFacade = new InversifyContainerFacade();
|
||||
@@ -229,12 +143,30 @@ describe('MangledIdentifierNamesGenerator', () => {
|
||||
ServiceIdentifiers.IIdentifierNamesGenerator,
|
||||
IdentifierNamesGenerator.MangledIdentifierNamesGenerator
|
||||
);
|
||||
|
||||
identifierPrefix = identifierNamesGenerator.getPrefix();
|
||||
});
|
||||
|
||||
it('should return prefix', () => {
|
||||
assert.equal(identifierPrefix, expectedIdentifierPrefix);
|
||||
})
|
||||
describe('variant #1: initial mangled name', () => {
|
||||
const expectedMangledIdentifierName: string = 'foo_a';
|
||||
|
||||
beforeEach(() => {
|
||||
mangledIdentifierName = identifierNamesGenerator.generateWithPrefix();
|
||||
});
|
||||
|
||||
it('should return mangled name with prefix', () => {
|
||||
assert.equal(mangledIdentifierName, expectedMangledIdentifierName);
|
||||
});
|
||||
});
|
||||
|
||||
describe('variant #2: second mangled name', () => {
|
||||
const expectedMangledIdentifierName: string = 'foo_b';
|
||||
|
||||
beforeEach(() => {
|
||||
mangledIdentifierName = identifierNamesGenerator.generateWithPrefix();
|
||||
});
|
||||
|
||||
it('should return mangled name with prefix', () => {
|
||||
assert.equal(mangledIdentifierName, expectedMangledIdentifierName);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user