• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2
3const common = require('../common');
4if (!common.hasCrypto)
5  common.skip('missing crypto');
6
7const assert = require('assert');
8const tls = require('tls');
9
10assert.throws(
11  () => tls.createSecureContext({ ciphers: 1 }),
12  {
13    code: 'ERR_INVALID_ARG_TYPE',
14    name: 'TypeError',
15    message: 'The "options.ciphers" property must be of type string.' +
16      ' Received type number (1)'
17  });
18
19assert.throws(
20  () => tls.createServer({ ciphers: 1 }),
21  {
22    code: 'ERR_INVALID_ARG_TYPE',
23    name: 'TypeError',
24    message: 'The "options.ciphers" property must be of type string.' +
25      ' Received type number (1)'
26  });
27
28assert.throws(
29  () => tls.createSecureContext({ key: 'dummykey', passphrase: 1 }),
30  {
31    code: 'ERR_INVALID_ARG_TYPE',
32    name: 'TypeError',
33    message: 'Pass phrase must be a string'
34  });
35
36assert.throws(
37  () => tls.createServer({ key: 'dummykey', passphrase: 1 }),
38  {
39    code: 'ERR_INVALID_ARG_TYPE',
40    name: 'TypeError',
41    message: 'Pass phrase must be a string'
42  });
43
44assert.throws(
45  () => tls.createServer({ ecdhCurve: 1 }),
46  {
47    code: 'ERR_INVALID_ARG_TYPE',
48    name: 'TypeError',
49    message: 'ECDH curve name must be a string'
50  });
51
52assert.throws(
53  () => tls.createServer({ handshakeTimeout: 'abcd' }),
54  {
55    code: 'ERR_INVALID_ARG_TYPE',
56    name: 'TypeError',
57    message: 'The "options.handshakeTimeout" property must be of type number.' +
58              " Received type string ('abcd')"
59  }
60);
61
62assert.throws(
63  () => tls.createServer({ sessionTimeout: 'abcd' }),
64  {
65    code: 'ERR_INVALID_ARG_TYPE',
66    name: 'TypeError',
67    message: 'Session timeout must be a 32-bit integer'
68  });
69
70assert.throws(
71  () => tls.createServer({ ticketKeys: 'abcd' }),
72  {
73    code: 'ERR_INVALID_ARG_TYPE',
74    name: 'TypeError',
75    message: 'Ticket keys must be a buffer'
76  });
77
78assert.throws(() => tls.createServer({ ticketKeys: Buffer.alloc(0) }),
79              /TypeError: Ticket keys length must be 48 bytes/);
80
81assert.throws(
82  () => tls.createSecurePair({}),
83  {
84    message: 'context must be a SecureContext',
85    code: 'ERR_TLS_INVALID_CONTEXT',
86    name: 'TypeError',
87  }
88);
89
90{
91  const buffer = Buffer.from('abcd');
92  const out = {};
93  tls.convertALPNProtocols(buffer, out);
94  out.ALPNProtocols.write('efgh');
95  assert(buffer.equals(Buffer.from('abcd')));
96  assert(out.ALPNProtocols.equals(Buffer.from('efgh')));
97}
98
99{
100  const arrayBufferViewStr = 'abcd';
101  const inputBuffer = Buffer.from(arrayBufferViewStr.repeat(8), 'utf8');
102  for (const expectView of common.getArrayBufferViews(inputBuffer)) {
103    const out = {};
104    tls.convertALPNProtocols(expectView, out);
105    assert(out.ALPNProtocols.equals(Buffer.from(expectView)));
106  }
107}
108
109{
110  const protocols = [(new String('a')).repeat(500)];
111  const out = {};
112  assert.throws(
113    () => tls.convertALPNProtocols(protocols, out),
114    {
115      code: 'ERR_OUT_OF_RANGE',
116      message: 'The byte length of the protocol at index 0 exceeds the ' +
117        'maximum length. It must be <= 255. Received 500'
118    }
119  );
120}
121
122assert.throws(() => { tls.createSecureContext({ minVersion: 'fhqwhgads' }); },
123              {
124                code: 'ERR_TLS_INVALID_PROTOCOL_VERSION',
125                name: 'TypeError'
126              });
127
128assert.throws(() => { tls.createSecureContext({ maxVersion: 'fhqwhgads' }); },
129              {
130                code: 'ERR_TLS_INVALID_PROTOCOL_VERSION',
131                name: 'TypeError'
132              });
133