From f27d5c5f5b0db4ddb9ab98e19254aedfcfe4625e Mon Sep 17 00:00:00 2001 From: Akito Ito Date: Fri, 10 Feb 2017 13:05:45 +0900 Subject: [PATCH] test: improve crypto coverage * call Certificate function directly * check exception when sign option is undefined PR-URL: https://github.com/nodejs/node/pull/11280 Reviewed-By: Rich Trott Reviewed-By: Colin Ihrig Reviewed-By: Santiago Gimeno Reviewed-By: James M Snell --- test/parallel/test-crypto-certificate.js | 3 +++ test/parallel/test-crypto-sign-verify.js | 7 +++++++ 2 files changed, 10 insertions(+) diff --git a/test/parallel/test-crypto-certificate.js b/test/parallel/test-crypto-certificate.js index ebd83b019ba146..c051716556410d 100644 --- a/test/parallel/test-crypto-certificate.js +++ b/test/parallel/test-crypto-certificate.js @@ -37,3 +37,6 @@ assert.strictEqual(certificate.exportChallenge(spkacFail), ''); function stripLineEndings(obj) { return obj.replace(/\n/g, ''); } + +// direct call Certificate() should return instance +assert(crypto.Certificate() instanceof crypto.Certificate); diff --git a/test/parallel/test-crypto-sign-verify.js b/test/parallel/test-crypto-sign-verify.js index ae78cd9d8b3420..81b2c109b69b20 100644 --- a/test/parallel/test-crypto-sign-verify.js +++ b/test/parallel/test-crypto-sign-verify.js @@ -70,3 +70,10 @@ const keyPem = fs.readFileSync(common.fixturesDir + '/test_key.pem', 'ascii'); verified = verStream.verify(certPem, s3); assert.strictEqual(verified, true, 'sign and verify (stream)'); } + +// Test throws exception when key options is null +{ + assert.throws(() => { + crypto.createSign('RSA-SHA1').update('Test123').sign(null, 'base64'); + }, /^Error: No key provided to sign$/); +}