detect-child-process.js 900 B

1234567891011121314151617181920212223242526272829303132333435
  1. 'use strict';
  2. const RuleTester = require('eslint').RuleTester;
  3. const tester = new RuleTester();
  4. const ruleName = 'detect-child-process';
  5. const Rule = require(`../rules/${ruleName}`);
  6. const valid = 'child_process.exec(\'ls\')';
  7. const invalidRequire = 'require(\'child_process\')';
  8. const invalidExec = 'var child = require(\'child_process\'); child.exec(com)';
  9. tester.run(`${ruleName} (require("child_process"))`, Rule, {
  10. valid: [{ code: valid }],
  11. invalid: [
  12. {
  13. code: invalidRequire,
  14. errors: [{ message: 'Found require("child_process")' }]
  15. }
  16. ]
  17. });
  18. tester.run(`${ruleName} (child_process.exec() wih non literal 1st arg.)`, Rule, {
  19. valid: [{ code: valid }],
  20. invalid: [
  21. {
  22. code: invalidExec,
  23. errors: [
  24. { message: 'Found require("child_process")' },
  25. { message: 'Found child_process.exec() with non Literal first argument' }]
  26. }
  27. ]
  28. });