aboutsummaryrefslogtreecommitdiff
path: root/test/parallel/test-crypto-sign-verify.js
diff options
context:
space:
mode:
Diffstat (limited to 'test/parallel/test-crypto-sign-verify.js')
-rw-r--r--test/parallel/test-crypto-sign-verify.js124
1 files changed, 35 insertions, 89 deletions
diff --git a/test/parallel/test-crypto-sign-verify.js b/test/parallel/test-crypto-sign-verify.js
index 7619d91191..11cbdbc210 100644
--- a/test/parallel/test-crypto-sign-verify.js
+++ b/test/parallel/test-crypto-sign-verify.js
@@ -315,105 +315,51 @@ common.expectsError(
}));
}
-[1, [], {}, undefined, null, true, Infinity].forEach((i) => {
- common.expectsError(
- () => crypto.createSign(),
- {
- code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
- message: 'The "algorithm" argument must be of type string'
- }
- );
- common.expectsError(
- () => crypto.createVerify(),
- {
- code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
- message: 'The "algorithm" argument must be of type string'
- }
- );
-});
-
{
const sign = crypto.createSign('SHA1');
const verify = crypto.createVerify('SHA1');
- [1, [], {}, undefined, null, true, Infinity].forEach((i) => {
- common.expectsError(
- () => sign.update(i),
- {
- code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
- message: 'The "data" argument must be one of type string, Buffer, ' +
- 'TypedArray, or DataView'
- }
- );
- common.expectsError(
- () => verify.update(i),
- {
- code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
- message: 'The "data" argument must be one of type string, Buffer, ' +
- 'TypedArray, or DataView'
- }
- );
- common.expectsError(
- () => sign._write(i, 'utf8', () => {}),
- {
- code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
- message: 'The "data" argument must be one of type string, Buffer, ' +
- 'TypedArray, or DataView'
- }
- );
- common.expectsError(
- () => verify._write(i, 'utf8', () => {}),
- {
- code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
- message: 'The "data" argument must be one of type string, Buffer, ' +
- 'TypedArray, or DataView'
- }
- );
+ [1, [], {}, undefined, null, true, Infinity].forEach((input) => {
+ const type = typeof input;
+ const errObj = {
+ code: 'ERR_INVALID_ARG_TYPE',
+ name: 'TypeError [ERR_INVALID_ARG_TYPE]',
+ message: 'The "algorithm" argument must be of type string. ' +
+ `Received type ${type}`
+ };
+ assert.throws(() => crypto.createSign(input), errObj);
+ assert.throws(() => crypto.createVerify(input), errObj);
+
+ errObj.message = 'The "data" argument must be one of type string, ' +
+ `Buffer, TypedArray, or DataView. Received type ${type}`;
+ assert.throws(() => sign.update(input), errObj);
+ assert.throws(() => verify.update(input), errObj);
+ assert.throws(() => sign._write(input, 'utf8', () => {}), errObj);
+ assert.throws(() => verify._write(input, 'utf8', () => {}), errObj);
});
[
Uint8Array, Uint16Array, Uint32Array, Float32Array, Float64Array
- ].forEach((i) => {
+ ].forEach((clazz) => {
// These should all just work
- sign.update(new i());
- verify.update(new i());
+ sign.update(new clazz());
+ verify.update(new clazz());
});
- [1, {}, [], Infinity].forEach((i) => {
- common.expectsError(
- () => sign.sign(i),
- {
- code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
- message: 'The "key" argument must be one of type string, Buffer, ' +
- 'TypedArray, or DataView'
- }
- );
-
- common.expectsError(
- () => verify.verify(i),
- {
- code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
- message: 'The "key" argument must be one of type string, Buffer, ' +
- 'TypedArray, or DataView'
- }
- );
-
- common.expectsError(
- () => verify.verify('test', i),
- {
- code: 'ERR_INVALID_ARG_TYPE',
- type: TypeError,
- message: 'The "signature" argument must be one of type string, ' +
- 'Buffer, TypedArray, or DataView'
- }
- );
+ [1, {}, [], Infinity].forEach((input) => {
+ const type = typeof input;
+ const errObj = {
+ code: 'ERR_INVALID_ARG_TYPE',
+ name: 'TypeError [ERR_INVALID_ARG_TYPE]',
+ message: 'The "key" argument must be one of type string, Buffer, ' +
+ `TypedArray, or DataView. Received type ${type}`
+ };
+
+ assert.throws(() => sign.sign(input), errObj);
+ assert.throws(() => verify.verify(input), errObj);
+
+ errObj.message = 'The "signature" argument must be one of type string, ' +
+ `Buffer, TypedArray, or DataView. Received type ${type}`;
+ assert.throws(() => verify.verify('test', input), errObj);
});
}