Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tools: add check for using process.binding crypto #17867

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion test/parallel/test-accessor-properties.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
'use strict';

require('../common');
const common = require('../common');

if (!common.hasCrypto)
common.skip('missing crypto');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than skipping this entire test, can we move the crypto stuff to its if block and only run those tests if hasCrypto is true? This way, we aren't skipping the non-crypto tests in the file.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good, I'll do that.

// This tests that the accessor properties do not raise assertions
// when called with incompatible receivers.

Expand Down
2 changes: 2 additions & 0 deletions test/parallel/test-http2-util-headers-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down
4 changes: 3 additions & 1 deletion test/parallel/test-http2-util-update-options-buffer.js
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
3 changes: 2 additions & 1 deletion test/parallel/test-repl-tab-complete.js
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,8 @@ editor.completer('var log = console.l', common.mustCall((error, data) => {

['Let', 'Const', 'Klass'].forEach((type) => {
const query = `lexical${type[0]}`;
const expected = hasInspector ? [[`lexical${type}`], query] : [];
const expected = hasInspector ? [[`lexical${type}`], query] :
[[], `lexical${type[0]}`];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unrelated change?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually it is related. Without this I get the error mentioned in the commit:

assert.js:43
  throw new errors.AssertionError(obj);
  ^

AssertionError [ERR_ASSERTION]: [ [], 'lexicalL' ] deepStrictEqual []
    at testRepl.complete.common.mustCall
      (node/test/parallel/test-repl-tab-complete.js:549:14)
    at /node/test/common/index.js:530:15
    at completionGroupsLoaded (repl.js:1204:5)
    at REPLServer.complete (repl.js:1090:11)
    at REPLServer.completer (repl.js:450:14)
    at REPLServer.complete (repl.js:919:18)
    at __dirname.forEach (parallel/test-repl-tab-complete.js:548:14)
    at Array.forEach (<anonymous>)
    at Object.<anonymous> (parallel/test-repl-tab-complete.js:545:29)
    at Module._compile (module.js:660:30)

testRepl.complete(query, common.mustCall((error, data) => {
assert.deepStrictEqual(data, expected);
}));
Expand Down
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