summaryrefslogtreecommitdiff
path: root/test/parallel/test-https-argument-of-creating.js
blob: 6f1564826eaf7403a4eedbfa8f00f54b9a71d50f (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
'use strict';

const common = require('../common');
if (!common.hasCrypto)
  common.skip('missing crypto');

const assert = require('assert');
const https = require('https');
const tls = require('tls');

const dftProtocol = {};

// Test for immutable `opts`
{
  const opts = { foo: 'bar', ALPNProtocols: [ 'http/1.1' ] };
  const server = https.createServer(opts);

  tls.convertALPNProtocols([ 'http/1.1' ], dftProtocol);
  assert.deepStrictEqual(opts, { foo: 'bar', ALPNProtocols: [ 'http/1.1' ] });
  assert.strictEqual(server.ALPNProtocols.compare(dftProtocol.ALPNProtocols),
                     0);
}


// Validate that `createServer` can work with the only argument requestListener
{
  const mustNotCall = common.mustNotCall();
  const server = https.createServer(mustNotCall);

  tls.convertALPNProtocols([ 'http/1.1' ], dftProtocol);
  assert.strictEqual(server.ALPNProtocols.compare(dftProtocol.ALPNProtocols),
                     0);
  assert.strictEqual(server.listeners('request').length, 1);
  assert.strictEqual(server.listeners('request')[0], mustNotCall);
}


// Validate that `createServer` can work with no arguments
{
  const server = https.createServer();

  assert.strictEqual(server.ALPNProtocols.compare(dftProtocol.ALPNProtocols),
                     0);
  assert.strictEqual(server.listeners('request').length, 0);
}