Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: make tests pass when configured --without-ssl #11631

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions test/addons/openssl-binding/binding.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@
'targets': [
{
'target_name': 'binding',
'sources': ['binding.cc'],
'include_dirs': ['../../../deps/openssl/openssl/include'],
'conditions': [
['node_use_openssl=="true"', {
'sources': ['binding.cc'],
'include_dirs': ['../../../deps/openssl/openssl/include'],
}]
]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm kind of surprised this works. gyp generally doesn't like it when there are no source files to compile.

},
]
}
4 changes: 4 additions & 0 deletions test/addons/openssl-binding/test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
'use strict';

const common = require('../../common');
if (!common.hasCrypto) {
common.skip('missing crypto');
process.exit(0);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Existing uses of common.skip() in other tests return afterwards rather than calll process.exit().

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll take another look at this. Just returning does not work in this case but I'll try and dig a little further.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case I don't think we can just return as that would cause the tests that require tls-connect should not be able to proceed if there is no crypto. There might be other/better ways to deal with this but perhaps that should be done as a separate PR in that case.

}
const assert = require('assert');
const binding = require(`./build/${common.buildType}/binding`);
const bytes = new Uint8Array(1024);
Expand Down
7 changes: 7 additions & 0 deletions test/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -638,3 +638,10 @@ exports.expectsError = function expectsError({code, type, message}) {
return true;
};
};

exports.skipIfInspectorDisabled = function skipIfInspectorDisabled() {
if (!exports.hasCrypto) {
exports.skip('missing ssl support so inspector is disabled');
process.exit(0);
}
};
16 changes: 6 additions & 10 deletions test/fixtures/tls-connect.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,15 @@
const common = require('../common');
const fs = require('fs');
const join = require('path').join;
// Check if Node was compiled --without-ssl and if so exit early
// as the require of tls will otherwise throw an Error.
if (!common.hasCrypto) {
common.skip('missing crypto');
process.exit(0);
}
const tls = require('tls');
const util = require('util');

module.exports = exports = checkCrypto;

function checkCrypto() {
if (!common.hasCrypto) {
common.skip('missing crypto');
process.exit(0);
}
return exports;
}

exports.assert = require('assert');
exports.debug = util.debuglog('test');
exports.tls = tls;
Expand Down
3 changes: 2 additions & 1 deletion test/inspector/test-inspector.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use strict';
require('../common');
const common = require('../common');
common.skipIfInspectorDisabled();
const assert = require('assert');
const helper = require('./inspector-helper.js');

Expand Down
1 change: 1 addition & 0 deletions test/parallel/test-cluster-inspector-debug-port.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';
// Flags: --inspect={PORT}
const common = require('../common');
common.skipIfInspectorDisabled();
const assert = require('assert');
const cluster = require('cluster');
const debuggerPort = common.PORT;
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-tls-addca.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const common = require('../common');
const join = require('path').join;
const {
assert, connect, keys, tls
} = require(join(common.fixturesDir, 'tls-connect'))();
} = require(join(common.fixturesDir, 'tls-connect'));

const contextWithoutCert = tls.createSecureContext({});
const contextWithCert = tls.createSecureContext({});
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-tls-ca-concat.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const common = require('../common');
const join = require('path').join;
const {
assert, connect, keys
} = require(join(common.fixturesDir, 'tls-connect'))();
} = require(join(common.fixturesDir, 'tls-connect'));

