Skip to content

Commit

Permalink
test: improve crypto coverage
Browse files Browse the repository at this point in the history
* check exception when ECDH curve is undefined
* check exception when getPublicKey format is invalid

PR-URL: #11279
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Yuta Hiroto <hello@about-hiroppy.com>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information
樋口 彰 authored and jasnell committed Mar 7, 2017
1 parent 5f1b9a4 commit 444066e
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions test/parallel/test-crypto-dh.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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$/);

0 comments on commit 444066e

Please sign in to comment.