2015-09-28 11:33:33 +05:30
|
|
|
'use strict';
|
|
|
|
|
2016-05-30 01:45:20 +02:00
|
|
|
const common = require('../common');
|
2017-07-01 02:29:09 +03:00
|
|
|
if (!common.hasCrypto)
|
2016-05-30 01:45:20 +02:00
|
|
|
common.skip('missing crypto');
|
|
|
|
|
2015-09-28 11:33:33 +05:30
|
|
|
const assert = require('assert');
|
|
|
|
const tls = require('tls');
|
|
|
|
|
2017-07-10 20:55:21 -04:00
|
|
|
assert.throws(() => tls.createSecureContext({ ciphers: 1 }),
|
2015-09-28 11:33:33 +05:30
|
|
|
/TypeError: Ciphers must be a string/);
|
|
|
|
|
2017-07-10 20:55:21 -04:00
|
|
|
assert.throws(() => tls.createServer({ ciphers: 1 }),
|
2015-09-28 11:33:33 +05:30
|
|
|
/TypeError: Ciphers must be a string/);
|
|
|
|
|
2017-07-10 20:55:21 -04:00
|
|
|
assert.throws(() => tls.createSecureContext({ key: 'dummykey', passphrase: 1 }),
|
2015-09-28 11:33:33 +05:30
|
|
|
/TypeError: Pass phrase must be a string/);
|
|
|
|
|
2017-07-10 20:55:21 -04:00
|
|
|
assert.throws(() => tls.createServer({ key: 'dummykey', passphrase: 1 }),
|
2015-09-28 11:33:33 +05:30
|
|
|
/TypeError: Pass phrase must be a string/);
|
|
|
|
|
2017-07-10 20:55:21 -04:00
|
|
|
assert.throws(() => tls.createServer({ ecdhCurve: 1 }),
|
2015-09-28 11:33:33 +05:30
|
|
|
/TypeError: ECDH curve name must be a string/);
|
|
|
|
|
2017-12-06 22:16:44 +05:30
|
|
|
common.expectsError(() => tls.createServer({ handshakeTimeout: 'abcd' }),
|
|
|
|
{
|
|
|
|
code: 'ERR_INVALID_ARG_TYPE',
|
|
|
|
type: TypeError,
|
|
|
|
message: 'The "timeout" argument must be of type number'
|
|
|
|
}
|
2017-07-25 10:37:08 -07:00
|
|
|
);
|
2015-09-28 11:33:33 +05:30
|
|
|
|
2017-07-10 20:55:21 -04:00
|
|
|
assert.throws(() => tls.createServer({ sessionTimeout: 'abcd' }),
|
2015-09-28 11:33:33 +05:30
|
|
|
/TypeError: Session timeout must be a 32-bit integer/);
|
|
|
|
|
2017-07-10 20:55:21 -04:00
|
|
|
assert.throws(() => tls.createServer({ ticketKeys: 'abcd' }),
|
2015-09-28 11:33:33 +05:30
|
|
|
/TypeError: Ticket keys must be a buffer/);
|
|
|
|
|
2017-07-10 20:55:21 -04:00
|
|
|
assert.throws(() => tls.createServer({ ticketKeys: Buffer.alloc(0) }),
|
2015-09-28 11:33:33 +05:30
|
|
|
/TypeError: Ticket keys length must be 48 bytes/);
|
|
|
|
|
|
|
|
assert.throws(() => tls.createSecurePair({}),
|
2017-12-23 05:55:37 +01:00
|
|
|
/TypeError: Second argument should be a SecureContext instance/);
|
2016-08-11 00:46:06 +05:30
|
|
|
|
|
|
|
{
|
|
|
|
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')));
|
|
|
|
}
|
2017-03-22 07:42:04 +01:00
|
|
|
|
|
|
|
{
|
|
|
|
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')));
|
|
|
|
}
|