Skip to content

Commit 95312f1

Browse files
committed
crypt: move test-crypto-engine to addon
Fixes: nodejs#41633 - move test-crypto-engine so that dummy engine is only built if tests are run Signed-off-by: Michael Dawson <[email protected]>
1 parent cd5689e commit 95312f1

File tree

6 files changed

+140
-109
lines changed

6 files changed

+140
-109
lines changed

node.gyp

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1475,31 +1475,5 @@
14751475
},
14761476
]
14771477
}], # end aix section
1478-
# TODO(RaisinTen): Enable this to build on other platforms as well.
1479-
['(OS=="mac" or (OS=="linux" and target_arch=="x64")) and \
1480-
node_use_openssl=="true"', {
1481-
'targets': [
1482-
{
1483-
'target_name': 'test_crypto_engine',
1484-
'type': 'shared_library',
1485-
'include_dirs': ['deps/openssl/openssl/include'],
1486-
'sources': ['test/fixtures/test_crypto_engine.c'],
1487-
'conditions': [
1488-
['OS=="mac"', {
1489-
'dependencies': ['deps/openssl/openssl.gyp:openssl'],
1490-
'xcode_settings': {
1491-
'OTHER_CFLAGS': ['-Wno-deprecated-declarations'],
1492-
},
1493-
}],
1494-
['OS=="linux" and target_arch=="x64"', {
1495-
'cflags': [
1496-
'-Wno-deprecated-declarations',
1497-
'-fPIC',
1498-
],
1499-
}],
1500-
],
1501-
}, # test_crypto_engine
1502-
], # end targets
1503-
}], # end node_use_openssl section
15041478
], # end conditions block
15051479
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{
2+
'targets': [
3+
{
4+
'target_name': 'testsetengine',
5+
'type': 'none',
6+
'includes': ['../common.gypi'],
7+
'conditions': [
8+
['(OS=="mac" or (OS=="linux")) and '
9+
'node_use_openssl=="true" and '
10+
'node_shared=="false" and '
11+
'node_shared_openssl=="false"', {
12+
'type': 'shared_library',
13+
'sources': [ 'testsetengine.cc' ],
14+
'product_extension': 'engine',
15+
'include_dirs': ['../../../deps/openssl/openssl/include'],
16+
'conditions': [
17+
['OS=="mac"', {
18+
'xcode_settings': {
19+
'OTHER_CFLAGS': ['-Wno-deprecated-declarations'],
20+
},
21+
}],
22+
['OS=="linux"', {
23+
'cflags': [
24+
'-Wno-deprecated-declarations',
25+
],
26+
}],
27+
],
28+
}],
29+
],
30+
}
31+
]
32+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
'use strict';
2+
const common = require('../../common');
3+
4+
// This tests crypto.setEngine().
5+
6+
if (!common.hasCrypto)
7+
common.skip('missing crypto');
8+
9+
const assert = require('assert');
10+
const crypto = require('crypto');
11+
const fs = require('fs');
12+
const path = require('path');
13+
14+
const engine = path.join(__dirname,
15+
`/build/${common.buildType}/testsetengine.engine`);
16+
17+
if (!fs.existsSync(engine))
18+
common.skip('no engine');
19+
20+
assert.throws(() => crypto.setEngine(true), /ERR_INVALID_ARG_TYPE/);
21+
assert.throws(() => crypto.setEngine('/path/to/engine', 'notANumber'),
22+
/ERR_INVALID_ARG_TYPE/);
23+
24+
{
25+
const invalidEngineName = 'xxx';
26+
assert.throws(() => crypto.setEngine(invalidEngineName),
27+
/ERR_CRYPTO_ENGINE_UNKNOWN/);
28+
assert.throws(() => crypto.setEngine(invalidEngineName,
29+
crypto.constants.ENGINE_METHOD_RSA),
30+
/ERR_CRYPTO_ENGINE_UNKNOWN/);
31+
}
32+
33+
crypto.setEngine('dynamic');
34+
crypto.setEngine('dynamic');
35+
36+
crypto.setEngine('dynamic', crypto.constants.ENGINE_METHOD_RSA);
37+
crypto.setEngine('dynamic', crypto.constants.ENGINE_METHOD_RSA);
38+
39+
{
40+
const engineId = path.parse(engine).name;
41+
const execDir = path.parse(engine).dir;
42+
43+
crypto.setEngine(engine);
44+
// OpenSSL 3.0.1 and 1.1.1m now throw errors if an engine is loaded again
45+
// with a duplicate absolute path.
46+
// TODO(richardlau): figure out why this fails on macOS but not Linux.
47+
//crypto.setEngine(engine);
48+
49+
// crypto.setEngine(engine, crypto.constants.ENGINE_METHOD_RSA);
50+
// crypto.setEngine(engine, crypto.constants.ENGINE_METHOD_RSA);
51+
52+
process.env.OPENSSL_ENGINES = execDir;
53+
54+
crypto.setEngine(engineId);
55+
crypto.setEngine(engineId);
56+
57+
crypto.setEngine(engineId, crypto.constants.ENGINE_METHOD_RSA);
58+
crypto.setEngine(engineId, crypto.constants.ENGINE_METHOD_RSA);
59+
}
60+
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#include <openssl/engine.h>
2+
3+
#include <assert.h>
4+
#include <string.h>
5+
#include <stdlib.h>
6+
7+
#ifndef ENGINE_CMD_BASE
8+
# error did not get engine.h
9+
#endif
10+
11+
#define TEST_ENGINE_ID "testsetengine"
12+
#define TEST_ENGINE_NAME "dummy test engine"
13+
14+
#ifdef _WIN32
15+
# define DEFAULT_VISIBILITY __declspec(dllexport)
16+
#else
17+
# define DEFAULT_VISIBILITY __attribute__((visibility("default")))
18+
#endif
19+
20+
namespace {
21+
22+
int EngineInit(ENGINE* engine) {
23+
return 1;
24+
}
25+
26+
int EngineFinish(ENGINE* engine) {
27+
return 1;
28+
}
29+
30+
int EngineDestroy(ENGINE* engine) {
31+
return 1;
32+
}
33+
34+
int bind_fn(ENGINE* engine, const char* id) {
35+
ENGINE_set_id(engine, TEST_ENGINE_ID);
36+
ENGINE_set_name(engine, TEST_ENGINE_NAME);
37+
ENGINE_set_init_function(engine, EngineInit);
38+
ENGINE_set_finish_function(engine, EngineFinish);
39+
ENGINE_set_destroy_function(engine, EngineDestroy);
40+
return 1;
41+
}
42+
43+
extern "C" {
44+
DEFAULT_VISIBILITY IMPLEMENT_DYNAMIC_CHECK_FN();
45+
DEFAULT_VISIBILITY IMPLEMENT_DYNAMIC_BIND_FN(bind_fn);
46+
}
47+
48+
} // anonymous namespace

test/fixtures/test_crypto_engine.c

Lines changed: 0 additions & 20 deletions
This file was deleted.

test/parallel/test-crypto-engine.js

Lines changed: 0 additions & 63 deletions
This file was deleted.

0 commit comments

Comments
 (0)