0
0
mirror of https://github.com/nodejs/node.git synced 2024-11-21 21:19:50 +01:00
nodejs/test/parallel/test-https-argument-of-creating.js
mscdex 71b36b3068
https: only use default ALPNProtocols when appropriate
PR-URL: https://github.com/nodejs/node/pull/54411
Reviewed-By: Robert Nagy <ronagy@icloud.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Paolo Insogna <paolo@cowtech.it>
Reviewed-By: Tim Perry <pimterry@gmail.com>
Reviewed-By: Ethan Arrowood <ethan@arrowood.dev>
Reviewed-By: James M Snell <jasnell@gmail.com>
2024-09-01 03:04:10 +00:00

59 lines
1.6 KiB
JavaScript

'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 = common.mustNotMutateObjectDeep({
foo: 'bar',
ALPNProtocols: [ 'http/1.1' ],
});
const server = https.createServer(opts);
tls.convertALPNProtocols([ 'http/1.1' ], dftProtocol);
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);
}
// Validate that `createServer` only uses defaults when appropriate
{
const ALPNCallback = () => {};
const server = https.createServer({
ALPNCallback,
});
assert.strictEqual(server.ALPNProtocols, undefined);
assert.strictEqual(server.ALPNCallback, ALPNCallback);
}