mirror of
https://github.com/http-party/node-http-proxy.git
synced 2025-12-08 20:59:18 +00:00
[test] Fix tests in https mode
Tests can be run in https mode by adding the --https flag vows test/*-test.js --spec --https
This commit is contained in:
parent
ff829467d3
commit
1ee6beff6a
@ -72,7 +72,7 @@ TestRunner.prototype.assertProxied = function (host, proxyPort, port, createProx
|
||||
}
|
||||
};
|
||||
|
||||
test[assertion] = function (err, res, body) {;
|
||||
test[assertion] = function (err, res, body) {
|
||||
assert.isNull(err);
|
||||
assert.equal(body, output);
|
||||
};
|
||||
@ -81,13 +81,14 @@ TestRunner.prototype.assertProxied = function (host, proxyPort, port, createProx
|
||||
};
|
||||
|
||||
TestRunner.prototype.assertResponseCode = function (proxyPort, statusCode, createProxy) {
|
||||
var assertion = "should receive " + statusCode + " responseCode";
|
||||
var assertion = "should receive " + statusCode + " responseCode",
|
||||
protocol = this.protocol;
|
||||
|
||||
var test = {
|
||||
topic: function () {
|
||||
var that = this, options = {
|
||||
method: 'GET',
|
||||
uri: 'http://localhost:' + proxyPort,
|
||||
uri: protocol + '://localhost:' + proxyPort,
|
||||
headers: {
|
||||
host: 'unknown.com'
|
||||
}
|
||||
@ -115,7 +116,9 @@ TestRunner.prototype.assertResponseCode = function (proxyPort, statusCode, creat
|
||||
// Creates the reverse proxy server
|
||||
//
|
||||
TestRunner.prototype.startProxyServer = function (port, targetPort, host, callback) {
|
||||
var that = this, proxyServer = httpProxy.createServer(targetPort, host);
|
||||
var that = this,
|
||||
options = that.options,
|
||||
proxyServer = httpProxy.createServer(targetPort, host, options);
|
||||
|
||||
proxyServer.listen(port, function () {
|
||||
that.testServers.push(proxyServer);
|
||||
@ -164,15 +167,22 @@ TestRunner.prototype.startProxyServerWithTable = function (port, options, callba
|
||||
//
|
||||
TestRunner.prototype.startProxyServerWithTableAndLatency = function (port, latency, options, callback) {
|
||||
// Initialize the nodeProxy and start proxying the request
|
||||
var proxyServer, that = this, proxy = new httpProxy.HttpProxy(merge({}, options, this.options));
|
||||
proxyServer = http.createServer(function (req, res) {
|
||||
var proxyServer,
|
||||
that = this,
|
||||
proxy = new httpProxy.HttpProxy(merge({}, options, that.options));
|
||||
|
||||
var handler = function (req, res) {
|
||||
var buffer = proxy.buffer(req);
|
||||
setTimeout(function () {
|
||||
proxy.proxyRequest(req, res, {
|
||||
buffer: buffer
|
||||
});
|
||||
}, latency);
|
||||
}, this.options);
|
||||
};
|
||||
|
||||
proxyServer = that.options.https
|
||||
? https.createServer(that.options.https, handler, that.options)
|
||||
: http.createServer(handler, that.options);
|
||||
|
||||
proxyServer.listen(port, function () {
|
||||
that.testServers.push(proxyServer);
|
||||
@ -200,7 +210,7 @@ TestRunner.prototype.startTargetServer = function (port, output, callback) {
|
||||
var that = this, targetServer, handler = function (req, res) {
|
||||
res.writeHead(200, { 'Content-Type': 'text/plain' });
|
||||
res.write(output);
|
||||
res.end();
|
||||
res.end();
|
||||
};
|
||||
|
||||
targetServer = this.options.https
|
||||
|
||||
@ -78,13 +78,13 @@ vows.describe('node-http-proxy/proxy-table/' + protocol).addBatch({
|
||||
data = fs.readFileSync(routeFile),
|
||||
config = JSON.parse(data);
|
||||
|
||||
config.router['dynamic.com'] = "127.0.0.1:8103"
|
||||
config.router['dynamic.com'] = "127.0.0.1:8103";
|
||||
fs.writeFileSync(routeFile, JSON.stringify(config));
|
||||
|
||||
this.server.on('routes', function () {
|
||||
var options = {
|
||||
method: 'GET',
|
||||
uri: 'http://localhost:8100',
|
||||
uri: protocol + '://localhost:8100',
|
||||
headers: {
|
||||
host: 'dynamic.com'
|
||||
}
|
||||
|
||||
@ -70,7 +70,7 @@ vows.describe('node-http-proxy/websocket').addBatch({
|
||||
ws.send(utils.encode('from client'));
|
||||
});
|
||||
});
|
||||
})
|
||||
});
|
||||
},
|
||||
"the target server should receive the message": function (err, msg) {
|
||||
assert.equal(msg, 'from client');
|
||||
@ -100,7 +100,7 @@ vows.describe('node-http-proxy/websocket').addBatch({
|
||||
}
|
||||
});
|
||||
});
|
||||
})
|
||||
});
|
||||
},
|
||||
"the client should receive the message": function (err, msg) {
|
||||
assert.equal(msg, 'from server');
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user