From 4c3b7258d695c684d50591a552b0f3e662093582 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 PR-URL: https://github.com/nodejs/node/pull/24400 Reviewed-By: Refael Ackermann Reviewed-By: Matteo Collina Reviewed-By: James M Snell --- 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',