Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit f778fa2

Browse filesBrowse files
RaisinTenBethGriggs
authored andcommitted
test: test crypto.setEngine() using an actual engine
Signed-off-by: Darshan Sen <darshan.sen@postman.com> PR-URL: #40481 Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent ef46cb4 commit f778fa2
Copy full SHA for f778fa2

File tree

Expand file treeCollapse file tree

5 files changed

+103
-39
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

5 files changed

+103
-39
lines changed
Open diff view settings
Collapse file

‎Makefile‎

Copy file name to clipboardExpand all lines: Makefile
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1327,6 +1327,7 @@ LINT_CPP_FILES = $(filter-out $(LINT_CPP_EXCLUDE), $(wildcard \
13271327
test/cctest/*.h \
13281328
test/embedding/*.cc \
13291329
test/embedding/*.h \
1330+
test/fixtures/*.c \
13301331
test/js-native-api/*/*.cc \
13311332
test/js-native-api/*/*.h \
13321333
test/node-api/*/*.cc \
Collapse file

‎node.gyp‎

Copy file name to clipboardExpand all lines: node.gyp
+26Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1391,5 +1391,31 @@
13911391
},
13921392
]
13931393
}], # end aix section
1394+
# TODO(RaisinTen): Enable this to build on other platforms as well.
1395+
['(OS=="mac" or (OS=="linux" and target_arch=="x64")) and \
1396+
node_use_openssl=="true"', {
1397+
'targets': [
1398+
{
1399+
'target_name': 'test_crypto_engine',
1400+
'type': 'shared_library',
1401+
'include_dirs': ['deps/openssl/openssl/include'],
1402+
'sources': ['test/fixtures/test_crypto_engine.c'],
1403+
'conditions': [
1404+
['OS=="mac"', {
1405+
'dependencies': ['deps/openssl/openssl.gyp:openssl'],
1406+
'xcode_settings': {
1407+
'OTHER_CFLAGS': ['-Wno-deprecated-declarations'],
1408+
},
1409+
}],
1410+
['OS=="linux" and target_arch=="x64"', {
1411+
'cflags': [
1412+
'-Wno-deprecated-declarations',
1413+
'-fPIC',
1414+
],
1415+
}],
1416+
],
1417+
}, # test_crypto_engine
1418+
], # end targets
1419+
}], # end node_use_openssl section
13941420
], # end conditions block
13951421
}
Collapse file

‎test/fixtures/test_crypto_engine.c‎

Copy file name to clipboard
+20Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#include <openssl/engine.h>
2+
3+
#include <stdio.h>
4+
5+
int bind(ENGINE* e, const char* id) {
6+
if (ENGINE_set_id(e, "libtest_crypto_engine") == 0) {
7+
fprintf(stderr, "ENGINE_set_id() failed.\n");
8+
return 0;
9+
}
10+
11+
if (ENGINE_set_name(e, "A test crypto engine") == 0) {
12+
fprintf(stderr, "ENGINE_set_name() failed.\n");
13+
return 0;
14+
}
15+
16+
return 1;
17+
}
18+
19+
IMPLEMENT_DYNAMIC_BIND_FN(bind)
20+
IMPLEMENT_DYNAMIC_CHECK_FN()
Collapse file
+54-37Lines changed: 54 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,60 @@
11
'use strict';
22
const common = require('../common');
3+
if (!common.hasCrypto) common.skip('missing crypto');
34

4-
if (!common.hasCrypto)
5-
common.skip('missing crypto');
5+
// This tests crypto.setEngine().
66

77
const assert = require('assert');
88
const crypto = require('crypto');
9-
const invalidEngineName = 'xxx';
10-
11-
assert.throws(
12-
() => crypto.setEngine(true),
13-
{
14-
code: 'ERR_INVALID_ARG_TYPE',
15-
name: 'TypeError',
16-
message: 'The "id" argument must be of type string. Received type boolean' +
17-
' (true)'
18-
});
19-
20-
assert.throws(
21-
() => crypto.setEngine('/path/to/engine', 'notANumber'),
22-
{
23-
code: 'ERR_INVALID_ARG_TYPE',
24-
name: 'TypeError',
25-
message: 'The "flags" argument must be of type number. Received type' +
26-
" string ('notANumber')"
27-
});
28-
29-
assert.throws(
30-
() => crypto.setEngine(invalidEngineName),
31-
{
32-
code: 'ERR_CRYPTO_ENGINE_UNKNOWN',
33-
name: 'Error',
34-
message: `Engine "${invalidEngineName}" was not found`
35-
});
36-
37-
assert.throws(
38-
() => crypto.setEngine(invalidEngineName, crypto.constants.ENGINE_METHOD_RSA),
39-
{
40-
code: 'ERR_CRYPTO_ENGINE_UNKNOWN',
41-
name: 'Error',
42-
message: `Engine "${invalidEngineName}" was not found`
43-
});
9+
const fs = require('fs');
10+
const path = require('path');
11+
12+
assert.throws(() => crypto.setEngine(true), /ERR_INVALID_ARG_TYPE/);
13+
assert.throws(() => crypto.setEngine('/path/to/engine', 'notANumber'),
14+
/ERR_INVALID_ARG_TYPE/);
15+
16+
{
17+
const invalidEngineName = 'xxx';
18+
assert.throws(() => crypto.setEngine(invalidEngineName),
19+
/ERR_CRYPTO_ENGINE_UNKNOWN/);
20+
assert.throws(() => crypto.setEngine(invalidEngineName,
21+
crypto.constants.ENGINE_METHOD_RSA),
22+
/ERR_CRYPTO_ENGINE_UNKNOWN/);
23+
}
24+
25+
crypto.setEngine('dynamic');
26+
crypto.setEngine('dynamic');
27+
28+
crypto.setEngine('dynamic', crypto.constants.ENGINE_METHOD_RSA);
29+
crypto.setEngine('dynamic', crypto.constants.ENGINE_METHOD_RSA);
30+
31+
{
32+
const engineName = 'test_crypto_engine';
33+
let engineLib;
34+
if (common.isOSX)
35+
engineLib = `lib${engineName}.dylib`;
36+
else if (common.isLinux && process.arch === 'x64')
37+
engineLib = `lib${engineName}.so`;
38+
39+
if (engineLib !== undefined) {
40+
const execDir = path.dirname(process.execPath);
41+
const enginePath = path.join(execDir, engineLib);
42+
const engineId = path.parse(engineLib).name;
43+
44+
fs.accessSync(enginePath);
45+
46+
crypto.setEngine(enginePath);
47+
crypto.setEngine(enginePath);
48+
49+
crypto.setEngine(enginePath, crypto.constants.ENGINE_METHOD_RSA);
50+
crypto.setEngine(enginePath, 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+
}
Collapse file

‎tools/run-worker.js‎

Copy file name to clipboardExpand all lines: tools/run-worker.js
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ if (typeof require === 'undefined') {
55
}
66

77
const path = require('path');
8-
const { Worker } = require('worker_threads');
8+
const { Worker, SHARE_ENV } = require('worker_threads');
99

10-
new Worker(path.resolve(process.cwd(), process.argv[2]))
10+
new Worker(path.resolve(process.cwd(), process.argv[2]), { env: SHARE_ENV })
1111
.on('exit', (code) => process.exitCode = code);

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.