detect-object-injection.js 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. 'use strict';
  2. const RuleTester = require('eslint').RuleTester;
  3. const tester = new RuleTester();
  4. const ruleName = 'detect-object-injection';
  5. const Rule = require(`../rules/${ruleName}`);
  6. const valid = 'var a = {};';
  7. // const invalidVariable = "TODO";
  8. // const invalidFunction = "TODO";
  9. const invalidGeneric = 'var a = {}; a[b] = 4';
  10. // TODO
  11. // tester.run(`${ruleName} (Variable Assigned to)`, Rule, {
  12. // valid: [{ code: valid }],
  13. // invalid: [
  14. // {
  15. // code: invalidVariable,
  16. // errors: [{ message: 'Variable Assigned to Object Injection Sink' }]
  17. // }
  18. // ]
  19. // });
  20. //
  21. //
  22. // tester.run(`${ruleName} (Function)`, Rule, {
  23. // valid: [{ code: valid }],
  24. // invalid: [
  25. // {
  26. // code: invalidFunction,
  27. // errors: [{ message: `Variable Assigned to Object Injection Sink: <input>: 1\n\t${invalidFunction}\n\n` }]
  28. // }
  29. // ]
  30. // });
  31. tester.run(`${ruleName} (Generic)`, Rule, {
  32. valid: [{ code: valid }],
  33. invalid: [
  34. {
  35. code: invalidGeneric,
  36. errors: [{ message: 'Generic Object Injection Sink' }]
  37. }
  38. ]
  39. });