選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。
 
 
 
 
 
 

298 行
7.3 KiB

  1. import test from 'ava';
  2. import password from './src/domain/password'
  3. import {V1ToV2DefaultRule, V1ToV2Rule, RulesController} from './src/domain/rules';
  4. test('buildAllPasswords', t => {
  5. const controller = new RulesController();
  6. controller.addRules([new V1ToV2DefaultRule(), new V1ToV2Rule()]);
  7. var profiles = [{
  8. "site": "example.org",
  9. "login": "test@example.org",
  10. "lowercase": true,
  11. "uppercase": true,
  12. "numbers": true,
  13. "symbols": true,
  14. "counter": 1,
  15. "length": 12,
  16. "version": 1
  17. }, {
  18. "site": "bank.example.org",
  19. "login": "test@example.org",
  20. "lowercase": false,
  21. "uppercase": false,
  22. "numbers": true,
  23. "symbols": false,
  24. "counter": 2,
  25. "length": 6,
  26. "version": 1
  27. }];
  28. return password
  29. .buildAllPasswords(controller.applyRules(profiles), 'password', 'password')
  30. .then(newPasswordProfiles => {
  31. t.deepEqual(newPasswordProfiles[0].oldPassword, 'esIZ9,amEW5,');
  32. t.deepEqual(newPasswordProfiles[0].newPassword, '[nYxh6=osW)aH99b');
  33. t.deepEqual(newPasswordProfiles[1].oldPassword, '342387');
  34. t.deepEqual(newPasswordProfiles[1].newPassword, '446545');
  35. });
  36. });
  37. test('buildAllPasswords different master passwords', t => {
  38. const controller = new RulesController();
  39. controller.addRules([new V1ToV2DefaultRule(), new V1ToV2Rule()]);
  40. var profiles = [{
  41. "site": "example.org",
  42. "login": "test@example.org",
  43. "lowercase": true,
  44. "uppercase": true,
  45. "numbers": true,
  46. "symbols": true,
  47. "counter": 1,
  48. "length": 12,
  49. "version": 1
  50. }, {
  51. "site": "bank.example.org",
  52. "login": "test@example.org",
  53. "lowercase": false,
  54. "uppercase": false,
  55. "numbers": true,
  56. "symbols": false,
  57. "counter": 2,
  58. "length": 6,
  59. "version": 1
  60. }];
  61. return password
  62. .buildAllPasswords(controller.applyRules(profiles), 'password', 'new_password')
  63. .then(newPasswordProfiles => {
  64. t.is(newPasswordProfiles[0].oldPassword, 'esIZ9,amEW5,');
  65. t.is(newPasswordProfiles[0].newPassword, '\\-q5pba3wj1AHABY');
  66. t.is(newPasswordProfiles[1].oldPassword, '342387');
  67. t.is(newPasswordProfiles[1].newPassword, '559909');
  68. });
  69. });
  70. test('V1ToV2DefaultRule', t => {
  71. const rule = new V1ToV2DefaultRule();
  72. const expectedProfile = {
  73. "site": "example.org",
  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. const newProfile = rule.apply({
  84. "site": "example.org",
  85. "login": "test@example.org",
  86. "lowercase": true,
  87. "uppercase": true,
  88. "numbers": true,
  89. "symbols": true,
  90. "counter": 1,
  91. "length": 12,
  92. "version": 1
  93. });
  94. t.deepEqual(newProfile, expectedProfile);
  95. });
  96. test('V1ToV2DefaultRule matchRule', t => {
  97. const rule = new V1ToV2DefaultRule();
  98. t.true(rule.matchRule({
  99. "site": "example.org",
  100. "login": "test@example.org",
  101. "lowercase": true,
  102. "uppercase": true,
  103. "numbers": true,
  104. "symbols": true,
  105. "counter": 1,
  106. "length": 12,
  107. "version": 1
  108. }));
  109. t.false(rule.matchRule({
  110. "site": "example.org",
  111. "login": "test@example.org",
  112. "lowercase": false,
  113. "uppercase": true,
  114. "numbers": true,
  115. "symbols": true,
  116. "counter": 1,
  117. "length": 12,
  118. "version": 1
  119. }));
  120. t.false(rule.matchRule({
  121. "site": "example.org",
  122. "login": "test@example.org",
  123. "lowercase": true,
  124. "uppercase": false,
  125. "numbers": true,
  126. "symbols": true,
  127. "counter": 1,
  128. "length": 12,
  129. "version": 1
  130. }));
  131. t.false(rule.matchRule({
  132. "site": "example.org",
  133. "login": "test@example.org",
  134. "lowercase": true,
  135. "uppercase": true,
  136. "numbers": false,
  137. "symbols": true,
  138. "counter": 1,
  139. "length": 12,
  140. "version": 1
  141. }));
  142. t.false(rule.matchRule({
  143. "site": "example.org",
  144. "login": "test@example.org",
  145. "lowercase": true,
  146. "uppercase": true,
  147. "numbers": true,
  148. "symbols": false,
  149. "counter": 1,
  150. "length": 12,
  151. "version": 1
  152. }));
  153. t.false(rule.matchRule({
  154. "site": "example.org",
  155. "login": "test@example.org",
  156. "lowercase": true,
  157. "uppercase": true,
  158. "numbers": true,
  159. "symbols": true,
  160. "counter": 2,
  161. "length": 12,
  162. "version": 1
  163. }));
  164. t.false(rule.matchRule({
  165. "site": "example.org",
  166. "login": "test@example.org",
  167. "lowercase": true,
  168. "uppercase": true,
  169. "numbers": true,
  170. "symbols": true,
  171. "counter": 1,
  172. "length": 13,
  173. "version": 1
  174. }));
  175. t.false(rule.matchRule({
  176. "site": "example.org",
  177. "login": "test@example.org",
  178. "lowercase": true,
  179. "uppercase": true,
  180. "numbers": true,
  181. "symbols": true,
  182. "counter": 1,
  183. "length": 12,
  184. "version": 2
  185. }));
  186. });
  187. test('V1ToV2DefaultRule no change because not a default profile', t => {
  188. const rule = new V1ToV2DefaultRule();
  189. const expectedProfile = {
  190. "site": "example.org",
  191. "login": "test@example.org",
  192. "lowercase": true,
  193. "uppercase": true,
  194. "numbers": true,
  195. "symbols": true,
  196. "counter": 2,
  197. "length": 12,
  198. "version": 1
  199. };
  200. const newProfile = rule.apply(expectedProfile);
  201. t.deepEqual(newProfile, expectedProfile);
  202. });
  203. test('V1ToV2Rule', t => {
  204. const rule = new V1ToV2Rule();
  205. const expectedProfile = {
  206. "version": 2
  207. };
  208. const newProfile = rule.apply({
  209. "version": 1
  210. });
  211. t.deepEqual(newProfile, expectedProfile);
  212. });
  213. test('RulesController addRule', t => {
  214. const controller = new RulesController();
  215. controller.addRule(new V1ToV2DefaultRule());
  216. controller.addRule(new V1ToV2Rule());
  217. t.is(controller.rules.length, 2);
  218. });
  219. test('RulesController addRules', t => {
  220. const controller = new RulesController();
  221. controller.addRules([new V1ToV2DefaultRule()]);
  222. t.is(controller.rules.length, 1);
  223. });
  224. test('RulesController applyRules', t => {
  225. const controller = new RulesController();
  226. controller.addRules([new V1ToV2DefaultRule(), new V1ToV2Rule()]);
  227. const oldProfile = {
  228. "site": "example.org",
  229. "login": "test@example.org",
  230. "lowercase": true,
  231. "uppercase": true,
  232. "numbers": true,
  233. "symbols": true,
  234. "counter": 1,
  235. "length": 12,
  236. "version": 1
  237. };
  238. const newProfile = {
  239. "site": "example.org",
  240. "login": "test@example.org",
  241. "lowercase": true,
  242. "uppercase": true,
  243. "numbers": true,
  244. "symbols": true,
  245. "counter": 1,
  246. "length": 16,
  247. "version": 2
  248. };
  249. const expectedProfiles = [{oldProfile: oldProfile, newProfile: newProfile}];
  250. const newProfiles = controller.applyRules([oldProfile]);
  251. t.is(newProfiles.length, 1);
  252. t.deepEqual(newProfiles[0], expectedProfiles[0]);
  253. });
  254. test('RulesController applyRules no default profile', t => {
  255. const controller = new RulesController();
  256. controller.addRules([new V1ToV2DefaultRule(), new V1ToV2Rule()]);
  257. const oldProfile = {
  258. "site": "example.org",
  259. "login": "test@example.org",
  260. "lowercase": false,
  261. "uppercase": false,
  262. "numbers": true,
  263. "symbols": false,
  264. "counter": 1,
  265. "length": 6,
  266. "version": 1
  267. };
  268. const newProfile = {
  269. "site": "example.org",
  270. "login": "test@example.org",
  271. "lowercase": false,
  272. "uppercase": false,
  273. "numbers": true,
  274. "symbols": false,
  275. "counter": 1,
  276. "length": 6,
  277. "version": 2
  278. };
  279. const expectedProfiles = [{oldProfile: oldProfile, newProfile: newProfile}];
  280. const newProfiles = controller.applyRules([oldProfile]);
  281. t.is(newProfiles.length, 1);
  282. t.deepEqual(newProfiles[0], expectedProfiles[0]);
  283. });