mirror of
https://github.com/javascript-obfuscator/javascript-obfuscator
synced 2026-08-09 12:42:29 +00:00
Merge pull request #730 from javascript-obfuscator/removed-unnecessary-cli-sanitizers
Removed unnecessary CLI sanitizers
This commit is contained in:
Vendored
+1
-1
File diff suppressed because one or more lines are too long
Vendored
+1
-1
File diff suppressed because one or more lines are too long
@@ -10,18 +10,17 @@ import { IObfuscatedCode } from '../interfaces/source-code/IObfuscatedCode';
|
||||
|
||||
import { initializable } from '../decorators/Initializable';
|
||||
|
||||
import { IdentifierNamesGenerator } from '../enums/generators/identifier-names-generators/IdentifierNamesGenerator';
|
||||
import { LoggingPrefix } from '../enums/logger/LoggingPrefix';
|
||||
import { ObfuscationTarget } from '../enums/ObfuscationTarget';
|
||||
import { OptionsPreset } from '../enums/options/presets/OptionsPreset';
|
||||
import { SourceMapMode } from '../enums/source-map/SourceMapMode';
|
||||
import { StringArrayEncoding } from '../enums/StringArrayEncoding';
|
||||
|
||||
import { DEFAULT_PRESET } from '../options/presets/Default';
|
||||
|
||||
import { ArraySanitizer } from './sanitizers/ArraySanitizer';
|
||||
import { BooleanSanitizer } from './sanitizers/BooleanSanitizer';
|
||||
import { IdentifierNamesGeneratorSanitizer } from './sanitizers/IdentifierNamesGeneratorSanitizer';
|
||||
import { ObfuscationTargetSanitizer } from './sanitizers/ObfuscatingTargetSanitizer';
|
||||
import { OptionsPresetSanitizer } from './sanitizers/OptionsPresetSanitizer';
|
||||
import { SourceMapModeSanitizer } from './sanitizers/SourceMapModeSanitizer';
|
||||
import { StringArrayEncodingSanitizer } from './sanitizers/StringArrayEncodingSanitizer';
|
||||
|
||||
import { CLIUtils } from './utils/CLIUtils';
|
||||
import { JavaScriptObfuscator } from '../JavaScriptObfuscatorFacade';
|
||||
@@ -233,9 +232,8 @@ export class JavaScriptObfuscatorCLI implements IInitializable {
|
||||
.option(
|
||||
'--identifier-names-generator <string>',
|
||||
'Sets identifier names generator. ' +
|
||||
'Values: hexadecimal, mangled, mangled-shuffled, dictionary. ' +
|
||||
'Default: hexadecimal',
|
||||
IdentifierNamesGeneratorSanitizer
|
||||
`Values: ${CLIUtils.stringifyOptionAvailableValues(IdentifierNamesGenerator)}. ` +
|
||||
`Default: ${IdentifierNamesGenerator.HexadecimalIdentifierNamesGenerator}`
|
||||
)
|
||||
.option(
|
||||
'--identifiers-prefix <string>',
|
||||
@@ -257,9 +255,8 @@ export class JavaScriptObfuscatorCLI implements IInitializable {
|
||||
.option(
|
||||
'--options-preset <string>',
|
||||
'Allows to set options preset. ' +
|
||||
'Values: default, low-obfuscation, medium-obfuscation, high-obfuscation. ' +
|
||||
'Default: default',
|
||||
OptionsPresetSanitizer
|
||||
`Values: ${CLIUtils.stringifyOptionAvailableValues(OptionsPreset)}. ` +
|
||||
`Default: ${OptionsPreset.Default}`
|
||||
)
|
||||
.option(
|
||||
'--reserved-names <list> (comma separated, without whitespaces)',
|
||||
@@ -317,9 +314,8 @@ export class JavaScriptObfuscatorCLI implements IInitializable {
|
||||
.option(
|
||||
'--source-map-mode <string>',
|
||||
'Specify source map output mode. ' +
|
||||
'Values: inline, separate. ' +
|
||||
'Default: separate',
|
||||
SourceMapModeSanitizer
|
||||
`Values: ${CLIUtils.stringifyOptionAvailableValues(SourceMapMode)}. ` +
|
||||
`Default: ${SourceMapMode.Separate}`
|
||||
)
|
||||
.option(
|
||||
'--split-strings <boolean>',
|
||||
@@ -338,10 +334,10 @@ export class JavaScriptObfuscatorCLI implements IInitializable {
|
||||
)
|
||||
.option(
|
||||
'--string-array-encoding <list> (comma separated, without whitespaces)',
|
||||
'Encodes each string in strings array using base64 or rc4 (this option can slow down your code speed. ' +
|
||||
'Values: none, base64, rc4. ' +
|
||||
'Default: none',
|
||||
StringArrayEncodingSanitizer
|
||||
'Encodes each string in strings array using base64 or rc4 (this option can slow down your code speed). ' +
|
||||
`Values: ${CLIUtils.stringifyOptionAvailableValues(StringArrayEncoding)}. ` +
|
||||
`Default: ${StringArrayEncoding.None}`,
|
||||
ArraySanitizer
|
||||
)
|
||||
.option(
|
||||
'--string-array-threshold <number>',
|
||||
@@ -351,9 +347,8 @@ export class JavaScriptObfuscatorCLI implements IInitializable {
|
||||
.option(
|
||||
'--target <string>',
|
||||
'Allows to set target environment for obfuscated code. ' +
|
||||
'Values: browser, browser-no-eval, node. ' +
|
||||
'Default: browser',
|
||||
ObfuscationTargetSanitizer
|
||||
`Values: ${CLIUtils.stringifyOptionAvailableValues(ObfuscationTarget)}. ` +
|
||||
`Default: ${ObfuscationTarget.Browser}`
|
||||
)
|
||||
.option(
|
||||
'--transform-object-keys <boolean>',
|
||||
|
||||
@@ -1,21 +0,0 @@
|
||||
import { TCLISanitizer } from '../../types/cli/TCLISanitizer';
|
||||
|
||||
import { IdentifierNamesGenerator } from '../../enums/generators/identifier-names-generators/IdentifierNamesGenerator';
|
||||
|
||||
/**
|
||||
* @param {string} value
|
||||
* @returns {string}
|
||||
*/
|
||||
export const IdentifierNamesGeneratorSanitizer: TCLISanitizer <string> = (value: string): string => {
|
||||
const isCorrectIdentifierNamesGenerator: boolean = Object
|
||||
.keys(IdentifierNamesGenerator)
|
||||
.some((key: string): boolean => {
|
||||
return IdentifierNamesGenerator[<keyof typeof IdentifierNamesGenerator>key] === value;
|
||||
});
|
||||
|
||||
if (!isCorrectIdentifierNamesGenerator) {
|
||||
throw new ReferenceError('Invalid value of `--identifier-names-generator` option');
|
||||
}
|
||||
|
||||
return value;
|
||||
};
|
||||
@@ -1,21 +0,0 @@
|
||||
import { TCLISanitizer } from '../../types/cli/TCLISanitizer';
|
||||
|
||||
import { ObfuscationTarget } from '../../enums/ObfuscationTarget';
|
||||
|
||||
/**
|
||||
* @param {string} value
|
||||
* @returns {string}
|
||||
*/
|
||||
export const ObfuscationTargetSanitizer: TCLISanitizer <string> = (value: string): string => {
|
||||
const isCorrectTarget: boolean = Object
|
||||
.keys(ObfuscationTarget)
|
||||
.some((key: string): boolean => {
|
||||
return ObfuscationTarget[<keyof typeof ObfuscationTarget>key] === value;
|
||||
});
|
||||
|
||||
if (!isCorrectTarget) {
|
||||
throw new ReferenceError('Invalid value of `--target` option');
|
||||
}
|
||||
|
||||
return value;
|
||||
};
|
||||
@@ -1,21 +0,0 @@
|
||||
import { TCLISanitizer } from '../../types/cli/TCLISanitizer';
|
||||
|
||||
import { OptionsPreset } from '../../enums/options/presets/OptionsPreset';
|
||||
|
||||
/**
|
||||
* @param {string} value
|
||||
* @returns {string}
|
||||
*/
|
||||
export const OptionsPresetSanitizer: TCLISanitizer <string> = (value: string): string => {
|
||||
const isCorrectOptionsPreset: boolean = Object
|
||||
.keys(OptionsPreset)
|
||||
.some((key: string): boolean => {
|
||||
return OptionsPreset[<keyof typeof OptionsPreset>key] === value;
|
||||
});
|
||||
|
||||
if (!isCorrectOptionsPreset) {
|
||||
throw new ReferenceError('Invalid value of `--options-preset` option');
|
||||
}
|
||||
|
||||
return value;
|
||||
};
|
||||
@@ -1,21 +0,0 @@
|
||||
import { TCLISanitizer } from '../../types/cli/TCLISanitizer';
|
||||
|
||||
import { SourceMapMode } from '../../enums/source-map/SourceMapMode';
|
||||
|
||||
/**
|
||||
* @param {string} value
|
||||
* @returns {string}
|
||||
*/
|
||||
export const SourceMapModeSanitizer: TCLISanitizer <string> = (value: string): string => {
|
||||
const isCorrectSourceMapMode: boolean = Object
|
||||
.keys(SourceMapMode)
|
||||
.some((key: string): boolean => {
|
||||
return SourceMapMode[<keyof typeof SourceMapMode>key] === value;
|
||||
});
|
||||
|
||||
if (!isCorrectSourceMapMode) {
|
||||
throw new ReferenceError('Invalid value of `--source-map-mode` option');
|
||||
}
|
||||
|
||||
return value;
|
||||
};
|
||||
@@ -1,26 +0,0 @@
|
||||
import { TCLISanitizer } from '../../types/cli/TCLISanitizer';
|
||||
import { TStringArrayEncoding } from '../../types/options/TStringArrayEncoding';
|
||||
|
||||
import { StringArrayEncoding } from '../../enums/StringArrayEncoding';
|
||||
|
||||
import { ArraySanitizer } from './ArraySanitizer';
|
||||
|
||||
/**
|
||||
* @param {string} value
|
||||
* @returns {TStringArrayEncoding[]}
|
||||
*/
|
||||
export const StringArrayEncodingSanitizer: TCLISanitizer <TStringArrayEncoding[]> = (value: string): TStringArrayEncoding[] => {
|
||||
const valuesAsArray: TStringArrayEncoding[] = <TStringArrayEncoding[]>ArraySanitizer(value);
|
||||
|
||||
const isCorrectStringArrayEncodings: boolean = valuesAsArray.every((item: TStringArrayEncoding) =>
|
||||
Object
|
||||
.values(StringArrayEncoding)
|
||||
.includes(item)
|
||||
);
|
||||
|
||||
if (!isCorrectStringArrayEncodings) {
|
||||
throw new ReferenceError('Invalid value of `--string-array-encoding` option');
|
||||
}
|
||||
|
||||
return valuesAsArray;
|
||||
};
|
||||
@@ -2,6 +2,8 @@ import * as path from 'path';
|
||||
|
||||
import { TDictionary } from '../../types/TDictionary';
|
||||
|
||||
import { StringSeparator } from '../../enums/StringSeparator';
|
||||
|
||||
export class CLIUtils {
|
||||
/**
|
||||
* @type {string[]}
|
||||
@@ -37,4 +39,12 @@ export class CLIUtils {
|
||||
|
||||
return config;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {TDictionary} optionEnum
|
||||
* @returns {string}
|
||||
*/
|
||||
public static stringifyOptionAvailableValues (optionEnum: TDictionary): string {
|
||||
return Object.values(optionEnum).join(`${StringSeparator.Comma} `);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,11 +12,6 @@ import './unit-tests/analyzers/scope-analyzer/ScopeAnalyzer.spec';
|
||||
import './unit-tests/analyzers/string-array-storage-analyzer/StringArrayStorageAnalyzer.spec';
|
||||
import './unit-tests/cli/sanitizers/ArraySanitizer.spec';
|
||||
import './unit-tests/cli/sanitizers/BooleanSanitizer.spec';
|
||||
import './unit-tests/cli/sanitizers/IdentifierNamesGeneratorSanitizer.spec';
|
||||
import './unit-tests/cli/sanitizers/ObfuscationTargetSanitizer.spec';
|
||||
import './unit-tests/cli/sanitizers/OptionsPresetSanitizer.spec';
|
||||
import './unit-tests/cli/sanitizers/SourceMapModeSanitizer.spec';
|
||||
import './unit-tests/cli/sanitizers/StringArrayEncodingSanitizer.spec';
|
||||
import './unit-tests/cli/utils/CLIUtils.spec';
|
||||
import './unit-tests/cli/utils/ObfuscatedCodeWriter.spec';
|
||||
import './unit-tests/cli/utils/SourceCodeReader.spec';
|
||||
|
||||
@@ -1,34 +0,0 @@
|
||||
import { assert } from 'chai';
|
||||
|
||||
import { IdentifierNamesGeneratorSanitizer } from '../../../../src/cli/sanitizers/IdentifierNamesGeneratorSanitizer';
|
||||
|
||||
describe('IdentifierNamesGeneratorSanitizer', () => {
|
||||
describe('Variant #1: valid identifier names generator', () => {
|
||||
const inputValue: string = 'mangled';
|
||||
const expectedValue: string = inputValue;
|
||||
|
||||
let value: string;
|
||||
|
||||
before(() => {
|
||||
value = IdentifierNamesGeneratorSanitizer(inputValue);
|
||||
});
|
||||
|
||||
it('should sanitize value', () => {
|
||||
assert.equal(value, expectedValue);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Variant #2: invalid identifier names generator', () => {
|
||||
const inputValue: string = 'foo';
|
||||
|
||||
let testFunc: () => void;
|
||||
|
||||
before(() => {
|
||||
testFunc = () => IdentifierNamesGeneratorSanitizer(inputValue);
|
||||
});
|
||||
|
||||
it('should throw error', () => {
|
||||
assert.throw(testFunc, ReferenceError);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -1,34 +0,0 @@
|
||||
import { assert } from 'chai';
|
||||
|
||||
import { ObfuscationTargetSanitizer } from '../../../../src/cli/sanitizers/ObfuscatingTargetSanitizer';
|
||||
|
||||
describe('ObfuscationTargetSanitizer', () => {
|
||||
describe('Variant #1: valid obfuscation target', () => {
|
||||
const inputValue: string = 'browser';
|
||||
const expectedValue: string = inputValue;
|
||||
|
||||
let value: string;
|
||||
|
||||
before(() => {
|
||||
value = ObfuscationTargetSanitizer(inputValue);
|
||||
});
|
||||
|
||||
it('should sanitize value', () => {
|
||||
assert.equal(value, expectedValue);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Variant #2: invalid obfuscation target', () => {
|
||||
const inputValue: string = 'foo';
|
||||
|
||||
let testFunc: () => void;
|
||||
|
||||
before(() => {
|
||||
testFunc = () => ObfuscationTargetSanitizer(inputValue);
|
||||
});
|
||||
|
||||
it('should throw error', () => {
|
||||
assert.throw(testFunc, ReferenceError);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -1,34 +0,0 @@
|
||||
import { assert } from 'chai';
|
||||
|
||||
import { OptionsPresetSanitizer } from '../../../../src/cli/sanitizers/OptionsPresetSanitizer';
|
||||
|
||||
describe('OptionsPresetSanitizer', () => {
|
||||
describe('Variant #1: valid options preset', () => {
|
||||
const inputValue: string = 'low-obfuscation';
|
||||
const expectedValue: string = inputValue;
|
||||
|
||||
let value: string;
|
||||
|
||||
before(() => {
|
||||
value = OptionsPresetSanitizer(inputValue);
|
||||
});
|
||||
|
||||
it('should sanitize value', () => {
|
||||
assert.equal(value, expectedValue);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Variant #2: invalid options preset', () => {
|
||||
const inputValue: string = 'foo';
|
||||
|
||||
let testFunc: () => void;
|
||||
|
||||
before(() => {
|
||||
testFunc = () => OptionsPresetSanitizer(inputValue);
|
||||
});
|
||||
|
||||
it('should throw error', () => {
|
||||
assert.throw(testFunc, ReferenceError);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -1,34 +0,0 @@
|
||||
import { assert } from 'chai';
|
||||
|
||||
import { SourceMapModeSanitizer } from '../../../../src/cli/sanitizers/SourceMapModeSanitizer';
|
||||
|
||||
describe('SourceMapModeSanitizer', () => {
|
||||
describe('Variant #1: valid source map mode', () => {
|
||||
const inputValue: string = 'inline';
|
||||
const expectedValue: string = inputValue;
|
||||
|
||||
let value: string;
|
||||
|
||||
before(() => {
|
||||
value = SourceMapModeSanitizer(inputValue);
|
||||
});
|
||||
|
||||
it('should sanitize value', () => {
|
||||
assert.equal(value, expectedValue);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Variant #2: invalid source map mode', () => {
|
||||
const inputValue: string = 'foo';
|
||||
|
||||
let testFunc: () => void;
|
||||
|
||||
before(() => {
|
||||
testFunc = () => SourceMapModeSanitizer(inputValue);
|
||||
});
|
||||
|
||||
it('should throw error', () => {
|
||||
assert.throw(testFunc, ReferenceError);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -1,70 +0,0 @@
|
||||
import { assert } from 'chai';
|
||||
|
||||
import { TStringArrayEncoding } from '../../../../src/types/options/TStringArrayEncoding';
|
||||
|
||||
import { StringArrayEncoding } from '../../../../src/enums/StringArrayEncoding';
|
||||
|
||||
import { StringArrayEncodingSanitizer } from '../../../../src/cli/sanitizers/StringArrayEncodingSanitizer';
|
||||
|
||||
describe('StringArrayEncodingSanitizer', () => {
|
||||
describe('Variant #1: string array encoding `base64`', () => {
|
||||
const inputValue: string = 'base64';
|
||||
const expectedValue: TStringArrayEncoding[] = [StringArrayEncoding.Base64];
|
||||
|
||||
let value: TStringArrayEncoding[];
|
||||
|
||||
before(() => {
|
||||
value = StringArrayEncodingSanitizer(inputValue);
|
||||
});
|
||||
|
||||
it('should sanitize value', () => {
|
||||
assert.deepEqual(value, expectedValue);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Variant #2: string array encoding `base64, rc4`', () => {
|
||||
const inputValue: string = 'base64,rc4';
|
||||
const expectedValue: TStringArrayEncoding[] = [
|
||||
StringArrayEncoding.Base64,
|
||||
StringArrayEncoding.Rc4
|
||||
];
|
||||
|
||||
let value: TStringArrayEncoding[];
|
||||
|
||||
before(() => {
|
||||
value = StringArrayEncodingSanitizer(inputValue);
|
||||
});
|
||||
|
||||
it('should sanitize value', () => {
|
||||
assert.deepEqual(value, expectedValue);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Variant #3: string array encoding `foo`', () => {
|
||||
const inputValue: string = 'foo';
|
||||
|
||||
let testFunc: () => TStringArrayEncoding[];
|
||||
|
||||
before(() => {
|
||||
testFunc = () => StringArrayEncodingSanitizer(inputValue);
|
||||
});
|
||||
|
||||
it('should throw an error for invalid encoding', () => {
|
||||
assert.throws(testFunc, 'Invalid value');
|
||||
});
|
||||
});
|
||||
|
||||
describe('Variant #4: string array encoding `base64,foo`', () => {
|
||||
const inputValue: string = 'base64,foo';
|
||||
|
||||
let testFunc: () => TStringArrayEncoding[];
|
||||
|
||||
before(() => {
|
||||
testFunc = () => StringArrayEncodingSanitizer(inputValue);
|
||||
});
|
||||
|
||||
it('should throw an error for invalid encoding', () => {
|
||||
assert.throws(testFunc, 'Invalid value');
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -2,6 +2,8 @@ import { assert } from 'chai';
|
||||
|
||||
import { TInputOptions } from '../../../../src/types/options/TInputOptions';
|
||||
|
||||
import { StringArrayEncoding } from '../../../../src/enums/StringArrayEncoding';
|
||||
|
||||
import { CLIUtils } from '../../../../src/cli/utils/CLIUtils';
|
||||
|
||||
describe('CLIUtils', () => {
|
||||
@@ -83,4 +85,20 @@ describe('CLIUtils', () => {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('stringifyOptionAvailableValues', () => {
|
||||
describe('Variant #1: should stringify option available values', () => {
|
||||
const expectedResult: string = 'none, base64, rc4';
|
||||
|
||||
let result: Object;
|
||||
|
||||
before(() => {
|
||||
result = CLIUtils.stringifyOptionAvailableValues(StringArrayEncoding);
|
||||
});
|
||||
|
||||
it('should return option available values as string', () => {
|
||||
assert.deepEqual(result, expectedResult);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user