node/test/parallel/test-crypto-engine.js
Leko 0afcea280e
test: add test case for missing branch
- The case of id is string, flags is number
- The case of flags is not 0

PR-URL: https://github.com/nodejs/node/pull/17418
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Jon Moss <me@jonathanmoss.me>
2017-12-12 03:28:07 -05:00

40 lines
976 B
JavaScript

'use strict';
const common = require('../common');
if (!common.hasCrypto)
common.skip('missing crypto');
const crypto = require('crypto');
const invalidEngineName = 'xxx';
common.expectsError(
() => crypto.setEngine(true),
{
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
message: 'The "id" argument must be of type string'
});
common.expectsError(
() => crypto.setEngine('/path/to/engine', 'notANumber'),
{
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
message: 'The "flags" argument must be of type number'
});
common.expectsError(
() => crypto.setEngine(invalidEngineName),
{
code: 'ERR_CRYPTO_ENGINE_UNKNOWN',
type: Error,
message: `Engine "${invalidEngineName}" was not found`
});
common.expectsError(
() => crypto.setEngine(invalidEngineName, crypto.constants.ENGINE_METHOD_RSA),
{
code: 'ERR_CRYPTO_ENGINE_UNKNOWN',
type: Error,
message: `Engine "${invalidEngineName}" was not found`
});