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>
This commit is contained in:
parent
1151016d0a
commit
c86e383c41
@ -2,6 +2,7 @@ var path = require('path');
|
|||||||
var fs = require('fs');
|
var fs = require('fs');
|
||||||
var assert = require('assert');
|
var assert = require('assert');
|
||||||
var os = require('os');
|
var os = require('os');
|
||||||
|
var child_process = require('child_process');
|
||||||
|
|
||||||
exports.testDir = path.dirname(__filename);
|
exports.testDir = path.dirname(__filename);
|
||||||
exports.fixturesDir = path.join(exports.testDir, 'fixtures');
|
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.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') {
|
if (process.platform === 'win32') {
|
||||||
exports.PIPE = '\\\\.\\pipe\\libuv-test';
|
exports.PIPE = '\\\\.\\pipe\\libuv-test';
|
||||||
exports.opensslCli += '.exe';
|
|
||||||
} else {
|
} else {
|
||||||
exports.PIPE = exports.tmpDir + '/test.sock';
|
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') {
|
if (process.platform === 'win32') {
|
||||||
exports.faketimeCli = false;
|
exports.faketimeCli = false;
|
||||||
} else {
|
} else {
|
||||||
|
@ -9,6 +9,11 @@ var fs = require('fs');
|
|||||||
var spawn = require('child_process').spawn;
|
var spawn = require('child_process').spawn;
|
||||||
var tls = require('tls');
|
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 cert = fs.readFileSync(common.fixturesDir + '/test_cert.pem');
|
||||||
var key = fs.readFileSync(common.fixturesDir + '/test_key.pem');
|
var key = fs.readFileSync(common.fixturesDir + '/test_key.pem');
|
||||||
var server = tls.createServer({ cert: cert, key: key }, assert.fail);
|
var server = tls.createServer({ cert: cert, key: key }, assert.fail);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user