123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103 |
- import { assert } from 'chai';
- import { IdentifierNamesGenerator } from '../../../../src/enums/generators/identifier-names-generators/IdentifierNamesGenerator';
- import { NO_ADDITIONAL_NODES_PRESET } from '../../../../src/options/presets/NoCustomNodes';
- import { readFileAsString } from '../../../helpers/readFileAsString';
- import { JavaScriptObfuscator } from '../../../../src/JavaScriptObfuscatorFacade';
- describe('DomainLockCodeHelper', () => {
- describe('`domainLock` option is set', () => {
- describe('Variant #1: base behaviour', () => {
- const regExp: RegExp = /var _0x([a-f0-9]){4,6} *= *new RegExp/;
- let obfuscatedCode: string;
- before(() => {
- const code: string = readFileAsString(__dirname + '/fixtures/simple-input.js');
- obfuscatedCode = JavaScriptObfuscator.obfuscate(
- code,
- {
- ...NO_ADDITIONAL_NODES_PRESET,
- domainLock: ['.example.com']
- }
- ).getObfuscatedCode();
- });
- it('should correctly append code helper into the obfuscated code', () => {
- assert.match(obfuscatedCode, regExp);
- });
- });
- describe('Variant #2: identifier names when appended inside global scope', () => {
- const regExp: RegExp = /var foo[a-z] *= *foo[a-z]\(this, *function *\(\) *{/;
- let obfuscatedCode: string;
- before(() => {
- const code: string = readFileAsString(__dirname + '/fixtures/simple-input.js');
- obfuscatedCode = JavaScriptObfuscator.obfuscate(
- code,
- {
- ...NO_ADDITIONAL_NODES_PRESET,
- domainLock: ['.example.com'],
- identifierNamesGenerator: IdentifierNamesGenerator.MangledIdentifierNamesGenerator,
- identifiersPrefix: 'foo'
- }
- ).getObfuscatedCode();
- });
- it('should add prefix to the helper identifiers inside global scope', () => {
- assert.match(obfuscatedCode, regExp);
- });
- });
- describe('Variant #3: identifier names when appended inside function scope', () => {
- const regExp: RegExp = /var [a-z] *= *[a-z]\(this, *function *\(\) *{/;
- let obfuscatedCode: string;
- before(() => {
- const code: string = readFileAsString(__dirname + '/fixtures/append-inside-function-scope.js');
- obfuscatedCode = JavaScriptObfuscator.obfuscate(
- code,
- {
- ...NO_ADDITIONAL_NODES_PRESET,
- domainLock: ['.example.com'],
- identifierNamesGenerator: IdentifierNamesGenerator.MangledIdentifierNamesGenerator,
- identifiersPrefix: 'foo'
- }
- ).getObfuscatedCode();
- });
- it('should not add prefix to the helper identifiers inside global scope', () => {
- assert.match(obfuscatedCode, regExp);
- });
- });
- });
- describe('`domainLock` option isn\'t set', () => {
- const regExp: RegExp = /var _0x([a-f0-9]){4,6} *= *new RegExp/;
- let obfuscatedCode: string;
- before(() => {
- const code: string = readFileAsString(__dirname + '/fixtures/simple-input.js');
- obfuscatedCode = JavaScriptObfuscator.obfuscate(
- code,
- {
- ...NO_ADDITIONAL_NODES_PRESET,
- domainLock: []
- }
- ).getObfuscatedCode();
- });
- it('shouldn\'t append code helper into the obfuscated code', () => {
- assert.notMatch(obfuscatedCode, regExp);
- });
- });
- });
|