1'use strict'; 2 3// Test that TLSSocket can take arrays of strings for ALPNProtocols. 4 5const common = require('../common'); 6 7if (!common.hasCrypto) 8 common.skip('missing crypto'); 9 10const tls = require('tls'); 11 12new tls.TLSSocket(null, { 13 ALPNProtocols: ['http/1.1'], 14}); 15 16const assert = require('assert'); 17const net = require('net'); 18const fixtures = require('../common/fixtures'); 19 20const key = fixtures.readKey('agent1-key.pem'); 21const cert = fixtures.readKey('agent1-cert.pem'); 22 23const server = net.createServer(common.mustCall((s) => { 24 const tlsSocket = new tls.TLSSocket(s, { 25 isServer: true, 26 server, 27 key, 28 cert, 29 ALPNProtocols: ['http/1.1'], 30 }); 31 32 tlsSocket.on('secure', common.mustCall(() => { 33 assert.strictEqual(tlsSocket.alpnProtocol, 'http/1.1'); 34 tlsSocket.end(); 35 server.close(); 36 })); 37})); 38 39server.listen(0, common.mustCall(() => { 40 const alpnOpts = { 41 port: server.address().port, 42 rejectUnauthorized: false, 43 ALPNProtocols: ['h2', 'http/1.1'] 44 }; 45 46 tls.connect(alpnOpts, common.mustCall(function() { 47 this.end(); 48 })); 49})); 50