summaryrefslogtreecommitdiff
path: root/test/parallel/test-tls-basic-validations.js
diff options
context:
space:
mode:
authorJoyee Cheung <joyeec9h3@gmail.com>2018-04-16 22:58:19 +0800
committerJoyee Cheung <joyeec9h3@gmail.com>2018-04-19 12:09:26 +0800
commit2c23e31c317025f6064c194f8850a474f4b6bf53 (patch)
tree8f25f315719122321a912cf1bae35a6f76a51edf /test/parallel/test-tls-basic-validations.js
parent7e269f52667104c94dcf65e527b04c2632d701bb (diff)
downloadandroid-node-v8-2c23e31c317025f6064c194f8850a474f4b6bf53.tar.gz
android-node-v8-2c23e31c317025f6064c194f8850a474f4b6bf53.tar.bz2
android-node-v8-2c23e31c317025f6064c194f8850a474f4b6bf53.zip
src: throw ERR_INVALID_ARG_TYPE in C++ argument checks
- Moves THROW_AND_RETURN_IF_NOT_BUFFER and THROW_AND_RETURN_IF_NOT_STRING from node_crypto.cc to node_errors.h so it can be reused. - Move THROW_AND_RETURN_UNLESS_BUFFER in util.h to node_buffer.cc and call THROW_AND_RETURN_IF_NOT_BUFFER there. The only other reference to THROW_AND_RETURN_UNLESS_BUFFER in node_i18n.cc can be safely replaced by an assertion since the argument will be checked in JS land. - Migrate ERR_INVALID_ARG_TYPE errors in C++. We can move the checks to JS land if possible later without having to go semver-major. PR-URL: https://github.com/nodejs/node/pull/20121 Reviewed-By: Daniel Bevenius <daniel.bevenius@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
Diffstat (limited to 'test/parallel/test-tls-basic-validations.js')
-rw-r--r--test/parallel/test-tls-basic-validations.js78
1 files changed, 57 insertions, 21 deletions
diff --git a/test/parallel/test-tls-basic-validations.js b/test/parallel/test-tls-basic-validations.js
index 74d56546eb..3840acc024 100644
--- a/test/parallel/test-tls-basic-validations.js
+++ b/test/parallel/test-tls-basic-validations.js
@@ -7,35 +7,71 @@ if (!common.hasCrypto)
const assert = require('assert');
const tls = require('tls');
-assert.throws(() => tls.createSecureContext({ ciphers: 1 }),
- /TypeError: Ciphers must be a string/);
+common.expectsError(
+ () => tls.createSecureContext({ ciphers: 1 }),
+ {
+ code: 'ERR_INVALID_ARG_TYPE',
+ type: TypeError,
+ message: 'Ciphers must be a string'
+ });
-assert.throws(() => tls.createServer({ ciphers: 1 }),
- /TypeError: Ciphers must be a string/);
+common.expectsError(
+ () => tls.createServer({ ciphers: 1 }),
+ {
+ code: 'ERR_INVALID_ARG_TYPE',
+ type: TypeError,
+ message: 'Ciphers must be a string'
+ });
-assert.throws(() => tls.createSecureContext({ key: 'dummykey', passphrase: 1 }),
- /TypeError: Pass phrase must be a string/);
+common.expectsError(
+ () => tls.createSecureContext({ key: 'dummykey', passphrase: 1 }),
+ {
+ code: 'ERR_INVALID_ARG_TYPE',
+ type: TypeError,
+ message: 'Pass phrase must be a string'
+ });
-assert.throws(() => tls.createServer({ key: 'dummykey', passphrase: 1 }),
- /TypeError: Pass phrase must be a string/);
+common.expectsError(
+ () => tls.createServer({ key: 'dummykey', passphrase: 1 }),
+ {
+ code: 'ERR_INVALID_ARG_TYPE',
+ type: TypeError,
+ message: 'Pass phrase must be a string'
+ });
-assert.throws(() => tls.createServer({ ecdhCurve: 1 }),
- /TypeError: ECDH curve name must be a string/);
+common.expectsError(
+ () => tls.createServer({ ecdhCurve: 1 }),
+ {
+ code: 'ERR_INVALID_ARG_TYPE',
+ type: TypeError,
+ message: 'ECDH curve name must be a string'
+ });
-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'
- }
+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'
+ }
);
-assert.throws(() => tls.createServer({ sessionTimeout: 'abcd' }),
- /TypeError: Session timeout must be a 32-bit integer/);
+common.expectsError(
+ () => tls.createServer({ sessionTimeout: 'abcd' }),
+ {
+ code: 'ERR_INVALID_ARG_TYPE',
+ type: TypeError,
+ message: 'Session timeout must be a 32-bit integer'
+ });
-assert.throws(() => tls.createServer({ ticketKeys: 'abcd' }),
- /TypeError: Ticket keys must be a buffer/);
+common.expectsError(
+ () => tls.createServer({ ticketKeys: 'abcd' }),
+ {
+ code: 'ERR_INVALID_ARG_TYPE',
+ type: TypeError,
+ message: 'Ticket keys must be a buffer'
+ });
assert.throws(() => tls.createServer({ ticketKeys: Buffer.alloc(0) }),
/TypeError: Ticket keys length must be 48 bytes/);