Skip to content

Commit 31d919b

Browse files
committed
[tests] added HTTPS to HTTPS test
1 parent 6a6dfbb commit 31d919b

File tree

1 file changed

+47
-5
lines changed

1 file changed

+47
-5
lines changed

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

+47-5
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ describe('lib/http-proxy.js', function() {
3838
}
3939
}).listen(ports.proxy);
4040

41-
var req = https.request({
41+
https.request({
4242
host: 'localhost',
4343
port: ports.proxy,
4444
path: '/',
@@ -56,10 +56,7 @@ describe('lib/http-proxy.js', function() {
5656
proxy._server.close();
5757
done();
5858
})
59-
});
60-
61-
req.on('error', function (err) { console.log('Erroring', err); });
62-
req.end();
59+
}).end();
6360
})
6461
});
6562
describe('HTTP to HTTPS', function () {
@@ -102,6 +99,51 @@ describe('lib/http-proxy.js', function() {
10299
}).end();
103100
})
104101
})
102+
describe('HTTPS to HTTPS', function () {
103+
it('should proxy the request en send back the response', function (done) {
104+
var ports = { source: gen.port, proxy: gen.port };
105+
var source = https.createServer({
106+
key: fs.readFileSync(path.join(__dirname, 'fixtures', 'agent2-key.pem')),
107+
cert: fs.readFileSync(path.join(__dirname, 'fixtures', 'agent2-cert.pem')),
108+
}, function(req, res) {
109+
expect(req.method).to.eql('GET');
110+
expect(req.headers.host.split(':')[1]).to.eql(ports.proxy);
111+
res.writeHead(200, { 'Content-Type': 'text/plain' });
112+
res.end('Hello from ' + ports.source);
113+
});
114+
115+
source.listen(ports.source);
116+
117+
var proxy = httpProxy.createProxyServer({
118+
target: 'https://127.0.0.1:' + ports.source,
119+
ssl: {
120+
key: fs.readFileSync(path.join(__dirname, 'fixtures', 'agent2-key.pem')),
121+
cert: fs.readFileSync(path.join(__dirname, 'fixtures', 'agent2-cert.pem')),
122+
},
123+
secure: false
124+
}).listen(ports.proxy);
125+
126+
https.request({
127+
host: 'localhost',
128+
port: ports.proxy,
129+
path: '/',
130+
method: 'GET',
131+
rejectUnauthorized: false
132+
}, function(res) {
133+
expect(res.statusCode).to.eql(200);
134+
135+
res.on('data', function (data) {
136+
expect(data.toString()).to.eql('Hello from ' + ports.source);
137+
});
138+
139+
res.on('end', function () {
140+
source.close();
141+
proxy._server.close();
142+
done();
143+
})
144+
}).end();
145+
})
146+
});
105147
describe('HTTPS not allow SSL self signed', function () {
106148
it('should fail with error', function (done) {
107149
var ports = { source: gen.port, proxy: gen.port };

0 commit comments

Comments
 (0)