You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

69 line
2.8 KiB

  1. import test from 'ava';
  2. import lesspass from '../index';
  3. test('should createHmac', t => {
  4. var encryptedLogin = '9f505f3a95fe0485da3242cb81c9fe25c2f400d8399737655a8dad2b52778d88';
  5. var salt = 'lesspass.com1';
  6. return lesspass._createHmac(encryptedLogin, salt).then(hmac => {
  7. t.is('be00f942fc8aa67d8e76fc2456862b9d66d166ebfdd3dc2f0116e278209532ed', hmac);
  8. });
  9. });
  10. test('should derive encrypted login with default options', t => {
  11. const encryptedLogin = '90cff82b8847525370a8f29a59ecf45db62c719a535788ad0df58d32304e925d';
  12. const site = 'lesspass.com';
  13. const option = {
  14. counter: 1,
  15. length: 12,
  16. lowercase: true,
  17. uppercase: true,
  18. numbers: true,
  19. symbols: true,
  20. };
  21. var p1 = lesspass._deriveEncryptedLogin(encryptedLogin, site);
  22. var p2 = lesspass._deriveEncryptedLogin(encryptedLogin, site, option);
  23. Promise.all([p1, p2]).then(generatedPasswords => {
  24. t.is(generatedPasswords[0], generatedPasswords[1])
  25. });
  26. });
  27. test('should derive encrypted login with defined length', t => {
  28. var encryptedLogin = 'd79d8482f708122288af7b259393a58fe05840f4555cc935cdd3f062b9aa75ed';
  29. var site = 'lesspass.com';
  30. var option = {
  31. counter: 1,
  32. length: 10,
  33. };
  34. return lesspass._deriveEncryptedLogin(encryptedLogin, site, option).then(function (generatedPassword) {
  35. t.is(10, generatedPassword.length);
  36. })
  37. });
  38. test('should return two different passwords if site different', t => {
  39. const encryptedLogin = 'f4fd3885fb70085f2285c3382e2d9adb4c2553285fc45dd896791aa5e79070a9';
  40. const site = 'google.com';
  41. const site2 = 'facebook.com';
  42. var p1 = lesspass._deriveEncryptedLogin(encryptedLogin, site);
  43. var p2 = lesspass._deriveEncryptedLogin(encryptedLogin, site2);
  44. Promise.all([p1, p2]).then(derivedEncryptedLogins => {
  45. t.not(derivedEncryptedLogins[0], derivedEncryptedLogins[1])
  46. });
  47. });
  48. test('should return two different passwords if counter different', t => {
  49. const encryptedLogin = 'dfba06278c9aa24d992bc2d390a53efef482788859455875f72015335d085fcd';
  50. const site = 'lesspass.com';
  51. const option = {counter: 1};
  52. const option2 = {counter: 2};
  53. var p1 = lesspass._deriveEncryptedLogin(encryptedLogin, site, option);
  54. var p2 = lesspass._deriveEncryptedLogin(encryptedLogin, site, option2);
  55. Promise.all([p1, p2]).then(derivedEncryptedLogins => {
  56. t.not(derivedEncryptedLogins[0], derivedEncryptedLogins[1])
  57. });
  58. });
  59. test('should derive encrypted login with sha 256', t => {
  60. const encryptedLogin = '9f505f3a95fe0485da3242cb81c9fe25c2f400d8399737655a8dad2b52778d88';
  61. const site = 'lesspass.com';
  62. return lesspass._deriveEncryptedLogin(encryptedLogin, site).then(function (encryptedLogin) {
  63. t.is('be00f942fc8a', encryptedLogin);
  64. });
  65. });