From fb553b5b59fe295f84f5ce69b53c08298d352ef5 Mon Sep 17 00:00:00 2001 From: Leko Date: Sat, 2 Dec 2017 22:03:04 +0900 Subject: [PATCH] test: improve crypto test coverage - Call Sign without new - Call Verify without new - Call Verify#verify with options.padding !== options.padding >> 0 - Call Verify#verify with options.saltLength !== options.saltLength >> 0 PR-URL: https://github.com/nodejs/node/pull/17426 Reviewed-By: Colin Ihrig Reviewed-By: Anatoli Papirovski Reviewed-By: Luigi Pinca --- test/parallel/test-crypto-sign-verify.js | 36 ++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/test/parallel/test-crypto-sign-verify.js b/test/parallel/test-crypto-sign-verify.js index 5f0f8d8c7ebc04..abdbcd3a1e5350 100644 --- a/test/parallel/test-crypto-sign-verify.js +++ b/test/parallel/test-crypto-sign-verify.js @@ -15,6 +15,42 @@ const certPem = fixtures.readSync('test_cert.pem', 'ascii'); const keyPem = fixtures.readSync('test_key.pem', 'ascii'); const modSize = 1024; +{ + const Sign = crypto.Sign; + const instance = Sign('SHA256'); + assert(instance instanceof Sign, 'Sign is expected to return a new ' + + 'instance when called without `new`'); +} + +{ + const Verify = crypto.Verify; + const instance = Verify('SHA256'); + assert(instance instanceof Verify, 'Verify is expected to return a new ' + + 'instance when called without `new`'); +} + +common.expectsError( + () => crypto.createVerify('SHA256').verify({ + key: certPem, + padding: undefined, + }, ''), + { + code: 'ERR_INVALID_OPT_VALUE', + type: Error, + message: 'The value "undefined" is invalid for option "padding"' + }); + +common.expectsError( + () => crypto.createVerify('SHA256').verify({ + key: certPem, + saltLength: undefined, + }, ''), + { + code: 'ERR_INVALID_OPT_VALUE', + type: Error, + message: 'The value "undefined" is invalid for option "saltLength"' + }); + // Test signing and verifying { const s1 = crypto.createSign('SHA1')