Skip to content

Commit

Permalink
Adding domain whitelist #2
Browse files Browse the repository at this point in the history
  • Loading branch information
Sebastian Waschnick committed Sep 7, 2017
1 parent 6b11bbb commit c03fd49
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
6 changes: 2 additions & 4 deletions http_server.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@ let CACHE_DURATION = '10m';
let DOCUMENT_ROOT = __dirname + '/dist';

let domainWhitelist = function (req, res, next) {

let host = req.header("host") || req.header("Host");
console.info("Host", host, isHostInWhitelist(host));

if (isHostInWhitelist(host)) {
next();
} else {
Expand All @@ -34,8 +31,9 @@ function isHostInWhitelist(host) {
let length = split.length;
if (length >= 2) {
let domainNameWithEnding = split[length - 2] + '.' + split[length - 1];
console.info("domainNameWithEnding", domainNameWithEnding);
return whitelist.whitelist.includes(domainNameWithEnding);
} else if (host.startsWith("localhost")) {
return true;
}
return false;
}
Expand Down
20 changes: 20 additions & 0 deletions test/node/http.server.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,26 @@ describe('nodejs http server', () => {
}, 1000);
});

it('should work with whitelisted hosts and ignore header case', function (done) {
request(app)
.get('/end2end-tests/complete-integration-site-a.html')
.set({"Host": "finanzen.net"})
.end(function (error, response) {
expect(response.statusCode).to.equal(200);
done();
}, 1000);
});

it('should work with localhost', function (done) {
request(app)
.get('/end2end-tests/complete-integration-site-a.html')
.set({"host": "localhost:8080"})
.end(function (error, response) {
expect(response.statusCode).to.equal(200);
done();
}, 1000);
});

it('should return 403 with not whitelisted hosts', function (done) {
request(app)
.get('/end2end-tests/complete-integration-site-a.html')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ class HerokuPerformanceSimulation extends Simulation {

// 30_000 Request in 60s (= 500req/s) with 10x dynos
// setUp(myScenario.inject(rampUsers(30000) over (60 seconds)).protocols(httpConf))
setUp(myScenario.inject(rampUsers(60000) over (120 seconds)).protocols(httpConf))
setUp(myScenario.inject(rampUsers(30) over (30 seconds)).protocols(httpConf))
}

0 comments on commit c03fd49

Please sign in to comment.