From 8ee236f85a4890e5a2992c0829fc3a2d3a654ea4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A8=8B=E5=8F=A3=E3=80=80=E5=BD=B0?= Date: Fri, 10 Feb 2017 13:06:10 +0900 Subject: [PATCH] test: improve crypto coverage * check exception when ECDH curve is undefined * check exception when getPublicKey format is invalid PR-URL: https://github.com/nodejs/node/pull/11279 Reviewed-By: Colin Ihrig Reviewed-By: Yuta Hiroto Reviewed-By: Santiago Gimeno Reviewed-By: James M Snell --- test/parallel/test-crypto-dh.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/test/parallel/test-crypto-dh.js b/test/parallel/test-crypto-dh.js index 95a6df6fee58bb..b95863a13ff9e7 100644 --- a/test/parallel/test-crypto-dh.js +++ b/test/parallel/test-crypto-dh.js @@ -182,6 +182,10 @@ let firstByte = ecdh1.getPublicKey('buffer', 'compressed')[0]; assert(firstByte === 2 || firstByte === 3); firstByte = ecdh1.getPublicKey('buffer', 'hybrid')[0]; assert(firstByte === 6 || firstByte === 7); +// format value should be string +assert.throws(() => { + ecdh1.getPublicKey('buffer', 10); +}, /^TypeError: Bad format: 10$/); // ECDH should check that point is on curve const ecdh3 = crypto.createECDH('secp256k1'); @@ -277,3 +281,8 @@ ecdh5.setPrivateKey(cafebabeKey, 'hex'); // Verify object state did not change. assert.strictEqual(ecdh5.getPrivateKey('hex'), cafebabeKey); }); + +// invalid test: curve argument is undefined +assert.throws(() => { + crypto.createECDH(); +}, /^TypeError: "curve" argument should be a string$/);