Files
node/test/parallel/test-tls-basic-validations.js
T
Anna Henningsen 9301b8a9c6 tls: make deprecated tls.createSecurePair() use public API
Make the deprecated `tls.createSecurePair()` method use other public
APIs only (`TLSSocket` in particular).

Since `tls.createSecurePair()` has been runtime-deprecated only
since Node 8, it probably isn’t quite time to remove it yet,
but this patch removes almost all of the code complexity that
is retained by it.

The API, as it is documented, is retained. However, it is very likely
that some users have come to rely on parts of undocumented API
of the `SecurePair` class, especially since some of the existing
tests checked for those. Therefore, this should definitely be
considered a breaking change.

PR-URL: https://github.com/nodejs/node/pull/17882
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Minwoo Jung <minwoo@nodesource.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com>
2018-01-14 14:49:41 +01:00

76 lines
2.4 KiB
JavaScript

'use strict';
const common = require('../common');
if (!common.hasCrypto)
common.skip('missing crypto');
const assert = require('assert');
const tls = require('tls');
assert.throws(() => tls.createSecureContext({ ciphers: 1 }),
/TypeError: Ciphers must be a string/);
assert.throws(() => tls.createServer({ ciphers: 1 }),
/TypeError: Ciphers must be a string/);
assert.throws(() => tls.createSecureContext({ key: 'dummykey', passphrase: 1 }),
/TypeError: Pass phrase must be a string/);
assert.throws(() => tls.createServer({ key: 'dummykey', passphrase: 1 }),
/TypeError: Pass phrase must be a string/);
assert.throws(() => tls.createServer({ ecdhCurve: 1 }),
/TypeError: ECDH curve name must be a string/);
common.expectsError(() => tls.createServer({ handshakeTimeout: 'abcd' }),
{
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
message: 'The "timeout" argument must be of type number'
}
);
assert.throws(() => tls.createServer({ sessionTimeout: 'abcd' }),
/TypeError: Session timeout must be a 32-bit integer/);
assert.throws(() => tls.createServer({ ticketKeys: 'abcd' }),
/TypeError: Ticket keys must be a buffer/);
assert.throws(() => tls.createServer({ ticketKeys: Buffer.alloc(0) }),
/TypeError: Ticket keys length must be 48 bytes/);
assert.throws(() => tls.createSecurePair({}),
/TypeError: Second argument should be a SecureContext instance/);
{
const buffer = Buffer.from('abcd');
const out = {};
tls.convertALPNProtocols(buffer, out);
out.ALPNProtocols.write('efgh');
assert(buffer.equals(Buffer.from('abcd')));
assert(out.ALPNProtocols.equals(Buffer.from('efgh')));
}
{
const buffer = Buffer.from('abcd');
const out = {};
tls.convertNPNProtocols(buffer, out);
out.NPNProtocols.write('efgh');
assert(buffer.equals(Buffer.from('abcd')));
assert(out.NPNProtocols.equals(Buffer.from('efgh')));
}
{
const buffer = new Uint8Array(Buffer.from('abcd'));
const out = {};
tls.convertALPNProtocols(buffer, out);
assert(out.ALPNProtocols.equals(Buffer.from('abcd')));
}
{
const buffer = new Uint8Array(Buffer.from('abcd'));
const out = {};
tls.convertNPNProtocols(buffer, out);
assert(out.NPNProtocols.equals(Buffer.from('abcd')));
}