From 6707903faecbeadfd1fd2ca3e69650d0d9a46344 Mon Sep 17 00:00:00 2001 From: Leko Date: Tue, 5 Dec 2017 01:24:37 +0900 Subject: [PATCH] test: improve coverage for Cipheriv and Decipheriv PR-URL: https://github.com/nodejs/node/pull/17458 Reviewed-By: Luigi Pinca Reviewed-By: Jon Moss Reviewed-By: James M Snell Reviewed-By: Ruben Bridgewater --- .../test-crypto-cipheriv-decipheriv.js | 72 +++++++++++++++++++ 1 file changed, 72 insertions(+) diff --git a/test/parallel/test-crypto-cipheriv-decipheriv.js b/test/parallel/test-crypto-cipheriv-decipheriv.js index 01f6717e67a181..82a144257c414c 100644 --- a/test/parallel/test-crypto-cipheriv-decipheriv.js +++ b/test/parallel/test-crypto-cipheriv-decipheriv.js @@ -78,6 +78,78 @@ function testCipher3(key, iv) { `encryption/decryption with key ${key} and iv ${iv}`); } +{ + const Cipheriv = crypto.Cipheriv; + const key = '123456789012345678901234'; + const iv = '12345678'; + + const instance = Cipheriv('des-ede3-cbc', key, iv); + assert(instance instanceof Cipheriv, 'Cipheriv is expected to return a new ' + + 'instance when called without `new`'); + + common.expectsError( + () => crypto.createCipheriv(null), + { + code: 'ERR_INVALID_ARG_TYPE', + type: TypeError, + message: 'The "cipher" argument must be of type string' + }); + + common.expectsError( + () => crypto.createCipheriv('des-ede3-cbc', null), + { + code: 'ERR_INVALID_ARG_TYPE', + type: TypeError, + message: 'The "key" argument must be one of type string, Buffer, ' + + 'TypedArray, or DataView' + }); + + common.expectsError( + () => crypto.createCipheriv('des-ede3-cbc', key, null), + { + code: 'ERR_INVALID_ARG_TYPE', + type: TypeError, + message: 'The "iv" argument must be one of type string, Buffer, ' + + 'TypedArray, or DataView' + }); +} + +{ + const Decipheriv = crypto.Decipheriv; + const key = '123456789012345678901234'; + const iv = '12345678'; + + const instance = Decipheriv('des-ede3-cbc', key, iv); + assert(instance instanceof Decipheriv, 'Decipheriv expected to return a new' + + ' instance when called without `new`'); + + common.expectsError( + () => crypto.createDecipheriv(null), + { + code: 'ERR_INVALID_ARG_TYPE', + type: TypeError, + message: 'The "cipher" argument must be of type string' + }); + + common.expectsError( + () => crypto.createDecipheriv('des-ede3-cbc', null), + { + code: 'ERR_INVALID_ARG_TYPE', + type: TypeError, + message: 'The "key" argument must be one of type string, Buffer, ' + + 'TypedArray, or DataView' + }); + + common.expectsError( + () => crypto.createDecipheriv('des-ede3-cbc', key, null), + { + code: 'ERR_INVALID_ARG_TYPE', + type: TypeError, + message: 'The "iv" argument must be one of type string, Buffer, ' + + 'TypedArray, or DataView' + }); +} + testCipher1('0123456789abcd0123456789', '12345678'); testCipher1('0123456789abcd0123456789', Buffer.from('12345678')); testCipher1(Buffer.from('0123456789abcd0123456789'), '12345678');