node/test/parallel/test-tls-two-cas-one-string.js
Vse Mozhet Byt bc99efc973 test: simplify test skipping
* Make common.skip() exit.

  Also add common.printSkipMessage() for partial skips.

* Don't make needless things before skip

PR-URL: https://github.com/nodejs/node/pull/14021
Fixes: https://github.com/nodejs/node/issues/14016
Reviewed-By: Refael Ackermann <refack@gmail.com>
2017-07-19 15:02:06 -04:00

37 lines
981 B
JavaScript

'use strict';
const common = require('../common');
if (!common.hasCrypto)
common.skip('missing crypto');
const fs = require('fs');
const tls = require('tls');
const keydir = `${common.fixturesDir}/keys`;
const ca1 = fs.readFileSync(`${keydir}/ca1-cert.pem`, 'utf8');
const ca2 = fs.readFileSync(`${keydir}/ca2-cert.pem`, 'utf8');
const cert = fs.readFileSync(`${keydir}/agent3-cert.pem`, 'utf8');
const key = fs.readFileSync(`${keydir}/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 });
const host = common.localhostIPv4;
server.listen(0, host, function() {
tls.connect({ servername: 'agent3', host, port: this.address().port, ca });
});
if (next) {
server.once('close', next);
}
}
const array = [ca1, ca2];
const string = `${ca1}\n${ca2}`;
test(array, common.mustCall(() => test(string)));