1'use strict'; 2 3// This tests the errors thrown from TLSSocket.prototype.setServername 4 5const common = require('../common'); 6const fixtures = require('../common/fixtures'); 7 8if (!common.hasCrypto) 9 common.skip('missing crypto'); 10 11const assert = require('assert'); 12const { connect, TLSSocket } = require('tls'); 13const makeDuplexPair = require('../common/duplexpair'); 14const { clientSide, serverSide } = makeDuplexPair(); 15 16const key = fixtures.readKey('agent1-key.pem'); 17const cert = fixtures.readKey('agent1-cert.pem'); 18const ca = fixtures.readKey('ca1-cert.pem'); 19 20const client = connect({ 21 socket: clientSide, 22 ca, 23 host: 'agent1' // Hostname from certificate 24}); 25 26[undefined, null, 1, true, {}].forEach((value) => { 27 assert.throws(() => { 28 client.setServername(value); 29 }, { 30 code: 'ERR_INVALID_ARG_TYPE', 31 message: 'The "name" argument must be of type string.' + 32 common.invalidArgTypeHelper(value) 33 }); 34}); 35 36const server = new TLSSocket(serverSide, { 37 isServer: true, 38 key, 39 cert, 40 ca 41}); 42 43assert.throws(() => { 44 server.setServername('localhost'); 45}, { 46 code: 'ERR_TLS_SNI_FROM_SERVER', 47 message: 'Cannot issue SNI from a TLS server-side socket' 48}); 49