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