Skip to content

Commit 13fdf42

Browse files
committed
test: multiple cas works in any order
if the valid `ca` is the first item within the concatinated string then the bug addressed by #4099 was not getting exposed. This test makes sure the order of valid `ca` should not effect the expected behavior when multiple `ca` certs are concatinated.
1 parent a4f94b4 commit 13fdf42

File tree

1 file changed

+30
-15
lines changed

1 file changed

+30
-15
lines changed
Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
'use strict';
22

3+
const assert = require('assert');
34
const common = require('../common');
45
const tls = require('tls');
56
const fs = require('fs');
@@ -13,23 +14,37 @@ const cert =
1314
const key =
1415
fs.readFileSync(`${common.fixturesDir}/keys/agent3-key.pem`, 'utf8');
1516

16-
function test(ca, next) {
17-
const server = tls.createServer({ ca, cert, key }, function(conn) {
18-
this.close();
19-
conn.end();
20-
});
2117

22-
server.addContext('agent3', { ca, cert, key });
18+
function test(ca) {
19+
return new Promise(function(resolve, reject) {
20+
const server = tls.createServer(function(conn) {
21+
this.close();
22+
conn.end();
23+
});
2324

24-
const host = common.localhostIPv4;
25-
const port = common.PORT;
26-
server.listen(port, host, function() {
27-
tls.connect({ servername: 'agent3', host, port, ca });
28-
});
25+
server.addContext('agent3', { ca, cert, key });
2926

30-
server.once('close', next);
27+
const host = common.localhostIPv4;
28+
const port = common.PORT;
29+
server.listen(port, host, function() {
30+
var socket = tls.connect({ servername: 'agent3', host, port, ca });
31+
var socketError = false;
32+
socket.on('error', (e) => { socketError = e; });
33+
server.once('close',
34+
(e) => {
35+
return socketError ? reject(socketError) : resolve();
36+
});
37+
});
38+
});
3139
}
3240

33-
const array = [ca1, ca2];
34-
const string = ca1 + '\n' + ca2;
35-
test(array, () => test(string, () => {}));
41+
test(ca1 + '\n' + ca2)
42+
.then(test.bind(null, ca2 + '\n' + ca1))
43+
.then(test.bind(null, ca1 + ca2))
44+
.then(test.bind(null, ca2 + ca1))
45+
.then(test.bind(null, [ca1, ca2]))
46+
.then(test.bind(null, [ca2, ca1]));
47+
48+
process.on('unhandledRejection', function(reason) {
49+
assert.fail(null, null, reason);
50+
});

0 commit comments

Comments
 (0)