Default host to empty string when header is not found

A String object is required to not fail on `.match` interface.
This commit is contained in:
Raul Ochoa 2015-09-30 16:31:56 +02:00
parent ba6b8fbff1
commit 79375616d5
2 changed files with 25 additions and 1 deletions

View File

@ -8,7 +8,7 @@ module.exports = CdbRequest;
CdbRequest.prototype.userByReq = function(req) {
var host = req.headers.host;
var host = req.headers.host || '';
if (req.params.user) {
return req.params.user;
}

View File

@ -57,4 +57,28 @@ describe('req2params', function() {
assert.equal(user, undefined);
});
it('should not fail for undefined host header', function() {
var userFromHostConfig = global.environment.user_from_host;
global.environment.user_from_host = null;
var cdbRequest = new CdbRequest();
var user = cdbRequest.userByReq(createRequest(undefined));
global.environment.user_from_host = userFromHostConfig;
assert.equal(user, undefined);
});
it('should not fail for null host header', function() {
var userFromHostConfig = global.environment.user_from_host;
global.environment.user_from_host = null;
var cdbRequest = new CdbRequest();
var user = cdbRequest.userByReq(createRequest(null));
global.environment.user_from_host = userFromHostConfig;
assert.equal(user, undefined);
});
});