Skip to content

Commit 1402fef

Browse files
committed
test: make tests pass when configured without-ssl
Currently when node is build --without-ssl and the test are run, there are a number of failing test due to tests expecting crypto support to be available. This commit fixes fixes the failure and instead skips the tests that expect crypto to be available. PR-URL: #11631 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Ben Noordhuis <[email protected]>
1 parent 9352528 commit 1402fef

17 files changed

+67
-28
lines changed

test/addons/openssl-binding/binding.gyp

+6-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,12 @@
22
'targets': [
33
{
44
'target_name': 'binding',
5-
'sources': ['binding.cc'],
6-
'include_dirs': ['../../../deps/openssl/openssl/include'],
5+
'conditions': [
6+
['node_use_openssl=="true"', {
7+
'sources': ['binding.cc'],
8+
'include_dirs': ['../../../deps/openssl/openssl/include'],
9+
}]
10+
]
711
},
812
]
913
}

test/addons/openssl-binding/test.js

+4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
'use strict';
22

33
const common = require('../../common');
4+
if (!common.hasCrypto) {
5+
common.skip('missing crypto');
6+
process.exit(0);
7+
}
48
const assert = require('assert');
59
const binding = require(`./build/${common.buildType}/binding`);
610
const bytes = new Uint8Array(1024);

test/common.js

+7
Original file line numberDiff line numberDiff line change
@@ -638,3 +638,10 @@ exports.expectsError = function expectsError({code, type, message}) {
638638
return true;
639639
};
640640
};
641+
642+
exports.skipIfInspectorDisabled = function skipIfInspectorDisabled() {
643+
if (!exports.hasCrypto) {
644+
exports.skip('missing ssl support so inspector is disabled');
645+
process.exit(0);
646+
}
647+
};

test/fixtures/tls-connect.js

+6-10
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,15 @@
66
const common = require('../common');
77
const fs = require('fs');
88
const join = require('path').join;
9+
// Check if Node was compiled --without-ssl and if so exit early
10+
// as the require of tls will otherwise throw an Error.
11+
if (!common.hasCrypto) {
12+
common.skip('missing crypto');
13+
process.exit(0);
14+
}
915
const tls = require('tls');
1016
const util = require('util');
1117

12-
module.exports = exports = checkCrypto;
13-
14-
function checkCrypto() {
15-
if (!common.hasCrypto) {
16-
common.skip('missing crypto');
17-
process.exit(0);
18-
}
19-
return exports;
20-
}
21-
2218
exports.assert = require('assert');
2319
exports.debug = util.debuglog('test');
2420
exports.tls = tls;

test/inspector/test-inspector.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
'use strict';
2-
require('../common');
2+
const common = require('../common');
3+
common.skipIfInspectorDisabled();
34
const assert = require('assert');
45
const helper = require('./inspector-helper.js');
56

test/inspector/test-not-blocked-on-idle.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
'use strict';
2-
require('../common');
2+
const common = require('../common');
3+
common.skipIfInspectorDisabled();
34
const helper = require('./inspector-helper.js');
45

56
function shouldShutDown(session) {

test/parallel/test-cluster-inspector-debug-port.js

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'use strict';
22
// Flags: --inspect={PORT}
33
const common = require('../common');
4+
common.skipIfInspectorDisabled();
45
const assert = require('assert');
56
const cluster = require('cluster');
67
const debuggerPort = common.PORT;

test/parallel/test-tls-addca.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const common = require('../common');
88
const join = require('path').join;
99
const {
1010
assert, connect, keys, tls
11-
} = require(join(common.fixturesDir, 'tls-connect'))();
11+
} = require(join(common.fixturesDir, 'tls-connect'));
1212

1313
const contextWithoutCert = tls.createSecureContext({});
1414
const contextWithCert = tls.createSecureContext({});

test/parallel/test-tls-ca-concat.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const common = require('../common');
77
const join = require('path').join;
88
const {
99
assert, connect, keys
10-
} = require(join(common.fixturesDir, 'tls-connect'))();
10+
} = require(join(common.fixturesDir, 'tls-connect'));
1111

