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 italoacasas committed Feb 22, 2017
1 parent add7625 commit 8ee236f
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 @@ -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');
Expand Down Expand Up @@ -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$/);

0 comments on commit 8ee236f

Please sign in to comment.