Diffstat (limited to 'frontend/gamma/tests/tests/Clipperz/PM/PIN.test.js') (more/less context) (ignore whitespace changes)
-rw-r--r-- | frontend/gamma/tests/tests/Clipperz/PM/PIN.test.js | 97 |
1 files changed, 97 insertions, 0 deletions
diff --git a/frontend/gamma/tests/tests/Clipperz/PM/PIN.test.js b/frontend/gamma/tests/tests/Clipperz/PM/PIN.test.js new file mode 100644 index 0000000..ed795dd --- a/dev/null +++ b/frontend/gamma/tests/tests/Clipperz/PM/PIN.test.js | |||
@@ -0,0 +1,97 @@ | |||
1 | /* | ||
2 | |||
3 | Copyright 2008-2011 Clipperz Srl | ||
4 | |||
5 | This file is part of Clipperz Community Edition. | ||
6 | Clipperz Community Edition is an online password manager. | ||
7 | For further information about its features and functionalities please | ||
8 | refer to http://www.clipperz.com. | ||
9 | |||
10 | * Clipperz Community Edition is free software: you can redistribute | ||
11 | it and/or modify it under the terms of the GNU Affero General Public | ||
12 | License as published by the Free Software Foundation, either version | ||
13 | 3 of the License, or (at your option) any later version. | ||
14 | |||
15 | * Clipperz Community Edition is distributed in the hope that it will | ||
16 | be useful, but WITHOUT ANY WARRANTY; without even the implied | ||
17 | warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||
18 | See the GNU Affero General Public License for more details. | ||
19 | |||
20 | * You should have received a copy of the GNU Affero General Public | ||
21 | License along with Clipperz Community Edition. If not, see | ||
22 | <http://www.gnu.org/licenses/>. | ||
23 | |||
24 | */ | ||
25 | |||
26 | Clipperz.Crypto.PRNG.defaultRandomGenerator().fastEntropyAccumulationForTestingPurpose(); | ||
27 | |||
28 | Clipperz.PM.PIN['CREDENTIALS'] ='TEST.CLIPPERZ.CREDENTIALS'; | ||
29 | Clipperz.PM.PIN['FAILURE_COUNT'] ='TEST.CLIPPERZ.FAILED_LOGIN_COUNT'; | ||
30 | |||
31 | |||
32 | var tests = { | ||
33 | |||
34 | //------------------------------------------------------------------------- | ||
35 | |||
36 | 'clearCredentials': function () { | ||
37 | localStorage.removeItem(Clipperz.PM.PIN['CREDENTIALS']); | ||
38 | localStorage.removeItem(Clipperz.PM.PIN['FAILURE_COUNT']); | ||
39 | }, | ||
40 | |||
41 | //------------------------------------------------------------------------- | ||
42 | |||
43 | 'isSet': function () { | ||
44 | tests.clearCredentials(); | ||
45 | |||
46 | is(false, Clipperz.PM.PIN.isSet(), "after cleaning all values, credentials should not be set"); | ||
47 | |||
48 | Clipperz.PM.PIN.setCredentialsWithPIN("1234", {'username':'joe', 'passphrase':'eoj'}); | ||
49 | is(true, Clipperz.PM.PIN.isSet(), "once saved, they should be found"); | ||
50 | }, | ||
51 | |||
52 | 'recordFailedAttempt': function () { | ||
53 | tests.clearCredentials(); | ||
54 | |||
55 | Clipperz.PM.PIN.setCredentialsWithPIN("1234", {'username':'joe', 'passphrase':'eoj'}); | ||
56 | is(true, Clipperz.PM.PIN.isSet(), "once saved, they should be found"); | ||
57 | Clipperz.PM.PIN.recordFailedAttempt(); | ||
58 | is(true, Clipperz.PM.PIN.isSet(), "1st wrong PIN -> keep credentials"); | ||
59 | Clipperz.PM.PIN.recordFailedAttempt(); | ||
60 | is(true, Clipperz.PM.PIN.isSet(), "2nd wrong PIN -> keep credentials"); | ||
61 | Clipperz.PM.PIN.recordFailedAttempt(); | ||
62 | is(false, Clipperz.PM.PIN.isSet(), "3rd wrong PIN -> REMOVE credentials"); | ||
63 | |||
64 | Clipperz.PM.PIN.setCredentialsWithPIN("1234", {'username':'joe', 'passphrase':'eoj'}); | ||
65 | is(true, Clipperz.PM.PIN.isSet(), "once saved, they should be found"); | ||
66 | Clipperz.PM.PIN.recordFailedAttempt(); | ||
67 | is(true, Clipperz.PM.PIN.isSet(), "1st wrong PIN -> keep credentials"); | ||
68 | Clipperz.PM.PIN.recordFailedAttempt(); | ||
69 | is(true, Clipperz.PM.PIN.isSet(), "2nd wrong PIN -> keep credentials"); | ||
70 | Clipperz.PM.PIN.resetFailedAttemptCount(); | ||
71 | Clipperz.PM.PIN.recordFailedAttempt(); | ||
72 | is(true, Clipperz.PM.PIN.isSet(), "3rd wrong PIN, but with a successful use in between -> keep credentials"); | ||
73 | }, | ||
74 | |||
75 | 'credentialsWithPIN': function () { | ||
76 | varcredentials; | ||
77 | varpin; | ||
78 | var decryptedCredentials; | ||
79 | |||
80 | tests.clearCredentials(); | ||
81 | |||
82 | credentials = {'username': 'joe', 'passphrase':'foobar'}; | ||
83 | pin = '1234'; | ||
84 | Clipperz.PM.PIN.setCredentialsWithPIN(pin, credentials); | ||
85 | decryptedCredentials = Clipperz.PM.PIN.credentialsWithPIN(pin); | ||
86 | |||
87 | is(decryptedCredentials['username'],credentials['username']); | ||
88 | is(decryptedCredentials['passphrase'],credentials['passphrase']); | ||
89 | }, | ||
90 | |||
91 | //------------------------------------------------------------------------- | ||
92 | 'syntaxFix': MochiKit.Base.noop | ||
93 | }; | ||
94 | |||
95 | //############################################################################# | ||
96 | |||
97 | SimpleTest.runDeferredTests("Clipperz.PM.PIN", tests, {trace:false}); | ||