From c86e383c41f35b17ba79cc1c6dbfff674214177d Mon Sep 17 00:00:00 2001 From: Shigeki Ohtsu Date: Mon, 9 Feb 2015 13:56:38 +0900 Subject: [PATCH] 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 --- test/common.js | 34 +++++++++++++++++++++++------- test/parallel/test-tls-no-sslv3.js | 5 +++++ 2 files changed, 31 insertions(+), 8 deletions(-) diff --git a/test/common.js b/test/common.js index b682a46c324b81..1599de07be8177 100644 --- a/test/common.js +++ b/test/common.js @@ -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 { diff --git a/test/parallel/test-tls-no-sslv3.js b/test/parallel/test-tls-no-sslv3.js index 8bdc4c74232c9e..47a0aee224ba3f 100644 --- a/test/parallel/test-tls-no-sslv3.js +++ b/test/parallel/test-tls-no-sslv3.js @@ -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);