diff options
author | Alexander Avakov <yaavakov@gmail.com> | 2019-05-26 16:47:09 +0300 |
---|---|---|
committer | Rich Trott <rtrott@gmail.com> | 2019-05-30 15:37:02 +0200 |
commit | f692299764c83810ee2b7cde176b0d2b8cf839d6 (patch) | |
tree | 4cd5c54e6f390799b07a4a7e17ae17f3e6d1093e /test/parallel/test-crypto-key-objects.js | |
parent | a40aae8d1bd8e6d292cdfb20a59b101981673334 (diff) | |
download | android-node-v8-f692299764c83810ee2b7cde176b0d2b8cf839d6.tar.gz android-node-v8-f692299764c83810ee2b7cde176b0d2b8cf839d6.tar.bz2 android-node-v8-f692299764c83810ee2b7cde176b0d2b8cf839d6.zip |
crypto: fix KeyObject handle type error message
Fix KeyObject handle type error message. Add test to cover KeyObject
ERR_INVALID_ARG_TYPE exception.
PR-URL: https://github.com/nodejs/node/pull/27904
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Ujjwal Sharma <usharma1998@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Diffstat (limited to 'test/parallel/test-crypto-key-objects.js')
-rw-r--r-- | test/parallel/test-crypto-key-objects.js | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/test/parallel/test-crypto-key-objects.js b/test/parallel/test-crypto-key-objects.js index ab9005f859..2a3a3ec2f0 100644 --- a/test/parallel/test-crypto-key-objects.js +++ b/test/parallel/test-crypto-key-objects.js @@ -13,6 +13,7 @@ const { createSecretKey, createPublicKey, createPrivateKey, + KeyObject, randomBytes, publicEncrypt, privateDecrypt @@ -40,6 +41,27 @@ const privateDsa = fixtures.readKey('dsa_private_encrypted_1025.pem', } { + // Attempting to create a key of a wrong type should throw + const TYPE = 'wrong_type'; + + common.expectsError(() => new KeyObject(TYPE), { + type: TypeError, + code: 'ERR_INVALID_ARG_VALUE', + message: `The argument 'type' is invalid. Received '${TYPE}'` + }); +} + +{ + // Attempting to create a key with non-object handle should throw + common.expectsError(() => new KeyObject('secret', ''), { + type: TypeError, + code: 'ERR_INVALID_ARG_TYPE', + message: + 'The "handle" argument must be of type object. Received type string' + }); +} + +{ const keybuf = randomBytes(32); const key = createSecretKey(keybuf); assert.strictEqual(key.type, 'secret'); |