No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

api.tests.js 23 KiB

hace 8 años
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584
  1. var assert = chai.assert;
  2. describe('LessPass v1', function () {
  3. describe('encryptLogin', function () {
  4. it('should use pbkdf2 with 8192 iterations and sha256', function (done) {
  5. LessPass.encryptLogin('test@example.org', 'password').then(function (encryptedLogin) {
  6. assert.equal('d8af5f918db6b65b1db3d3984e5a400e39e1dbb19462220e4431de283809f472', encryptedLogin);
  7. done();
  8. });
  9. });
  10. it('should allow to customize number of iterations', function (done) {
  11. LessPass.encryptLogin('test@example.org', 'password', {iterations: 4096}).then(function (encryptedLogin) {
  12. assert.equal('0a91208545e3aa4935d3a22984ca097a7669259a04d261ac16361bdc1a2e960f', encryptedLogin);
  13. done();
  14. });
  15. });
  16. it('should allow to customize key length', function (done) {
  17. LessPass.encryptLogin('test@example.org', 'password', {keylen: 16}).then(function (encryptedLogin) {
  18. assert.equal('d8af5f918db6b65b1db3d3984e5a400e', encryptedLogin);
  19. done();
  20. });
  21. });
  22. it('should allow to customize iterations and key length', function (done) {
  23. LessPass.encryptLogin('test@example.org', 'password', {
  24. iterations: 4096,
  25. keylen: 16
  26. }).then(function (encryptedLogin) {
  27. assert.equal('0a91208545e3aa4935d3a22984ca097a', encryptedLogin);
  28. done();
  29. });
  30. });
  31. it('should allow utf8 parameter', function () {
  32. return LessPass.encryptLogin('test@example.org', '♥ LessPass ♥').then(function (encryptedLogin) {
  33. assert.equal('997fe81d3d0db236e039c75efdb487f17a902fdf94f9dacaa9884329c85d9651', encryptedLogin);
  34. });
  35. });
  36. it('encryptLogin auto generated test 0', function () {
  37. return LessPass.encryptLogin('contact@lesspass.com', 'password').then(function (encryptedLogin) {
  38. assert.equal('63d850713d0b2f7f2c4396fe93f4ac0c6bc7485f9e7473c4b8c4a33ec12199c0', encryptedLogin);
  39. });
  40. });
  41. it('encryptLogin auto generated test 1', function () {
  42. return LessPass.encryptLogin('contact@lesspass.com', 'password').then(function (encryptedLogin) {
  43. assert.equal('63d850713d0b2f7f2c4396fe93f4ac0c6bc7485f9e7473c4b8c4a33ec12199c0', encryptedLogin);
  44. });
  45. });
  46. it('encryptLogin auto generated test 2', function () {
  47. return LessPass.encryptLogin('contact@lesspass.com', 'password').then(function (encryptedLogin) {
  48. assert.equal('63d850713d0b2f7f2c4396fe93f4ac0c6bc7485f9e7473c4b8c4a33ec12199c0', encryptedLogin);
  49. });
  50. });
  51. it('encryptLogin auto generated test 3', function () {
  52. return LessPass.encryptLogin('contact@lesspass.com', 'password').then(function (encryptedLogin) {
  53. assert.equal('63d850713d0b2f7f2c4396fe93f4ac0c6bc7485f9e7473c4b8c4a33ec12199c0', encryptedLogin);
  54. });
  55. });
  56. it('encryptLogin auto generated test 4', function () {
  57. return LessPass.encryptLogin('contact@lesspass.com', 'password').then(function (encryptedLogin) {
  58. assert.equal('63d850713d0b2f7f2c4396fe93f4ac0c6bc7485f9e7473c4b8c4a33ec12199c0', encryptedLogin);
  59. });
  60. });
  61. it('encryptLogin auto generated test 5', function () {
  62. return LessPass.encryptLogin('contact@lesspass.com', 'password').then(function (encryptedLogin) {
  63. assert.equal('63d850713d0b2f7f2c4396fe93f4ac0c6bc7485f9e7473c4b8c4a33ec12199c0', encryptedLogin);
  64. });
  65. });
  66. it('encryptLogin auto generated test 6', function () {
  67. return LessPass.encryptLogin('contact@lesspass.com', 'password').then(function (encryptedLogin) {
  68. assert.equal('63d850713d0b2f7f2c4396fe93f4ac0c6bc7485f9e7473c4b8c4a33ec12199c0', encryptedLogin);
  69. });
  70. });
  71. it('encryptLogin auto generated test 7', function () {
  72. return LessPass.encryptLogin('contact@lesspass.com', 'password').then(function (encryptedLogin) {
  73. assert.equal('63d850713d0b2f7f2c4396fe93f4ac0c6bc7485f9e7473c4b8c4a33ec12199c0', encryptedLogin);
  74. });
  75. });
  76. it('encryptLogin auto generated test 8', function () {
  77. return LessPass.encryptLogin('contact@lesspass.com', 'password').then(function (encryptedLogin) {
  78. assert.equal('63d850713d0b2f7f2c4396fe93f4ac0c6bc7485f9e7473c4b8c4a33ec12199c0', encryptedLogin);
  79. });
  80. });
  81. it('encryptLogin auto generated test 9', function () {
  82. return LessPass.encryptLogin('lesspass', 'password').then(function (encryptedLogin) {
  83. assert.equal('7d05ee25597dcc3ac16d082aa910e7707f75be620ed8db5bef7245e2a8579116', encryptedLogin);
  84. });
  85. });
  86. it('encryptLogin auto generated test 10', function () {
  87. return LessPass.encryptLogin('contact@lesspass.com', 'password2').then(function (encryptedLogin) {
  88. assert.equal('ce853092fc54fe88c281e38df97bd5826d64e6bee315dc94939cbba8930df0e4', encryptedLogin);
  89. });
  90. });
  91. });
  92. describe('renderPassword', function () {
  93. it('render password', function (done) {
  94. var site = 'lesspass.com';
  95. var encryptedLogin = '63d850713d0b2f7f2c4396fe93f4ac0c6bc7485f9e7473c4b8c4a33ec12199c0';
  96. var passwordOptions = {
  97. counter: 1,
  98. length: 12,
  99. lowercase: true,
  100. uppercase: true,
  101. numbers: true,
  102. symbols: true
  103. };
  104. LessPass.renderPassword(encryptedLogin, site, passwordOptions).then(function (generatedPassword) {
  105. assert.equal('azYS7,olOL2]', generatedPassword);
  106. done();
  107. })
  108. });
  109. it('render password with a custom template', function () {
  110. var site = 'lesspass.com';
  111. var encryptedLogin = '63d850713d0b2f7f2c4396fe93f4ac0c6bc7485f9e7473c4b8c4a33ec12199c0';
  112. var passwordOptions = {
  113. counter: 1,
  114. length: 12,
  115. lowercase: true,
  116. uppercase: true,
  117. numbers: true,
  118. symbols: true,
  119. template: 'n'
  120. };
  121. return LessPass.renderPassword(encryptedLogin, site, passwordOptions).then(function (generatedPassword) {
  122. var i = generatedPassword.length;
  123. while (i--) {
  124. assert('0123456789'.indexOf(generatedPassword[i]) !== -1)
  125. }
  126. })
  127. });
  128. it('render password with a custom template too short', function () {
  129. var site = 'lesspass.com';
  130. var encryptedLogin = '63d850713d0b2f7f2c4396fe93f4ac0c6bc7485f9e7473c4b8c4a33ec12199c0';
  131. var passwordOptions = {
  132. counter: 1,
  133. length: 12,
  134. lowercase: true,
  135. uppercase: true,
  136. numbers: true,
  137. symbols: true,
  138. template: 'CvcnCVsn'
  139. };
  140. return LessPass.renderPassword(encryptedLogin, site, passwordOptions).then(function (generatedPassword) {
  141. assert.equal('Sor4WU:8Wad5', generatedPassword);
  142. })
  143. });
  144. it('render password with a custom template too long', function () {
  145. var site = 'lesspass.com';
  146. var encryptedLogin = '63d850713d0b2f7f2c4396fe93f4ac0c6bc7485f9e7473c4b8c4a33ec12199c0';
  147. var passwordOptions = {
  148. counter: 1,
  149. length: 6,
  150. lowercase: true,
  151. uppercase: true,
  152. numbers: true,
  153. symbols: true,
  154. template: 'CvcnCVsn'
  155. };
  156. return LessPass.renderPassword(encryptedLogin, site, passwordOptions).then(function (generatedPassword) {
  157. assert.equal('Sor4WU', generatedPassword);
  158. })
  159. });
  160. it('render password auto generated test 0', function () {
  161. var site = 'lesspass.com';
  162. var encryptedLogin = '63d850713d0b2f7f2c4396fe93f4ac0c6bc7485f9e7473c4b8c4a33ec12199c0';
  163. var passwordOptions = {
  164. counter: 1,
  165. length: 12,
  166. lowercase: true,
  167. uppercase: true,
  168. numbers: true,
  169. symbols: true
  170. };
  171. return LessPass.renderPassword(encryptedLogin, site, passwordOptions).then(function (generatedPassword) {
  172. assert.equal('azYS7,olOL2]', generatedPassword);
  173. })
  174. });
  175. it('render password auto generated test 1', function () {
  176. var site = 'lesspass.com';
  177. var encryptedLogin = '63d850713d0b2f7f2c4396fe93f4ac0c6bc7485f9e7473c4b8c4a33ec12199c0';
  178. var passwordOptions = {
  179. counter: 1,
  180. length: 14,
  181. lowercase: true,
  182. uppercase: true,
  183. numbers: true,
  184. symbols: true
  185. };
  186. return LessPass.renderPassword(encryptedLogin, site, passwordOptions).then(function (generatedPassword) {
  187. assert.equal('azYS7,olOL2]iz', generatedPassword);
  188. })
  189. });
  190. it('render password auto generated test 2', function () {
  191. var site = 'lesspass.com';
  192. var encryptedLogin = '63d850713d0b2f7f2c4396fe93f4ac0c6bc7485f9e7473c4b8c4a33ec12199c0';
  193. var passwordOptions = {
  194. counter: 1,
  195. length: 12,
  196. lowercase: true,
  197. uppercase: false,
  198. numbers: false,
  199. symbols: false,
  200. };
  201. return LessPass.renderPassword(encryptedLogin, site, passwordOptions).then(function (generatedPassword) {
  202. assert.equal('azyseqololat', generatedPassword);
  203. })
  204. });
  205. it('render password auto generated test 3', function () {
  206. var site = 'lesspass.com';
  207. var encryptedLogin = '63d850713d0b2f7f2c4396fe93f4ac0c6bc7485f9e7473c4b8c4a33ec12199c0';
  208. var passwordOptions = {
  209. counter: 1,
  210. length: 12,
  211. lowercase: false,
  212. uppercase: true,
  213. numbers: true,
  214. symbols: true
  215. };
  216. return LessPass.renderPassword(encryptedLogin, site, passwordOptions).then(function (generatedPassword) {
  217. assert.equal('AZ3[EQ7@OL2]', generatedPassword);
  218. })
  219. });
  220. it('render password auto generated test 4', function () {
  221. var site = 'lesspass.com';
  222. var encryptedLogin = '63d850713d0b2f7f2c4396fe93f4ac0c6bc7485f9e7473c4b8c4a33ec12199c0';
  223. var passwordOptions = {
  224. counter: 1,
  225. length: 12,
  226. lowercase: false,
  227. uppercase: false,
  228. numbers: true,
  229. symbols: true
  230. };
  231. return LessPass.renderPassword(encryptedLogin, site, passwordOptions).then(function (generatedPassword) {
  232. assert.equal('4?3[7,7@7@2]', generatedPassword);
  233. })
  234. });
  235. it('render password auto generated test 5', function () {
  236. var site = 'lesspass.com';
  237. var encryptedLogin = '63d850713d0b2f7f2c4396fe93f4ac0c6bc7485f9e7473c4b8c4a33ec12199c0';
  238. var passwordOptions = {
  239. counter: 1,
  240. length: 12,
  241. lowercase: false,
  242. uppercase: false,
  243. numbers: false,
  244. symbols: true
  245. };
  246. return LessPass.renderPassword(encryptedLogin, site, passwordOptions).then(function (generatedPassword) {
  247. assert.equal('[?=[&,:@:@[]', generatedPassword);
  248. })
  249. });
  250. it('render password auto generated test 6', function () {
  251. var site = 'lesspass.com';
  252. var encryptedLogin = '63d850713d0b2f7f2c4396fe93f4ac0c6bc7485f9e7473c4b8c4a33ec12199c0';
  253. var passwordOptions = {
  254. counter: 1,
  255. length: 12,
  256. lowercase: true,
  257. uppercase: true,
  258. numbers: true,
  259. symbols: false
  260. };
  261. return LessPass.renderPassword(encryptedLogin, site, passwordOptions).then(function (generatedPassword) {
  262. assert.equal('azYS7uwAW8at', generatedPassword);
  263. })
  264. });
  265. it('render password auto generated test 7', function () {
  266. var site = 'lesspass.com';
  267. var encryptedLogin = '63d850713d0b2f7f2c4396fe93f4ac0c6bc7485f9e7473c4b8c4a33ec12199c0';
  268. var passwordOptions = {
  269. counter: 1,
  270. length: 12,
  271. lowercase: true,
  272. uppercase: true,
  273. numbers: false,
  274. symbols: false
  275. };
  276. return LessPass.renderPassword(encryptedLogin, site, passwordOptions).then(function (generatedPassword) {
  277. assert.equal('azYSeqOLolAT', generatedPassword);
  278. })
  279. });
  280. it('render password auto generated test 8', function () {
  281. var site = 'lesspass.com';
  282. var encryptedLogin = '63d850713d0b2f7f2c4396fe93f4ac0c6bc7485f9e7473c4b8c4a33ec12199c0';
  283. var passwordOptions = {
  284. counter: 2,
  285. length: 12,
  286. lowercase: true,
  287. uppercase: true,
  288. numbers: true,
  289. symbols: true
  290. };
  291. return LessPass.renderPassword(encryptedLogin, site, passwordOptions).then(function (generatedPassword) {
  292. assert.equal('obYT2=olOV9=', generatedPassword);
  293. })
  294. });
  295. it('render password auto generated test 9', function () {
  296. var site = 'lesspass.com';
  297. var encryptedLogin = '7d05ee25597dcc3ac16d082aa910e7707f75be620ed8db5bef7245e2a8579116';
  298. var passwordOptions = {
  299. counter: 1,
  300. length: 12,
  301. lowercase: true,
  302. uppercase: true,
  303. numbers: true,
  304. symbols: true
  305. };
  306. return LessPass.renderPassword(encryptedLogin, site, passwordOptions).then(function (generatedPassword) {
  307. assert.equal('erOC1%imIW3,', generatedPassword);
  308. })
  309. });
  310. it('render password auto generated test 10', function () {
  311. var site = 'lesspass.com';
  312. var encryptedLogin = 'ce853092fc54fe88c281e38df97bd5826d64e6bee315dc94939cbba8930df0e4';
  313. var passwordOptions = {
  314. counter: 1,
  315. length: 12,
  316. lowercase: true,
  317. uppercase: true,
  318. numbers: true,
  319. symbols: true
  320. };
  321. return LessPass.renderPassword(encryptedLogin, site, passwordOptions).then(function (generatedPassword) {
  322. assert.equal('uvUM5_ucUP5=', generatedPassword);
  323. })
  324. });
  325. });
  326. describe('fingerprint', function () {
  327. it('createFingerprint', function () {
  328. return LessPass.createFingerprint('password').then(function (fingerprint) {
  329. assert.equal('e56a207acd1e6714735487c199c6f095844b7cc8e5971d86c003a7b6f36ef51e', fingerprint);
  330. })
  331. });
  332. });
  333. describe('generatePassword', function () {
  334. it('generate password', function () {
  335. var site = 'example.org';
  336. var login = 'contact@example.org';
  337. var masterPassword = 'password';
  338. var passwordProfile = {
  339. lowercase: true,
  340. uppercase: true,
  341. digits: true,
  342. symbols: true,
  343. length: 12,
  344. index: 1,
  345. version: 1,
  346. };
  347. return LessPass.generatePassword(site, login, masterPassword, passwordProfile).then(function (generatedPassword) {
  348. assert.equal('izIS5@ozYM2?', generatedPassword);
  349. });
  350. });
  351. it('generate password auto generated test 0', function () {
  352. var site = 'lesspass.com';
  353. var login = 'contact@lesspass.com';
  354. var masterPassword = 'password';
  355. var passwordProfile = {
  356. lowercase: true,
  357. uppercase: true,
  358. digits: true,
  359. symbols: true,
  360. length: 12,
  361. index: 1,
  362. version: 1,
  363. };
  364. return LessPass.generatePassword(site, login, masterPassword, passwordProfile).then(function (generatedPassword) {
  365. assert.equal('azYS7,olOL2]', generatedPassword);
  366. });
  367. });
  368. it('generate password auto generated test 1', function () {
  369. var site = 'lesspass.com';
  370. var login = 'contact@lesspass.com';
  371. var masterPassword = 'password';
  372. var passwordProfile = {
  373. lowercase: true,
  374. uppercase: true,
  375. digits: true,
  376. symbols: true,
  377. length: 14,
  378. index: 1,
  379. version: 1,
  380. };
  381. return LessPass.generatePassword(site, login, masterPassword, passwordProfile).then(function (generatedPassword) {
  382. assert.equal('azYS7,olOL2]iz', generatedPassword);
  383. });
  384. });
  385. it('generate password auto generated test 2', function () {
  386. var site = 'lesspass.com';
  387. var login = 'contact@lesspass.com';
  388. var masterPassword = 'password';
  389. var passwordProfile = {
  390. lowercase: true,
  391. uppercase: false,
  392. digits: false,
  393. symbols: false,
  394. length: 12,
  395. index: 1,
  396. version: 1,
  397. };
  398. return LessPass.generatePassword(site, login, masterPassword, passwordProfile).then(function (generatedPassword) {
  399. assert.equal('azyseqololat', generatedPassword);
  400. });
  401. });
  402. it('generate password auto generated test 3', function () {
  403. var site = 'lesspass.com';
  404. var login = 'contact@lesspass.com';
  405. var masterPassword = 'password';
  406. var passwordProfile = {
  407. lowercase: false,
  408. uppercase: true,
  409. digits: true,
  410. symbols: true,
  411. length: 12,
  412. index: 1,
  413. version: 1,
  414. };
  415. return LessPass.generatePassword(site, login, masterPassword, passwordProfile).then(function (generatedPassword) {
  416. assert.equal('AZ3[EQ7@OL2]', generatedPassword);
  417. });
  418. });
  419. it('generate password auto generated test 4', function () {
  420. var site = 'lesspass.com';
  421. var login = 'contact@lesspass.com';
  422. var masterPassword = 'password';
  423. var passwordProfile = {
  424. lowercase: false,
  425. uppercase: false,
  426. digits: true,
  427. symbols: true,
  428. length: 12,
  429. index: 1,
  430. version: 1,
  431. };
  432. return LessPass.generatePassword(site, login, masterPassword, passwordProfile).then(function (generatedPassword) {
  433. assert.equal('4?3[7,7@7@2]', generatedPassword);
  434. });
  435. });
  436. it('generate password auto generated test 5', function () {
  437. var site = 'lesspass.com';
  438. var login = 'contact@lesspass.com';
  439. var masterPassword = 'password';
  440. var passwordProfile = {
  441. lowercase: false,
  442. uppercase: false,
  443. digits: false,
  444. symbols: true,
  445. length: 12,
  446. index: 1,
  447. version: 1,
  448. };
  449. return LessPass.generatePassword(site, login, masterPassword, passwordProfile).then(function (generatedPassword) {
  450. assert.equal('[?=[&,:@:@[]', generatedPassword);
  451. });
  452. });
  453. it('generate password auto generated test 6', function () {
  454. var site = 'lesspass.com';
  455. var login = 'contact@lesspass.com';
  456. var masterPassword = 'password';
  457. var passwordProfile = {
  458. lowercase: true,
  459. uppercase: true,
  460. digits: true,
  461. symbols: false,
  462. length: 12,
  463. index: 1,
  464. version: 1,
  465. };
  466. return LessPass.generatePassword(site, login, masterPassword, passwordProfile).then(function (generatedPassword) {
  467. assert.equal('azYS7uwAW8at', generatedPassword);
  468. });
  469. });
  470. it('generate password auto generated test 7', function () {
  471. var site = 'lesspass.com';
  472. var login = 'contact@lesspass.com';
  473. var masterPassword = 'password';
  474. var passwordProfile = {
  475. lowercase: true,
  476. uppercase: true,
  477. digits: false,
  478. symbols: false,
  479. length: 12,
  480. index: 1,
  481. version: 1,
  482. };
  483. return LessPass.generatePassword(site, login, masterPassword, passwordProfile).then(function (generatedPassword) {
  484. assert.equal('azYSeqOLolAT', generatedPassword);
  485. });
  486. });
  487. it('generate password auto generated test 8', function () {
  488. var site = 'lesspass.com';
  489. var login = 'contact@lesspass.com';
  490. var masterPassword = 'password';
  491. var passwordProfile = {
  492. lowercase: true,
  493. uppercase: true,
  494. digits: true,
  495. symbols: true,
  496. length: 12,
  497. index: 2,
  498. version: 1,
  499. };
  500. return LessPass.generatePassword(site, login, masterPassword, passwordProfile).then(function (generatedPassword) {
  501. assert.equal('obYT2=olOV9=', generatedPassword);
  502. });
  503. });
  504. it('generate password auto generated test 9', function () {
  505. var site = 'lesspass.com';
  506. var login = 'lesspass';
  507. var masterPassword = 'password';
  508. var passwordProfile = {
  509. lowercase: true,
  510. uppercase: true,
  511. digits: true,
  512. symbols: true,
  513. length: 12,
  514. index: 1,
  515. version: 1,
  516. };
  517. return LessPass.generatePassword(site, login, masterPassword, passwordProfile).then(function (generatedPassword) {
  518. assert.equal('erOC1%imIW3,', generatedPassword);
  519. });
  520. });
  521. it('generate password auto generated test 10', function () {
  522. var site = 'lesspass.com';
  523. var login = 'contact@lesspass.com';
  524. var masterPassword = 'password2';
  525. var passwordProfile = {
  526. lowercase: true,
  527. uppercase: true,
  528. digits: true,
  529. symbols: true,
  530. length: 12,
  531. index: 1,
  532. version: 1,
  533. };
  534. return LessPass.generatePassword(site, login, masterPassword, passwordProfile).then(function (generatedPassword) {
  535. assert.equal('uvUM5_ucUP5=', generatedPassword);
  536. });
  537. });
  538. });
  539. });