mirror of
https://github.com/nodejs/node.git
synced 2025-05-10 05:30:00 +00:00

Because of a poorly constructed test, only one of the two test vectors ran. The test also failed to cover the authentication error that occurs when the server's certificate is not trusted. Both issues are fixed. Fix: https://github.com/nodejs/node/issues/10538 PR-URL: https://github.com/nodejs/node/pull/11005 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: James M Snell <jasnell@gmail.com>
60 lines
1.7 KiB
JavaScript
60 lines
1.7 KiB
JavaScript
'use strict';
|
|
const common = require('../common');
|
|
|
|
// Test a directly created TLS socket supports no options, and empty options.
|
|
|
|
const assert = require('assert');
|
|
const join = require('path').join;
|
|
const {
|
|
connect, keys, tls
|
|
} = require(join(common.fixturesDir, 'tls-connect'));
|
|
|
|
if (!common.hasCrypto) {
|
|
common.skip('missing crypto');
|
|
return;
|
|
}
|
|
|
|
test(undefined, (err) => {
|
|
assert.strictEqual(err.message, 'unable to verify the first certificate');
|
|
});
|
|
|
|
test({}, (err) => {
|
|
assert.strictEqual(err.message, 'unable to verify the first certificate');
|
|
});
|
|
|
|
test({secureContext: tls.createSecureContext({ca: keys.agent1.ca})}, (err) => {
|
|
assert.ifError(err);
|
|
});
|
|
|
|
function test(client, callback) {
|
|
callback = common.mustCall(callback);
|
|
connect({
|
|
server: {
|
|
key: keys.agent1.key,
|
|
cert: keys.agent1.cert,
|
|
},
|
|
}, function(err, pair, cleanup) {
|
|
assert.strictEqual(err.message, 'unable to verify the first certificate');
|
|
let recv = '';
|
|
pair.server.server.once('secureConnection', common.mustCall((conn) => {
|
|
conn.on('data', (data) => recv += data);
|
|
conn.on('end', common.mustCall(() => {
|
|
// Server sees nothing wrong with connection, even though the client's
|
|
// authentication of the server cert failed.
|
|
assert.strictEqual(recv, 'hello');
|
|
cleanup();
|
|
}));
|
|
}));
|
|
|
|
// Client doesn't support the 'secureConnect' event, and doesn't error if
|
|
// authentication failed. Caller must explicitly check for failure.
|
|
(new tls.TLSSocket(null, client)).connect(pair.server.server.address().port)
|
|
.on('connect', common.mustCall(function() {
|
|
this.end('hello');
|
|
}))
|
|
.on('secure', common.mustCall(function() {
|
|
callback(this.ssl.verifyError());
|
|
}));
|
|
});
|
|
}
|