mirror of
https://github.com/bitinflow/localtunnel.git
synced 2026-03-21 01:15:53 +00:00
add tests for host header transform
This commit is contained in:
@@ -8,7 +8,7 @@ var localtunnel = require('../');
|
|||||||
test('setup local http server', function(done) {
|
test('setup local http server', function(done) {
|
||||||
var server = http.createServer();
|
var server = http.createServer();
|
||||||
server.on('request', function(req, res) {
|
server.on('request', function(req, res) {
|
||||||
res.write('foo');
|
res.write(req.headers.host);
|
||||||
res.end();
|
res.end();
|
||||||
});
|
});
|
||||||
server.listen(function() {
|
server.listen(function() {
|
||||||
@@ -51,7 +51,7 @@ test('query localtunnel server w/ ident', function(done) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
res.on('end', function() {
|
res.on('end', function() {
|
||||||
assert.equal('foo', body);
|
assert(/.*[.]localtunnel[.]me/.test(body), body);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -67,3 +67,47 @@ test('request specific domain', function(done) {
|
|||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
suite('local-host');
|
||||||
|
|
||||||
|
test('setup localtunnel client', function(done) {
|
||||||
|
var opt = {
|
||||||
|
local_host: '127.0.0.1'
|
||||||
|
};
|
||||||
|
localtunnel(test._fake_port, opt, function(err, tunnel) {
|
||||||
|
assert.ifError(err);
|
||||||
|
assert.ok(new RegExp('^https:\/\/.*localtunnel.me' + '$').test(tunnel.url));
|
||||||
|
test._fake_url = tunnel.url;
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
test('override Host header with local-host', function(done) {
|
||||||
|
var uri = test._fake_url;
|
||||||
|
var parsed = url.parse(uri);
|
||||||
|
|
||||||
|
var opt = {
|
||||||
|
host: parsed.host,
|
||||||
|
port: 443,
|
||||||
|
headers: {
|
||||||
|
host: parsed.hostname
|
||||||
|
},
|
||||||
|
path: '/'
|
||||||
|
};
|
||||||
|
|
||||||
|
var req = https.request(opt, function(res) {
|
||||||
|
res.setEncoding('utf8');
|
||||||
|
var body = '';
|
||||||
|
|
||||||
|
res.on('data', function(chunk) {
|
||||||
|
body += chunk;
|
||||||
|
});
|
||||||
|
|
||||||
|
res.on('end', function() {
|
||||||
|
assert.equal(body, '127.0.0.1');
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
req.end();
|
||||||
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user