Skip to content

Commit

Permalink
tools: add check for using process.binding crypto
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
danbev authored and MylesBorins committed Jan 8, 2018
1 parent e5394e5 commit 7dddc7c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
7 changes: 6 additions & 1 deletion tools/eslint-rules/crypto-check.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,18 @@ const utils = require('./rules-utils.js');
const msg = 'Please add a hasCrypto check to allow this test to be skipped ' +
'when Node is built "--without-ssl".';

const cryptoModules = ['crypto', 'http2'];
const requireModules = cryptoModules.concat(['tls', 'https']);
const bindingModules = cryptoModules.concat(['tls_wrap']);

module.exports = function(context) {
const missingCheckNodes = [];
const requireNodes = [];
var hasSkipCall = false;

function testCryptoUsage(node) {
if (utils.isRequired(node, ['crypto', 'tls', 'https', 'http2'])) {
if (utils.isRequired(node, requireModules) ||
utils.isBinding(node, bindingModules)) {
requireNodes.push(node);
}
}
Expand Down
12 changes: 12 additions & 0 deletions tools/eslint-rules/rules-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,18 @@ module.exports.isRequired = function(node, modules) {
modules.includes(node.arguments[0].value);
};

/**
* Returns true if any of the passed in modules are used in
* binding calls.
*/
module.exports.isBinding = function(node, modules) {
if (node.callee.object) {
return node.callee.object.name === 'process' &&
node.callee.property.name === 'binding' &&
modules.includes(node.arguments[0].value);
}
};

/**
* Returns true is the node accesses any property in the properties
* array on the 'common' object.
Expand Down

0 comments on commit 7dddc7c

Please sign in to comment.