summaryrefslogtreecommitdiff
path: root/test/parallel/test-tls-socket-constructor-alpn-options-parsing.js
blob: 686f6444ef9d2f67a3976092cf7e1fa20d2a6a74 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
'use strict';

// Test that TLSSocket can take arrays of strings for ALPNProtocols.

const common = require('../common');

if (!common.hasCrypto)
  common.skip('missing crypto');

const tls = require('tls');

new tls.TLSSocket(null, {
  ALPNProtocols: ['http/1.1'],
});

const assert = require('assert');
const net = require('net');
const fixtures = require('../common/fixtures');

const key = fixtures.readKey('agent1-key.pem');
const cert = fixtures.readKey('agent1-cert.pem');

const server = net.createServer(common.mustCall((s) => {
  const tlsSocket = new tls.TLSSocket(s, {
    isServer: true,
    server,
    key,
    cert,
    ALPNProtocols: ['http/1.1'],
  });

  tlsSocket.on('secure', common.mustCall(() => {
    assert.strictEqual(tlsSocket.alpnProtocol, 'http/1.1');
    tlsSocket.end();
    server.close();
  }));
}));

server.listen(0, common.mustCall(() => {
  const alpnOpts = {
    port: server.address().port,
    rejectUnauthorized: false,
    ALPNProtocols: ['h2', 'http/1.1']
  };

  tls.connect(alpnOpts, common.mustCall(function() {
    this.end();
  }));
}));