0
0
mirror of https://github.com/nodejs/node.git synced 2024-12-01 16:10:02 +01:00
nodejs/test/parallel/test-tls-npn-server-client.js
Sakthipriyan Vairamani 80a1cf7425 test: fix messages and use return to skip tests
This is a followup of https://github.com/nodejs/io.js/pull/2109.
The tests which didn't make it in #2109, are included in this patch.
The skip messages are supposed to follow the format

    1..0 # Skipped: [Actual reason why the test is skipped]

and the tests should be skipped with the return statement.

PR-URL: https://github.com/nodejs/io.js/pull/2290
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
Reviewed-By: Johan Bergström <bugs@bergstroem.nu>
2015-08-03 21:32:48 +05:30

109 lines
2.6 KiB
JavaScript

'use strict';
if (!process.features.tls_npn) {
console.log('1..0 # Skipped: node compiled without OpenSSL or ' +
'with old OpenSSL version.');
return;
}
var common = require('../common'),
assert = require('assert'),
fs = require('fs');
if (!common.hasCrypto) {
console.log('1..0 # Skipped: missing crypto');
return;
}
var tls = require('tls');
function filenamePEM(n) {
return require('path').join(common.fixturesDir, 'keys', n + '.pem');
}
function loadPEM(n) {
return fs.readFileSync(filenamePEM(n));
}
var serverOptions = {
key: loadPEM('agent2-key'),
cert: loadPEM('agent2-cert'),
crl: loadPEM('ca2-crl'),
SNICallback: function(servername, cb) {
cb(null, tls.createSecureContext({
key: loadPEM('agent2-key'),
cert: loadPEM('agent2-cert'),
crl: loadPEM('ca2-crl'),
}));
},
NPNProtocols: ['a', 'b', 'c']
};
var serverPort = common.PORT;
var clientsOptions = [{
port: serverPort,
key: serverOptions.key,
cert: serverOptions.cert,
crl: serverOptions.crl,
NPNProtocols: ['a', 'b', 'c'],
rejectUnauthorized: false
}, {
port: serverPort,
key: serverOptions.key,
cert: serverOptions.cert,
crl: serverOptions.crl,
NPNProtocols: ['c', 'b', 'e'],
rejectUnauthorized: false
}, {
port: serverPort,
key: serverOptions.key,
cert: serverOptions.cert,
crl: serverOptions.crl,
rejectUnauthorized: false
}, {
port: serverPort,
key: serverOptions.key,
cert: serverOptions.cert,
crl: serverOptions.crl,
NPNProtocols: ['first-priority-unsupported', 'x', 'y'],
rejectUnauthorized: false
}];
var serverResults = [],
clientsResults = [];
var server = tls.createServer(serverOptions, function(c) {
serverResults.push(c.npnProtocol);
});
server.listen(serverPort, startTest);
function startTest() {
function connectClient(options, callback) {
var client = tls.connect(options, function() {
clientsResults.push(client.npnProtocol);
client.destroy();
callback();
});
};
connectClient(clientsOptions[0], function() {
connectClient(clientsOptions[1], function() {
connectClient(clientsOptions[2], function() {
connectClient(clientsOptions[3], function() {
server.close();
});
});
});
});
}
process.on('exit', function() {
assert.equal(serverResults[0], clientsResults[0]);
assert.equal(serverResults[1], clientsResults[1]);
assert.equal(serverResults[2], 'http/1.1');
assert.equal(clientsResults[2], false);
assert.equal(serverResults[3], 'first-priority-unsupported');
assert.equal(clientsResults[3], false);
});