test: add typeerror test for EC crypto keygen

PR-URL: https://github.com/nodejs/node/pull/24400
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
Matteo
2018-11-16 20:30:05 +01:00
committed by Rich Trott
parent e25e8b6886
commit 67b67ad050

View File

@@ -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',