25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

index.test.js 3.1 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. const assert = require("assert");
  2. const { calcEntropy, isSupported } = require("../src");
  3. describe("entropy", () => {
  4. it("calc entropy without crypto use default options and crypto", () => {
  5. const profile = {
  6. site: "example.org",
  7. login: "contact@example.org",
  8. };
  9. const masterPassword = "password";
  10. return calcEntropy(profile, masterPassword).then((entropy) => {
  11. assert.equal(
  12. "dc33d431bce2b01182c613382483ccdb0e2f66482cbba5e9d07dab34acc7eb1e",
  13. entropy
  14. );
  15. });
  16. });
  17. it("calc entropy pbkdf2 with default params (100000 iterations, 32 bytes length, sha256 digest)", () => {
  18. const profile = {
  19. site: "example.org",
  20. login: "contact@example.org",
  21. options: {
  22. counter: 1,
  23. },
  24. crypto: {
  25. method: "pbkdf2",
  26. iterations: 100000,
  27. keylen: 32,
  28. digest: "sha256",
  29. },
  30. };
  31. const masterPassword = "password";
  32. return calcEntropy(profile, masterPassword).then((entropy) => {
  33. assert.equal(
  34. "dc33d431bce2b01182c613382483ccdb0e2f66482cbba5e9d07dab34acc7eb1e",
  35. entropy
  36. );
  37. });
  38. });
  39. it("calc entropy pbkdf2 with unicode char", () => {
  40. const profile = {
  41. site: "example.org",
  42. login: "❤",
  43. options: {
  44. counter: 1,
  45. },
  46. crypto: {
  47. method: "pbkdf2",
  48. iterations: 100000,
  49. keylen: 32,
  50. digest: "sha256",
  51. },
  52. };
  53. const masterPassword = "I ❤ LessPass";
  54. return calcEntropy(profile, masterPassword).then((entropy) => {
  55. assert.equal(
  56. "4e66cab40690c01af55efd595f5963cc953d7e10273c01827881ebf8990c627f",
  57. entropy
  58. );
  59. });
  60. });
  61. it("calc entropy with different options (8192 iterations, 16 bytes length, sha512 digest)", () => {
  62. const profile = {
  63. site: "example.org",
  64. login: "contact@example.org",
  65. options: {
  66. counter: 1,
  67. },
  68. crypto: {
  69. method: "pbkdf2",
  70. iterations: 8192,
  71. keylen: 16,
  72. digest: "sha512",
  73. },
  74. };
  75. const masterPassword = "password";
  76. return calcEntropy(profile, masterPassword).then((entropy) => {
  77. assert.equal("fff211c16a4e776b3574c6a5c91fd252", entropy);
  78. });
  79. });
  80. it("calc entropy different if counter different 1", () => {
  81. const profile = {
  82. site: "example.org",
  83. login: "contact@example.org",
  84. options: {
  85. counter: 1,
  86. },
  87. crypto: {
  88. method: "pbkdf2",
  89. iterations: 100000,
  90. keylen: 32,
  91. digest: "sha256",
  92. },
  93. };
  94. const profile2 = {
  95. site: "example.org",
  96. login: "contact@example.org",
  97. options: {
  98. counter: 2,
  99. },
  100. crypto: {
  101. method: "pbkdf2",
  102. iterations: 100000,
  103. keylen: 32,
  104. digest: "sha256",
  105. },
  106. };
  107. const promises = [
  108. calcEntropy(profile, "password"),
  109. calcEntropy(profile2, "password"),
  110. ];
  111. Promise.all(promises).then((values) => {
  112. assert.notEqual(values[0], values[1]);
  113. });
  114. });
  115. });
  116. describe("isSupported", () => {
  117. it("isSupported", () =>
  118. isSupported().then((supported) => {
  119. assert(supported);
  120. }));
  121. });