1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- import 'reflect-metadata';
- import { assert } from 'chai';
- import { IObfuscationResult } from '../../../../../../src/interfaces/source-code/IObfuscationResult';
- import { NO_ADDITIONAL_NODES_PRESET } from '../../../../../../src/options/presets/NoCustomNodes';
- import { JavaScriptObfuscator } from '../../../../../../src/JavaScriptObfuscatorFacade';
- import { readFileAsString } from '../../../../../helpers/readFileAsString';
- describe('StringArrayTemplate', () => {
- describe('Prevailing kind of variables', () => {
- describe('`var` kind', () => {
- let obfuscatedCode: string,
- stringArrayRegExp: RegExp = /var (_0x(\w){4}) *= *\['.*'];/;
- beforeEach(() => {
- const code: string = readFileAsString(__dirname + '/fixtures/prevailing-kind-of-variables-var.js');
- const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
- code,
- {
- ...NO_ADDITIONAL_NODES_PRESET,
- stringArray: true,
- stringArrayThreshold: 1
- }
- );
- obfuscatedCode = obfuscationResult.getObfuscatedCode();
- });
- it('Should return correct kind of variables for string array', () => {
- assert.match(obfuscatedCode, stringArrayRegExp);
- });
- it('Should does not break on obfuscating', () => {
- assert.doesNotThrow(() => obfuscatedCode);
- });
- });
- describe('`const` kind', () => {
- let obfuscatedCode: string,
- stringArrayRegExp: RegExp = /const (_0x(\w){4}) *= *\['.*'];/;
- beforeEach(() => {
- const code: string = readFileAsString(__dirname + '/fixtures/prevailing-kind-of-variables-const.js');
- const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
- code,
- {
- ...NO_ADDITIONAL_NODES_PRESET,
- stringArray: true,
- stringArrayThreshold: 1
- }
- );
- obfuscatedCode = obfuscationResult.getObfuscatedCode();
- });
- it('Should return correct kind of variables for string array', () => {
- assert.match(obfuscatedCode, stringArrayRegExp);
- });
- it('Should does not break on obfuscating', () => {
- assert.doesNotThrow(() => obfuscatedCode);
- });
- });
- describe('`let` kind', () => {
- let obfuscatedCode: string,
- stringArrayRegExp: RegExp = /const (_0x(\w){4}) *= *\['.*'];/;
- beforeEach(() => {
- const code: string = readFileAsString(__dirname + '/fixtures/prevailing-kind-of-variables-let.js');
- const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
- code,
- {
- ...NO_ADDITIONAL_NODES_PRESET,
- stringArray: true,
- stringArrayThreshold: 1
- }
- );
- obfuscatedCode = obfuscationResult.getObfuscatedCode();
- });
- it('Should return correct kind of variables for string array', () => {
- assert.match(obfuscatedCode, stringArrayRegExp);
- });
- it('Should does not break on obfuscating', () => {
- assert.doesNotThrow(() => obfuscatedCode);
- });
- });
- });
- });
|