11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ci 31cb0ef41Sopenharmony_ci// Test that TLSSocket can take arrays of strings for ALPNProtocols. 41cb0ef41Sopenharmony_ci 51cb0ef41Sopenharmony_ciconst common = require('../common'); 61cb0ef41Sopenharmony_ci 71cb0ef41Sopenharmony_ciif (!common.hasCrypto) 81cb0ef41Sopenharmony_ci common.skip('missing crypto'); 91cb0ef41Sopenharmony_ci 101cb0ef41Sopenharmony_ciconst tls = require('tls'); 111cb0ef41Sopenharmony_ci 121cb0ef41Sopenharmony_cinew tls.TLSSocket(null, { 131cb0ef41Sopenharmony_ci ALPNProtocols: ['http/1.1'], 141cb0ef41Sopenharmony_ci}); 151cb0ef41Sopenharmony_ci 161cb0ef41Sopenharmony_ciconst assert = require('assert'); 171cb0ef41Sopenharmony_ciconst net = require('net'); 181cb0ef41Sopenharmony_ciconst fixtures = require('../common/fixtures'); 191cb0ef41Sopenharmony_ci 201cb0ef41Sopenharmony_ciconst key = fixtures.readKey('agent1-key.pem'); 211cb0ef41Sopenharmony_ciconst cert = fixtures.readKey('agent1-cert.pem'); 221cb0ef41Sopenharmony_ci 231cb0ef41Sopenharmony_ciconst server = net.createServer(common.mustCall((s) => { 241cb0ef41Sopenharmony_ci const tlsSocket = new tls.TLSSocket(s, { 251cb0ef41Sopenharmony_ci isServer: true, 261cb0ef41Sopenharmony_ci server, 271cb0ef41Sopenharmony_ci key, 281cb0ef41Sopenharmony_ci cert, 291cb0ef41Sopenharmony_ci ALPNProtocols: ['http/1.1'], 301cb0ef41Sopenharmony_ci }); 311cb0ef41Sopenharmony_ci 321cb0ef41Sopenharmony_ci tlsSocket.on('secure', common.mustCall(() => { 331cb0ef41Sopenharmony_ci assert.strictEqual(tlsSocket.alpnProtocol, 'http/1.1'); 341cb0ef41Sopenharmony_ci tlsSocket.end(); 351cb0ef41Sopenharmony_ci server.close(); 361cb0ef41Sopenharmony_ci })); 371cb0ef41Sopenharmony_ci})); 381cb0ef41Sopenharmony_ci 391cb0ef41Sopenharmony_ciserver.listen(0, common.mustCall(() => { 401cb0ef41Sopenharmony_ci const alpnOpts = { 411cb0ef41Sopenharmony_ci port: server.address().port, 421cb0ef41Sopenharmony_ci rejectUnauthorized: false, 431cb0ef41Sopenharmony_ci ALPNProtocols: ['h2', 'http/1.1'] 441cb0ef41Sopenharmony_ci }; 451cb0ef41Sopenharmony_ci 461cb0ef41Sopenharmony_ci tls.connect(alpnOpts, common.mustCall(function() { 471cb0ef41Sopenharmony_ci this.end(); 481cb0ef41Sopenharmony_ci })); 491cb0ef41Sopenharmony_ci})); 50