test: fix test failure with shared openssl

When configured with share openssl, use external openssl command and
check if it can be executed.

Fixes: https://github.com/iojs/io.js/issues/618
PR-URL: https://github.com/iojs/io.js/pull/762
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
pull/762/merge
Shigeki Ohtsu 2015-02-09 13:56:38 +09:00
parent 1151016d0a
commit c86e383c41
2 changed files with 31 additions and 8 deletions

View File

@ -2,6 +2,7 @@ var path = require('path');
var fs = require('fs');
var assert = require('assert');
var os = require('os');
var child_process = require('child_process');
exports.testDir = path.dirname(__filename);
exports.fixturesDir = path.join(exports.testDir, 'fixtures');
@ -18,10 +19,33 @@ if (process.env.TEST_THREAD_ID) {
}
exports.tmpDir = path.join(exports.testDir, exports.tmpDirName);
exports.opensslCli = path.join(path.dirname(process.execPath), 'openssl-cli');
var opensslCli = null;
// opensslCli defined lazily to reduce overhead of spawnSync
Object.defineProperty(exports, 'opensslCli', {get: function() {
if (opensslCli !== null) return opensslCli;
if (process.config.variables.node_shared_openssl) {
// use external command
opensslCli = 'openssl';
} else {
// use command built from sources included in io.js repository
opensslCli = path.join(path.dirname(process.execPath), 'openssl-cli');
}
if (process.platform === 'win32') opensslCli += '.exe';
var openssl_cmd = child_process.spawnSync(opensslCli, ['version']);
if (openssl_cmd.status !== 0 || openssl_cmd.error !== undefined) {
// openssl command cannot be executed
opensslCli = false;
}
return opensslCli;
}, enumerable: true });
if (process.platform === 'win32') {
exports.PIPE = '\\\\.\\pipe\\libuv-test';
exports.opensslCli += '.exe';
} else {
exports.PIPE = exports.tmpDir + '/test.sock';
}
@ -37,12 +61,6 @@ if (process.env.NODE_COMMON_PIPE) {
}
}
try {
fs.accessSync(exports.opensslCli);
} catch (err) {
exports.opensslCli = false;
}
if (process.platform === 'win32') {
exports.faketimeCli = false;
} else {

View File

@ -9,6 +9,11 @@ var fs = require('fs');
var spawn = require('child_process').spawn;
var tls = require('tls');
if (common.opensslCli === false) {
console.error('Skipping because openssl command cannot be executed');
process.exit(0);
}
var cert = fs.readFileSync(common.fixturesDir + '/test_cert.pem');
var key = fs.readFileSync(common.fixturesDir + '/test_key.pem');
var server = tls.createServer({ cert: cert, key: key }, assert.fail);