From 607158ab6ecbfd29046f5bd8123f678be7676fb2 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 6a067bef1be066..884b482fc53450 100644 --- a/test/parallel/test-crypto-dh.js +++ b/test/parallel/test-crypto-dh.js @@ -170,6 +170,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'); @@ -262,3 +266,8 @@ ecdh5.setPrivateKey(cafebabeKey, 'hex'); // Verify object state did not change. assert.equal(ecdh5.getPrivateKey('hex'), cafebabeKey); }); + +// invalid test: curve argument is undefined +assert.throws(() => { + crypto.createECDH(); +}, /^TypeError: "curve" argument should be a string$/);