From 19670bb4c971c01dd158de4133dc7df77ea6d296 Mon Sep 17 00:00:00 2001 From: Matteo Date: Fri, 16 Nov 2018 20:30:05 +0100 Subject: [PATCH] test: add typeerror test for EC crypto keygen --- test/parallel/test-crypto-keygen.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/test/parallel/test-crypto-keygen.js b/test/parallel/test-crypto-keygen.js index 072f69565af98e..241e4aa73ac684 100644 --- a/test/parallel/test-crypto-keygen.js +++ b/test/parallel/test-crypto-keygen.js @@ -625,6 +625,22 @@ function convertDERToPEM(label, der) { message: 'Invalid ECDH curve name' }); + // Test error type when curve is not a string + for (const namedCurve of [true, {}, [], 123]) { + common.expectsError(() => { + generateKeyPairSync('ec', { + namedCurve, + publicKeyEncoding: { type: 'spki', format: 'pem' }, + privateKeyEncoding: { type: 'sec1', format: 'pem' } + }); + }, { + type: TypeError, + code: 'ERR_INVALID_OPT_VALUE', + message: `The value "${namedCurve}" is invalid for option ` + + '"namedCurve"' + }); + } + // It should recognize both NIST and standard curve names. generateKeyPair('ec', { namedCurve: 'P-192',