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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
|
'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 }),
{
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError',
message: 'The "options.ciphers" property must be of type string.' +
' Received type number (1)'
});
assert.throws(
() => tls.createServer({ ciphers: 1 }),
{
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError',
message: 'The "options.ciphers" property must be of type string.' +
' Received type number (1)'
});
assert.throws(
() => tls.createSecureContext({ key: 'dummykey', passphrase: 1 }),
{
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError',
message: 'Pass phrase must be a string'
});
assert.throws(
() => tls.createServer({ key: 'dummykey', passphrase: 1 }),
{
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError',
message: 'Pass phrase must be a string'
});
assert.throws(
() => tls.createServer({ ecdhCurve: 1 }),
{
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError',
message: 'ECDH curve name must be a string'
});
assert.throws(
() => tls.createServer({ handshakeTimeout: 'abcd' }),
{
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError',
message: 'The "options.handshakeTimeout" property must be of type number.' +
" Received type string ('abcd')"
}
);
assert.throws(
() => tls.createServer({ sessionTimeout: 'abcd' }),
{
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError',
message: 'Session timeout must be a 32-bit integer'
});
assert.throws(
() => tls.createServer({ ticketKeys: 'abcd' }),
{
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError',
message: '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({}),
{
message: 'context must be a SecureContext',
code: 'ERR_TLS_INVALID_CONTEXT',
name: 'TypeError',
}
);
{
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 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)));
}
}
{
const protocols = [(new String('a')).repeat(500)];
const out = {};
assert.throws(
() => 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'
}
);
}
assert.throws(() => { tls.createSecureContext({ minVersion: 'fhqwhgads' }); },
{
code: 'ERR_TLS_INVALID_PROTOCOL_VERSION',
name: 'TypeError'
});
assert.throws(() => { tls.createSecureContext({ maxVersion: 'fhqwhgads' }); },
{
code: 'ERR_TLS_INVALID_PROTOCOL_VERSION',
name: 'TypeError'
});
|