Skip to content

Commit 0e85a84

Browse files
richardlautargos
authored andcommitted
test: fix test when compiled without engine support
Update the `addons/openssl-test-engine` test to pass when OpenSSL has been compiled without support for custom engines. OpenSSL 3 deprecated support for engines, with the recommendation to move to the provider model. PR-URL: #53232 Refs: https://github.com./openssl/openssl/blob/openssl-3.0.0/README-ENGINES.md Reviewed-By: Yagiz Nizipli <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Moshe Atlow <[email protected]> Reviewed-By: Ulises Gascón <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent cebbd83 commit 0e85a84

File tree

1 file changed

+35
-26
lines changed
  • test/addons/openssl-test-engine

1 file changed

+35
-26
lines changed

test/addons/openssl-test-engine/test.js

+35-26
Original file line numberDiff line numberDiff line change
@@ -11,50 +11,59 @@ const crypto = require('crypto');
1111
const fs = require('fs');
1212
const path = require('path');
1313

14+
// Engine support in OpenSSL is checked later on.
15+
let hasEngineSupport = true;
1416

15-
assert.throws(() => crypto.setEngine(true), /ERR_INVALID_ARG_TYPE/);
17+
assert.throws(() => crypto.setEngine(true), /ERR_INVALID_ARG_TYPE|ERR_CRYPTO_CUSTOM_ENGINE_NOT_SUPPORTED/);
1618
assert.throws(() => crypto.setEngine('/path/to/engine', 'notANumber'),
1719
/ERR_INVALID_ARG_TYPE/);
1820

1921
{
2022
const invalidEngineName = 'xxx';
2123
assert.throws(() => crypto.setEngine(invalidEngineName),
22-
/ERR_CRYPTO_ENGINE_UNKNOWN/);
24+
/ERR_CRYPTO_ENGINE_UNKNOWN|ERR_CRYPTO_CUSTOM_ENGINE_NOT_SUPPORTED/);
2325
assert.throws(() => crypto.setEngine(invalidEngineName,
2426
crypto.constants.ENGINE_METHOD_RSA),
25-
/ERR_CRYPTO_ENGINE_UNKNOWN/);
27+
/ERR_CRYPTO_ENGINE_UNKNOWN|ERR_CRYPTO_CUSTOM_ENGINE_NOT_SUPPORTED/);
2628
}
2729

28-
crypto.setEngine('dynamic');
29-
crypto.setEngine('dynamic');
30+
try {
31+
crypto.setEngine('dynamic');
32+
crypto.setEngine('dynamic');
3033

31-
crypto.setEngine('dynamic', crypto.constants.ENGINE_METHOD_RSA);
32-
crypto.setEngine('dynamic', crypto.constants.ENGINE_METHOD_RSA);
34+
crypto.setEngine('dynamic', crypto.constants.ENGINE_METHOD_RSA);
35+
crypto.setEngine('dynamic', crypto.constants.ENGINE_METHOD_RSA);
36+
} catch (err) {
37+
assert.strictEqual(err.code, 'ERR_CRYPTO_CUSTOM_ENGINE_NOT_SUPPORTED');
38+
hasEngineSupport = false;
39+
}
3340

34-
const engine = path.join(__dirname,
35-
`/build/${common.buildType}/testsetengine.engine`);
41+
if (hasEngineSupport) {
42+
const engine = path.join(__dirname,
43+
`/build/${common.buildType}/testsetengine.engine`);
3644

37-
if (!fs.existsSync(engine))
38-
common.skip('no engine');
45+
if (!fs.existsSync(engine))
46+
common.skip('no engine');
3947

40-
{
41-
const engineId = path.parse(engine).name;
42-
const execDir = path.parse(engine).dir;
48+
{
49+
const engineId = path.parse(engine).name;
50+
const execDir = path.parse(engine).dir;
4351

44-
crypto.setEngine(engine);
45-
// OpenSSL 3.0.1 and 1.1.1m now throw errors if an engine is loaded again
46-
// with a duplicate absolute path.
47-
// TODO(richardlau): figure out why this fails on macOS but not Linux.
48-
// crypto.setEngine(engine);
52+
crypto.setEngine(engine);
53+
// OpenSSL 3.0.1 and 1.1.1m now throw errors if an engine is loaded again
54+
// with a duplicate absolute path.
55+
// TODO(richardlau): figure out why this fails on macOS but not Linux.
56+
// crypto.setEngine(engine);
4957

50-
// crypto.setEngine(engine, crypto.constants.ENGINE_METHOD_RSA);
51-
// crypto.setEngine(engine, crypto.constants.ENGINE_METHOD_RSA);
58+
// crypto.setEngine(engine, crypto.constants.ENGINE_METHOD_RSA);
59+
// crypto.setEngine(engine, crypto.constants.ENGINE_METHOD_RSA);
5260

53-
process.env.OPENSSL_ENGINES = execDir;
61+
process.env.OPENSSL_ENGINES = execDir;
5462

55-
crypto.setEngine(engineId);
56-
crypto.setEngine(engineId);
63+
crypto.setEngine(engineId);
64+
crypto.setEngine(engineId);
5765

58-
crypto.setEngine(engineId, crypto.constants.ENGINE_METHOD_RSA);
59-
crypto.setEngine(engineId, crypto.constants.ENGINE_METHOD_RSA);
66+
crypto.setEngine(engineId, crypto.constants.ENGINE_METHOD_RSA);
67+
crypto.setEngine(engineId, crypto.constants.ENGINE_METHOD_RSA);
68+
}
6069
}

0 commit comments

Comments
 (0)