From e0d2842b29bfa6ec7eeb5370b6e898bd2b47ead5 Mon Sep 17 00:00:00 2001 From: Daniel Bevenius Date: Tue, 26 Dec 2017 09:48:38 +0100 Subject: [PATCH] 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: https://github.com/nodejs/node/pull/17867 Reviewed-By: James M Snell Reviewed-By: Ruben Bridgewater --- test/parallel/test-http2-util-headers-list.js | 2 ++ .../test-http2-util-update-options-buffer.js | 4 +++- tools/eslint-rules/crypto-check.js | 7 ++++++- tools/eslint-rules/rules-utils.js | 12 ++++++++++++ 4 files changed, 23 insertions(+), 2 deletions(-) diff --git a/test/parallel/test-http2-util-headers-list.js b/test/parallel/test-http2-util-headers-list.js index 0bbe1972d07981..0ff6b558d9a51b 100644 --- a/test/parallel/test-http2-util-headers-list.js +++ b/test/parallel/test-http2-util-headers-list.js @@ -5,6 +5,8 @@ // to pass to the internal binding layer. const common = require('../common'); +if (!common.hasCrypto) + common.skip('missing crypto'); const assert = require('assert'); const { mapToHeaders } = require('internal/http2/util'); diff --git a/test/parallel/test-http2-util-update-options-buffer.js b/test/parallel/test-http2-util-update-options-buffer.js index 4388d55682a54b..14e4ba23d8fdca 100644 --- a/test/parallel/test-http2-util-update-options-buffer.js +++ b/test/parallel/test-http2-util-update-options-buffer.js @@ -1,7 +1,9 @@ // Flags: --expose-internals 'use strict'; -require('../common'); +const common = require('../common'); +if (!common.hasCrypto) + common.skip('missing crypto'); // Test coverage for the updateOptionsBuffer method used internally // by the http2 implementation. diff --git a/tools/eslint-rules/crypto-check.js b/tools/eslint-rules/crypto-check.js index 9d24d3355dce7f..9570c24c030ef4 100644 --- a/tools/eslint-rules/crypto-check.js +++ b/tools/eslint-rules/crypto-check.js @@ -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); } } diff --git a/tools/eslint-rules/rules-utils.js b/tools/eslint-rules/rules-utils.js index f2f5428ed1cbc1..2bfab1c6399ee8 100644 --- a/tools/eslint-rules/rules-utils.js +++ b/tools/eslint-rules/rules-utils.js @@ -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.