Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. const assert = require("assert");
  2. const bigInt = require("big-integer");
  3. const chars = require("../src/chars");
  4. test("getSetOfCharacters", () => {
  5. const setOfCharacters = chars.getSetOfCharacters();
  6. assert.equal(
  7. "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~",
  8. setOfCharacters
  9. );
  10. assert.equal(26 * 2 + 10 + 32, setOfCharacters.length);
  11. assert.equal(
  12. chars.characterSubsets.lowercase +
  13. chars.characterSubsets.uppercase +
  14. chars.characterSubsets.digits +
  15. chars.characterSubsets.symbols,
  16. setOfCharacters
  17. );
  18. });
  19. test("getSetOfCharacters concat rules in order", () => {
  20. const setOfCharacters = chars.getSetOfCharacters([
  21. "lowercase",
  22. "uppercase",
  23. "digits"
  24. ]);
  25. assert.equal(
  26. "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789",
  27. setOfCharacters
  28. );
  29. assert.equal(26 * 2 + 10, setOfCharacters.length);
  30. });
  31. test("getSetOfCharacters only lowercase", () => {
  32. const setOfCharacters = chars.getSetOfCharacters(["lowercase"]);
  33. assert.equal("abcdefghijklmnopqrstuvwxyz", setOfCharacters);
  34. assert.equal(26, setOfCharacters.length);
  35. });
  36. test("getSetOfCharacters only uppercase", () => {
  37. const setOfCharacters = chars.getSetOfCharacters(["uppercase"]);
  38. assert.equal("ABCDEFGHIJKLMNOPQRSTUVWXYZ", setOfCharacters);
  39. assert.equal(26, setOfCharacters.length);
  40. });
  41. test("getSetOfCharacters only digits", () => {
  42. const setOfCharacters = chars.getSetOfCharacters(["digits"]);
  43. assert.equal("0123456789", setOfCharacters);
  44. assert.equal(10, setOfCharacters.length);
  45. });
  46. test("getSetOfCharacters only symbols", () => {
  47. const setOfCharacters = chars.getSetOfCharacters(["symbols"]);
  48. assert.equal("!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~", setOfCharacters);
  49. assert.equal(32, setOfCharacters.length);
  50. });
  51. test("getOneCharPerRule", () => {
  52. const oneCharPerSetOfCharacters = chars.getOneCharPerRule(bigInt(26 * 26), [
  53. "lowercase",
  54. "uppercase"
  55. ]);
  56. assert.equal("aA", oneCharPerSetOfCharacters.value);
  57. assert.equal(2, oneCharPerSetOfCharacters.value.length);
  58. assert.equal(1, oneCharPerSetOfCharacters.entropy);
  59. });
  60. test("getRules", () => {
  61. assert.deepEqual(["uppercase"], chars.getRules({ uppercase: true }));
  62. assert.deepEqual(
  63. ["lowercase", "uppercase"],
  64. chars.getRules({ uppercase: true, lowercase: true })
  65. );
  66. assert.deepEqual(
  67. ["lowercase"],
  68. chars.getRules({ lowercase: true, symbols: false })
  69. );
  70. assert.deepEqual(
  71. ["lowercase", "uppercase", "digits", "symbols"],
  72. chars.getRules({
  73. lowercase: true,
  74. uppercase: true,
  75. symbols: true,
  76. digits: true
  77. })
  78. );
  79. });
  80. test("insertStringPseudoRandomly", () => {
  81. const password = chars.insertStringPseudoRandomly(
  82. "123456",
  83. bigInt(7 * 6 + 2),
  84. "uT"
  85. );
  86. assert.equal("T12u3456", password);
  87. });