Skip to content

Commit ef533c9

Browse files
danbevMylesBorins
authored andcommitted
test: add hasCrypto when using binding('crypto')
Currently, when configured --without-ssl tests that use process.binding('crypto') fail with the following error: === release test-accessor-properties === Path: parallel/test-accessor-properties node/test/parallel/test-accessor-properties.js:16 const crypto = process.binding('crypto'); ^ Error: No such module: crypto at Object.<anonymous> (test-accessor-properties.js:16:24) at Module._compile (module.js:660:30) at Object.Module._extensions..js (module.js:671:10) at Module.load (module.js:577:32) at tryModuleLoad (module.js:517:12) at Function.Module._load (module.js:509:3) at Function.Module.runMain (module.js:701:10) at startup (bootstrap_node.js:194:16) at bootstrap_node.js:645:3 This commit adds a hasCrypto check. PR-URL: #17867 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]>
1 parent c91a7c0 commit ef533c9

3 files changed

+30
-25
lines changed

test/parallel/test-accessor-properties.js

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

3-
require('../common');
3+
const common = require('../common');
44

55
// This tests that the accessor properties do not raise assertions
66
// when called with incompatible receivers.
@@ -12,9 +12,6 @@ const assert = require('assert');
1212
const TTY = process.binding('tty_wrap').TTY;
1313
const UDP = process.binding('udp_wrap').UDP;
1414

15-
// There are accessor properties in crypto too
16-
const crypto = process.binding('crypto');
17-
1815
{
1916
// Should throw instead of raise assertions
2017
assert.throws(() => {
@@ -33,15 +30,6 @@ const crypto = process.binding('crypto');
3330
UDP.prototype.fd;
3431
}, TypeError);
3532

36-
assert.throws(() => {
37-
crypto.SecureContext.prototype._external;
38-
}, TypeError);
39-
40-
assert.throws(() => {
41-
crypto.Connection.prototype._external;
42-
}, TypeError);
43-
44-
4533
// Should not throw for Object.getOwnPropertyDescriptor
4634
assert.strictEqual(
4735
typeof Object.getOwnPropertyDescriptor(TTY.prototype, 'bytesRead'),
@@ -63,15 +51,28 @@ const crypto = process.binding('crypto');
6351
'object'
6452
);
6553

66-
assert.strictEqual(
67-
typeof Object.getOwnPropertyDescriptor(
68-
crypto.SecureContext.prototype, '_external'),
69-
'object'
70-
);
71-
72-
assert.strictEqual(
73-
typeof Object.getOwnPropertyDescriptor(
74-
crypto.Connection.prototype, '_external'),
75-
'object'
76-
);
54+
if (common.hasCrypto) { // eslint-disable-line crypto-check
55+
// There are accessor properties in crypto too
56+
const crypto = process.binding('crypto');
57+
58+
assert.throws(() => {
59+
crypto.SecureContext.prototype._external;
60+
}, TypeError);
61+
62+
assert.throws(() => {
63+
crypto.Connection.prototype._external;
64+
}, TypeError);
65+
66+
assert.strictEqual(
67+
typeof Object.getOwnPropertyDescriptor(
68+
crypto.SecureContext.prototype, '_external'),
69+
'object'
70+
);
71+
72+
assert.strictEqual(
73+
typeof Object.getOwnPropertyDescriptor(
74+
crypto.Connection.prototype, '_external'),
75+
'object'
76+
);
77+
}
7778
}

test/parallel/test-http2-util-headers-list.js

+2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
// to pass to the internal binding layer.
66

77
const common = require('../common');
8+
if (!common.hasCrypto)
9+
common.skip('missing crypto');
810
const assert = require('assert');
911
const { mapToHeaders } = require('internal/http2/util');
1012

test/parallel/test-http2-util-update-options-buffer.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
// Flags: --expose-internals
22
'use strict';
33

4-
require('../common');
4+
const common = require('../common');
5+
if (!common.hasCrypto)
6+
common.skip('missing crypto');
57

68
// Test coverage for the updateOptionsBuffer method used internally
79
// by the http2 implementation.

0 commit comments

Comments
 (0)