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

This makes a effort to make sure all of these errors will actually also show the received input. On top of that it refactors a few tests for better maintainability. It will also change the returned type to always be a simple typeof instead of special handling null. PR-URL: https://github.com/nodejs/node/pull/19445 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
48 lines
1.1 KiB
JavaScript
48 lines
1.1 KiB
JavaScript
'use strict';
|
|
|
|
// This tests the errors thrown from TLSSocket.prototype.setServername
|
|
|
|
const common = require('../common');
|
|
const fixtures = require('../common/fixtures');
|
|
|
|
if (!common.hasCrypto)
|
|
common.skip('missing crypto');
|
|
|
|
const { connect, TLSSocket } = require('tls');
|
|
const makeDuplexPair = require('../common/duplexpair');
|
|
const { clientSide, serverSide } = makeDuplexPair();
|
|
|
|
const key = fixtures.readKey('agent1-key.pem');
|
|
const cert = fixtures.readKey('agent1-cert.pem');
|
|
const ca = fixtures.readKey('ca1-cert.pem');
|
|
|
|
const client = connect({
|
|
socket: clientSide,
|
|
ca,
|
|
host: 'agent1' // Hostname from certificate
|
|
});
|
|
|
|
[undefined, null, 1, true, {}].forEach((value) => {
|
|
common.expectsError(() => {
|
|
client.setServername(value);
|
|
}, {
|
|
code: 'ERR_INVALID_ARG_TYPE',
|
|
message: 'The "name" argument must be of type string. ' +
|
|
`Received type ${typeof value}`
|
|
});
|
|
});
|
|
|
|
const server = new TLSSocket(serverSide, {
|
|
isServer: true,
|
|
key,
|
|
cert,
|
|
ca
|
|
});
|
|
|
|
common.expectsError(() => {
|
|
server.setServername('localhost');
|
|
}, {
|
|
code: 'ERR_TLS_SNI_FROM_SERVER',
|
|
message: 'Cannot issue SNI from a TLS server-side socket'
|
|
});
|