123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227 |
- import { assert } from 'chai';
- import { TInputOptions } from '../../../../src/types/options/TInputOptions';
- import { IOptions } from '../../../../src/interfaces/options/IOptions';
- import { DEFAULT_PRESET } from '../../../../src/options/presets/Default';
- import { Options } from '../../../../src/options/Options';
- import { OptionsNormalizer } from '../../../../src/options/OptionsNormalizer';
- /**
- * @param optionsPreset
- * @returns {IOptions}
- */
- function getNormalizedOptions (optionsPreset: TInputOptions): TInputOptions {
- const options: IOptions = new Options(optionsPreset);
- return OptionsNormalizer.normalizeOptions(options);
- }
- describe('OptionsNormalizer', () => {
- describe('normalizeOptions (options: IObfuscatorOptions): IObfuscatorOptions', () => {
- let optionsPreset: TInputOptions,
- expectedOptionsPreset: TInputOptions;
- it('should normalize options preset: controlFlowFlatteningThresholdRule', () => {
- optionsPreset = {
- ...DEFAULT_PRESET,
- controlFlowFlattening: true,
- controlFlowFlatteningThreshold: 0
- };
- expectedOptionsPreset = {
- ...DEFAULT_PRESET,
- controlFlowFlattening: false,
- controlFlowFlatteningThreshold: 0
- };
- assert.deepEqual(getNormalizedOptions(optionsPreset), expectedOptionsPreset);
- });
- it('should normalize options preset: deadCodeInjectionRule', () => {
- optionsPreset = {
- ...DEFAULT_PRESET,
- deadCodeInjection: true,
- deadCodeInjectionThreshold: 0.4,
- stringArray: false,
- stringArrayThreshold: 0
- };
- expectedOptionsPreset = {
- ...DEFAULT_PRESET,
- deadCodeInjection: true,
- deadCodeInjectionThreshold: 0.4,
- stringArray: true,
- stringArrayThreshold: 0.75
- };
- assert.deepEqual(getNormalizedOptions(optionsPreset), expectedOptionsPreset);
- });
- it('should normalize options preset: deadCodeInjectionRule. `stringArrayThreshold` option is not empty', () => {
- optionsPreset = {
- ...DEFAULT_PRESET,
- deadCodeInjection: true,
- deadCodeInjectionThreshold: 0.4,
- stringArray: false,
- stringArrayThreshold: 0.5
- };
- expectedOptionsPreset = {
- ...DEFAULT_PRESET,
- deadCodeInjection: true,
- deadCodeInjectionThreshold: 0.4,
- stringArray: true,
- stringArrayThreshold: 0.5
- };
- assert.deepEqual(getNormalizedOptions(optionsPreset), expectedOptionsPreset);
- });
- it('should normalize options preset: deadCodeInjectionThresholdRule', () => {
- optionsPreset = {
- ...DEFAULT_PRESET,
- deadCodeInjection: true,
- deadCodeInjectionThreshold: 0
- };
- expectedOptionsPreset = {
- ...DEFAULT_PRESET,
- deadCodeInjection: false,
- deadCodeInjectionThreshold: 0
- };
- assert.deepEqual(getNormalizedOptions(optionsPreset), expectedOptionsPreset);
- });
- it('should normalize options preset: domainLockRule', () => {
- optionsPreset = {
- ...DEFAULT_PRESET,
- domainLock: ['//localhost:9000', 'https://google.ru/abc?cde=fgh']
- };
- expectedOptionsPreset = {
- ...DEFAULT_PRESET,
- domainLock: ['localhost', 'google.ru']
- };
- assert.deepEqual(getNormalizedOptions(optionsPreset), expectedOptionsPreset);
- });
- it('should normalize options preset: selfDefendingRule', () => {
- optionsPreset = {
- ...DEFAULT_PRESET,
- selfDefending: true,
- compact: false
- };
- expectedOptionsPreset = {
- ...DEFAULT_PRESET,
- selfDefending: true,
- compact: true
- };
- assert.deepEqual(getNormalizedOptions(optionsPreset), expectedOptionsPreset);
- });
- it('should normalize options preset: sourceMapBaseUrlRule #1', () => {
- optionsPreset = {
- ...DEFAULT_PRESET,
- sourceMapBaseUrl: 'http://localhost:9000',
- };
- expectedOptionsPreset = {
- ...DEFAULT_PRESET,
- sourceMapBaseUrl: ''
- };
- assert.deepEqual(getNormalizedOptions(optionsPreset), expectedOptionsPreset);
- });
- it('should normalize options preset: sourceMapBaseUrlRule #2', () => {
- optionsPreset = {
- ...DEFAULT_PRESET,
- sourceMapBaseUrl: 'http://localhost:9000',
- sourceMapFileName: '/outputSourceMapName.map'
- };
- expectedOptionsPreset = {
- ...DEFAULT_PRESET,
- sourceMapBaseUrl: 'http://localhost:9000/',
- sourceMapFileName: 'outputSourceMapName.js.map'
- };
- assert.deepEqual(getNormalizedOptions(optionsPreset), expectedOptionsPreset);
- });
- it('should normalize options preset: sourceMapFileNameRule', () => {
- optionsPreset = {
- ...DEFAULT_PRESET,
- sourceMapBaseUrl: 'http://localhost:9000',
- sourceMapFileName: '//outputSourceMapName'
- };
- expectedOptionsPreset = {
- ...DEFAULT_PRESET,
- sourceMapBaseUrl: 'http://localhost:9000/',
- sourceMapFileName: 'outputSourceMapName.js.map'
- };
- assert.deepEqual(getNormalizedOptions(optionsPreset), expectedOptionsPreset);
- });
- it('should normalize options preset: stringArrayRule', () => {
- optionsPreset = {
- ...DEFAULT_PRESET,
- stringArray: false,
- stringArrayEncoding: 'rc4',
- stringArrayThreshold: 0.5,
- rotateStringArray: true
- };
- expectedOptionsPreset = {
- ...DEFAULT_PRESET,
- stringArray: false,
- stringArrayEncoding: false,
- stringArrayThreshold: 0,
- rotateStringArray: false
- };
- assert.deepEqual(getNormalizedOptions(optionsPreset), expectedOptionsPreset);
- });
- it('should normalize options preset: stringArrayEncodingRule', () => {
- optionsPreset = {
- ...DEFAULT_PRESET,
- stringArrayEncoding: true
- };
- expectedOptionsPreset = {
- ...DEFAULT_PRESET,
- stringArrayEncoding: 'base64'
- };
- assert.deepEqual(getNormalizedOptions(optionsPreset), expectedOptionsPreset);
- });
- it('should normalize options preset: stringArrayThresholdRule', () => {
- optionsPreset = {
- ...DEFAULT_PRESET,
- rotateStringArray: true,
- stringArray: true,
- stringArrayThreshold: 0
- };
- expectedOptionsPreset = {
- ...DEFAULT_PRESET,
- rotateStringArray: false,
- stringArray: false,
- stringArrayThreshold: 0
- };
- assert.deepEqual(getNormalizedOptions(optionsPreset), expectedOptionsPreset);
- });
- });
- });
|