Преглед изворни кода

Added more tests for domain lock

sanex3339 пре 7 година
родитељ
комит
15491fbd97

+ 3 - 0
CHANGELOG.md

@@ -3,6 +3,9 @@ Change Log
 v0.17.0
 v0.17.0
 ---
 ---
 * **Browser version**: Added browser version dist
 * **Browser version**: Added browser version dist
+* [#274](https://github.com/javascript-obfuscator/javascript-obfuscator/pull/274)`domainLock` now will work in SVG.
+  <br/>
+  Fixed https://github.com/javascript-obfuscator/javascript-obfuscator/issues/273
 * Fixed https://github.com/javascript-obfuscator/javascript-obfuscator/issues/271
 * Fixed https://github.com/javascript-obfuscator/javascript-obfuscator/issues/271
 * Fixed https://github.com/javascript-obfuscator/javascript-obfuscator/issues/264
 * Fixed https://github.com/javascript-obfuscator/javascript-obfuscator/issues/264
 * Fixed https://github.com/javascript-obfuscator/javascript-obfuscator/issues/260
 * Fixed https://github.com/javascript-obfuscator/javascript-obfuscator/issues/260

Разлика између датотеке није приказан због своје велике величине
+ 0 - 0
dist/index.browser.js


Разлика између датотеке није приказан због своје велике величине
+ 0 - 0
dist/index.cli.js


Разлика између датотеке није приказан због своје велике величине
+ 0 - 0
dist/index.js


+ 11 - 5
src/templates/domain-lock-nodes/domain-lock-node/DomainLockNodeTemplate.ts

@@ -66,13 +66,19 @@ export function DomainLockNodeTemplate (): string {
                     }
                     }
                 }
                 }
             }
             }
-
-            if ((!document && !domain) || (!that[document] && !that[document][domain] && !that[document][location] && !that[document][location][hostname])) {
+            
+            if (!document || !that[document]) {
                 return;
                 return;
             }
             }
