mirror of
https://github.com/javascript-obfuscator/javascript-obfuscator
synced 2026-08-09 12:42:29 +00:00
utils split on few utils classes
This commit is contained in:
+4
-4
@@ -2,7 +2,7 @@ import * as format from 'string-template';
|
||||
|
||||
import { DomainLockNodeTemplate } from '../../../../../src/templates/custom-nodes/domain-lock-nodes/domain-lock-node/DomainLockNodeTemplate';
|
||||
|
||||
import { Utils } from '../../../../../src/Utils';
|
||||
import { CryptUtils } from '../../../../../src/utils/CryptUtils';
|
||||
|
||||
|
||||
const assert: Chai.AssertStatic = require('chai').assert;
|
||||
@@ -46,7 +46,7 @@ describe('DomainLockNodeTemplate (): string', () => {
|
||||
[
|
||||
hiddenDomainsString,
|
||||
diff
|
||||
] = Utils.hideString(domainsString, domainsString.length * 3);
|
||||
] = CryptUtils.hideString(domainsString, domainsString.length * 3);
|
||||
|
||||
assert.doesNotThrow(() => getFunctionFromTemplate({
|
||||
domainLockFunctionName: 'domainLockFunction',
|
||||
@@ -62,7 +62,7 @@ describe('DomainLockNodeTemplate (): string', () => {
|
||||
[
|
||||
hiddenDomainsString,
|
||||
diff
|
||||
] = Utils.hideString(domainsString, domainsString.length * 3);
|
||||
] = CryptUtils.hideString(domainsString, domainsString.length * 3);
|
||||
|
||||
assert.doesNotThrow(() => getFunctionFromTemplate({
|
||||
domainLockFunctionName: 'domainLockFunction',
|
||||
@@ -78,7 +78,7 @@ describe('DomainLockNodeTemplate (): string', () => {
|
||||
[
|
||||
hiddenDomainsString,
|
||||
diff
|
||||
] = Utils.hideString(domainsString, domainsString.length * 3);
|
||||
] = CryptUtils.hideString(domainsString, domainsString.length * 3);
|
||||
|
||||
assert.throws(() => getFunctionFromTemplate({
|
||||
domainLockFunctionName: 'domainLockFunction',
|
||||
|
||||
+3
-3
@@ -6,7 +6,7 @@ import { StringArrayBase64DecodeNodeTemplate } from '../../../../../src/template
|
||||
import { StringArrayCallsWrapperTemplate } from '../../../../../src/templates/custom-nodes/string-array-nodes/string-array-calls-wrapper/StringArrayCallsWrapperTemplate';
|
||||
import { StringArrayRc4DecodeNodeTemplate } from '../../../../../src/templates/custom-nodes/string-array-nodes/string-array-calls-wrapper/StringArrayRC4DecodeNodeTemplate';
|
||||
|
||||
import { Utils } from '../../../../../src/Utils';
|
||||
import { CryptUtils } from '../../../../../src/utils/CryptUtils';
|
||||
|
||||
const assert: Chai.AssertStatic = require('chai').assert;
|
||||
|
||||
@@ -26,7 +26,7 @@ function getFunctionFromTemplateBase64Encoding (
|
||||
let stringArrayCallsWrapperTemplate: string = format(StringArrayCallsWrapperTemplate(), templateData);
|
||||
|
||||
return Function(`
|
||||
var ${stringArrayName} = ['${Utils.btoa('test1')}'];
|
||||
var ${stringArrayName} = ['${CryptUtils.btoa('test1')}'];
|
||||
|
||||
${stringArrayCallsWrapperTemplate}
|
||||
|
||||
@@ -52,7 +52,7 @@ function getFunctionFromTemplateRc4Encoding (
|
||||
let stringArrayCallsWrapperTemplate: string = format(StringArrayCallsWrapperTemplate(), templateData);
|
||||
|
||||
return Function(`
|
||||
var ${stringArrayName} = ['${Utils.btoa(Utils.rc4('test1', key))}'];
|
||||
var ${stringArrayName} = ['${CryptUtils.btoa(CryptUtils.rc4('test1', key))}'];
|
||||
|
||||
${stringArrayCallsWrapperTemplate}
|
||||
|
||||
|
||||
+6
-4
@@ -7,16 +7,18 @@ BabelPolyfill.append();
|
||||
/**
|
||||
* Unit tests
|
||||
*/
|
||||
import './unit-tests/ObfuscationResult.spec';
|
||||
import './unit-tests/OptionsNormalizer.spec';
|
||||
import './unit-tests/SourceMapCorrector.spec';
|
||||
import './unit-tests/cli/CLIUtils.spec';
|
||||
import './unit-tests/decorators/Initializable.spec';
|
||||
import './unit-tests/node/NodeAppender.spec';
|
||||
import './unit-tests/node/NodeUtils.spec';
|
||||
import './unit-tests/ObfuscationResult.spec';
|
||||
import './unit-tests/OptionsNormalizer.spec';
|
||||
import './unit-tests/SourceMapCorrector.spec';
|
||||
import './unit-tests/stack-trace-analyzer/StackTraceAnalyzer.spec';
|
||||
import './unit-tests/storages/ControlFlowStorage.spec';
|
||||
import './unit-tests/Utils.spec';
|
||||
import './unit-tests/utils/CryptUtils.spec';
|
||||
import './unit-tests/utils/RandomGeneratorUtils.spec';
|
||||
import './unit-tests/utils/Utils.spec';
|
||||
|
||||
/**
|
||||
* Functional tests
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
import { CryptUtils } from '../../../src/utils/CryptUtils';
|
||||
|
||||
const assert: Chai.AssertStatic = require('chai').assert;
|
||||
|
||||
describe('CryptUtils', () => {
|
||||
describe('btoa (string: string): string', () => {
|
||||
it('should create a base-64 encoded string from a given string', () => {
|
||||
assert.equal(CryptUtils.btoa('string'), 'c3RyaW5n');
|
||||
});
|
||||
});
|
||||
|
||||
describe('hideString (str: string, length: number): [string, string]', () => {
|
||||
let original1: string = 'example.com',
|
||||
[str1, diff] = CryptUtils.hideString(original1, 30);
|
||||
|
||||
it('should return a string with the original string within', () => {
|
||||
assert.isTrue(str1.length > original1.length);
|
||||
assert.equal(str1.replace(new RegExp('[' + diff + ']', 'g'), ''), original1);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('rc4 (string: string, key: string): string', () => {
|
||||
it('should encode string using the rc4 algorithm', () => {
|
||||
const string: string = 'test';
|
||||
const key: string = 'key';
|
||||
|
||||
assert.notEqual(CryptUtils.rc4(string, key), string);
|
||||
});
|
||||
|
||||
it('should encode and successfully decode string using the rc4 algorithm', () => {
|
||||
const string: string = 'test';
|
||||
const key: string = 'key';
|
||||
|
||||
assert.equal(CryptUtils.rc4(CryptUtils.rc4(string, key), key), string);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,12 @@
|
||||
import { RandomGeneratorUtils } from '../../../src/utils/RandomGeneratorUtils';
|
||||
|
||||
const assert: Chai.AssertStatic = require('chai').assert;
|
||||
|
||||
describe('RandomGeneratorUtils', () => {
|
||||
describe('getRandomVariableName (length: number = 6): string', () => {
|
||||
it('should return a string of given length with random variable name', () => {
|
||||
assert.match(RandomGeneratorUtils.getRandomVariableName(4), /^_0x(\w){4}$/);
|
||||
assert.match(RandomGeneratorUtils.getRandomVariableName(6), /^_0x(\w){4,6}$/);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Utils } from '../../src/Utils';
|
||||
import { Utils } from '../../../src/utils/Utils';
|
||||
|
||||
import { JSFuck } from '../../src/enums/JSFuck';
|
||||
import { JSFuck } from '../../../src/enums/JSFuck';
|
||||
|
||||
const assert: Chai.AssertStatic = require('chai').assert;
|
||||
|
||||
@@ -35,12 +35,6 @@ describe('Utils', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('btoa (string: string): string', () => {
|
||||
it('should creates a base-64 encoded string from a given string', () => {
|
||||
assert.equal(Utils.btoa('string'), 'c3RyaW5n');
|
||||
});
|
||||
});
|
||||
|
||||
describe('decToHex (dec: number): string', () => {
|
||||
it('should creates a string with hexadecimal value from a given decimal number', () => {
|
||||
assert.equal(Utils.decToHex(0), '0');
|
||||
@@ -60,13 +54,6 @@ describe('Utils', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('getRandomVariableName (length: number = 6): string', () => {
|
||||
it('should return a string of given length with random variable name', () => {
|
||||
assert.match(Utils.getRandomVariableName(4), /^_0x(\w){4}$/);
|
||||
assert.match(Utils.getRandomVariableName(6), /^_0x(\w){4,6}$/);
|
||||
});
|
||||
});
|
||||
|
||||
describe('isInteger (number: number): boolean', () => {
|
||||
it('should return true if given number or string is integer', () => {
|
||||
assert.equal(Utils.isInteger(4), true);
|
||||
@@ -118,15 +105,4 @@ describe('Utils', () => {
|
||||
assert.equal(Utils.stringToUnicodeEscapeSequence('string'), expected);
|
||||
});
|
||||
});
|
||||
|
||||
describe('hideString (str: string, length: number): [string, string]', () => {
|
||||
let original1: string = 'example.com',
|
||||
[str1, diff] = Utils.hideString(original1, 30);
|
||||
|
||||
it('should return a string with the original string within', () => {
|
||||
assert.isTrue(str1.length > original1.length);
|
||||
assert.equal(str1.replace(new RegExp('[' + diff + ']', 'g'), ''), original1);
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user