Pārlūkot izejas kodu

Fixed order of StringArrayCallsWrapper code helpers, added tests

sanex 4 gadi atpakaļ
vecāks
revīzija
017ade47db

Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 0 - 0
dist/index.browser.js


Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 0 - 0
dist/index.cli.js


Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 0 - 0
dist/index.js


+ 1 - 1
src/custom-code-helpers/string-array/StringArrayCallsWrapperBase64CodeHelper.ts

@@ -1,9 +1,9 @@
 import { injectable, } from 'inversify';
 
 import { AtobTemplate } from './templates/string-array-calls-wrapper/AtobTemplate';
+import { StringArrayBase64DecodeTemplate } from './templates/string-array-calls-wrapper/StringArrayBase64DecodeTemplate';
 
 import { StringArrayCallsWrapperCodeHelper } from './StringArrayCallsWrapperCodeHelper';
-import { StringArrayBase64DecodeTemplate } from './templates/string-array-calls-wrapper/StringArrayBase64DecodeTemplate';
 
 @injectable()
 export class StringArrayCallsWrapperBase64CodeHelper extends StringArrayCallsWrapperCodeHelper {

+ 4 - 2
src/custom-code-helpers/string-array/group/StringArrayCodeHelperGroup.ts

@@ -96,13 +96,15 @@ export class StringArrayCodeHelperGroup extends AbstractCustomCodeHelperGroup {
         );
 
         // stringArrayCallsWrapper helper nodes append
-        for (const stringArrayEncoding of this.options.stringArrayEncoding) {
+        const stringArrayEncodingsLength: number = this.options.stringArrayEncoding.length;
+        for (let i = 0; i < stringArrayEncodingsLength; i++) {
+            const stringArrayEncoding: TStringArrayEncoding = this.options.stringArrayEncoding[i];
             const stringArrayCallsWrapperCodeHelperName: CustomCodeHelper = this.getStringArrayCallsWrapperCodeHelperName(stringArrayEncoding);
 
             this.appendCustomNodeIfExist(
                 stringArrayCallsWrapperCodeHelperName,
                 (customCodeHelper: ICustomCodeHelper<TInitialData<StringArrayCallsWrapperCodeHelper>>) => {
-                    NodeAppender.insertAtIndex(nodeWithStatements, customCodeHelper.getNode(), 1);
+                    NodeAppender.insertAtIndex(nodeWithStatements, customCodeHelper.getNode(), i + 1);
                 }
             );
         }

+ 45 - 0
test/functional-tests/custom-code-helpers/string-array/group/StringArrayCodeHelperGroup.spec.ts

@@ -0,0 +1,45 @@
+import { assert } from 'chai';
+
+import { StringArrayEncoding } from '../../../../../src/enums/StringArrayEncoding';
+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('StringArrayCodeHelperGroup', () => {
+    const regExp: RegExp = new RegExp(
+        'var b *= *function\\(\\w, *\\w\\) *{.*return \\w;}; *' +
+        'var c *= *function\\(\\w, *\\w\\) *{.*return \\w;}; *' +
+        'var d *= *function\\(\\w, *\\w\\) *{.*return \\w;};'
+    );
+
+    describe('StringArrayCallsWrapper code helper names', () => {
+        let obfuscatedCode: string;
+
+        before(() => {
+            const code: string = readFileAsString(__dirname + '/fixtures/simple-input.js');
+
+            obfuscatedCode = JavaScriptObfuscator.obfuscate(
+                code,
+                {
+                    ...NO_ADDITIONAL_NODES_PRESET,
+                    identifierNamesGenerator: IdentifierNamesGenerator.MangledIdentifierNamesGenerator,
+                    stringArray: true,
+                    stringArrayThreshold: 1,
+                    stringArrayEncoding: [
+                        StringArrayEncoding.None,
+                        StringArrayEncoding.Base64,
+                        StringArrayEncoding.Rc4
+                    ]
+                }
+            ).getObfuscatedCode();
+        });
+
+        it('should place multiple StringArrayCallsWrapper code helper names in the correct order', () => {
+            assert.match(obfuscatedCode, regExp);
+        });
+    });
+});

+ 3 - 0
test/functional-tests/custom-code-helpers/string-array/group/fixtures/simple-input.js

@@ -0,0 +1,3 @@
+var foo = 'foo';
+var bar = 'bar';
+var baz = 'baz';

+ 1 - 0
test/index.spec.ts

@@ -67,6 +67,7 @@ import './functional-tests/custom-code-helpers/self-defending/templates/SelfDefe
 import './functional-tests/custom-code-helpers/string-array/StringArrayCallsWrapperCodeHelper.spec';
 import './functional-tests/custom-code-helpers/string-array/StringArrayCodeHelper.spec';
 import './functional-tests/custom-code-helpers/string-array/StringArrayRotateFunctionCodeHelper.spec';
+import './functional-tests/custom-code-helpers/string-array/group/StringArrayCodeHelperGroup.spec';
 import './functional-tests/custom-code-helpers/string-array/templates/string-array-calls-wrapper-node-template/StringArrayCallsWrapperNodeTemplate.spec';
 import './functional-tests/custom-code-helpers/string-array/templates/string-array-rotate-function-template/StringArrayRotateFunctionTemplate.spec';
 import './functional-tests/custom-code-helpers/string-array/templates/string-array-template/StringArrayTemplate.spec';

Daži faili netika attēloti, jo izmaiņu fails ir pārāk liels