Skip to content

Commit

Permalink
test: improve coverage for Cipheriv and Decipheriv
Browse files Browse the repository at this point in the history
PR-URL: #17458
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Jon Moss <me@jonathanmoss.me>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
  • Loading branch information
Leko authored and apapirovski committed Dec 8, 2017
1 parent 84b7a86 commit 6707903
Showing 1 changed file with 72 additions and 0 deletions.
72 changes: 72 additions & 0 deletions test/parallel/test-crypto-cipheriv-decipheriv.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down

0 comments on commit 6707903

Please sign in to comment.