-
-            var currentDomain = that[document][domain] || that[document][location][hostname];
-
+            
+            var documentDomain = that[document][domain];
+            var documentLocationHostName = !!that[document][location] && that[document][location][hostname];  
+            var currentDomain = documentDomain || documentLocationHostName;
+          
+            if (!currentDomain) {
+                return;
+            }
+          
             var ok = false;
             var ok = false;
                         
                         
             for (var i = 0; i < domains.length; i++) {
             for (var i = 0; i < domains.length; i++) {

+ 254 - 106
test/functional-tests/templates/domain-lock-nodes/DomainLockNodeTemplate.spec.ts

@@ -15,22 +15,61 @@ import { GlobalVariableTemplate1 } from '../../../../src/templates/GlobalVariabl
 import { InversifyContainerFacade } from '../../../../src/container/InversifyContainerFacade';
 import { InversifyContainerFacade } from '../../../../src/container/InversifyContainerFacade';
 
 
 /**
 /**
- * @param templateData
- * @param callsControllerFunctionName
- * @param currentDomain
- * @param withoutDomain
- * @returns {Function}
+ * @param {string} currentDomain
+ * @returns {string}
  */
  */
-function getFunctionFromTemplate (templateData: any, callsControllerFunctionName: string,  currentDomain: string, domainIsPresent = true) {
-    const domainLockTemplate: string = format(DomainLockNodeTemplate(), templateData);
+function getDocumentDomainTemplate (currentDomain: string): string {
+    return `
+        document = {
+            domain: '${currentDomain}'
+        };
+    `
+}
 
 
-    return Function(`
+/**
+ * @param {string} currentDomain
+ * @returns {string}
+ */
+function getDocumentLocationTemplate (currentDomain: string): string {
+    return `
         document = {
         document = {
-            ${ domainIsPresent ?`domain: '${currentDomain}',` : `` }
             location: {
             location: {
                 hostname: '${currentDomain}'
                 hostname: '${currentDomain}'
             }
             }
         };
         };
+    `
+}
+
+/**
+ * @param {string} currentDomain
+ * @returns {string}
+ */
+function getDocumentDomainAndLocationTemplate (currentDomain: string): string {
+    return `
+        document = {
+            domain: '${currentDomain}',
+            location: {
+                hostname: '${currentDomain}'
+            }
+        };
+    `
+}
+
+/**
+ * @param templateData
+ * @param {string} callsControllerFunctionName
+ * @param {string} documentTemplate
+ * @returns {Function}
+ */
+function getFunctionFromTemplate (
+    templateData: any,
+    callsControllerFunctionName: string,
+    documentTemplate: string
+): Function {
+    const domainLockTemplate: string = format(DomainLockNodeTemplate(), templateData);
+
+    return Function(`
+        ${documentTemplate}
 
 
         var ${callsControllerFunctionName} = (function(){            
         var ${callsControllerFunctionName} = (function(){            
             return function (context, fn){	
             return function (context, fn){	
@@ -68,13 +107,17 @@ describe('DomainLockNodeTemplate', () => {
                 diff
                 diff
             ] = cryptUtils.hideString(domainsString, domainsString.length * 3);
             ] = cryptUtils.hideString(domainsString, domainsString.length * 3);
 
 
-            testFunc = () => getFunctionFromTemplate({
-                domainLockFunctionName: 'domainLockFunction',
-                diff: diff,
-                domains: hiddenDomainsString,
-                globalVariableTemplate: GlobalVariableTemplate1(),
-                singleNodeCallControllerFunctionName
-            }, singleNodeCallControllerFunctionName, currentDomain);
+            testFunc = () => getFunctionFromTemplate(
+                {
+                    domainLockFunctionName: 'domainLockFunction',
+                    diff: diff,
+                    domains: hiddenDomainsString,
+                    globalVariableTemplate: GlobalVariableTemplate1(),
+                    singleNodeCallControllerFunctionName
+                },
+                singleNodeCallControllerFunctionName,
+                getDocumentDomainTemplate(currentDomain)
+            );
         });
         });
 
 
         it('should correctly run code inside template', () => {
         it('should correctly run code inside template', () => {
@@ -94,13 +137,17 @@ describe('DomainLockNodeTemplate', () => {
                 diff
                 diff
             ] = cryptUtils.hideString(domainsString, domainsString.length * 3);
             ] = cryptUtils.hideString(domainsString, domainsString.length * 3);
 
 
-            testFunc = () => getFunctionFromTemplate({
-                domainLockFunctionName: 'domainLockFunction',
-                diff: diff,
-                domains: hiddenDomainsString,
-                globalVariableTemplate: GlobalVariableTemplate1(),
-                singleNodeCallControllerFunctionName
-            }, singleNodeCallControllerFunctionName, currentDomain);
+            testFunc = () => getFunctionFromTemplate(
+                {
+                    domainLockFunctionName: 'domainLockFunction',
+                    diff: diff,
+                    domains: hiddenDomainsString,
+                    globalVariableTemplate: GlobalVariableTemplate1(),
+                    singleNodeCallControllerFunctionName
+                },
+                singleNodeCallControllerFunctionName,
+                getDocumentDomainTemplate(currentDomain)
+            );
         });
         });
 
 
         it('should correctly run code inside template', () => {
         it('should correctly run code inside template', () => {
@@ -121,13 +168,17 @@ describe('DomainLockNodeTemplate', () => {
                     diff
                     diff
                 ] = cryptUtils.hideString(domainsString, domainsString.length * 3);
                 ] = cryptUtils.hideString(domainsString, domainsString.length * 3);
 
 
-                testFunc = () => getFunctionFromTemplate({
-                    domainLockFunctionName: 'domainLockFunction',
-                    diff: diff,
-                    domains: hiddenDomainsString,
-                    globalVariableTemplate: GlobalVariableTemplate1(),
-                    singleNodeCallControllerFunctionName
-                }, singleNodeCallControllerFunctionName, currentDomain);
+                testFunc = () => getFunctionFromTemplate(
+                    {
+                        domainLockFunctionName: 'domainLockFunction',
+                        diff: diff,
+                        domains: hiddenDomainsString,
+                        globalVariableTemplate: GlobalVariableTemplate1(),
+                        singleNodeCallControllerFunctionName
+                    },
+                    singleNodeCallControllerFunctionName,
+                    getDocumentDomainTemplate(currentDomain)
+                );
             });
             });
 
 
             it('should correctly run code inside template', () => {
             it('should correctly run code inside template', () => {
@@ -147,13 +198,17 @@ describe('DomainLockNodeTemplate', () => {
                     diff
                     diff
                 ] = cryptUtils.hideString(domainsString, domainsString.length * 3);
                 ] = cryptUtils.hideString(domainsString, domainsString.length * 3);
 
 
-                testFunc = () => getFunctionFromTemplate({
-                    domainLockFunctionName: 'domainLockFunction',
-                    diff: diff,
-                    domains: hiddenDomainsString,
-                    globalVariableTemplate: GlobalVariableTemplate1(),
-                    singleNodeCallControllerFunctionName
-                }, singleNodeCallControllerFunctionName, currentDomain);
+                testFunc = () => getFunctionFromTemplate(
+                    {
+                        domainLockFunctionName: 'domainLockFunction',
+                        diff: diff,
+                        domains: hiddenDomainsString,
+                        globalVariableTemplate: GlobalVariableTemplate1(),
+                        singleNodeCallControllerFunctionName
+                    },
+                    singleNodeCallControllerFunctionName,
+                    getDocumentDomainTemplate(currentDomain)
+                );
             });
             });
 
 
             it('should correctly run code inside template', () => {
             it('should correctly run code inside template', () => {
@@ -173,13 +228,17 @@ describe('DomainLockNodeTemplate', () => {
                     diff
                     diff
                 ] = cryptUtils.hideString(domainsString, domainsString.length * 3);
                 ] = cryptUtils.hideString(domainsString, domainsString.length * 3);
 
 
-                testFunc = () => getFunctionFromTemplate({
-                    domainLockFunctionName: 'domainLockFunction',
-                    diff: diff,
-                    domains: hiddenDomainsString,
-                    globalVariableTemplate: GlobalVariableTemplate1(),
-                    singleNodeCallControllerFunctionName
-                }, singleNodeCallControllerFunctionName, currentDomain);
+                testFunc = () => getFunctionFromTemplate(
+                    {
+                        domainLockFunctionName: 'domainLockFunction',
+                        diff: diff,
+                        domains: hiddenDomainsString,
+                        globalVariableTemplate: GlobalVariableTemplate1(),
+                        singleNodeCallControllerFunctionName
+                    },
+                    singleNodeCallControllerFunctionName,
+                    getDocumentDomainTemplate(currentDomain)
+                );
             });
             });
 
 
             it('should correctly run code inside template', () => {
             it('should correctly run code inside template', () => {
@@ -199,13 +258,17 @@ describe('DomainLockNodeTemplate', () => {
                     diff
                     diff
                 ] = cryptUtils.hideString(domainsString, domainsString.length * 3);
                 ] = cryptUtils.hideString(domainsString, domainsString.length * 3);
 
 
-                testFunc = () => getFunctionFromTemplate({
-                    domainLockFunctionName: 'domainLockFunction',
-                    diff: diff,
-                    domains: hiddenDomainsString,
-                    globalVariableTemplate: GlobalVariableTemplate1(),
-                    singleNodeCallControllerFunctionName
-                }, singleNodeCallControllerFunctionName, currentDomain);
+                testFunc = () => getFunctionFromTemplate(
+                    {
+                        domainLockFunctionName: 'domainLockFunction',
+                        diff: diff,
+                        domains: hiddenDomainsString,
+                        globalVariableTemplate: GlobalVariableTemplate1(),
+                        singleNodeCallControllerFunctionName
+                    },
+                    singleNodeCallControllerFunctionName,
+                    getDocumentDomainTemplate(currentDomain)
+                );
             });
             });
 
 
             it('should correctly run code inside template', () => {
             it('should correctly run code inside template', () => {
@@ -226,13 +289,17 @@ describe('DomainLockNodeTemplate', () => {
                 diff
                 diff
             ] = cryptUtils.hideString(domainsString, domainsString.length * 3);
             ] = cryptUtils.hideString(domainsString, domainsString.length * 3);
 
 
-            testFunc = () => getFunctionFromTemplate({
-                domainLockFunctionName: 'domainLockFunction',
-                diff: diff,
-                domains: hiddenDomainsString,
-                globalVariableTemplate: GlobalVariableTemplate1(),
-                singleNodeCallControllerFunctionName
-            }, singleNodeCallControllerFunctionName, currentDomain);
+            testFunc = () => getFunctionFromTemplate(
+                {
+                    domainLockFunctionName: 'domainLockFunction',
+                    diff: diff,
+                    domains: hiddenDomainsString,
+                    globalVariableTemplate: GlobalVariableTemplate1(),
+                    singleNodeCallControllerFunctionName
+                },
+                singleNodeCallControllerFunctionName,
+                getDocumentDomainTemplate(currentDomain)
+            );
         });
         });
 
 
         it('should correctly run code inside template', () => {
         it('should correctly run code inside template', () => {
@@ -253,13 +320,17 @@ describe('DomainLockNodeTemplate', () => {
                     diff
                     diff
                 ] = cryptUtils.hideString(domainsString, domainsString.length * 3);
                 ] = cryptUtils.hideString(domainsString, domainsString.length * 3);
 
 
-                testFunc = () => getFunctionFromTemplate({
-                    domainLockFunctionName: 'domainLockFunction',
-                    diff: diff,
-                    domains: hiddenDomainsString,
-                    globalVariableTemplate: GlobalVariableTemplate1(),
-                    singleNodeCallControllerFunctionName
-                }, singleNodeCallControllerFunctionName, currentDomain);
+                testFunc = () => getFunctionFromTemplate(
+                    {
+                        domainLockFunctionName: 'domainLockFunction',
+                        diff: diff,
+                        domains: hiddenDomainsString,
+                        globalVariableTemplate: GlobalVariableTemplate1(),
+                        singleNodeCallControllerFunctionName
+                    },
+                    singleNodeCallControllerFunctionName,
+                    getDocumentDomainTemplate(currentDomain)
+                );
             });
             });
 
 
             it('should throw an error', () => {
             it('should throw an error', () => {
@@ -280,12 +351,15 @@ describe('DomainLockNodeTemplate', () => {
                 ] = cryptUtils.hideString(domainsString, domainsString.length * 3);
                 ] = cryptUtils.hideString(domainsString, domainsString.length * 3);
 
 
                 testFunc = () => getFunctionFromTemplate({
                 testFunc = () => getFunctionFromTemplate({
-                    domainLockFunctionName: 'domainLockFunction',
-                    diff: diff,
-                    domains: hiddenDomainsString,
-                    globalVariableTemplate: GlobalVariableTemplate1(),
-                    singleNodeCallControllerFunctionName
-                }, singleNodeCallControllerFunctionName, currentDomain);
+                        domainLockFunctionName: 'domainLockFunction',
+                        diff: diff,
+                        domains: hiddenDomainsString,
+                        globalVariableTemplate: GlobalVariableTemplate1(),
+                        singleNodeCallControllerFunctionName
+                    },
+                    singleNodeCallControllerFunctionName,
+                    getDocumentDomainTemplate(currentDomain)
+                );
             });
             });
 
 
             it('should throw an error', () => {
             it('should throw an error', () => {
@@ -305,13 +379,17 @@ describe('DomainLockNodeTemplate', () => {
                     diff
                     diff
                 ] = cryptUtils.hideString(domainsString, domainsString.length * 3);
                 ] = cryptUtils.hideString(domainsString, domainsString.length * 3);
 
 
-                testFunc = () => getFunctionFromTemplate({
-                    domainLockFunctionName: 'domainLockFunction',
-                    diff: diff,
-                    domains: hiddenDomainsString,
-                    globalVariableTemplate: GlobalVariableTemplate1(),
-                    singleNodeCallControllerFunctionName
-                }, singleNodeCallControllerFunctionName, currentDomain);
+                testFunc = () => getFunctionFromTemplate(
+                    {
+                        domainLockFunctionName: 'domainLockFunction',
+                        diff: diff,
+                        domains: hiddenDomainsString,
+                        globalVariableTemplate: GlobalVariableTemplate1(),
+                        singleNodeCallControllerFunctionName
+                    },
+                    singleNodeCallControllerFunctionName,
+                    getDocumentDomainTemplate(currentDomain)
+                );
             });
             });
 
 
             it('should throw an error', () => {
             it('should throw an error', () => {
@@ -320,36 +398,72 @@ describe('DomainLockNodeTemplate', () => {
         });
         });
     });
     });
 
 
-    describe('Variant #5: current hostname matches with `domainsString`', () => {
-        const domainsString: string = ['www.example.com'].join(';');
-        const currentDomain: string = 'www.example.com';
+    describe('Variant #6: location.hostname', () => {
+        describe('Variant #1: current location.hostname matches with `domainsString`', () => {
+            const domainsString: string = ['www.example.com'].join(';');
+            const currentHostName: string = 'www.example.com';
 
 
-        let testFunc: () => void;
+            let testFunc: () => void;
 
 
-        before(() => {
-            const [
-                hiddenDomainsString,
-                diff
-            ] = cryptUtils.hideString(domainsString, domainsString.length * 3);
+            before(() => {
+                const [
+                    hiddenDomainsString,
+                    diff
+                ] = cryptUtils.hideString(domainsString, domainsString.length * 3);
+
+                testFunc = () => getFunctionFromTemplate(
+                    {
+                        domainLockFunctionName: 'domainLockFunction',
+                        diff: diff,
+                        domains: hiddenDomainsString,
+                        globalVariableTemplate: GlobalVariableTemplate1(),
+                        singleNodeCallControllerFunctionName
+                    },
+                    singleNodeCallControllerFunctionName,
+                    getDocumentLocationTemplate(currentHostName)
+                );
+            });
 
 
-            testFunc = () => getFunctionFromTemplate({
-                domainLockFunctionName: 'domainLockFunction',
-                diff: diff,
-                domains: hiddenDomainsString,
-                globalVariableTemplate: GlobalVariableTemplate1(),
-                singleNodeCallControllerFunctionName
-            }, singleNodeCallControllerFunctionName, currentDomain, false);
+            it('should correctly run code inside template', () => {
+                assert.doesNotThrow(testFunc);
+            });
         });
         });
 
 
-        it('should correctly run code inside template', () => {
-            assert.doesNotThrow(testFunc);
+        describe('Variant #2: current location.hostname doesn\'t match with `domainsString`', () => {
+            const domainsString: string = ['www.example.com'].join(';');
+            const currentHostName: string = 'www.test.com';
+
+            let testFunc: () => void;
+
+            before(() => {
+                const [
+                    hiddenDomainsString,
+                    diff
+                ] = cryptUtils.hideString(domainsString, domainsString.length * 3);
+
+                testFunc = () => getFunctionFromTemplate(
+                    {
+                        domainLockFunctionName: 'domainLockFunction',
+                        diff: diff,
+                        domains: hiddenDomainsString,
+                        globalVariableTemplate: GlobalVariableTemplate1(),
+                        singleNodeCallControllerFunctionName
+                    },
+                    singleNodeCallControllerFunctionName,
+                    getDocumentLocationTemplate(currentHostName)
+                );
+            });
+
+            it('should throw an error', () => {
+                assert.throws(testFunc);
+            });
         });
         });
     });
     });
 
 
-    describe('Variant #6: current hostname doesn\'t match with `domainsString`', () => {
-        describe('Variant #1', () => {
+    describe('Variant #7: domain and location.hostname presented', () => {
+        describe('Variant #1: current domain matches with `domainsString`', () => {
             const domainsString: string = ['www.example.com'].join(';');
             const domainsString: string = ['www.example.com'].join(';');
-            const currentDomain: string = 'www.test.com';
+            const currentHostName: string = 'www.example.com';
 
 
             let testFunc: () => void;
             let testFunc: () => void;
 
 
@@ -359,13 +473,47 @@ describe('DomainLockNodeTemplate', () => {
                     diff
                     diff
                 ] = cryptUtils.hideString(domainsString, domainsString.length * 3);
                 ] = cryptUtils.hideString(domainsString, domainsString.length * 3);
 
 
-                testFunc = () => getFunctionFromTemplate({
-                    domainLockFunctionName: 'domainLockFunction',
-                    diff: diff,
-                    domains: hiddenDomainsString,
-                    globalVariableTemplate: GlobalVariableTemplate1(),
-                    singleNodeCallControllerFunctionName
-                }, singleNodeCallControllerFunctionName, currentDomain, false);
+                testFunc = () => getFunctionFromTemplate(
+                    {
+                        domainLockFunctionName: 'domainLockFunction',
+                        diff: diff,
+                        domains: hiddenDomainsString,
+                        globalVariableTemplate: GlobalVariableTemplate1(),
+                        singleNodeCallControllerFunctionName
+                    },
+                    singleNodeCallControllerFunctionName,
+                    getDocumentDomainAndLocationTemplate(currentHostName)
+                );
+            });
+
+            it('should correctly run code inside template', () => {
+                assert.doesNotThrow(testFunc);
+            });
+        });
+
+        describe('Variant #2: current domain doesn\'t match with `domainsString`', () => {
+            const domainsString: string = ['www.example.com'].join(';');
+            const currentHostName: string = 'www.test.com';
+
+            let testFunc: () => void;
+
+            before(() => {
+                const [
+                    hiddenDomainsString,
+                    diff
+                ] = cryptUtils.hideString(domainsString, domainsString.length * 3);
+
+                testFunc = () => getFunctionFromTemplate(
+                    {
+                        domainLockFunctionName: 'domainLockFunction',
+                        diff: diff,
+                        domains: hiddenDomainsString,
+                        globalVariableTemplate: GlobalVariableTemplate1(),
+                        singleNodeCallControllerFunctionName
+                    },
+                    singleNodeCallControllerFunctionName,
+                    getDocumentDomainAndLocationTemplate(currentHostName)
+                );
             });
             });
 
 
             it('should throw an error', () => {
             it('should throw an error', () => {

Неке датотеке нису приказане због велике количине промена