瀏覽代碼

FunctionControlFlowTransformer tests: testing few items in controlFlowNode storage

sanex3339 8 年之前
父節點
當前提交
725c26577e

+ 4 - 0
test/fixtures/node-transformers/node-control-flow-transformers/function-control-flow-transformer-multiple-items-1.js

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

+ 28 - 0
test/functional-tests/node-transformers/node-control-flow-transformers/FunctionControlFlowTransformer.spec.ts

@@ -86,5 +86,33 @@ describe('FunctionControlFlowTransformer', () => {
                 assert.closeTo((totalValue - samplesCount) / samplesCount, expectedValue, delta);
             });
         });
+
+        describe('variant #3 - single `control flow storage` node with multiple items', () => {
+            const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
+                readFileAsString(
+                    './test/fixtures/node-transformers/node-control-flow-transformers/function-control-flow-transformer-multiple-items-1.js'
+                ),
+                {
+                    ...NO_CUSTOM_NODES_PRESET,
+                    controlFlowFlattening: true,
+                    controlFlowFlatteningThreshold: 1
+                }
+            );
+            const obfuscatedCode: string = obfuscationResult.getObfuscatedCode();
+            const regexp: RegExp = new RegExp(
+                `var *${variableMatch} *= *\\{` +
+                    `'(\\\\x[a-f0-9]*){3}' *: *function *${variableMatch} *\\(${variableMatch}, *${variableMatch}\\) *\\{` +
+                        `return *${variableMatch} *\\+ *${variableMatch};` +
+                    `\\}, *` +
+                    `'(\\\\x[a-f0-9]*){3}' *: *function *${variableMatch} *\\(${variableMatch}, *${variableMatch}\\) *\\{` +
+                        `return *${variableMatch} *- *${variableMatch};` +
+                    `\\}` +
+                `\\};`
+            );
+
+            it('should add `control flow storage` node with multiple items to the obfuscated code', () => {
+                assert.match(obfuscatedCode, regexp);
+            });
+        });
     });
 });