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.
 
 
 
 
 
 

155 regels
3.7 KiB

  1. import test from 'ava';
  2. import migration from './src/services/migration'
  3. test('transformProfilesFromV1ToV2', t => {
  4. var profiles = [
  5. {
  6. "site": "example.org",
  7. "login": "test@example.org",
  8. "lowercase": true,
  9. "uppercase": true,
  10. "numbers": true,
  11. "symbols": true,
  12. "counter": 1,
  13. "length": 12,
  14. "version": 1
  15. },
  16. {
  17. "site": "bank.example.org",
  18. "login": "test@example.org",
  19. "lowercase": false,
  20. "uppercase": false,
  21. "numbers": true,
  22. "symbols": false,
  23. "counter": 2,
  24. "length": 6,
  25. "version": 1
  26. },
  27. {
  28. "site": "example.com",
  29. "login": "test@example.org",
  30. "lowercase": true,
  31. "uppercase": true,
  32. "numbers": true,
  33. "symbols": true,
  34. "counter": 1,
  35. "length": 16,
  36. "version": 2
  37. }
  38. ];
  39. var expectedProfiles = [
  40. {
  41. oldProfile: profiles[0],
  42. newProfile: {
  43. "site": "example.org",
  44. "login": "test@example.org",
  45. "lowercase": true,
  46. "uppercase": true,
  47. "numbers": true,
  48. "symbols": true,
  49. "counter": 1,
  50. "length": 16,
  51. "version": 2
  52. },
  53. updated: true
  54. },
  55. {
  56. oldProfile: profiles[1],
  57. newProfile: {
  58. "site": "bank.example.org",
  59. "login": "test@example.org",
  60. "lowercase": false,
  61. "uppercase": false,
  62. "numbers": true,
  63. "symbols": false,
  64. "counter": 2,
  65. "length": 6,
  66. "version": 2
  67. },
  68. updated: false
  69. },
  70. {
  71. oldProfile: profiles[2],
  72. newProfile: {
  73. "site": "example.com",
  74. "login": "test@example.org",
  75. "lowercase": true,
  76. "uppercase": true,
  77. "numbers": true,
  78. "symbols": true,
  79. "counter": 1,
  80. "length": 16,
  81. "version": 2
  82. },
  83. updated: false
  84. }
  85. ];
  86. t.deepEqual(migration.transformProfilesFromV1ToV2(profiles), expectedProfiles);
  87. });
  88. test('buildAllPasswords', t => {
  89. var profiles = [{
  90. "site": "example.org",
  91. "login": "test@example.org",
  92. "lowercase": true,
  93. "uppercase": true,
  94. "numbers": true,
  95. "symbols": true,
  96. "counter": 1,
  97. "length": 12,
  98. "version": 1
  99. }, {
  100. "site": "bank.example.org",
  101. "login": "test@example.org",
  102. "lowercase": false,
  103. "uppercase": false,
  104. "numbers": true,
  105. "symbols": false,
  106. "counter": 2,
  107. "length": 6,
  108. "version": 1
  109. }];
  110. return migration
  111. .buildAllPasswords(migration.transformProfilesFromV1ToV2(profiles), 'password', 'password')
  112. .then(newPasswordProfiles => {
  113. t.deepEqual(newPasswordProfiles[0].oldPassword, 'esIZ9,amEW5,');
  114. t.deepEqual(newPasswordProfiles[0].newPassword, '[nYxh6=osW)aH99b');
  115. t.deepEqual(newPasswordProfiles[1].oldPassword, '342387');
  116. t.deepEqual(newPasswordProfiles[1].newPassword, '446545');
  117. });
  118. });
  119. test('buildAllPasswords different master passwords', t => {
  120. var profiles = [{
  121. "site": "example.org",
  122. "login": "test@example.org",
  123. "lowercase": true,
  124. "uppercase": true,
  125. "numbers": true,
  126. "symbols": true,
  127. "counter": 1,
  128. "length": 12,
  129. "version": 1
  130. }, {
  131. "site": "bank.example.org",
  132. "login": "test@example.org",
  133. "lowercase": false,
  134. "uppercase": false,
  135. "numbers": true,
  136. "symbols": false,
  137. "counter": 2,
  138. "length": 6,
  139. "version": 1
  140. }];
  141. return migration
  142. .buildAllPasswords(migration.transformProfilesFromV1ToV2(profiles), 'password', 'new_password')
  143. .then(newPasswordProfiles => {
  144. t.is(newPasswordProfiles[0].oldPassword, 'esIZ9,amEW5,');
  145. t.is(newPasswordProfiles[0].newPassword, '\\-q5pba3wj1AHABY');
  146. t.is(newPasswordProfiles[1].oldPassword, '342387');
  147. t.is(newPasswordProfiles[1].newPassword, '559909');
  148. });
  149. });