connect({
client: {
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-tls-cert-chains-concat.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const common = require('../common');
const join = require('path').join;
const {
assert, connect, debug, keys
} = require(join(common.fixturesDir, 'tls-connect'))();
} = require(join(common.fixturesDir, 'tls-connect'));

// agent6-cert.pem includes cert for agent6 and ca3
connect({
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-tls-cert-chains-in-ca.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const common = require('../common');
const join = require('path').join;
const {
assert, connect, debug, keys
} = require(join(common.fixturesDir, 'tls-connect'))();
} = require(join(common.fixturesDir, 'tls-connect'));


// agent6-cert.pem includes cert for agent6 and ca3, split it apart and
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-tls-connect-secure-context.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const common = require('../common');
const join = require('path').join;
const {
assert, connect, keys, tls
} = require(join(common.fixturesDir, 'tls-connect'))();
} = require(join(common.fixturesDir, 'tls-connect'));

connect({
client: {
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-tls-peer-certificate.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const common = require('../common');
const join = require('path').join;
const {
assert, connect, debug, keys
} = require(join(common.fixturesDir, 'tls-connect'))();
} = require(join(common.fixturesDir, 'tls-connect'));

connect({
client: {rejectUnauthorized: false},
Expand Down
5 changes: 0 additions & 5 deletions test/parallel/test-tls-socket-default-options.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,6 @@ const {
connect, keys, tls
} = require(join(common.fixturesDir, 'tls-connect'));

if (!common.hasCrypto) {
common.skip('missing crypto');
return;
}

test(undefined, (err) => {
assert.strictEqual(err.message, 'unable to verify the first certificate');
});
Expand Down
1 change: 1 addition & 0 deletions test/sequential/test-debugger-debug-brk.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use strict';
const common = require('../common');
common.skipIfInspectorDisabled();
const assert = require('assert');
const spawn = require('child_process').spawn;

Expand Down
14 changes: 13 additions & 1 deletion test/testpy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import os
from os.path import join, dirname, exists
import re
import ast


FLAGS_PATTERN = re.compile(r"//\s+Flags:(.*)")
Expand Down Expand Up @@ -64,7 +65,18 @@ def GetCommand(self):
# PORT should match the definition in test/common.js.
env = { 'PORT': int(os.getenv('NODE_COMMON_PORT', '12346')) }
env['PORT'] += self.thread_id * 100
result += flags_match.group(1).strip().format(**env).split()
flag = flags_match.group(1).strip().format(**env).split()
# The following block reads config.gypi to extract the v8_enable_inspector
# value. This is done to check if the inspector is disabled in which case
# the '--inspect' flag cannot be passed to the node process as it will
# cause node to exit and report the test as failed. The use case
# is currently when Node is configured --without-ssl and the tests should
# still be runnable but skip any tests that require ssl (which includes the
# inspector related tests).
if flag[0].startswith('--inspect') and self.context.v8_enable_inspector == 0:
print('Skipping as inspector is disabled')
else:
result += flag
files_match = FILES_PATTERN.search(source);
additional_files = []
if files_match:
Expand Down
21 changes: 19 additions & 2 deletions tools/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import multiprocessing
import errno
import copy
import ast

from os.path import join, dirname, abspath, basename, isdir, exists
from datetime import datetime
Expand Down Expand Up @@ -867,7 +868,8 @@ class Context(object):

def __init__(self, workspace, buildspace, verbose, vm, args, expect_fail,
timeout, processor, suppress_dialogs,
store_unexpected_output, repeat, abort_on_timeout):
store_unexpected_output, repeat, abort_on_timeout,
v8_enable_inspector):
self.workspace = workspace
self.buildspace = buildspace
self.verbose = verbose
Expand All @@ -880,6 +882,7 @@ def __init__(self, workspace, buildspace, verbose, vm, args, expect_fail,
self.store_unexpected_output = store_unexpected_output
self.repeat = repeat
self.abort_on_timeout = abort_on_timeout
self.v8_enable_inspector = v8_enable_inspector

def GetVm(self, arch, mode):
if arch == 'none':
Expand Down Expand Up @@ -912,6 +915,19 @@ def RunTestCases(cases_to_run, progress, tasks, flaky_tests_mode):
progress = PROGRESS_INDICATORS[progress](cases_to_run, flaky_tests_mode)
return progress.Run(tasks)

def GetV8InspectorEnabledFlag():
# The following block reads config.gypi to extract the v8_enable_inspector
# value. This is done to check if the inspector is disabled in which case
# the '--inspect' flag cannot be passed to the node process as it will
# cause node to exit and report the test as failed. The use case
# is currently when Node is configured --without-ssl and the tests should
# still be runnable but skip any tests that require ssl (which includes the
# inspector related tests).
with open('config.gypi', 'r') as f:
s = f.read()
config_gypi = ast.literal_eval(s)
return config_gypi['variables']['v8_enable_inspector']


# -------------------------------------------
# --- T e s t C o n f i g u r a t i o n ---
Expand Down Expand Up @@ -1587,7 +1603,8 @@ def Main():
options.suppress_dialogs,
options.store_unexpected_output,
options.repeat,
options.abort_on_timeout)
options.abort_on_timeout,
GetV8InspectorEnabledFlag())

# Get status for tests
sections = [ ]
Expand Down