This commit adds a mustNotCall() helper for testing. This provides an alternative to using common.fail() as a callback, or creating a callback function for the sole purpose of calling common.fail(). PR-URL: https://github.com/nodejs/node/pull/11152 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com> Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com> Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com> Reviewed-By: Yuta Hiroto <hello@about-hiroppy.com>
50 lines
1.1 KiB
JavaScript
50 lines
1.1 KiB
JavaScript
'use strict';
|
|
const common = require('../common');
|
|
|
|
if (!common.hasCrypto) {
|
|
common.skip('missing crypto');
|
|
return;
|
|
}
|
|
const crypto = require('crypto');
|
|
const tls = require('tls');
|
|
|
|
crypto.DEFAULT_ENCODING = 'buffer';
|
|
|
|
const fs = require('fs');
|
|
|
|
const certPem = fs.readFileSync(common.fixturesDir + '/test_cert.pem', 'ascii');
|
|
|
|
const options = {
|
|
key: fs.readFileSync(common.fixturesDir + '/keys/agent1-key.pem'),
|
|
cert: fs.readFileSync(common.fixturesDir + '/keys/agent1-cert.pem')
|
|
};
|
|
|
|
const server = tls.Server(options, (socket) => {
|
|
setImmediate(() => {
|
|
verify();
|
|
setImmediate(() => {
|
|
socket.destroy();
|
|
});
|
|
});
|
|
});
|
|
|
|
function verify() {
|
|
crypto.createVerify('RSA-SHA1')
|
|
.update('Test')
|
|
.verify(certPem, 'asdfasdfas', 'base64');
|
|
}
|
|
|
|
server.listen(0, common.mustCall(() => {
|
|
tls.connect({
|
|
port: server.address().port,
|
|
rejectUnauthorized: false
|
|
}, common.mustCall(() => {
|
|
verify();
|
|
}))
|
|
.on('error', common.mustNotCall())
|
|
.on('close', common.mustCall(() => {
|
|
server.close();
|
|
})).resume();
|
|
}));
|
|
|
|
server.unref();
|