Commits

Patrick Streule committed 2b458fd

ACDEV-1242: add whitelist tests

  • Participants
  • Parent commits 787df70

Comments (0)

Files changed (1)

File test/config_test.js

-var helper = require('./test_helper');
 var assert = require('assert');
 var http = require('http');
 var express = require('express');
 var app = express();
 var ac = require('../index');
+var config = require('../lib/internal/config');
 var logger = require('./logger');
 var addon = {};
 
         done();
     });
 
+    describe('Whitelist', function() {
+
+        it('should accept single-segment hostnames in dev mode', function (done) {
+            assert(matches(addon.config, 'localhost'));
+            done();
+        });
+
+        it('should accept multi-segment hostnames in dev mode', function (done) {
+            assert(matches(addon.config, 'machine.local'));
+            done();
+        });
+
+        it('should accept fully qualified domain names', function (done) {
+            var cfg = createWhiteListConfig("*.atlassian.net");
+            assert(matches(cfg, 'connect.atlassian.net'));
+            done();
+        });
+
+        it('should not accept partial domain name matches', function (done) {
+            var cfg = createWhiteListConfig("*.jira.com");
+            assert(!matches(cfg, 'test.jira.com.hh.ht'));
+            done();
+        });
+
+        function matches(cfg, host) {
+            return cfg.whitelistRegexp().some(function (re) { return re.test(host); });
+        }
+
+        function createWhiteListConfig(domain) {
+            return config("development", { "development": { "whitelist": [domain] }});
+        }
+    });
+
 });