No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.
 
 
 
 
 
 

138 líneas
4.3 KiB

  1. import test from 'ava';
  2. import lesspass from '../src/lesspass';
  3. test('should create encrypted hash with pbkdf2 (8192 iterations and sha 256)', t => {
  4. const login = 'test@lesspass.com';
  5. const masterPassword = 'password';
  6. return lesspass._encryptLogin(login, masterPassword).then(hash => {
  7. t.is('90cff82b8847525370a8f29a59ecf45db62c719a535788ad0df58d32304e925d', hash);
  8. });
  9. });
  10. test('should create encrypted hash with 64 chars length', t => {
  11. return lesspass._encryptLogin('♥', '♥ ♥').then(hash => {
  12. t.is(64, hash.length);
  13. });
  14. });
  15. test('should reject promise if no parameter', t => {
  16. t.plan(1);
  17. return lesspass._encryptLogin('', '').catch(() => {
  18. t.pass('promise rejected with empty parameter');
  19. });
  20. });
  21. test('should derive hash with default length', t => {
  22. const hash = '9f505f3a95fe0485da3242cb81c9fe25c2f400d8399737655a8dad2b52778d88';
  23. const site = 'lesspass.com';
  24. t.is(12, lesspass._deriveHash(hash, site).length);
  25. });
  26. test('should derive hash with default options', t => {
  27. const hash = '90cff82b8847525370a8f29a59ecf45db62c719a535788ad0df58d32304e925d';
  28. const site = 'lesspass.com';
  29. const option = {
  30. counter: 1,
  31. password: {
  32. length: 12,
  33. settings: ['lowercase', 'uppercase', 'numbers', 'symbols']
  34. }
  35. };
  36. t.is(
  37. lesspass._deriveHash(hash, site),
  38. lesspass._deriveHash(hash, site, option)
  39. );
  40. });
  41. test('should derive hash with defined length', t => {
  42. const hash = 'd79d8482f708122288af7b259393a58fe05840f4555cc935cdd3f062b9aa75ed';
  43. const site = 'lesspass.com';
  44. const option = {
  45. counter: 1,
  46. password: {
  47. length: 10
  48. }
  49. };
  50. t.is(10, lesspass._deriveHash(hash, site, option).length);
  51. });
  52. test('should return two different passwords if site different', t => {
  53. const hash = 'f4fd3885fb70085f2285c3382e2d9adb4c2553285fc45dd896791aa5e79070a9';
  54. const site = 'google.com';
  55. const site2 = 'facebook.com';
  56. t.not(
  57. lesspass._deriveHash(hash, site),
  58. lesspass._deriveHash(hash, site2)
  59. );
  60. });
  61. test('should return two different passwords if counter different', t => {
  62. const hash = 'dfba06278c9aa24d992bc2d390a53efef482788859455875f72015335d085fcd';
  63. const site = 'lesspass.com';
  64. const option = {counter: 1};
  65. const option2 = {counter: 2};
  66. t.not(
  67. lesspass._deriveHash(hash, site, option),
  68. lesspass._deriveHash(hash, site, option2)
  69. );
  70. });
  71. test('should print different password if templates different', t => {
  72. const hash = '78ae5892055ab59fdd54489ae30928d322841a27590b65cf875fcfdd083f7c32';
  73. t.not(lesspass._prettyPrint(hash, 'cv'), lesspass._prettyPrint(hash, 'vc'));
  74. });
  75. test('must return a string of the same length as the input', t => {
  76. const hash = 'f5785e569ab5d38b02e2248c798ac17df90f57a85f34a9d5382408c2f0d9532d';
  77. t.is(hash.length, lesspass._prettyPrint(hash, 'cv').length);
  78. });
  79. test('should return char inside a string based on modulo of the index', t => {
  80. const template = 'cv';
  81. t.is('c', lesspass._getCharType(template, 0));
  82. t.is('v', lesspass._getCharType(template, 1));
  83. t.is('c', lesspass._getCharType(template, 10));
  84. });
  85. test('should convert a string into an array of char code', t => {
  86. const charCodes = lesspass._string2charCodes('ab40f6ee71');
  87. t.is(97, charCodes[0]);
  88. t.is(98, charCodes[1]);
  89. t.is(10, charCodes.length);
  90. });
  91. test('should get password char based on its type and index', t => {
  92. const typeVowel = 'V';
  93. t.is('A', lesspass._getPasswordChar(typeVowel, 0));
  94. });
  95. test('should modulo if overflow', t => {
  96. const typeVowel = 'V';
  97. t.is('E', lesspass._getPasswordChar(typeVowel, 1));
  98. t.is('E', lesspass._getPasswordChar(typeVowel, 7));
  99. });
  100. test('should get default template', t => {
  101. t.is('Cvcvns', lesspass._getTemplate());
  102. });
  103. test('should get template from password setting', t => {
  104. t.is('vc', lesspass._getTemplate(['lowercase']));
  105. t.is('VC', lesspass._getTemplate(['uppercase']));
  106. t.is('n', lesspass._getTemplate(['numbers']));
  107. t.is('s', lesspass._getTemplate(['symbols']));
  108. });
  109. test('should concatenate template if two password settings', t => {
  110. t.is('vcVC', lesspass._getTemplate(['lowercase', 'uppercase']));
  111. t.is('vcns', lesspass._getTemplate(['lowercase', 'numbers', 'symbols']));
  112. });
  113. test('should not care about order of password settings', t => {
  114. t.is(
  115. lesspass._getTemplate(['uppercase', 'lowercase']),
  116. lesspass._getTemplate(['lowercase', 'uppercase'])
  117. );
  118. });