detect-possible-timing-attacks.js 833 B

123456789101112131415161718192021222324252627282930313233343536
  1. 'use strict';
  2. const RuleTester = require('eslint').RuleTester;
  3. const tester = new RuleTester();
  4. const ruleName = 'detect-possible-timing-attacks';
  5. const Rule = require(`../rules/${ruleName}`);
  6. const valid = 'if (age === 5) {}';
  7. const invalidLeft = 'if (password === \'mypass\') {}';
  8. const invalidRigth = 'if (\'mypass\' === password) {}';
  9. // We only check with one string "password" and operator "==="
  10. // to KISS.
  11. tester.run(`${ruleName} (left side)`, Rule, {
  12. valid: [{ code: valid }],
  13. invalid: [
  14. {
  15. code: invalidLeft,
  16. errors: [{ message: 'Potential timing attack, left side: true' }]
  17. }
  18. ]
  19. });
  20. tester.run(`${ruleName} (right side)`, Rule, {
  21. valid: [{ code: valid }],
  22. invalid: [
  23. {
  24. code: invalidRigth,
  25. errors: [{ message: 'Potential timing attack, right side: true' }]
  26. }
  27. ]
  28. });