/
test-tls-basic-validations.js
80 lines (64 loc) · 2.4 KB
/
test-tls-basic-validations.js
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
'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/);
common.expectsError(
() => tls.createSecurePair({}),
{
code: 'ERR_ASSERTION',
message: 'context.context must be a NativeSecureContext'
}
);
{
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')));
}