mirror of
https://github.com/bitinflow/server.git
synced 2026-03-13 13:35:53 +00:00
add test for invalid subdomain requests
This commit is contained in:
@@ -30,10 +30,10 @@
|
||||
},
|
||||
"devDependencies": {
|
||||
"mocha": "1.18.2",
|
||||
"localtunnel": "1.1.1"
|
||||
"localtunnel": "1.1.2"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "mocha --ui qunit -- test",
|
||||
"test": "mocha --ui qunit --reporter list -- test",
|
||||
"start": "./bin/server"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -183,7 +183,7 @@ module.exports = function(opt) {
|
||||
|
||||
// limit requested hostnames to 20 characters
|
||||
if (! /^[A-Za-z0-9]{4,20}$/.test(req_id)) {
|
||||
var err = new Error('');
|
||||
var err = new Error('Invalid subdomain. Subdomains must be between 4 and 20 alphanumeric characters.');
|
||||
err.statusCode = 403;
|
||||
return next(err);
|
||||
}
|
||||
@@ -191,8 +191,7 @@ module.exports = function(opt) {
|
||||
debug('making new client with id %s', req_id);
|
||||
new_client(req_id, opt, function(err, info) {
|
||||
if (err) {
|
||||
res.statusCode = 500;
|
||||
return res.end(err.message);
|
||||
return next(err);
|
||||
}
|
||||
|
||||
var url = schema + '://' + req_id + '.' + req.headers.host;
|
||||
|
||||
@@ -91,6 +91,19 @@ test('request specific domain', function(done) {
|
||||
});
|
||||
});
|
||||
|
||||
test('request domain that is too long', function(done) {
|
||||
var opt = {
|
||||
host: 'http://localhost:' + lt_server_port,
|
||||
subdomain: 'thisdomainisoutsidethesizeofwhatweallow'
|
||||
};
|
||||
|
||||
localtunnel(test._fake_port, opt, function(err, tunnel) {
|
||||
assert(err);
|
||||
assert.equal(err.message, 'Invalid subdomain. Subdomains must be between 4 and 20 alphanumeric characters.');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
test('shutdown', function() {
|
||||
localtunnel_server.close();
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user