mirror of
https://github.com/javascript-obfuscator/javascript-obfuscator
synced 2026-08-09 12:42:29 +00:00
Updated test for BaseIdentifierObfuscatingReplacer and ArrayStorage
This commit is contained in:
+27
-3
@@ -7,12 +7,12 @@ import { readFileAsString } from '../../../../../helpers/readFileAsString';
|
||||
import { JavaScriptObfuscator } from '../../../../../../src/JavaScriptObfuscatorFacade';
|
||||
|
||||
describe('BaseIdentifierObfuscatingReplacer', () => {
|
||||
describe('Base rule', () => {
|
||||
describe('Variant #1: default behaviour', () => {
|
||||
describe('Reserved names', () => {
|
||||
describe('Variant #1: ignore local reserved names', () => {
|
||||
let obfuscatedCode: string;
|
||||
|
||||
before(() => {
|
||||
const code: string = readFileAsString(__dirname + '/fixtures/simple-input.js');
|
||||
const code: string = readFileAsString(__dirname + '/fixtures/local-reserved-names.js');
|
||||
|
||||
obfuscatedCode = JavaScriptObfuscator.obfuscate(
|
||||
code,
|
||||
@@ -30,5 +30,29 @@ describe('BaseIdentifierObfuscatingReplacer', () => {
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Variant #1: ignore global reserved names', () => {
|
||||
let obfuscatedCode: string;
|
||||
|
||||
before(() => {
|
||||
const code: string = readFileAsString(__dirname + '/fixtures/global-reserved-names.js');
|
||||
|
||||
obfuscatedCode = JavaScriptObfuscator.obfuscate(
|
||||
code,
|
||||
{
|
||||
...NO_ADDITIONAL_NODES_PRESET,
|
||||
renameGlobals: true,
|
||||
reservedNames: ['[abc|ghi]']
|
||||
}
|
||||
).getObfuscatedCode();
|
||||
});
|
||||
|
||||
it('Should keep reserved names without transformations when `reservedNames` option is enabled', () => {
|
||||
assert.match(
|
||||
obfuscatedCode,
|
||||
/var *abc *= *0x1; *var *_0x([a-f0-9]){4,6} *= *0x2; *var *ghi *= *0x3;/
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
var abc = 1;
|
||||
var def = 2;
|
||||
var ghi = 3;
|
||||
@@ -74,6 +74,23 @@ describe('ArrayStorage', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('getStorageId', () => {
|
||||
const storageIdRegExp: RegExp = /^[a-zA-Z0-9]{6}$/;
|
||||
|
||||
let storageId: string;
|
||||
|
||||
before(() => {
|
||||
storage = getStorageInstance<string>();
|
||||
storage.set(storageKey, storageValue);
|
||||
|
||||
storageId = storage.getStorageId();
|
||||
});
|
||||
|
||||
it('should return storage id', () => {
|
||||
assert.match(storageId, storageIdRegExp);
|
||||
});
|
||||
});
|
||||
|
||||
describe('get', () => {
|
||||
describe('Variant #1: value exist', () => {
|
||||
const expectedValue: string = storageValue;
|
||||
@@ -194,27 +211,62 @@ describe('ArrayStorage', () => {
|
||||
});
|
||||
|
||||
describe('mergeWith', () => {
|
||||
const secondStorageKey: number = 1;
|
||||
const secondStorageValue: string = 'bar';
|
||||
describe('Base merge', () => {
|
||||
const secondStorageKey: number = 1;
|
||||
const secondStorageValue: string = 'bar';
|
||||
|
||||
const expectedArray: string[] = [storageValue, secondStorageValue];
|
||||
const expectedArray: string[] = [storageValue, secondStorageValue];
|
||||
|
||||
let array: string[];
|
||||
let array: string[];
|
||||
|
||||
before(() => {
|
||||
storage = getStorageInstance<string>();
|
||||
storage.set(storageKey, storageValue);
|
||||
before(() => {
|
||||
storage = getStorageInstance<string>();
|
||||
storage.set(storageKey, storageValue);
|
||||
|
||||
const secondStorage: IArrayStorage <string> = getStorageInstance<string>();
|
||||
secondStorage.set(secondStorageKey, secondStorageValue);
|
||||
const secondStorage: IArrayStorage <string> = getStorageInstance<string>();
|
||||
secondStorage.set(secondStorageKey, secondStorageValue);
|
||||
|
||||
storage.mergeWith(secondStorage, false);
|
||||
storage.mergeWith(secondStorage, false);
|
||||
|
||||
array = storage.getStorage();
|
||||
array = storage.getStorage();
|
||||
});
|
||||
|
||||
it('should merge two storages', () => {
|
||||
assert.deepEqual(array, expectedArray);
|
||||
});
|
||||
});
|
||||
|
||||
it('should merge two storages', () => {
|
||||
assert.deepEqual(array, expectedArray);
|
||||
describe('Merge with storage id', () => {
|
||||
const secondStorageKey: number = 1;
|
||||
const secondStorageValue: string = 'bar';
|
||||
|
||||
const expectedArray: string[] = [storageValue, secondStorageValue];
|
||||
|
||||
let array: string[];
|
||||
let storageId: string;
|
||||
let expectedStorageId: string;
|
||||
|
||||
before(() => {
|
||||
storage = getStorageInstance<string>();
|
||||
storage.set(storageKey, storageValue);
|
||||
|
||||
const secondStorage: IArrayStorage <string> = getStorageInstance<string>();
|
||||
expectedStorageId = secondStorage.getStorageId();
|
||||
secondStorage.set(secondStorageKey, secondStorageValue);
|
||||
|
||||
storage.mergeWith(secondStorage, true);
|
||||
|
||||
storageId = storage.getStorageId();
|
||||
array = storage.getStorage();
|
||||
});
|
||||
|
||||
it('should update storage id', () => {
|
||||
assert.deepEqual(storageId, expectedStorageId);
|
||||
});
|
||||
|
||||
it('should merge two storages', () => {
|
||||
assert.deepEqual(array, expectedArray);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user