diff options
author | Joyee Cheung <joyeec9h3@gmail.com> | 2018-01-11 01:42:08 +0800 |
---|---|---|
committer | Joyee Cheung <joyeec9h3@gmail.com> | 2018-01-17 02:20:16 +0800 |
commit | 9ffebeab48e2e0b61dc0817430f089b6a1482ea7 (patch) | |
tree | 1ae99cf7e60636ea1d5fe3b643781054dbe114b7 /test | |
parent | f75bc2c1a596e8b0dca83527ed1bad614e69eaef (diff) | |
download | android-node-v8-9ffebeab48e2e0b61dc0817430f089b6a1482ea7.tar.gz android-node-v8-9ffebeab48e2e0b61dc0817430f089b6a1482ea7.tar.bz2 android-node-v8-9ffebeab48e2e0b61dc0817430f089b6a1482ea7.zip |
tls: migrate argument type-checking errors
* Throw ERR_INVALID_ARG_TYPE from public APIs
* Assert argument types in bindings instead of throwing errors
PR-URL: https://github.com/nodejs/node/pull/18125
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Fedor Indutny <fedor.indutny@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'test')
-rw-r--r-- | test/parallel/test-tls-basic-validations.js | 9 | ||||
-rw-r--r-- | test/parallel/test-tls-error-servername.js | 30 |
2 files changed, 37 insertions, 2 deletions
diff --git a/test/parallel/test-tls-basic-validations.js b/test/parallel/test-tls-basic-validations.js index fc2743ce04..501cfd91d0 100644 --- a/test/parallel/test-tls-basic-validations.js +++ b/test/parallel/test-tls-basic-validations.js @@ -39,8 +39,13 @@ assert.throws(() => tls.createServer({ ticketKeys: 'abcd' }), assert.throws(() => tls.createServer({ ticketKeys: Buffer.alloc(0) }), /TypeError: Ticket keys length must be 48 bytes/); -assert.throws(() => tls.createSecurePair({}), - /TypeError: Second argument should be a SecureContext instance/); +common.expectsError( + () => tls.createSecurePair({}), + { + code: 'ERR_ASSERTION', + message: 'context.context must be a NativeSecureContext' + } +); { const buffer = Buffer.from('abcd'); diff --git a/test/parallel/test-tls-error-servername.js b/test/parallel/test-tls-error-servername.js new file mode 100644 index 0000000000..5c1960fce3 --- /dev/null +++ b/test/parallel/test-tls-error-servername.js @@ -0,0 +1,30 @@ +'use strict'; + +// This tests the errors thrown from TLSSocket.prototype.setServername + +const common = require('../common'); +const fixtures = require('../common/fixtures'); + +if (!common.hasCrypto) + common.skip('missing crypto'); + +const { connect } = require('tls'); +const makeDuplexPair = require('../common/duplexpair'); +const { clientSide } = makeDuplexPair(); + +const ca = fixtures.readKey('ca1-cert.pem'); + +const client = connect({ + socket: clientSide, + ca, + host: 'agent1' // Hostname from certificate +}); + +[undefined, null, 1, true, {}].forEach((value) => { + common.expectsError(() => { + client.setServername(value); + }, { + code: 'ERR_INVALID_ARG_TYPE', + message: 'The "name" argument must be of type string' + }); +}); |