diff --git a/test/parallel/test-crypto-cipher-decipher.js b/test/parallel/test-crypto-cipher-decipher.js index 78172d00035..2a4d188dc4b 100644 --- a/test/parallel/test-crypto-cipher-decipher.js +++ b/test/parallel/test-crypto-cipher-decipher.js @@ -70,6 +70,81 @@ testCipher1(Buffer.from('MySecretKey123')); testCipher2('0123456789abcdef'); testCipher2(Buffer.from('0123456789abcdef')); +{ + const Cipher = crypto.Cipher; + const instance = crypto.Cipher('aes-256-cbc', 'secret'); + assert(instance instanceof Cipher, 'Cipher is expected to return a new ' + + 'instance when called without `new`'); + + common.expectsError( + () => crypto.createCipher(null), + { + code: 'ERR_INVALID_ARG_TYPE', + type: TypeError, + message: 'The "cipher" argument must be of type string' + }); + + common.expectsError( + () => crypto.createCipher('aes-256-cbc', null), + { + code: 'ERR_INVALID_ARG_TYPE', + type: TypeError, + message: 'The "password" argument must be one of type string, Buffer, ' + + 'TypedArray, or DataView' + }); + + common.expectsError( + () => crypto.createCipher('aes-256-cbc', 'secret').update(null), + { + code: 'ERR_INVALID_ARG_TYPE', + type: TypeError, + message: 'The "data" argument must be one of type string, Buffer, ' + + 'TypedArray, or DataView' + }); + + common.expectsError( + () => crypto.createCipher('aes-256-cbc', 'secret').setAuthTag(null), + { + code: 'ERR_INVALID_ARG_TYPE', + type: TypeError, + message: 'The "buffer" argument must be one of type Buffer, ' + + 'TypedArray, or DataView' + }); + + common.expectsError( + () => crypto.createCipher('aes-256-cbc', 'secret').setAAD(null), + { + code: 'ERR_INVALID_ARG_TYPE', + type: TypeError, + message: 'The "buffer" argument must be one of type Buffer, ' + + 'TypedArray, or DataView' + }); +} + +{ + const Decipher = crypto.Decipher; + const instance = crypto.Decipher('aes-256-cbc', 'secret'); + assert(instance instanceof Decipher, 'Decipher is expected to return a new ' + + 'instance when called without `new`'); + + common.expectsError( + () => crypto.createDecipher(null), + { + code: 'ERR_INVALID_ARG_TYPE', + type: TypeError, + message: 'The "cipher" argument must be of type string' + }); + + common.expectsError( + () => crypto.createDecipher('aes-256-cbc', null), + { + code: 'ERR_INVALID_ARG_TYPE', + type: TypeError, + message: 'The "password" argument must be one of type string, Buffer, ' + + 'TypedArray, or DataView' + }); +} + // Base64 padding regression test, see #4837. { const c = crypto.createCipher('aes-256-cbc', 'secret');