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

8 лет назад
7 лет назад
8 лет назад
8 лет назад
7 лет назад
7 лет назад
7 лет назад
7 лет назад
7 лет назад
7 лет назад
7 лет назад
7 лет назад
7 лет назад
7 лет назад
7 лет назад
7 лет назад
7 лет назад
7 лет назад
7 лет назад
7 лет назад
8 лет назад
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. import test from 'ava';
  2. import timekeeper from 'timekeeper';
  3. import mutations from '../src/store/mutations';
  4. import * as types from '../src/store/mutation-types';
  5. test('LOGOUT', t => {
  6. const LOGOUT = mutations[types.LOGOUT];
  7. const state = {authenticated: true};
  8. LOGOUT(state);
  9. t.false(state.authenticated);
  10. });
  11. test('LOGIN', t => {
  12. const LOGIN = mutations[types.LOGIN];
  13. const state = {authenticated: false};
  14. LOGIN(state);
  15. t.true(state.authenticated);
  16. });
  17. test('SET_PASSWORD', t => {
  18. const SET_PASSWORD = mutations[types.SET_PASSWORD];
  19. const state = {password: null};
  20. SET_PASSWORD(state, {password: {uppercase: true, version: 2}});
  21. t.is(state.password.version, 2);
  22. t.true(state.password.uppercase);
  23. });
  24. test('SET_PASSWORD dont change lastUse date', t => {
  25. const SET_PASSWORD = mutations[types.SET_PASSWORD];
  26. const now = 1485989236000;
  27. const time = new Date(now);
  28. timekeeper.freeze(time);
  29. const state = {lastUse: null, password: null};
  30. SET_PASSWORD(state, {password: {}});
  31. t.true(state.lastUse === null);
  32. timekeeper.reset();
  33. });
  34. test('PASSWORD_GENERATED change lastUse date', t => {
  35. const PASSWORD_GENERATED = mutations[types.PASSWORD_GENERATED];
  36. const now = 1485989236000;
  37. const time = new Date(now);
  38. timekeeper.freeze(time);
  39. const state = {lastUse: null};
  40. PASSWORD_GENERATED(state);
  41. t.is(now, state.lastUse);
  42. timekeeper.reset();
  43. });
  44. test('SET_PASSWORD immutable', t => {
  45. const SET_PASSWORD = mutations[types.SET_PASSWORD];
  46. const state = {};
  47. const password = {version: 2};
  48. SET_PASSWORD(state, {password});
  49. password.version = 1;
  50. t.is(state.password.version, 2);
  51. });
  52. test('SET_DEFAULT_PASSWORD', t => {
  53. const SET_DEFAULT_PASSWORD = mutations[types.SET_DEFAULT_PASSWORD];
  54. const state = {
  55. defaultPassword: {
  56. site: '',
  57. login: '',
  58. uppercase: true,
  59. lowercase: true,
  60. numbers: true,
  61. symbols: true,
  62. length: 16,
  63. counter: 1,
  64. version: 2
  65. }
  66. };
  67. SET_DEFAULT_PASSWORD(state, {password: {symbols: false, length: 30}});
  68. t.is(state.defaultPassword.length, 30);
  69. t.false(state.defaultPassword.symbols);
  70. });
  71. test('SET_PASSWORDS', t => {
  72. const SET_PASSWORDS = mutations[types.SET_PASSWORDS];
  73. const state = {
  74. passwords: []
  75. };
  76. SET_PASSWORDS(state, {passwords: [{site: 'site1'}, {site: 'site2'}]});
  77. t.is(state.passwords[0].site, 'site1');
  78. t.is(state.passwords[1].site, 'site2');
  79. });
  80. test('DELETE_PASSWORD', t => {
  81. const DELETE_PASSWORD = mutations[types.DELETE_PASSWORD];
  82. const state = {
  83. passwords: [{id: '1', site: 'site1'}, {id: '2', site: 'site2'}]
  84. };
  85. t.is(state.passwords.length, 2);
  86. DELETE_PASSWORD(state, {id: '1'});
  87. t.is(state.passwords.length, 1);
  88. });
  89. test('DELETE_PASSWORD clean password with default password if same id', t => {
  90. const DELETE_PASSWORD = mutations[types.DELETE_PASSWORD];
  91. const state = {
  92. passwords: [{id: '1', length: 30}, {id: '2', length: 16}],
  93. password: {id: '1', length: 30},
  94. defaultPassword: {length: 16}
  95. };
  96. DELETE_PASSWORD(state, {id: '1'});
  97. t.is(state.password.length, 16);
  98. });
  99. test('SET_BASE_URL', t => {
  100. const SET_BASE_URL = mutations[types.SET_BASE_URL];
  101. const state = {
  102. baseURL: 'https://lesspass.com'
  103. };
  104. const baseURL = 'https://example.org';
  105. SET_BASE_URL(state, {baseURL: baseURL});
  106. t.is(state.baseURL, baseURL);
  107. });
  108. test('SET_VERSION', t => {
  109. const SET_VERSION = mutations[types.SET_VERSION];
  110. const state = {
  111. password: {version: 2},
  112. };
  113. SET_VERSION(state, {version: 1});
  114. t.is(state.password.version, 1);
  115. });
  116. test('SET_VERSION password null', t => {
  117. const SET_VERSION = mutations[types.SET_VERSION];
  118. const state = {
  119. password: null,
  120. };
  121. SET_VERSION(state, {version: 2});
  122. t.is(state.password.version, 2);
  123. });
  124. test('LOAD_PASSWORD_FIRST_TIME 5 minutes after last use', t => {
  125. const now = 1485989236000;
  126. const time = new Date(now);
  127. timekeeper.freeze(time);
  128. const fiveMinutesBefore = now - 5 * 60 * 1000;
  129. const state = {
  130. lastUse: fiveMinutesBefore,
  131. password: {
  132. login: 'test@example.org',
  133. length: 30
  134. },
  135. defaultPassword: {
  136. login: '',
  137. length: 16
  138. }
  139. };
  140. const LOAD_PASSWORD_FIRST_TIME = mutations[types.LOAD_PASSWORD_FIRST_TIME];
  141. LOAD_PASSWORD_FIRST_TIME(state);
  142. t.is(state.password.login, 'test@example.org');
  143. t.is(state.password.length, 30);
  144. timekeeper.reset();
  145. });
  146. test('LOAD_PASSWORD_FIRST_TIME more than 10 minutes after last use', t => {
  147. const now = 1485989236000;
  148. const time = new Date(now);
  149. timekeeper.freeze(time);
  150. const twentyMinutesBefore = now - 20 * 60 * 1000;
  151. const state = {
  152. lastUse: twentyMinutesBefore,
  153. password: {
  154. login: 'test@example.org',
  155. length: 30
  156. },
  157. defaultPassword: {
  158. login: '',
  159. length: 16
  160. }
  161. };
  162. const LOAD_PASSWORD_FIRST_TIME = mutations[types.LOAD_PASSWORD_FIRST_TIME];
  163. LOAD_PASSWORD_FIRST_TIME(state);
  164. t.is(state.password.login, '');
  165. t.is(state.password.length, 16);
  166. timekeeper.reset();
  167. });
  168. test('LOAD_PASSWORD_FIRST_TIME last use null', t => {
  169. const time = new Date(1485989236000);
  170. timekeeper.freeze(time);
  171. const state = {
  172. lastUse: null,
  173. password: {
  174. site: '',
  175. version: 1
  176. },
  177. defaultPassword: {
  178. site: '',
  179. version: 2
  180. }
  181. };
  182. const LOAD_PASSWORD_FIRST_TIME = mutations[types.LOAD_PASSWORD_FIRST_TIME];
  183. LOAD_PASSWORD_FIRST_TIME(state);
  184. t.is(state.password.version, 2);
  185. timekeeper.reset();
  186. });
  187. test('LOAD_PASSWORD_FOR_SITE', t => {
  188. const state = {
  189. password: {
  190. site: ''
  191. },
  192. passwords: [
  193. {id: '1', site: 'www.example.org'},
  194. {id: '2', site: 'www.google.com'}
  195. ]
  196. };
  197. const LOAD_PASSWORD_FOR_SITE = mutations[types.LOAD_PASSWORD_FOR_SITE];
  198. LOAD_PASSWORD_FOR_SITE(state, {site: 'google.com'});
  199. t.is(state.password.id, '2');
  200. t.is(state.password.site, 'www.google.com');
  201. });
  202. test('LOAD_PASSWORD_FOR_SITE no passwords', t => {
  203. const state = {
  204. password: {
  205. site: ''
  206. },
  207. passwords: []
  208. };
  209. const LOAD_PASSWORD_FOR_SITE = mutations[types.LOAD_PASSWORD_FOR_SITE];
  210. LOAD_PASSWORD_FOR_SITE(state, {site: 'google.com'});
  211. t.false('id' in state.password);
  212. t.is(state.password.site, 'google.com');
  213. });
  214. test('LOAD_PASSWORD_FOR_SITE multiple accounts matching criteria', t => {
  215. const state = {
  216. password: {
  217. site: ''
  218. },
  219. passwords: [
  220. {id: '1', site: 'www.example.org'},
  221. {id: '2', site: 'www.google.com'},
  222. {id: '3', site: 'account.google.com'},
  223. ]
  224. };
  225. const LOAD_PASSWORD_FOR_SITE = mutations[types.LOAD_PASSWORD_FOR_SITE];
  226. LOAD_PASSWORD_FOR_SITE(state, {site: 'google.com', url: 'https://www.google.com'});
  227. t.is(state.password.id, '2');
  228. t.is(state.password.site, 'www.google.com');
  229. });