Skip to content

Commit

Permalink
test: fix test failure with shared openssl
Browse files Browse the repository at this point in the history
When configured with share openssl, use external openssl command and
check if it can be executed.

Fixes: nodejs#618
PR-URL: nodejs#762
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
  • Loading branch information
Shigeki Ohtsu committed Feb 9, 2015
1 parent 1151016 commit c86e383
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 8 deletions.
34 changes: 26 additions & 8 deletions test/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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';
}
Expand All @@ -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 {
Expand Down
5 changes: 5 additions & 0 deletions test/parallel/test-tls-no-sslv3.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit c86e383

Please sign in to comment.