Skip to content

Commit

Permalink
test: multiple cas works in any order
Browse files Browse the repository at this point in the history
if the valid `ca` is the first item within the concatinated string
then the bug addressed by nodejs#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.
  • Loading branch information
suryagh committed May 6, 2016
1 parent a4f94b4 commit 13fdf42
Showing 1 changed file with 30 additions and 15 deletions.
45 changes: 30 additions & 15 deletions test/parallel/test-tls-two-cas-one-string.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use strict';

const assert = require('assert');
const common = require('../common');
const tls = require('tls');
const fs = require('fs');
Expand All @@ -13,23 +14,37 @@ const cert =
const key =
fs.readFileSync(`${common.fixturesDir}/keys/agent3-key.pem`, 'utf8');

function test(ca, next) {
const server = tls.createServer({ ca, cert, key }, function(conn) {
this.close();
conn.end();
});

server.addContext('agent3', { ca, cert, key });
function test(ca) {
return new Promise(function(resolve, reject) {
const server = tls.createServer(function(conn) {
this.close();
conn.end();
});

const host = common.localhostIPv4;
const port = common.PORT;
server.listen(port, host, function() {
tls.connect({ servername: 'agent3', host, port, ca });
});
server.addContext('agent3', { ca, cert, key });

server.once('close', next);
const host = common.localhostIPv4;
const port = common.PORT;
server.listen(port, host, function() {
var socket = tls.connect({ servername: 'agent3', host, port, ca });
var socketError = false;
socket.on('error', (e) => { socketError = e; });
server.once('close',
(e) => {
return socketError ? reject(socketError) : resolve();
});
});
});
}

const array = [ca1, ca2];
const string = ca1 + '\n' + ca2;
test(array, () => test(string, () => {}));
test(ca1 + '\n' + ca2)
.then(test.bind(null, ca2 + '\n' + ca1))
.then(test.bind(null, ca1 + ca2))
.then(test.bind(null, ca2 + ca1))
.then(test.bind(null, [ca1, ca2]))
.then(test.bind(null, [ca2, ca1]));

process.on('unhandledRejection', function(reason) {
assert.fail(null, null, reason);
});

0 comments on commit 13fdf42

Please sign in to comment.