Skip to content

Commit c86e383

Browse files
author
Shigeki Ohtsu
committed
test: fix test failure with shared openssl
When configured with share openssl, use external openssl command and check if it can be executed. Fixes: #618 PR-URL: #762 Reviewed-By: Ben Noordhuis <[email protected]>
1 parent 1151016 commit c86e383

File tree

2 files changed

+31
-8
lines changed

2 files changed

+31
-8
lines changed

test/common.js

+26-8
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ var path = require('path');
22
var fs = require('fs');
33
var assert = require('assert');
44
var os = require('os');
5+
var child_process = require('child_process');
56

67
exports.testDir = path.dirname(__filename);
78
exports.fixturesDir = path.join(exports.testDir, 'fixtures');
@@ -18,10 +19,33 @@ if (process.env.TEST_THREAD_ID) {
1819
}
1920
exports.tmpDir = path.join(exports.testDir, exports.tmpDirName);
2021

21-
exports.opensslCli = path.join(path.dirname(process.execPath), 'openssl-cli');
22+
var opensslCli = null;
23+
24+
// opensslCli defined lazily to reduce overhead of spawnSync
25+
Object.defineProperty(exports, 'opensslCli', {get: function() {
26+
if (opensslCli !== null) return opensslCli;
27+
28+
if (process.config.variables.node_shared_openssl) {
29+
// use external command
30+
opensslCli = 'openssl';
31+
} else {
32+
// use command built from sources included in io.js repository
33+
opensslCli = path.join(path.dirname(process.execPath), 'openssl-cli');
34+
}
35+
36+
if (process.platform === 'win32') opensslCli += '.exe';
37+
38+
var openssl_cmd = child_process.spawnSync(opensslCli, ['version']);
39+
if (openssl_cmd.status !== 0 || openssl_cmd.error !== undefined) {
40+
// openssl command cannot be executed
41+
opensslCli = false;
42+
}
43+
return opensslCli;
44+
}, enumerable: true });
45+
46+
2247
if (process.platform === 'win32') {
2348
exports.PIPE = '\\\\.\\pipe\\libuv-test';
24-
exports.opensslCli += '.exe';
2549
} else {
2650
exports.PIPE = exports.tmpDir + '/test.sock';
2751
}
@@ -37,12 +61,6 @@ if (process.env.NODE_COMMON_PIPE) {
3761
}
3862
}
3963

40-
try {
41-
fs.accessSync(exports.opensslCli);
42-
} catch (err) {
43-
exports.opensslCli = false;
44-
}
45-
4664
if (process.platform === 'win32') {
4765
exports.faketimeCli = false;
4866
} else {

test/parallel/test-tls-no-sslv3.js

+5
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ var fs = require('fs');
99
var spawn = require('child_process').spawn;
1010
var tls = require('tls');
1111

12+
if (common.opensslCli === false) {
13+
console.error('Skipping because openssl command cannot be executed');
14+
process.exit(0);
15+
}
16+
1217
var cert = fs.readFileSync(common.fixturesDir + '/test_cert.pem');
1318
var key = fs.readFileSync(common.fixturesDir + '/test_key.pem');
1419
var server = tls.createServer({ cert: cert, key: key }, assert.fail);

0 commit comments

Comments
 (0)