Skip to content

Commit 84b7a86

Browse files
Lekoapapirovski
authored andcommitted
test: improve coverage for Cipher and Decipher
Cipher - Call constructor withour new keyword - Call constructor with cipher is not string - Call constructor with cipher is string and password is not string - Call Cipher#update with data is not string - Call Cipher#setAuthTag with tagbuf is not string - Call Cipher#setAAD with aadbuf is not string Decipher - Call constructor withour new keyword - Call constructor with cipher is not string - Call constructor with cipher is string and password is not string PR-URL: #17449 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com> Reviewed-By: Jon Moss <me@jonathanmoss.me> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
1 parent de3a7db commit 84b7a86

File tree

1 file changed

+75
-0
lines changed

1 file changed

+75
-0
lines changed

test/parallel/test-crypto-cipher-decipher.js

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,81 @@ testCipher1(Buffer.from('MySecretKey123'));
7070
testCipher2('0123456789abcdef');
7171
testCipher2(Buffer.from('0123456789abcdef'));
7272

73+
{
74+
const Cipher = crypto.Cipher;
75+
const instance = crypto.Cipher('aes-256-cbc', 'secret');
76+
assert(instance instanceof Cipher, 'Cipher is expected to return a new ' +
77+
'instance when called without `new`');
78+
79+
common.expectsError(
80+
() => crypto.createCipher(null),
81+
{
82+
code: 'ERR_INVALID_ARG_TYPE',
83+
type: TypeError,
84+
message: 'The "cipher" argument must be of type string'
85+
});
86+
87+
common.expectsError(
88+
() => crypto.createCipher('aes-256-cbc', null),
89+
{
90+
code: 'ERR_INVALID_ARG_TYPE',
91+
type: TypeError,
92+
message: 'The "password" argument must be one of type string, Buffer, ' +
93+
'TypedArray, or DataView'
94+
});
95+
96+
common.expectsError(
97+
() => crypto.createCipher('aes-256-cbc', 'secret').update(null),
98+
{
99+
code: 'ERR_INVALID_ARG_TYPE',
100+
type: TypeError,
101+
message: 'The "data" argument must be one of type string, Buffer, ' +
102+
'TypedArray, or DataView'
103+
});
104+
105+
common.expectsError(
106+
() => crypto.createCipher('aes-256-cbc', 'secret').setAuthTag(null),
107+
{
108+
code: 'ERR_INVALID_ARG_TYPE',
109+
type: TypeError,
110+
message: 'The "buffer" argument must be one of type Buffer, ' +
111+
'TypedArray, or DataView'
112+
});
113+
114+
common.expectsError(
115+
() => crypto.createCipher('aes-256-cbc', 'secret').setAAD(null),
116+
{
117+
code: 'ERR_INVALID_ARG_TYPE',
118+
type: TypeError,
119+
message: 'The "buffer" argument must be one of type Buffer, ' +
120+
'TypedArray, or DataView'
121+
});
122+
}
123+
124+
{
125+
const Decipher = crypto.Decipher;
126+
const instance = crypto.Decipher('aes-256-cbc', 'secret');
127+
assert(instance instanceof Decipher, 'Decipher is expected to return a new ' +
128+
'instance when called without `new`');
129+
130+
common.expectsError(
131+
() => crypto.createDecipher(null),
132+
{
133+
code: 'ERR_INVALID_ARG_TYPE',
134+
type: TypeError,
135+
message: 'The "cipher" argument must be of type string'
136+
});
137+
138+
common.expectsError(
139+
() => crypto.createDecipher('aes-256-cbc', null),
140+
{
141+
code: 'ERR_INVALID_ARG_TYPE',
142+
type: TypeError,
143+
message: 'The "password" argument must be one of type string, Buffer, ' +
144+
'TypedArray, or DataView'
145+
});
146+
}
147+
73148
// Base64 padding regression test, see #4837.
74149
{
75150
const c = crypto.createCipher('aes-256-cbc', 'secret');

0 commit comments

Comments
 (0)