author | Clipperz <info@clipperz.com> | 2013-01-08 15:21:04 (UTC) |
---|---|---|
committer | Clipperz <info@clipperz.com> | 2013-01-08 15:21:04 (UTC) |
commit | 816fc35420a434b1d54ae5833d617608f7456048 (patch) (side-by-side diff) | |
tree | 95b8caf354083593d7775e4dda6f4c556b44a2d9 /frontend/gamma/tests/tests/Clipperz/PM/PIN.test.js | |
parent | 267603e3aa3cf0029411e67ae14018b52344c296 (diff) | |
download | clipperz-816fc35420a434b1d54ae5833d617608f7456048.zip clipperz-816fc35420a434b1d54ae5833d617608f7456048.tar.gz clipperz-816fc35420a434b1d54ae5833d617608f7456048.tar.bz2 |
Updated version of /gamma
Tons of changes, included a new draft of the mobile version (still VERY rough)
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 @@ +/* + +Copyright 2008-2011 Clipperz Srl + +This file is part of Clipperz Community Edition. +Clipperz Community Edition is an online password manager. +For further information about its features and functionalities please +refer to http://www.clipperz.com. + +* Clipperz Community Edition 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 Community Edition 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 Community Edition. 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}); |