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');
|
|
|
|
|
2018-04-16 22:58:19 +08:00
|
|
|
common.expectsError(
|
|
|
|
() => tls.createSecureContext({ ciphers: 1 }),
|
|
|
|
{
|
|
|
|
code: 'ERR_INVALID_ARG_TYPE',
|
|
|
|
type: TypeError,
|
|
|
|
message: 'Ciphers must be a string'
|
|
|
|
});
|
2015-09-28 11:33:33 +05:30
|
|
|
|
2018-04-16 22:58:19 +08:00
|
|
|
common.expectsError(
|
|
|
|
() => tls.createServer({ ciphers: 1 }),
|
|
|
|
{
|
|
|
|
code: 'ERR_INVALID_ARG_TYPE',
|
|
|
|
type: TypeError,
|
|
|
|
message: 'Ciphers must be a string'
|
|
|
|
});
|
2015-09-28 11:33:33 +05:30
|
|
|
|
2018-04-16 22:58:19 +08:00
|
|
|
common.expectsError(
|
|
|
|
() => tls.createSecureContext({ key: 'dummykey', passphrase: 1 }),
|
|
|
|
{
|
|
|
|
code: 'ERR_INVALID_ARG_TYPE',
|
|
|
|
type: TypeError,
|
|
|
|
message: 'Pass phrase must be a string'
|
|
|
|
});
|
2015-09-28 11:33:33 +05:30
|
|
|
|
2018-04-16 22:58:19 +08:00
|
|
|
common.expectsError(
|
|
|
|
() => tls.createServer({ key: 'dummykey', passphrase: 1 }),
|
|
|
|
{
|
|
|
|
code: 'ERR_INVALID_ARG_TYPE',
|
|
|
|
type: TypeError,
|
|
|
|
message: 'Pass phrase must be a string'
|
|
|
|
});
|
2015-09-28 11:33:33 +05:30
|
|
|
|
2018-04-16 22:58:19 +08:00
|
|
|
common.expectsError(
|
|
|
|
() => tls.createServer({ ecdhCurve: 1 }),
|
|
|
|
{
|
|
|
|
code: 'ERR_INVALID_ARG_TYPE',
|
|
|
|
type: TypeError,
|
|
|
|
message: 'ECDH curve name must be a string'
|
|
|
|
});
|
2015-09-28 11:33:33 +05:30
|
|
|
|
2018-04-16 22:58:19 +08:00
|
|
|
common.expectsError(
|
|
|
|
() => tls.createServer({ handshakeTimeout: 'abcd' }),
|
|
|
|
{
|
|
|
|
code: 'ERR_INVALID_ARG_TYPE',
|
|
|
|
type: TypeError,
|
|
|
|
message: 'The "options.handshakeTimeout" property must ' +
|
|
|
|
'be of type number. Received type string'
|
|
|
|
}
|
2017-07-25 10:37:08 -07:00
|
|
|
);
|
2015-09-28 11:33:33 +05:30
|
|
|
|
2018-04-16 22:58:19 +08:00
|
|
|
common.expectsError(
|
|
|
|
() => tls.createServer({ sessionTimeout: 'abcd' }),
|
|
|
|
{
|
|
|
|
code: 'ERR_INVALID_ARG_TYPE',
|
|
|
|
type: TypeError,
|
|
|
|
message: 'Session timeout must be a 32-bit integer'
|
|
|
|
});
|
2015-09-28 11:33:33 +05:30
|
|
|
|
2018-04-16 22:58:19 +08:00
|
|
|
common.expectsError(
|
|
|
|
() => tls.createServer({ ticketKeys: 'abcd' }),
|
|
|
|
{
|
|
|
|
code: 'ERR_INVALID_ARG_TYPE',
|
|
|
|
type: TypeError,
|
|
|
|
message: 'Ticket keys must be a buffer'
|
|
|
|
});
|
2015-09-28 11:33:33 +05:30
|
|
|
|
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/);
|
|
|
|
|
2018-01-11 01:42:08 +08:00
|
|
|
common.expectsError(
|
|
|
|
() => tls.createSecurePair({}),
|
|
|
|
{
|
|
|
|
code: 'ERR_ASSERTION',
|
|
|
|
message: 'context.context must be a NativeSecureContext'
|
|
|
|
}
|
|
|
|
);
|
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')));
|
|
|
|
}
|
|
|
|
|
2017-03-22 07:42:04 +01:00
|
|
|
{
|
2018-10-01 22:52:30 -04:00
|
|
|
const arrayBufferViewStr = 'abcd';
|
|
|
|
const inputBuffer = Buffer.from(arrayBufferViewStr.repeat(8), 'utf8');
|
|
|
|
for (const expectView of common.getArrayBufferViews(inputBuffer)) {
|
|
|
|
const out = {};
|
|
|
|
tls.convertALPNProtocols(expectView, out);
|
|
|
|
assert(out.ALPNProtocols.equals(Buffer.from(expectView)));
|
|
|
|
}
|
2017-03-22 07:42:04 +01:00
|
|
|
}
|
2018-10-12 14:44:10 -04:00
|
|
|
|
|
|
|
{
|
|
|
|
const protocols = [(new String('a')).repeat(500)];
|
|
|
|
const out = {};
|
|
|
|
common.expectsError(
|
|
|
|
() => tls.convertALPNProtocols(protocols, out),
|
|
|
|
{
|
|
|
|
code: 'ERR_OUT_OF_RANGE',
|
|
|
|
message: 'The byte length of the protocol at index 0 exceeds the ' +
|
|
|
|
'maximum length. It must be <= 255. Received 500'
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|