disallow uppercase domains, with test

This commit is contained in:
Siddhartha Sahai
2015-01-03 04:39:09 +05:30
parent 5046c360ba
commit fa4802d488
2 changed files with 16 additions and 3 deletions

View File

@@ -197,8 +197,8 @@ module.exports = function(opt) {
var req_id = req.param('req_id'); var req_id = req.param('req_id');
// limit requested hostnames to 20 characters // limit requested hostnames to 20 characters
if (! /^[A-Za-z0-9]{4,20}$/.test(req_id)) { if (! /^[a-z0-9]{4,20}$/.test(req_id)) {
var err = new Error('Invalid subdomain. Subdomains must be between 4 and 20 alphanumeric characters.'); var err = new Error('Invalid subdomain. Subdomains must be lowercase and between 4 and 20 alphanumeric characters.');
err.statusCode = 403; err.statusCode = 403;
return next(err); return next(err);
} }

View File

@@ -126,7 +126,20 @@ test('request domain that is too long', function(done) {
localtunnel(test._fake_port, opt, function(err, tunnel) { localtunnel(test._fake_port, opt, function(err, tunnel) {
assert(err); assert(err);
assert.equal(err.message, 'Invalid subdomain. Subdomains must be between 4 and 20 alphanumeric characters.'); assert.equal(err.message, 'Invalid subdomain. Subdomains must be lowercase and between 4 and 20 alphanumeric characters.');
done();
});
});
test('request uppercase domain', function(done) {
var opt = {
host: 'http://localhost:' + lt_server_port,
subdomain: 'ABCD'
};
localtunnel(test._fake_port, opt, function(err, tunnel) {
assert(err);
assert.equal(err.message, 'Invalid subdomain. Subdomains must be lowercase and between 4 and 20 alphanumeric characters.');
done(); done();
}); });
}); });