Pārlūkot izejas kodu

Added functional tests for dictionary names generator

sanex3339 5 gadi atpakaļ
vecāks
revīzija
9c186a4e34

+ 23 - 0
test/functional-tests/javascript-obfuscator/JavaScriptObfuscator.spec.ts

@@ -569,6 +569,29 @@ describe('JavaScriptObfuscator', () => {
             });
         });
 
+        describe('dictionary identifier names generator', () => {
+            const regExp: RegExp = /var *[ab] *= *0x1; *var *[ab] *= *0x2; *var *A *= *0x3;/;
+
+            let obfuscatedCode: string;
+
+            beforeEach(() => {
+                const code: string = readFileAsString(__dirname + '/fixtures/dictionary-identifiers.js');
+
+                obfuscatedCode = JavaScriptObfuscator.obfuscate(
+                    code,
+                    {
+                        ...NO_ADDITIONAL_NODES_PRESET,
+                        identifierNamesGenerator: IdentifierNamesGenerator.DictionaryIdentifierNamesGenerator,
+                        identifiersDictionary: ['a', 'b']
+                    }
+                ).getObfuscatedCode();
+            });
+
+            it('should generate identifier based on the dictionary', () => {
+                assert.match(obfuscatedCode, regExp);
+            });
+        });
+
         describe('parse module', () => {
             describe('Variant #1: import', () => {
                 const importRegExp: RegExp = /import *{foo} *from *'.\/foo';/;

+ 5 - 0
test/functional-tests/javascript-obfuscator/fixtures/dictionary-identifiers.js

@@ -0,0 +1,5 @@
+(function () {
+    var test1 = 1;
+    var test2 = 2;
+    var test3 = 3;
+})();