sanex3339
2017-12-14 01:47:13 +03:00
parent 70c78859c2
commit c0fd72eabd
12 changed files with 115 additions and 38 deletions
-1
View File
@@ -35,7 +35,6 @@ import { NO_CUSTOM_NODES_PRESET } from '../../src/options/presets/NoCustomNodes'
{
...NO_CUSTOM_NODES_PRESET,
compact: false,
identifierNamesGenerator: 'mangled'
}
).getObfuscatedCode();
@@ -9,14 +9,13 @@ import { readFileAsString } from '../../../../helpers/readFileAsString';
import { JavaScriptObfuscator } from '../../../../../src/JavaScriptObfuscatorFacade';
describe('MethodDefinitionTransformer', () => {
const code: string = readFileAsString(__dirname + '/fixtures/input.js');
describe('variant #1: default behaviour', () => {
const regExp: RegExp = /\['bar'\]\(\)\{\}/;
let obfuscatedCode: string;
before(() => {
const code: string = readFileAsString(__dirname + '/fixtures/sample-input.js');
const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
code,
{
@@ -39,6 +38,7 @@ describe('MethodDefinitionTransformer', () => {
let obfuscatedCode: string;
before(() => {
const code: string = readFileAsString(__dirname + '/fixtures/sample-input.js');
const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
code,
{
@@ -66,6 +66,7 @@ describe('MethodDefinitionTransformer', () => {
let obfuscatedCode: string;
before(() => {
const code: string = readFileAsString(__dirname + '/fixtures/sample-input.js');
const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
code,
{
@@ -280,7 +280,7 @@ describe('DeadCodeInjectionTransformer', () => {
});
});
describe('variant #7- chance of `IfStatement` variant', () => {
describe('variant #7 - chance of `IfStatement` variant', () => {
const samplesCount: number = 1000;
const delta: number = 0.1;
const expectedDistribution: number = 0.25;
@@ -413,4 +413,26 @@ describe('VariableDeclarationTransformer', () => {
assert.match(obfuscatedCode, computedObjectExpressionRegExp);
});
});
describe('variant #12: method definition key identifier', () => {
const regExp: RegExp = /\['bar'] *\(\) *{}/;
let obfuscatedCode: string;
before(() => {
const code: string = readFileAsString(__dirname + '/fixtures/method-definition-identifier.js');
const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
code,
{
...NO_CUSTOM_NODES_PRESET
}
);
obfuscatedCode = obfuscationResult.getObfuscatedCode();
});
it('shouldn\'t transform method definition node key identifier', () => {
assert.match(obfuscatedCode, regExp);
});
});
});
@@ -0,0 +1,7 @@
(function () {
var bar = 1;
class Foo {
bar() {}
}
})();