2018-01-10 17:42:08 +00:00
|
|
|
'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');
|
|
|
|
|
2019-12-25 17:02:16 +00:00
|
|
|
const assert = require('assert');
|
2018-01-10 19:33:49 +00:00
|
|
|
const { connect, TLSSocket } = require('tls');
|
2024-07-26 08:09:23 +00:00
|
|
|
const { duplexPair } = require('stream');
|
|
|
|
const [ clientSide, serverSide ] = duplexPair();
|
2018-01-10 17:42:08 +00:00
|
|
|
|
2018-01-10 19:33:49 +00:00
|
|
|
const key = fixtures.readKey('agent1-key.pem');
|
|
|
|
const cert = fixtures.readKey('agent1-cert.pem');
|
2018-01-10 17:42:08 +00:00
|
|
|
const ca = fixtures.readKey('ca1-cert.pem');
|
|
|
|
|
|
|
|
const client = connect({
|
|
|
|
socket: clientSide,
|
|
|
|
ca,
|
|
|
|
host: 'agent1' // Hostname from certificate
|
|
|
|
});
|
|
|
|
|
|
|
|
[undefined, null, 1, true, {}].forEach((value) => {
|
2019-12-25 17:02:16 +00:00
|
|
|
assert.throws(() => {
|
2018-01-10 17:42:08 +00:00
|
|
|
client.setServername(value);
|
|
|
|
}, {
|
|
|
|
code: 'ERR_INVALID_ARG_TYPE',
|
2019-09-23 06:17:25 +00:00
|
|
|
message: 'The "name" argument must be of type string.' +
|
|
|
|
common.invalidArgTypeHelper(value)
|
2018-01-10 17:42:08 +00:00
|
|
|
});
|
|
|
|
});
|
2018-01-10 19:33:49 +00:00
|
|
|
|
|
|
|
const server = new TLSSocket(serverSide, {
|
|
|
|
isServer: true,
|
|
|
|
key,
|
|
|
|
cert,
|
|
|
|
ca
|
|
|
|
});
|
|
|
|
|
2019-12-25 17:02:16 +00:00
|
|
|
assert.throws(() => {
|
2018-01-10 19:33:49 +00:00
|
|
|
server.setServername('localhost');
|
|
|
|
}, {
|
|
|
|
code: 'ERR_TLS_SNI_FROM_SERVER',
|
|
|
|
message: 'Cannot issue SNI from a TLS server-side socket'
|
|
|
|
});
|