浏览代码

Merge remote-tracking branch 'origin/master'

sanex3339 7 年之前
父节点
当前提交
0a63934e62

文件差异内容过多而无法显示
+ 0 - 0
dist/index.browser.js


文件差异内容过多而无法显示
+ 0 - 0
dist/index.cli.js


文件差异内容过多而无法显示
+ 0 - 0
dist/index.js


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

@@ -30,7 +30,9 @@ export function DomainLockNodeTemplate (): string {
             var domains = "{domains}".replace(regExp, "").split(";");
             var document;
             var domain;
-                        
+            var location;
+            var hostname;
+
             for (var d in that) {
                 if (d.length == 8 && d.charCodeAt(7) == 116 && d.charCodeAt(5) == 101 && d.charCodeAt(3) == 117 && d.charCodeAt(0) == 100) {
                     document = d;
@@ -46,12 +48,30 @@ export function DomainLockNodeTemplate (): string {
                     break;
                 }
             }
-            
-            if ((!document && !domain) || (!that[document] && !that[document][domain])) {
+
+            if (!("~" > domain)) {
+                for (var d2 in that[document]) {
+                    if (d2.length == 8 && d2.charCodeAt(7) == 110 && d2.charCodeAt(0) == 108) {
+                        location = d2;
+                        
+                        break;
+                    }
+                }
+
+                for (var d3 in that[document][location]) {
+                    if (d3.length == 8 && d3.charCodeAt(7) == 101 && d3.charCodeAt(0) == 104) {
+                        hostname = d3;
+                        
+                        break;
+                    }
+                }
+            }
+
+            if ((!document && !domain) || (!that[document] && !that[document][domain] && !that[document][location] && !that[document][location][hostname])) {
                 return;
             }
-            
-            var currentDomain = that[document][domain];
+
+            var currentDomain = that[document][domain] || that[document][location][hostname];
 
             var ok = false;
                         

+ 60 - 2
test/functional-tests/templates/domain-lock-nodes/DomainLockNodeTemplate.spec.ts

@@ -18,14 +18,18 @@ import { InversifyContainerFacade } from '../../../../src/container/InversifyCon
  * @param templateData
  * @param callsControllerFunctionName
  * @param currentDomain
+ * @param withoutDomain
  * @returns {Function}
  */
-function getFunctionFromTemplate (templateData: any, callsControllerFunctionName: string,  currentDomain: string) {
+function getFunctionFromTemplate (templateData: any, callsControllerFunctionName: string,  currentDomain: string, domainIsPresent = true) {
     const domainLockTemplate: string = format(DomainLockNodeTemplate(), templateData);
 
     return Function(`
         document = {
-            domain: '${currentDomain}'
+            ${ domainIsPresent ?`domain: '${currentDomain}',` : `` }
+            location: {
+                hostname: '${currentDomain}'
+            }
         };
 
         var ${callsControllerFunctionName} = (function(){            
@@ -315,4 +319,58 @@ describe('DomainLockNodeTemplate', () => {
             });
         });
     });
+
+    describe('Variant #5: current hostname matches with `domainsString`', () => {
+        const domainsString: string = ['www.example.com'].join(';');
+        const currentDomain: string = 'www.example.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, currentDomain, false);
+        });
+
+        it('should correctly run code inside template', () => {
+            assert.doesNotThrow(testFunc);
+        });
+    });
+
+    describe('Variant #6: current hostname doesn\'t match with `domainsString`', () => {
+        describe('Variant #1', () => {
+            const domainsString: string = ['www.example.com'].join(';');
+            const currentDomain: 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, currentDomain, false);
+            });
+
+            it('should throw an error', () => {
+                assert.throws(testFunc);
+            });
+        });
+    });
 });

部分文件因为文件数量过多而无法显示