1212
connect({
1313
client: {

test/parallel/test-tls-cert-chains-concat.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const common = require('../common');
77
const join = require('path').join;
88
const {
99
assert, connect, debug, keys
10-
} = require(join(common.fixturesDir, 'tls-connect'))();
10+
} = require(join(common.fixturesDir, 'tls-connect'));
1111

1212
// agent6-cert.pem includes cert for agent6 and ca3
1313
connect({

test/parallel/test-tls-cert-chains-in-ca.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const common = require('../common');
77
const join = require('path').join;
88
const {
99
assert, connect, debug, keys
10-
} = require(join(common.fixturesDir, 'tls-connect'))();
10+
} = require(join(common.fixturesDir, 'tls-connect'));
1111

1212

1313
// agent6-cert.pem includes cert for agent6 and ca3, split it apart and

test/parallel/test-tls-connect-secure-context.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const common = require('../common');
66
const join = require('path').join;
77
const {
88
assert, connect, keys, tls
9-
} = require(join(common.fixturesDir, 'tls-connect'))();
9+
} = require(join(common.fixturesDir, 'tls-connect'));
1010

1111
connect({
1212
client: {

test/parallel/test-tls-peer-certificate.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const common = require('../common');
66
const join = require('path').join;
77
const {
88
assert, connect, debug, keys
9-
} = require(join(common.fixturesDir, 'tls-connect'))();
9+
} = require(join(common.fixturesDir, 'tls-connect'));
1010

1111
connect({
1212
client: {rejectUnauthorized: false},

test/parallel/test-tls-socket-default-options.js

-5
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,6 @@ const {
99
connect, keys, tls
1010
} = require(join(common.fixturesDir, 'tls-connect'));
1111

12-
if (!common.hasCrypto) {
13-
common.skip('missing crypto');
14-
return;
15-
}
16-
1712
test(undefined, (err) => {
1813
assert.strictEqual(err.message, 'unable to verify the first certificate');
1914
});

test/sequential/test-debugger-debug-brk.js

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
'use strict';
22
const common = require('../common');
3+
common.skipIfInspectorDisabled();
34
const assert = require('assert');
45
const spawn = require('child_process').spawn;
56

test/testpy/__init__.py

+13-1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import os
3030
from os.path import join, dirname, exists
3131
import re
32+
import ast
3233

3334

3435
FLAGS_PATTERN = re.compile(r"//\s+Flags:(.*)")
@@ -64,7 +65,18 @@ def GetCommand(self):
6465
# PORT should match the definition in test/common.js.
6566
env = { 'PORT': int(os.getenv('NODE_COMMON_PORT', '12346')) }
6667
env['PORT'] += self.thread_id * 100
67-
result += flags_match.group(1).strip().format(**env).split()
68+
flag = flags_match.group(1).strip().format(**env).split()
69+
# The following block reads config.gypi to extract the v8_enable_inspector
70+
# value. This is done to check if the inspector is disabled in which case
71+
# the '--inspect' flag cannot be passed to the node process as it will
72+
# cause node to exit and report the test as failed. The use case
73+
# is currently when Node is configured --without-ssl and the tests should
74+
# still be runnable but skip any tests that require ssl (which includes the
75+
# inspector related tests).
76+
if flag[0].startswith('--inspect') and self.context.v8_enable_inspector == 0:
77+
print('Skipping as inspector is disabled')
78+
else:
79+
result += flag
6880
files_match = FILES_PATTERN.search(source);
6981
additional_files = []
7082
if files_match:

tools/test.py

+19-2
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
import multiprocessing
4444
import errno
4545
import copy
46+
import ast
4647

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

868869
def __init__(self, workspace, buildspace, verbose, vm, args, expect_fail,
869870
timeout, processor, suppress_dialogs,
870-
store_unexpected_output, repeat, abort_on_timeout):
871+
store_unexpected_output, repeat, abort_on_timeout,
872+
v8_enable_inspector):
871873
self.workspace = workspace
872874
self.buildspace = buildspace
873875
self.verbose = verbose
@@ -880,6 +882,7 @@ def __init__(self, workspace, buildspace, verbose, vm, args, expect_fail,
880882
self.store_unexpected_output = store_unexpected_output
881883
self.repeat = repeat
882884
self.abort_on_timeout = abort_on_timeout
885+
self.v8_enable_inspector = v8_enable_inspector
883886

884887
def GetVm(self, arch, mode):
885888
if arch == 'none':
@@ -912,6 +915,19 @@ def RunTestCases(cases_to_run, progress, tasks, flaky_tests_mode):
912915
progress = PROGRESS_INDICATORS[progress](cases_to_run, flaky_tests_mode)
913916
return progress.Run(tasks)
914917

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

916932
# -------------------------------------------
917933
# --- T e s t C o n f i g u r a t i o n ---
@@ -1587,7 +1603,8 @@ def Main():
15871603
options.suppress_dialogs,
15881604
options.store_unexpected_output,
15891605
options.repeat,
1590-
options.abort_on_timeout)
1606+
options.abort_on_timeout,
1607+
GetV8InspectorEnabledFlag())
15911608

15921609
# Get status for tests
15931610
sections = [ ]

0 commit comments

Comments
 (0)