Skip to content

Commit 8085178

Browse files
committed
[tests] Using target field, tests now pass. We are missing the tests using forward field
1 parent 1204a35 commit 8085178

File tree

1 file changed

+50
-11
lines changed

1 file changed

+50
-11
lines changed

Diff for: test/lib-https-proxy-test.js

+50-11
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ describe('lib/http-proxy.js', function() {
2222
it('should proxy the request en send back the response', function (done) {
2323
var ports = { source: gen.port, proxy: gen.port };
2424
var source = http.createServer(function(req, res) {
25-
console.log('Request:', req.headers);
2625
expect(req.method).to.eql('GET');
2726
expect(req.headers.host.split(':')[1]).to.eql(ports.proxy);
2827
res.writeHead(200, { 'Content-Type': 'text/plain' });
@@ -32,7 +31,7 @@ describe('lib/http-proxy.js', function() {
3231
source.listen(ports.source);
3332

3433
var proxy = httpProxy.createProxyServer({
35-
forward: 'http://127.0.0.1:' + ports.source,
34+
target: 'http://127.0.0.1:' + ports.source,
3635
ssl: {
3736
key: fs.readFileSync(path.join(__dirname, 'fixtures', 'agent2-key.pem')),
3837
cert: fs.readFileSync(path.join(__dirname, 'fixtures', 'agent2-cert.pem')),
@@ -44,22 +43,62 @@ describe('lib/http-proxy.js', function() {
4443
port: ports.proxy,
4544
path: '/',
4645
method: 'GET',
47-
localAddress: '127.0.0.1',
4846
rejectUnauthorized: false
4947
}, function(res) {
50-
console.log(res);
51-
res.on('data', function (ch) {
52-
console.log('Chunks', ch)
48+
expect(res.statusCode).to.eql(200);
49+
50+
res.on('data', function (data) {
51+
expect(data.toString()).to.eql('Hello from ' + ports.source);
52+
});
53+
54+
res.on('end', function () {
55+
source.close();
56+
proxy._server.close();
57+
done();
5358
})
54-
console.log('Response:', res.statusCode);
55-
source.close();
56-
proxy._server.close();
57-
done();
5859
});
5960

6061
req.on('error', function (err) { console.log('Erroring', err); });
6162
req.end();
6263
})
63-
})
64+
});
65+
describe('HTTP to HTTPS', function () {
66+
it('should proxy the request en send back the response', function (done) {
67+
var ports = { source: gen.port, proxy: gen.port };
68+
var source = https.createServer({
69+
key: fs.readFileSync(path.join(__dirname, 'fixtures', 'agent2-key.pem')),
70+
cert: fs.readFileSync(path.join(__dirname, 'fixtures', 'agent2-cert.pem')),
71+
}, function (req, res) {
72+
expect(req.method).to.eql('GET');
73+
expect(req.headers.host.split(':')[1]).to.eql(ports.proxy);
74+
res.writeHead(200, { 'Content-Type': 'text/plain' });
75+
res.end('Hello from ' + ports.source);
76+
});
77+
78+
source.listen(ports.source);
79+
80+
var proxy = httpProxy.createProxyServer({
81+
target: 'https://127.0.0.1:' + ports.source,
82+
}).listen(ports.proxy);
83+
84+
http.request({
85+
hostname: '127.0.0.1',
86+
port: ports.proxy,
87+
method: 'GET'
88+
}, function(res) {
89+
expect(res.statusCode).to.eql(200);
90+
91+
res.on('data', function (data) {
92+
expect(data.toString()).to.eql('Hello from ' + ports.source);
93+
});
94+
95+
res.on('end', function () {
96+
source.close();
97+
proxy._server.close();
98+
done();
99+
});
100+
}).end();
101+
})
102+
})
64103
});
65104
});

0 commit comments

Comments
 (0)