Skip to content

Commit e0d2842

Browse files
danbevMylesBorins
authored andcommitted
tools: add check for using process.binding crypto
Currently, when configuring --without-ssl any tests that use process.binding('crypto') will not report a lint warning. This is because the eslint check only generates a warning when using require. This commit adds a check for using binding in addition to require. PR-URL: #17867 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]>
1 parent 35aaee1 commit e0d2842

File tree

4 files changed

+23
-2
lines changed

4 files changed

+23
-2
lines changed

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.

tools/eslint-rules/crypto-check.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,18 @@ const utils = require('./rules-utils.js');
1616
const msg = 'Please add a hasCrypto check to allow this test to be skipped ' +
1717
'when Node is built "--without-ssl".';
1818

19+
const cryptoModules = ['crypto', 'http2'];
20+
const requireModules = cryptoModules.concat(['tls', 'https']);
21+
const bindingModules = cryptoModules.concat(['tls_wrap']);
22+
1923
module.exports = function(context) {
2024
const missingCheckNodes = [];
2125
const requireNodes = [];
2226
var hasSkipCall = false;
2327

2428
function testCryptoUsage(node) {
25-
if (utils.isRequired(node, ['crypto', 'tls', 'https', 'http2'])) {
29+
if (utils.isRequired(node, requireModules) ||
30+
utils.isBinding(node, bindingModules)) {
2631
requireNodes.push(node);
2732
}
2833
}

tools/eslint-rules/rules-utils.js

+12
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,18 @@ module.exports.isRequired = function(node, modules) {
1212
modules.includes(node.arguments[0].value);
1313
};
1414

15+
/**
16+
* Returns true if any of the passed in modules are used in
17+
* binding calls.
18+
*/
19+
module.exports.isBinding = function(node, modules) {
20+
if (node.callee.object) {
21+
return node.callee.object.name === 'process' &&
22+
node.callee.property.name === 'binding' &&
23+
modules.includes(node.arguments[0].value);
24+
}
25+
};
26+
1527
/**
1628
* Returns true is the node accesses any property in the properties
1729
* array on the 'common' object.

0 commit comments

Comments
 (0)