Commits

Patrick Streule committed e9987ca Merge

Merged in feature/AC-1113-disable-whitelist-in-dev-mode-0-9-x (pull request #57)

AC-1113: Fix and tests

Comments (0)

Files changed (2)

lib/internal/config.js

         whitelist: function () {
             var list = get(modeValues, 'whitelist', 'AC_HOST_WHITELIST');
             if (!list) {
-                list = mode === 'production' ? '*.jira.com' : ['*.*','*'];
+                list = mode === 'production' ? '*.jira.com' : '';
             }
             if (_.isString(list)) {
-                list = [list];
+                list = list.split(',').map(function(glob) {
+                    return glob.trim();
+                });
             }
             return list;
         },
 
         whitelistRegexp: function () {
             return this.whitelist().map(function (glob) {
-                return new RegExp('^' + glob.replace(/\./g, '\\.').replace(/\*/g, '[^.]*') + '$');
+                return glob !== '' ? new RegExp('^' + glob.replace(/\./g, '\\.').replace(/\*/g, '[^.]*') + '$') : new RegExp('.*');
             });
         }
 

test/config_test.js

         });
 
         it('should accept multi-segment hostnames in dev mode', function (done) {
-            assert(matches(addon.config, 'machine.local'));
+            assert(matches(addon.config, 'machine.dyn.syd.atlassian.com'));
             done();
         });
 
             done();
         });
 
+        it('should not accept subdomains', function (done) {
+            var cfg = createWhiteListConfig("*.jira.com");
+            assert(!matches(cfg, 'foo.test.jira.com'));
+            done();
+        });
+
+        it('should accept multiple comma separated patterns', function (done) {
+            var cfg = createWhiteListConfig("*.jira.com, *.atlassian.net");
+            assert(matches(cfg, 'connect.jira.com'));
+            assert(matches(cfg, 'connect.atlassian.net'));
+            assert(!matches(cfg, 'connect.jira-dev.com'));
+            done();
+        });
+
         function matches(cfg, host) {
             return cfg.whitelistRegexp().some(function (re) { return re.test(host); });
         }
 
         function createWhiteListConfig(domain) {
-            return config("development", { "development": { "whitelist": [domain] }});
+            return config("development", { "development": { "whitelist": domain }});
         }
     });