Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 
 
 
 

102 строки
4.6 KiB

  1. import assert from 'assert';
  2. import {lesspass} from '../app/lesspass';
  3. describe('lesspass', ()=> {
  4. describe('public api', ()=> {
  5. it('should create password', function () {
  6. var master_password = "password";
  7. var site_information = {
  8. 'site_name': 'facebook',
  9. 'password_length': 12,
  10. 'password_type': ['strong'],
  11. 'counter': 1
  12. };
  13. assert.equal('Vexu8[Syce4&', lesspass.create_password(master_password, site_information));
  14. });
  15. });
  16. describe('hash', ()=> {
  17. it('should have default length of 12', ()=> {
  18. var master_password = "password";
  19. var site_information = {'site_name': 'facebook'};
  20. assert.equal(12, lesspass._create_hash(master_password, site_information).length);
  21. });
  22. it('should be able to create hash with defined length', ()=> {
  23. var master_password = "password";
  24. var site_information = {
  25. 'site_name': 'facebook',
  26. 'password_length': 10
  27. };
  28. assert.equal(10, lesspass._create_hash(master_password, site_information).length);
  29. });
  30. it('should return two different passwords if site different', ()=> {
  31. var master_password = "password";
  32. var site_information = {'site_name': 'facebook'};
  33. var site_information2 = {'site_name': 'google'};
  34. assert.notEqual(
  35. lesspass._create_hash(master_password, site_information),
  36. lesspass._create_hash(master_password, site_information2)
  37. );
  38. });
  39. it('should return two different passwords if counter different', ()=> {
  40. var master_password = "password";
  41. var old_site_information = {'site_name': 'facebook'};
  42. var site_information = {'site_name': 'facebook', 'counter': 2};
  43. assert.notEqual(
  44. lesspass._create_hash(master_password, site_information),
  45. lesspass._create_hash(master_password, old_site_information)
  46. );
  47. });
  48. });
  49. describe('password templates', ()=> {
  50. it('should get default template from password type', ()=> {
  51. assert.equal('Cvcvns', lesspass._getTemplate());
  52. });
  53. it('should get template from password type', ()=> {
  54. assert.equal('vc', lesspass._getTemplate(['lowercase']));
  55. assert.equal('VC', lesspass._getTemplate(['uppercase']));
  56. assert.equal('n', lesspass._getTemplate(['number']));
  57. assert.equal('s', lesspass._getTemplate(['symbols']));
  58. });
  59. it('should concatenate template if two password types', ()=> {
  60. assert.equal('vcVC', lesspass._getTemplate(['lowercase', 'uppercase']));
  61. assert.equal('vcns', lesspass._getTemplate(['lowercase', 'number', 'symbols']));
  62. });
  63. it('should not care about order of type in password types', ()=> {
  64. assert.equal(
  65. lesspass._getTemplate(['uppercase', 'lowercase']),
  66. lesspass._getTemplate(['lowercase', 'uppercase'])
  67. );
  68. });
  69. it('should return char inside template based on modulo of the index', function () {
  70. var template = 'cv';
  71. assert.equal('c', lesspass._getCharType(template, 0));
  72. assert.equal('v', lesspass._getCharType(template, 1));
  73. assert.equal('c', lesspass._getCharType(template, 10));
  74. });
  75. });
  76. describe('crypto', ()=> {
  77. it('should convert a string into a char code table', ()=> {
  78. var charCodes = lesspass._string2charCodes('ab40f6ee71');
  79. assert.equal(97, charCodes[0]);
  80. assert.equal(98, charCodes[1]);
  81. assert.equal(10, charCodes.length);
  82. });
  83. it('should return password size same size of hash given', function () {
  84. var hash = 'Y2Vi2a112A';
  85. assert.equal(10, lesspass._encode(hash, 'cv').length);
  86. });
  87. it('should return different values if templates are different', function () {
  88. var hash = 'a';
  89. assert.notEqual(lesspass._encode(hash, 'cv'), lesspass._encode(hash, 'vc'));
  90. });
  91. it('should get password char based on its type and index', function () {
  92. var typeVowel = 'V';
  93. assert.equal('A', lesspass._getPasswordChar(typeVowel, 0));
  94. });
  95. it('should modulo if overflow', function () {
  96. var typeVowel = 'V';
  97. assert.equal('E', lesspass._getPasswordChar(typeVowel, 1));
  98. assert.equal('E', lesspass._getPasswordChar(typeVowel, 7));
  99. });
  100. });
  101. });