author | Giulio Cesare Solaroli <giulio.cesare@clipperz.com> | 2013-04-19 15:09:28 (UTC) |
---|---|---|
committer | Giulio Cesare Solaroli <giulio.cesare@clipperz.com> | 2013-04-19 15:09:28 (UTC) |
commit | 074e70457c90344b3c1cb236105638d692a0066b (patch) (side-by-side diff) | |
tree | c5ffabd3eaf74cbeb69974beacdb5a5f8c235adc | |
parent | 48c9280c9a255f2a85ad5729830df884e64a9c5d (diff) | |
download | clipperz-074e70457c90344b3c1cb236105638d692a0066b.zip clipperz-074e70457c90344b3c1cb236105638d692a0066b.tar.gz clipperz-074e70457c90344b3c1cb236105638d692a0066b.tar.bz2 |
Fixed an issue on the AES-CTR block mode
The previous version of the CTR encoding was incrementing the counter in a weird way, mixing up data from the previous block.
The current fix can correctly decrypt data encoded with AES-CTR using other libraries/languages (currently tested only with Python).
22 files changed, 2098 insertions, 79 deletions
diff --git a/frontend/beta/js/Clipperz/Crypto/AES_2.js b/frontend/beta/js/Clipperz/Crypto/AES_2.js new file mode 100644 index 0000000..9735d17 --- a/dev/null +++ b/frontend/beta/js/Clipperz/Crypto/AES_2.js @@ -0,0 +1,829 @@ +/* + +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/. + +*/ + +try { if (typeof(Clipperz.ByteArray) == 'undefined') { throw ""; }} catch (e) { + throw "Clipperz.Crypto.AES_2 depends on Clipperz.ByteArray!"; +} + +// Dependency commented to avoid a circular reference +//try { if (typeof(Clipperz.Crypto.PRNG) == 'undefined') { throw ""; }} catch (e) { +// throw "Clipperz.Crypto.AES_2 depends on Clipperz.Crypto.PRNG!"; +//} + +if (typeof(Clipperz.Crypto.AES_2) == 'undefined') { Clipperz.Crypto.AES_2 = {}; } + +//############################################################################# + +Clipperz.Crypto.AES_2.DeferredExecutionContext = function(args) { + args = args || {}; + + this._key = args.key; + this._message = args.message; + this._result = args.message.clone(); + this._nonce = args.nonce; + this._messageLength = this._message.length(); + + this._messageArray = this._message.arrayValues(); + this._resultArray = this._result.arrayValues(); + this._nonceArray = this._nonce.arrayValues(); + + this._executionStep = 0; + + return this; +} + +Clipperz.Crypto.AES_2.DeferredExecutionContext.prototype = MochiKit.Base.update(null, { + + 'key': function() { + return this._key; + }, + + 'message': function() { + return this._message; + }, + + 'messageLength': function() { + return this._messageLength; + }, + + 'result': function() { + return new Clipperz.ByteArray(this.resultArray()); + }, + + 'nonce': function() { + return this._nonce; + }, + + 'messageArray': function() { + return this._messageArray; + }, + + 'resultArray': function() { + return this._resultArray; + }, + + 'nonceArray': function() { + return this._nonceArray; + }, + + 'elaborationChunkSize': function() { + return Clipperz.Crypto.AES_2.DeferredExecution.chunkSize; + }, + + 'executionStep': function() { + return this._executionStep; + }, + + 'setExecutionStep': function(aValue) { + this._executionStep = aValue; + }, + + 'pause': function(aValue) { + return MochiKit.Async.wait(Clipperz.Crypto.AES_2.DeferredExecution.pauseTime, aValue); + }, + + //----------------------------------------------------------------------------- + __syntaxFix__: "syntax fix" + +}); + +//############################################################################# + +Clipperz.Crypto.AES_2.Key = function(args) { + args = args || {}; + + this._key = args.key; + this._keySize = args.keySize || this.key().length(); + + if (this.keySize() == 128/8) { + this._b = 176; + this._numberOfRounds = 10; + } else if (this.keySize() == 256/8) { + this._b = 240; + this._numberOfRounds = 14; + } else { + MochiKit.Logging.logError("AES unsupported key size: " + (this.keySize() * 8) + " bits"); + throw Clipperz.Crypto.AES_2.exception.UnsupportedKeySize; + } + + this._stretchedKey = null; + + return this; +} + +Clipperz.Crypto.AES_2.Key.prototype = MochiKit.Base.update(null, { + + 'asString': function() { + return "Clipperz.Crypto.AES_2.Key (" + this.key().toHexString() + ")"; + }, + + //----------------------------------------------------------------------------- + + 'key': function() { + return this._key; + }, + + 'keySize': function() { + return this._keySize; + }, + + 'b': function() { + return this._b; + }, + + 'numberOfRounds': function() { + return this._numberOfRounds; + }, + //========================================================================= + + 'keyScheduleCore': function(aWord, aRoundConstantsIndex) { + var result; + var sbox; + + sbox = Clipperz.Crypto.AES_2.sbox(); + + result = [ sbox[aWord[1]] ^ Clipperz.Crypto.AES_2.roundConstants()[aRoundConstantsIndex], + sbox[aWord[2]], + sbox[aWord[3]], + sbox[aWord[0]] ]; + + return result; + }, + + //----------------------------------------------------------------------------- + + 'xorWithPreviousStretchValues': function(aKey, aWord, aPreviousWordIndex) { + var result; + var i,c; + + result = []; + c = 4; + for (i=0; i<c; i++) { + result[i] = aWord[i] ^ aKey.byteAtIndex(aPreviousWordIndex + i); + } + + return result; + }, + + //----------------------------------------------------------------------------- + + 'sboxShakeup': function(aWord) { + var result; + var sbox; + var i,c; + + result = []; + sbox = Clipperz.Crypto.AES_2.sbox(); + c =4; + for (i=0; i<c; i++) { + result[i] = sbox[aWord[i]]; + } + + return result; + }, + + //----------------------------------------------------------------------------- + + 'stretchKey': function(aKey) { + var currentWord; + var keyLength; + var previousStretchIndex; + var i,c; + + keyLength = aKey.length(); + previousStretchIndex = keyLength - this.keySize(); + + currentWord = [ aKey.byteAtIndex(keyLength - 4), + aKey.byteAtIndex(keyLength - 3), + aKey.byteAtIndex(keyLength - 2), + aKey.byteAtIndex(keyLength - 1) ]; + currentWord = this.keyScheduleCore(currentWord, keyLength / this.keySize()); + + if (this.keySize() == 256/8) { + c = 8; + } else if (this.keySize() == 128/8){ + c = 4; + } + + for (i=0; i<c; i++) { + if (i == 4) { + // fifth streatch word + currentWord = this.sboxShakeup(currentWord); + } + + currentWord = this.xorWithPreviousStretchValues(aKey, currentWord, previousStretchIndex + (i*4)); + aKey.appendBytes(currentWord); + } + + return aKey; + }, + + //----------------------------------------------------------------------------- + + 'stretchedKey': function() { + if (this._stretchedKey == null) { + var stretchedKey; + + stretchedKey = this.key().clone(); + + while (stretchedKey.length() < this.keySize()) { + stretchedKey.appendByte(0); + } + + while (stretchedKey.length() < this.b()) { + stretchedKey = this.stretchKey(stretchedKey); + } + + this._stretchedKey = stretchedKey.split(0, this.b()); + } + + return this._stretchedKey; + }, + + //========================================================================= + __syntaxFix__: "syntax fix" +}); + +//############################################################################# + +Clipperz.Crypto.AES_2.State = function(args) { + args = args || {}; + + this._data = args.block.slice(0); + this._key = args.key; + + return this; +} + +Clipperz.Crypto.AES_2.State.prototype = MochiKit.Base.update(null, { + + 'key': function() { + return this._key; + }, + + //----------------------------------------------------------------------------- + + 'data': function() { + return this._data; + }, + + 'setData': function(aValue) { + this._data = aValue; + }, + + //========================================================================= + + 'addRoundKey': function(aRoundNumber) { + // each byte of the state is combined with the round key; each round key is derived from the cipher key using a key schedule. + var data; + var stretchedKey; + var firstStretchedKeyIndex; + var i,c; + + data = this.data(); + stretchedKey = this.key().stretchedKey(); + firstStretchedKeyIndex = aRoundNumber * (128/8); + c = 128/8; + for (i=0; i<c; i++) { + data[i] = data[i] ^ stretchedKey.byteAtIndex(firstStretchedKeyIndex + i); + } + }, + + //----------------------------------------------------------------------------- + + 'subBytes': function() { + // a non-linear substitution step where each byte is replaced with another according to a lookup table. + var i,c; + var data; + var sbox; + + data = this.data(); + sbox = Clipperz.Crypto.AES_2.sbox(); + + c = 16; + for (i=0; i<c; i++) { + data[i] = sbox[data[i]]; + } + }, + + //----------------------------------------------------------------------------- + + 'shiftRows': function() { + // a transposition step where each row of the state is shifted cyclically a certain number of steps. + var newValue; + var data; + var shiftMapping; + var i,c; + + newValue = new Array(16); + data = this.data(); + shiftMapping = Clipperz.Crypto.AES_2.shiftRowMapping(); +// [0, 5, 10, 15, 4, 9, 14, 3, 8, 13, 2, 7, 12, 1, 6, 11]; + c = 16; + for (i=0; i<c; i++) { + newValue[i] = data[shiftMapping[i]]; + } + for (i=0; i<c; i++) { + data[i] = newValue[i]; + } + }, + + //----------------------------------------------------------------------------- +/* + 'mixColumnsWithValues': function(someValues) { + var result; + var a; + var i,c; + + c = 4; + result = []; + a = []; + for (i=0; i<c; i++) { + a[i] = []; + a[i][1] = someValues[i] + if ((a[i][1] & 0x80) == 0x80) { + a[i][2] = (a[i][1] << 1) ^ 0x11b; + } else { + a[i][2] = a[i][1] << 1; + } + + a[i][3] = a[i][2] ^ a[i][1]; + } + + for (i=0; i<c; i++) { + var x; + + x = Clipperz.Crypto.AES_2.mixColumnsMatrix()[i]; + result[i] = a[0][x[0]] ^ a[1][x[1]] ^ a[2][x[2]] ^ a[3][x[3]]; + } + + return result; + }, + + 'mixColumns': function() { + // a mixing operation which operates on the columns of the state, combining the four bytes in each column using a linear transformation. + var data; + var i, c; + + data = this.data(); + c = 4; + for(i=0; i<c; i++) { + var blockIndex; + var mixedValues; + + blockIndex = i * 4; + mixedValues = this.mixColumnsWithValues([ data[blockIndex + 0], + data[blockIndex + 1], + data[blockIndex + 2], + data[blockIndex + 3]]); + data[blockIndex + 0] = mixedValues[0]; + data[blockIndex + 1] = mixedValues[1]; + data[blockIndex + 2] = mixedValues[2]; + data[blockIndex + 3] = mixedValues[3]; + } + }, +*/ + + 'mixColumns': function() { + // a mixing operation which operates on the columns of the state, combining the four bytes in each column using a linear transformation. + var data; + var i, c; + var a_1; + var a_2; + + a_1 = new Array(4); + a_2 = new Array(4); + + data = this.data(); + c = 4; + for(i=0; i<c; i++) { + var blockIndex; + var ii, cc; + + blockIndex = i * 4; + + cc = 4; + for (ii=0; ii<cc; ii++) { + var value; + + value = data[blockIndex + ii]; + a_1[ii] = value; + a_2[ii] = (value & 0x80) ? ((value << 1) ^ 0x011b) : (value << 1); + } + + data[blockIndex + 0] = a_2[0] ^ a_1[1] ^ a_2[1] ^ a_1[2] ^ a_1[3]; + data[blockIndex + 1] = a_1[0] ^ a_2[1] ^ a_1[2] ^ a_2[2] ^ a_1[3]; + data[blockIndex + 2] = a_1[0] ^ a_1[1] ^ a_2[2] ^ a_1[3] ^ a_2[3]; + data[blockIndex + 3] = a_1[0] ^ a_2[0] ^ a_1[1] ^ a_1[2] ^ a_2[3]; + } + }, + + //========================================================================= + + 'spinRound': function(aRoundNumber) { + this.addRoundKey(aRoundNumber); + this.subBytes(); + this.shiftRows(); + this.mixColumns(); + }, + + 'spinLastRound': function() { + this.addRoundKey(this.key().numberOfRounds() - 1); + this.subBytes(); + this.shiftRows(); + this.addRoundKey(this.key().numberOfRounds()); + }, + + //========================================================================= + + 'encrypt': function() { + var i,c; + + c = this.key().numberOfRounds() - 1; + for (i=0; i<c; i++) { + this.spinRound(i); + } + + this.spinLastRound(); + }, + + //========================================================================= + __syntaxFix__: "syntax fix" +}); + +//############################################################################# + +Clipperz.Crypto.AES_2.VERSION = "0.1"; +Clipperz.Crypto.AES_2.NAME = "Clipperz.Crypto.AES_2"; + +MochiKit.Base.update(Clipperz.Crypto.AES_2, { + +// http://www.cs.eku.edu/faculty/styer/460/Encrypt/JS-AES.html +// http://en.wikipedia.org/wiki/Advanced_Encryption_Standard +// http://en.wikipedia.org/wiki/Rijndael_key_schedule +// http://en.wikipedia.org/wiki/Rijndael_S-box + + '__repr__': function () { + return "[" + this.NAME + " " + this.VERSION + "]"; + }, + + 'toString': function () { + return this.__repr__(); + }, + + //============================================================================= + + '_sbox': null, + 'sbox': function() { + if (Clipperz.Crypto.AES_2._sbox == null) { + Clipperz.Crypto.AES_2._sbox = [ +0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b, 0xfe, 0xd7, 0xab, 0x76, +0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0, 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0, +0xb7, 0xfd, 0x93, 0x26, 0x36, 0x3f, 0xf7, 0xcc, 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15, +0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a, 0x07, 0x12, 0x80, 0xe2, 0xeb, 0x27, 0xb2, 0x75, +0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0, 0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84, +0x53, 0xd1, 0x00, 0xed, 0x20, 0xfc, 0xb1, 0x5b, 0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf, +0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, 0x45, 0xf9, 0x02, 0x7f, 0x50, 0x3c, 0x9f, 0xa8, +0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5, 0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2, +0xcd, 0x0c, 0x13, 0xec, 0x5f, 0x97, 0x44, 0x17, 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73, +0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, 0x46, 0xee, 0xb8, 0x14, 0xde, 0x5e, 0x0b, 0xdb, +0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c, 0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79, +0xe7, 0xc8, 0x37, 0x6d, 0x8d, 0xd5, 0x4e, 0xa9, 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08, +0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6, 0xe8, 0xdd, 0x74, 0x1f, 0x4b, 0xbd, 0x8b, 0x8a, +0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e, 0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e, +0xe1, 0xf8, 0x98, 0x11, 0x69, 0xd9, 0x8e, 0x94, 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf, +0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 0x41, 0x99, 0x2d, 0x0f, 0xb0, 0x54, 0xbb, 0x16 + ]; + } + + return Clipperz.Crypto.AES_2._sbox; + }, + + //----------------------------------------------------------------------------- + // + // 0 4 8 12 0 4 8 12 + // 1 5 9 13 => 5 9 13 1 + // 2 6 10 14 10 14 2 6 + // 3 7 11 15 15 3 7 11 + // + '_shiftRowMapping': null, + 'shiftRowMapping': function() { + if (Clipperz.Crypto.AES_2._shiftRowMapping == null) { + Clipperz.Crypto.AES_2._shiftRowMapping = [0, 5, 10, 15, 4, 9, 14, 3, 8, 13, 2, 7, 12, 1, 6, 11]; + } + + return Clipperz.Crypto.AES_2._shiftRowMapping; + }, + + //----------------------------------------------------------------------------- + + '_mixColumnsMatrix': null, + 'mixColumnsMatrix': function() { + if (Clipperz.Crypto.AES_2._mixColumnsMatrix == null) { + Clipperz.Crypto.AES_2._mixColumnsMatrix = [ [2, 3, 1 ,1], + [1, 2, 3, 1], + [1, 1, 2, 3], + [3, 1, 1, 2] ]; + } + + return Clipperz.Crypto.AES_2._mixColumnsMatrix; + }, + + '_roundConstants': null, + 'roundConstants': function() { + if (Clipperz.Crypto.AES_2._roundConstants == null) { + Clipperz.Crypto.AES_2._roundConstants = [ , 1, 2, 4, 8, 16, 32, 64, 128, 27, 54, 108, 216, 171, 77, 154]; +// Clipperz.Crypto.AES_2._roundConstants = [ , 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a]; + } + + return Clipperz.Crypto.AES_2._roundConstants; + }, + + //============================================================================= + + 'incrementNonce': function(nonce) { + var i; + var done; + + done = false; + i = nonce.length - 1; + + while ((i>=0) && (done == false)) { + var currentByteValue; + + currentByteValue = nonce[i]; + + if (currentByteValue == 0xff) { + nonce[i] = 0; + if (i>= 0) { + i --; + } else { + done = true; + } + } else { + nonce[i] = currentByteValue + 1; + done = true; + } + } + }, + + //----------------------------------------------------------------------------- + + 'encryptBlock': function(aKey, aBlock) { + var result; + var state; + + state = new Clipperz.Crypto.AES_2.State({block:aBlock, key:aKey}); +//is(state.data(), 'before'); + state.encrypt(); + result = state.data(); + + return result; + }, + + //----------------------------------------------------------------------------- + + 'encryptBlocks': function(aKey, aMessage, aNonce) { + var result; + var nonce; + var self; + var messageIndex; + var messageLength; + var blockSize; + + self = Clipperz.Crypto.AES_2; + blockSize = 128/8; + messageLength = aMessage.length; + nonce = aNonce; + + result = aMessage; + messageIndex = 0; + while (messageIndex < messageLength) { + var encryptedBlock; + var i,c; + + encryptedBlock = self.encryptBlock(aKey, nonce); + + if ((messageLength - messageIndex) > blockSize) { + c = blockSize; + } else { + c = messageLength - messageIndex; + } + + for (i=0; i<c; i++) { + result[messageIndex + i] = result[messageIndex + i] ^ encryptedBlock[i]; + } + + messageIndex += blockSize; + self.incrementNonce(nonce); + } + + return result; + }, + + //----------------------------------------------------------------------------- + + 'encrypt': function(aKey, someData, aNonce) { + var result; + var nonce; + var encryptedData; + var key; + + key = new Clipperz.Crypto.AES_2.Key({key:aKey}); + nonce = aNonce ? aNonce.clone() : Clipperz.Crypto.PRNG.defaultRandomGenerator().getRandomBytes(128/8); + + encryptedData = Clipperz.Crypto.AES_2.encryptBlocks(key, someData.arrayValues(), nonce.arrayValues()); + + result = nonce.appendBytes(encryptedData); + + return result; + }, + + //----------------------------------------------------------------------------- + + 'decrypt': function(aKey, someData) { + var result; + var nonce; + var encryptedData; + var decryptedData; + var dataIterator; + var key; + + key = new Clipperz.Crypto.AES_2.Key({key:aKey}); + + encryptedData = someData.arrayValues(); + nonce = encryptedData.slice(0, (128/8)); + encryptedData = encryptedData.slice(128/8); + decryptedData = Clipperz.Crypto.AES_2.encryptBlocks(key, encryptedData, nonce); + + result = new Clipperz.ByteArray(decryptedData); + + return result; + }, + + //============================================================================= + + 'deferredEncryptExecutionChunk': function(anExecutionContext) { + var result; + var nonce; + var self; + var messageIndex; + var messageLength; + var blockSize; + var executionLimit; + + self = Clipperz.Crypto.AES_2; + blockSize = 128/8; + messageLength = anExecutionContext.messageArray().length; + nonce = anExecutionContext.nonceArray(); + result = anExecutionContext.resultArray(); + + messageIndex = anExecutionContext.executionStep(); + executionLimit = messageIndex + anExecutionContext.elaborationChunkSize(); + executionLimit = Math.min(executionLimit, messageLength); + + while (messageIndex < executionLimit) { + var encryptedBlock; + var i,c; + + encryptedBlock = self.encryptBlock(anExecutionContext.key(), nonce); + + if ((executionLimit - messageIndex) > blockSize) { + c = blockSize; + } else { + c = executionLimit - messageIndex; + } + + for (i=0; i<c; i++) { + result[messageIndex + i] = result[messageIndex + i] ^ encryptedBlock[i]; + } + + messageIndex += blockSize; + self.incrementNonce(nonce); + } + anExecutionContext.setExecutionStep(messageIndex); + + return anExecutionContext; + }, + + //----------------------------------------------------------------------------- + + 'deferredEncryptBlocks': function(anExecutionContext) { + var deferredResult; + var messageSize; + var i,c; + var now; + + messageSize = anExecutionContext.messageLength(); + + deferredResult = new MochiKit.Async.Deferred(); +//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Clipperz.Crypto.AES_2.deferredEncryptBlocks - START: " + res); return res;}); +// deferredResult.addCallback(MochiKit.Base.method(anExecutionContext, 'pause')); + + c = Math.ceil(messageSize / anExecutionContext.elaborationChunkSize()); + for (i=0; i<c; i++) { +//deferredResult.addBoth(function(res) {now = new Date(); return res;}); +//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Clipperz.Crypto.AES_2.deferredEncryptBlocks - : (" + i + ") - " + res); return res;}); + deferredResult.addCallback(Clipperz.Crypto.AES_2.deferredEncryptExecutionChunk); +//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("[" + (new Date() - now) + "]Clipperz.Crypto.AES_2.deferredEncryptBlocks"); return res;}); +//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Clipperz.Crypto.AES_2.deferredEncryptBlocks - : (" + i + ") -- " + res); return res;}); + deferredResult.addCallback(MochiKit.Base.method(anExecutionContext, 'pause')); +//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Clipperz.Crypto.AES_2.deferredEncryptBlocks - : (" + i + ") --- " + res); return res;}); + } +//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Clipperz.Crypto.AES_2.deferredEncryptBlocks - END: " + res); return res;}); + + deferredResult.callback(anExecutionContext); + + return deferredResult; + }, + + //----------------------------------------------------------------------------- + + 'deferredEncrypt': function(aKey, someData, aNonce) { + var deferredResult; + var executionContext; + var result; + var nonce; + var key; + + key = new Clipperz.Crypto.AES_2.Key({key:aKey}); + nonce = aNonce ? aNonce.clone() : Clipperz.Crypto.PRNG.defaultRandomGenerator().getRandomBytes(128/8); + + executionContext = new Clipperz.Crypto.AES_2.DeferredExecutionContext({key:key, message:someData, nonce:nonce}); + + deferredResult = new MochiKit.Async.Deferred(); +//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Clipperz.Crypto.AES_2.deferredEncrypt - 1: " + res); return res;}); + deferredResult.addCallback(Clipperz.Crypto.AES_2.deferredEncryptBlocks); +//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Clipperz.Crypto.AES_2.deferredEncrypt - 2: " + res); return res;}); + deferredResult.addCallback(function(anExecutionContext) { + var result; + + result = anExecutionContext.nonce().clone(); + result.appendBytes(anExecutionContext.resultArray()); + + return result; + }); +//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Clipperz.Crypto.AES_2.deferredEncrypt - 3: " + res); return res;}); + deferredResult.callback(executionContext) + + return deferredResult; + }, + + //----------------------------------------------------------------------------- + + 'deferredDecrypt': function(aKey, someData) { + var deferredResult + var nonce; + var message; + var key; + + key = new Clipperz.Crypto.AES_2.Key({key:aKey}); + nonce = someData.split(0, (128/8)); + message = someData.split(128/8); + executionContext = new Clipperz.Crypto.AES_2.DeferredExecutionContext({key:key, message:message, nonce:nonce}); + + deferredResult = new MochiKit.Async.Deferred(); + deferredResult.addCallback(Clipperz.Crypto.AES_2.deferredEncryptBlocks); + deferredResult.addCallback(function(anExecutionContext) { + return anExecutionContext.result(); + }); + deferredResult.callback(executionContext); + + return deferredResult; + }, + + //----------------------------------------------------------------------------- + __syntaxFix__: "syntax fix" + +}); + +//############################################################################# + +Clipperz.Crypto.AES_2.DeferredExecution = { + 'chunkSize': 4096, // 1024 4096 8192 16384 32768; + 'pauseTime': 0.2 +} + +Clipperz.Crypto.AES_2.exception = { + 'UnsupportedKeySize': new MochiKit.Base.NamedError("Clipperz.Crypto.AES_2.exception.UnsupportedKeySize") +}; diff --git a/frontend/beta/js/Clipperz/PM/Crypto.js b/frontend/beta/js/Clipperz/PM/Crypto.js index ad16ff0..e1e87ec 100644 --- a/frontend/beta/js/Clipperz/PM/Crypto.js +++ b/frontend/beta/js/Clipperz/PM/Crypto.js @@ -1,498 +1,525 @@ /* 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/. */ if (typeof(Clipperz) == 'undefined') { Clipperz = {}; } if (typeof(Clipperz.PM) == 'undefined') { Clipperz.PM = {}; } if (typeof(Clipperz.PM.Crypto) == 'undefined') { Clipperz.PM.Crypto = {}; } Clipperz.PM.Crypto.VERSION = "0.2"; Clipperz.PM.Crypto.NAME = "Clipperz.PM.Crypto"; MochiKit.Base.update(Clipperz.PM.Crypto, { '__repr__': function () { return "[" + this.NAME + " " + this.VERSION + "]"; }, //------------------------------------------------------------------------- 'toString': function () { return this.__repr__(); }, //------------------------------------------------------------------------- 'communicationProtocol': { 'currentVersion': '0.2', 'versions': { '0.1': Clipperz.PM.Connection.SRP['1.0'], //Clipperz.Crypto.SRP.versions['1.0'].Connection, '0.2': Clipperz.PM.Connection.SRP['1.1'] //Clipperz.Crypto.SRP.versions['1.1'].Connection, }, 'fallbackVersions': { 'current': '0.1', '0.2': '0.1', '0.1': null } }, //------------------------------------------------------------------------- 'encryptingFunctions': { - 'currentVersion': '0.3', + 'currentVersion': '0.4', 'versions': { //##################################################################### '0.1': { 'encrypt': function(aKey, aValue) { return Clipperz.Crypto.Base.encryptUsingSecretKey(aKey, Clipperz.Base.serializeJSON(aValue)); }, 'deferredEncrypt': function(aKey, aValue) { var deferredResult; deferredResult = new MochiKit.Async.Deferred(); deferredResult.addCallback(Clipperz.PM.Crypto.encryptingFunctions.versions['0.1'].encrypt, aKey, aValue); deferredResult.callback(); return deferredResult; }, 'decrypt': function(aKey, aValue) { var result; if (aValue != null) { result = Clipperz.Base.evalJSON(Clipperz.Crypto.Base.decryptUsingSecretKey(aKey, aValue)); } else { result = null; } return result; }, 'deferredDecrypt': function(aKey, aValue) { var deferredResult; deferredResult = new MochiKit.Async.Deferred(); deferredResult.addCallback(Clipperz.PM.Crypto.encryptingFunctions.versions['0.1'].decrypt, aKey, aValue); deferredResult.callback(); return deferredResult; }, 'hash': function(aValue) { var result; var strngResult; stringResult = Clipperz.Crypto.Base.computeHashValue(aValue.asString()); // !!!!!!! result = new Clipperz.ByteArray("0x" + stringResult); return result; } }, //##################################################################### '0.2': { 'encrypt': function(aKey, aValue, aNonce) { var result; var key, value; var dataToEncrypt; var encryptedData; key = Clipperz.Crypto.SHA.sha_d256(new Clipperz.ByteArray(aKey)); value = new Clipperz.ByteArray(Clipperz.Base.serializeJSON(aValue)); dataToEncrypt = Clipperz.Crypto.SHA.sha_d256(value).appendBlock(value); encryptedData = Clipperz.Crypto.AES.encrypt(key, dataToEncrypt, aNonce); result = encryptedData.toBase64String(); return result; }, 'deferredEncrypt': function(aKey, aValue, aNonce) { var deferredResult; var key, value; var dataToEncrypt; var encryptedData; key = Clipperz.Crypto.SHA.sha_d256(new Clipperz.ByteArray(aKey)); value = new Clipperz.ByteArray(Clipperz.Base.serializeJSON(aValue)); dataToEncrypt = Clipperz.Crypto.SHA.sha_d256(value).appendBlock(value); deferredResult = new MochiKit.Async.Deferred() deferredResult.addCallback(Clipperz.Crypto.AES.deferredEncrypt, key, dataToEncrypt, aNonce); deferredResult.addCallback(function(aResult) { return aResult.toBase64String(); }) deferredResult.callback(); return deferredResult; }, 'decrypt': function(aKey, aValue) { var result; if (aValue != null) { var key, value; var decryptedData; var decryptedData; key = Clipperz.Crypto.SHA.sha_d256(new Clipperz.ByteArray(aKey)); value = new Clipperz.ByteArray().appendBase64String(aValue); decryptedData = Clipperz.Crypto.AES.decrypt(key, value); decryptedData = decryptedData.split((256/8)); try { result = Clipperz.Base.evalJSON(decryptedData.asString()); } catch (exception) { MochiKit.Logging.logError("Error while decrypting data"); throw Clipperz.Crypto.Base.exception.CorruptedMessage; } } else { result = null; } return result; }, 'deferredDecrypt': function(aKey, aValue) { var result; if (aValue != null) { var deferredResult; var key, value; var decryptedData; result = new MochiKit.Async.Deferred(); key = Clipperz.Crypto.SHA.sha_d256(new Clipperz.ByteArray(aKey)); value = new Clipperz.ByteArray().appendBase64String(aValue); deferredResult = new MochiKit.Async.Deferred() deferredResult.addCallback(Clipperz.Crypto.AES.deferredDecrypt, key, value); deferredResult.addCallback(function(aResult) { var result; var decryptedData; decryptedData = aResult.split((256/8)); try { result = Clipperz.Base.evalJSON(decryptedData.asString()); } catch (exception) { MochiKit.Logging.logError("Error while decrypting data"); throw Clipperz.Crypto.Base.exception.CorruptedMessage; } return result; }) deferredResult.callback(); result = deferredResult; } else { result = MochiKit.Async.succeed(null); } return result; }, 'hash': Clipperz.Crypto.SHA.sha_d256 }, //##################################################################### '0.3': { 'encrypt': function(aKey, aValue, aNonce) { var result; var key, value; var data; var dataToEncrypt; var encryptedData; key = Clipperz.Crypto.SHA.sha_d256(new Clipperz.ByteArray(aKey)); value = Clipperz.Base.serializeJSON(aValue); data = new Clipperz.ByteArray(value); encryptedData = Clipperz.Crypto.AES.encrypt(key, data, aNonce); result = encryptedData.toBase64String(); return result; }, 'deferredEncrypt': function(aKey, aValue, aNonce) { var deferredResult; var key, value; var data; var dataToEncrypt; var encryptedData; key = Clipperz.Crypto.SHA.sha_d256(new Clipperz.ByteArray(aKey)); value = Clipperz.Base.serializeJSON(aValue); data = new Clipperz.ByteArray(value); deferredResult = new MochiKit.Async.Deferred() //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Clipperz.PM.Crypto.deferredEncrypt - 1: " + res); return res;}); deferredResult.addCallback(Clipperz.Crypto.AES.deferredEncrypt, key, data, aNonce); //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Clipperz.PM.Crypto.deferredEncrypt - 2: " + res); return res;}); deferredResult.addCallback(function(aResult) { return aResult.toBase64String(); }) //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Clipperz.PM.Crypto.deferredEncrypt - 3: " + res); return res;}); deferredResult.callback(); return deferredResult; }, 'decrypt': function(aKey, aValue) { var result; if (aValue != null) { var key, value; var decryptedData; var decryptedValue; key = Clipperz.Crypto.SHA.sha_d256(new Clipperz.ByteArray(aKey)); value = new Clipperz.ByteArray().appendBase64String(aValue); decryptedData = Clipperz.Crypto.AES.decrypt(key, value); value = decryptedData.asString(); try { result = Clipperz.Base.evalJSON(value); } catch (exception) { MochiKit.Logging.logError("Error while decrypting data"); throw Clipperz.Crypto.Base.exception.CorruptedMessage; } } else { result = null; } return result; }, 'deferredDecrypt': function(aKey, aValue) { var deferredResult; // var now; deferredResult = new MochiKit.Async.Deferred(); - now = new Date; +// now = new Date; //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("[" + (new Date() - now) + "] Clipperz.PM.Crypto.deferredDecrypt - 1: " + res); return res;}); if (aValue != null) { var key, value; var decryptedData; var decryptedValue; key = Clipperz.Crypto.SHA.sha_d256(new Clipperz.ByteArray(aKey)); //MochiKit.Logging.logDebug("[" + (new Date() - now) + "] computed key"); value = new Clipperz.ByteArray().appendBase64String(aValue); //MochiKit.Logging.logDebug("[" + (new Date() - now) + "] appendedBase64String"); //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("[" + (new Date() - now) + "] Clipperz.PM.Crypto.deferredDecrypt - 1.1: " /* + res*/); return res;}); deferredResult.addCallback(Clipperz.Crypto.AES.deferredDecrypt, key, value); //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("[" + (new Date() - now) + "] Clipperz.PM.Crypto.deferredDecrypt - 2: " /* + res*/); return res;}); deferredResult.addCallback(MochiKit.Async.wait, 0.1); //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("[" + (new Date() - now) + "] Clipperz.PM.Crypto.deferredDecrypt - 3: " /* + res*/); return res;}); deferredResult.addCallback(function(aResult) { return aResult.asString(); }); //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("[" + (new Date() - now) + "] Clipperz.PM.Crypto.deferredDecrypt - 4: " /* + res*/); return res;}); deferredResult.addCallback(MochiKit.Async.wait, 0.1); //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("[" + (new Date() - now) + "] Clipperz.PM.Crypto.deferredDecrypt - 5: " /* + res*/); return res;}); deferredResult.addCallback(Clipperz.Base.evalJSON); //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("[" + (new Date() - now) + "] Clipperz.PM.Crypto.deferredDecrypt - 6: " /* + res*/); return res;}); deferredResult.addErrback(function(anError) { MochiKit.Logging.logError("Error while decrypting data"); throw Clipperz.Crypto.Base.exception.CorruptedMessage; }) //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("[" + (new Date() - now) + "] Clipperz.PM.Crypto.deferredDecrypt - 7: " /* + res*/); return res;}); } else { deferredResult.addCallback(function() { return null; }); } deferredResult.callback(); return deferredResult; }, 'hash': Clipperz.Crypto.SHA.sha_d256 }, //##################################################################### -/* + '0.4': { 'encrypt': function(aKey, aValue, aNonce) { var result; var key, value; var data; var dataToEncrypt; var encryptedData; -//MochiKit.Logging.logDebug(">>> [" + (new Date()).valueOf() + "] Clipperz.PM.Crypto.versions[0.3].encrypt"); key = Clipperz.Crypto.SHA.sha_d256(new Clipperz.ByteArray(aKey)); -//MochiKit.Logging.logDebug("--- [" + (new Date()).valueOf() + "] Clipperz.PM.Crypto.versions[0.3].encrypt - 1"); value = Clipperz.Base.serializeJSON(aValue); -//MochiKit.Logging.logDebug("--- [" + (new Date()).valueOf() + "] Clipperz.PM.Crypto.versions[0.3].encrypt - 2"); -/ * -//MochiKit.Logging.logDebug("--> encrypt.fullSize: " + value.length); - value = value.replace(/":{"label":"/g, '":{l:"'); - value = value.replace(/":{"key":"/g, '":{k:"'); - value = value.replace(/":{"notes":"/g, '":{n:"'); - value = value.replace(/":{"record":"/g, '":{r:"'); - value = value.replace(/", "label":"/g, '",l:"'); - value = value.replace(/", "favicon":"/g, '",f:"'); -//MochiKit.Logging.logDebug("<-- encrypt.compressed: " + value.length); -* / data = new Clipperz.ByteArray(value); -//MochiKit.Logging.logDebug("--- [" + (new Date()).valueOf() + "] Clipperz.PM.Crypto.versions[0.3].encrypt - 3"); - encryptedData = Clipperz.Crypto.AES.encrypt(key, data, aNonce); -//MochiKit.Logging.logDebug("--- [" + (new Date()).valueOf() + "] Clipperz.PM.Crypto.versions[0.3].encrypt - 4"); + encryptedData = Clipperz.Crypto.AES_2.encrypt(key, data, aNonce); result = encryptedData.toBase64String(); -//MochiKit.Logging.logDebug("<<< [" + (new Date()).valueOf() + "] Clipperz.PM.Crypto.versions[0.3].encrypt"); return result; }, + 'deferredEncrypt': function(aKey, aValue, aNonce) { + var deferredResult; + var key, value; + var data; + var dataToEncrypt; + var encryptedData; + + key = Clipperz.Crypto.SHA.sha_d256(new Clipperz.ByteArray(aKey)); + value = Clipperz.Base.serializeJSON(aValue); + data = new Clipperz.ByteArray(value); + + deferredResult = new MochiKit.Async.Deferred() + deferredResult.addCallback(Clipperz.Crypto.AES_2.deferredEncrypt, key, data, aNonce); + deferredResult.addCallback(function(aResult) { + return aResult.toBase64String(); + }) + deferredResult.callback(); + + return deferredResult; + }, + 'decrypt': function(aKey, aValue) { var result; if (aValue != null) { var key, value; var decryptedData; var decryptedValue; key = Clipperz.Crypto.SHA.sha_d256(new Clipperz.ByteArray(aKey)); value = new Clipperz.ByteArray().appendBase64String(aValue); - decryptedData = Clipperz.Crypto.AES.decrypt(key, value); + decryptedData = Clipperz.Crypto.AES_2.decrypt(key, value); value = decryptedData.asString(); -/ * - value = value.replace(/":{l:"/g, '":{"label":"'); - value = value.replace(/":{k:"/g, '":{"key":"'); - value = value.replace(/":{n:"/g, '":{"notes":"'); - value = value.replace(/":{r:"/g, '":{"record":"'); - value = value.replace(/",l:"/g, '", "label":"'); - value = value.replace(/",f:"/g, '", "favicon":"'); -* / try { result = Clipperz.Base.evalJSON(value); } catch (exception) { MochiKit.Logging.logError("Error while decrypting data"); throw Clipperz.Crypto.Base.exception.CorruptedMessage; } - - } else { result = null; } return result; }, + 'deferredDecrypt': function(aKey, aValue) { + var deferredResult; + + deferredResult = new MochiKit.Async.Deferred(); + if (aValue != null) { + var key, value; + var decryptedData; + var decryptedValue; + + key = Clipperz.Crypto.SHA.sha_d256(new Clipperz.ByteArray(aKey)); + value = new Clipperz.ByteArray().appendBase64String(aValue); + deferredResult.addCallback(Clipperz.Crypto.AES_2.deferredDecrypt, key, value); + deferredResult.addCallback(MochiKit.Async.wait, 0.1); + deferredResult.addCallback(function(aResult) { + return aResult.asString(); + }); + deferredResult.addCallback(MochiKit.Async.wait, 0.1); + deferredResult.addCallback(Clipperz.Base.evalJSON); + deferredResult.addErrback(function(anError) { + MochiKit.Logging.logError("Error while decrypting data"); + throw Clipperz.Crypto.Base.exception.CorruptedMessage; + }) + } else { + deferredResult.addCallback(function() { + return null; + }); + } + deferredResult.callback(); + + return deferredResult; + }, + 'hash': Clipperz.Crypto.SHA.sha_d256 }, -*/ + //##################################################################### __syntaxFix__: "syntax fix" } }, //------------------------------------------------------------------------- 'encrypt': function(aKey, aValue, aVersion) { return Clipperz.PM.Crypto.encryptingFunctions.versions[aVersion].encrypt(aKey, aValue); }, 'deferredEncrypt': function(aKey, aValue, aVersion) { return Clipperz.PM.Crypto.encryptingFunctions.versions[aVersion].deferredEncrypt(aKey, aValue); }, 'encryptWithCurrentVersion': function(aKey, aValue) { return Clipperz.PM.Crypto.encrypt(aKey, aValue, Clipperz.PM.Crypto.encryptingFunctions.currentVersion); }, 'deferredEncryptWithCurrentVersion': function(aKey, aValue) { return Clipperz.PM.Crypto.deferredEncrypt(aKey, aValue, Clipperz.PM.Crypto.encryptingFunctions.currentVersion); }, //......................................................................... 'decrypt': function(aKey, aValue, aVersion) { return Clipperz.PM.Crypto.encryptingFunctions.versions[aVersion].decrypt(aKey, aValue); }, 'deferredDecrypt': function(aKey, aValue, aVersion) { return Clipperz.PM.Crypto.encryptingFunctions.versions[aVersion].deferredDecrypt(aKey, aValue); }, //------------------------------------------------------------------------- 'randomKey': function() { return Clipperz.Crypto.PRNG.defaultRandomGenerator().getRandomBytes(32).toHexString().substring(2); }, //------------------------------------------------------------------------- 'passwordEntropy': function(aValue) { var result; var bitPerChar; bitPerChar = 4; if (/[a-z]/.test(aValue)) { bitPerChar ++; } if (/[A-Z]/.test(aValue)) { bitPerChar ++; } if (/[^a-zA-Z0-9]/.test(aValue)) { bitPerChar ++; } //MochiKit.Logging.logDebug("--- bitPerChar: " + bitPerChar); result = aValue.length * bitPerChar; return result; }, //------------------------------------------------------------------------- 'nullValue': "####", //------------------------------------------------------------------------- __syntaxFix__: "syntax fix" }); //***************************************************************************** MochiKit.Base.update(Clipperz.PM.Crypto.communicationProtocol.versions, { 'current': Clipperz.PM.Crypto.communicationProtocol.versions[Clipperz.PM.Crypto.communicationProtocol.currentVersion] }); MochiKit.Base.update(Clipperz.PM.Crypto.encryptingFunctions.versions, { 'current': Clipperz.PM.Crypto.encryptingFunctions.versions[Clipperz.PM.Crypto.encryptingFunctions.currentVersion] }); //***************************************************************************** diff --git a/frontend/beta/properties/beta.properties.json b/frontend/beta/properties/beta.properties.json index bfa152d..7d34677 100644 --- a/frontend/beta/properties/beta.properties.json +++ b/frontend/beta/properties/beta.properties.json @@ -1,194 +1,195 @@ { "copyright.values": { "mochikit.repository": "http://svn.mochikit.com/mochikit/trunk/", "mochikit.version": "1249" }, "html.template": "index_template.html", "js": [ "MochiKit/Base.js", "MochiKit/Iter.js", "MochiKit/DOM.js", "MochiKit/Style.js", "MochiKit/Signal.js", "MochiKit/Format.js", "MochiKit/Async.js", "MochiKit/Selector.js", "MochiKit/Logging.js", "MochiKit/LoggingPane.js", "YUI/yahoo.js", "YUI/animation.js", "YUI/event.js", "YUI/dom.js", "YUI/dragdrop.js", "YUI/logger.js", "YUI-extensions/yutil.js", "YUI-extensions/Bench.js", "YUI-extensions/Date.js", "YUI-extensions/DomHelper.js", "YUI-extensions/Element.js", "YUI-extensions/CompositeElement.js", "YUI-extensions/State.js", "YUI-extensions/EventManager.js", "YUI-extensions/KeyMap.js", "YUI-extensions/Layer.js", "YUI-extensions/MixedCollection.js", "YUI-extensions/State.js", "YUI-extensions/UpdateManager.js", "YUI-extensions/anim/Actor.js", "YUI-extensions/anim/Animator.js", "YUI-extensions/dd/Registry.js", "YUI-extensions/dd/ScrollManager.js", "YUI-extensions/dd/StatusProxy.js", "YUI-extensions/layout/ContentPanels.js", "YUI-extensions/layout/LayoutManager.js", "YUI-extensions/layout/BorderLayout.js", "YUI-extensions/layout/BasicLayoutRegion.js", "YUI-extensions/layout/LayoutRegion.js", "YUI-extensions/layout/LayoutStateManager.js", "YUI-extensions/layout/SplitLayoutRegion.js", "YUI-extensions/layout/BorderLayoutRegions.js", "YUI-extensions/widgets/BasicDialog.js", "YUI-extensions/widgets/Button.js", "YUI-extensions/widgets/MessageBox.js", "YUI-extensions/widgets/Resizable.js", "YUI-extensions/widgets/SplitBar.js", "YUI-extensions/widgets/TabPanel.js", "YUI-extensions/widgets/TemplateView.js", "YUI-extensions/widgets/Toolbar.js", "YUI-extensions/widgets/InlineEditor.js", "YUI-extensions/widgets/QuickTips.js", "YUI-extensions/CSS.js", "JSON/json2.js", "Clipperz/ByteArray.js", "Clipperz/Base.js", "Clipperz/CSVProcessor.js", "Clipperz/KeePassExportProcessor.js", "Clipperz/Date.js", "Clipperz/DOM.js", "Clipperz/Signal.js", "Clipperz/Style.js", "Clipperz/Set.js", "Clipperz/NotificationCenter.js", "Clipperz/Crypto/SHA.js", "Clipperz/Crypto/AES.js", + "Clipperz/Crypto/AES_2.js", "Clipperz/Crypto/PRNG.js", "Clipperz/Crypto/BigInt.js", "Clipperz/Crypto/Base.js", "Clipperz/Crypto/SRP.js", "Clipperz/Crypto/RSA.js", "Clipperz/PM/Strings/Strings_en-US.js", "Clipperz/PM/Strings/Strings_it-IT.js", "Clipperz/PM/Strings/Strings_pt-BR.js", "Clipperz/PM/Strings/Strings_ja-JP.js", "Clipperz/PM/Strings/Strings_zh-CN.js", "Clipperz/PM/Strings/Strings_es-ES.js", "Clipperz/PM/Strings/Strings_fr-FR.js", "Clipperz/PM/Strings/Strings_ru-RU.js", "Clipperz/PM/Strings.js", "Clipperz/PM/Strings/MessagePanelConfigurations.js", "Clipperz/PM/Date.js", "Clipperz/PM/Components/BaseComponent.js", "Clipperz/PM/Components/MessageBox.js", "Clipperz/PM/Components/TextFormField.js", "Clipperz/PM/Components/PasswordEntropyDisplay.js", "Clipperz/PM/Components/PasswordGenerator.js", "Clipperz/PM/Components/Panels/BasePanel.js", "Clipperz/PM/Components/Panels/LoginPanel.js", "Clipperz/PM/Components/Panels/MainPanel.js", "Clipperz/PM/Components/Panels/AccountPanel.js", "Clipperz/PM/Components/Panels/DataPanel.js", "Clipperz/PM/Components/Panels/ContactsPanel.js", "Clipperz/PM/Components/Panels/ToolsPanel.js", "Clipperz/PM/Components/Panels/LogoutPanel.js", "Clipperz/PM/Components/RecordDetail/MainComponent.js", "Clipperz/PM/Components/RecordDetail/AbstractComponent.js", "Clipperz/PM/Components/RecordDetail/HeaderComponent.js", "Clipperz/PM/Components/RecordDetail/TitleComponent.js", "Clipperz/PM/Components/RecordDetail/NotesComponent.js", "Clipperz/PM/Components/RecordDetail/FieldComponent.js", "Clipperz/PM/Components/RecordDetail/AbstractFieldSubComponent.js", "Clipperz/PM/Components/RecordDetail/FieldButtonComponent.js", "Clipperz/PM/Components/RecordDetail/FieldLabelComponent.js", "Clipperz/PM/Components/RecordDetail/FieldDragHandler.js", "Clipperz/PM/Components/RecordDetail/FieldValueComponent.js", "Clipperz/PM/Components/RecordDetail/FieldTypeComponent.js", "Clipperz/PM/Components/RecordDetail/DirectLoginsComponent.js", "Clipperz/PM/Components/RecordDetail/DirectLoginComponent.js", "Clipperz/PM/Components/RecordDetail/DirectLoginBindingComponent.js", "Clipperz/PM/Components/RecordDetail/DirectLoginValueComponent.js", "Clipperz/PM/Components/RecordDetail/CreationWizard.js", "Clipperz/PM/Components/TabPanel/TabPanelController.js", "Clipperz/PM/Components/Import/MainComponent.js", "Clipperz/PM/Components/Import/GenericImportComponent.js", "Clipperz/PM/Components/Import/CSVImportComponent.js", "Clipperz/PM/Components/Import/CSVImport/CSVImportColumns.js", "Clipperz/PM/Components/Import/CSVImport/CSVImportHeader.js", "Clipperz/PM/Components/Import/CSVImport/CSVImportTitle.js", "Clipperz/PM/Components/Import/CSVImport/CSVImportNotes.js", "Clipperz/PM/Components/Import/CSVImport/CSVImportFields.js", "Clipperz/PM/Components/Import/ExcelImportComponent.js", "Clipperz/PM/Components/Import/PasswordPlusImportComponent.js", "Clipperz/PM/Components/Import/ClipperzImportComponent.js", "Clipperz/PM/Components/Import/RoboFormImportComponent.js", "Clipperz/PM/Components/Import/KeePassImportComponent.js", "Clipperz/PM/Components/Printing/Header.js", "Clipperz/PM/Components/Printing/Record.js", "Clipperz/PM/Components/Printing/Footer.js", "Clipperz/PM/Components/OTP/MainComponent.js", "Clipperz/PM/Components/Compact/CompactHeader.js", "Clipperz/PM/Components/Compact/LoginForm.js", "Clipperz/PM/Components/Compact/CompactInterface.js", "Clipperz/PM/Toll.js", "Clipperz/PM/Proxy.js", "Clipperz/PM/Proxy/Proxy.JSON.js", "Clipperz/PM/Proxy/Proxy.Offline.js", "Clipperz/PM/Proxy/Proxy.Offline.DataStore.js", "Clipperz/PM/Connection.js", "Clipperz/PM/Crypto.js", "Clipperz/PM/BookmarkletProcessor.js", "Clipperz/PM/DataModel/User.js", "Clipperz/PM/DataModel/UserPreferences.js", "Clipperz/PM/DataModel/Header.js", "Clipperz/PM/DataModel/Statistics.js", "Clipperz/PM/DataModel/Record.js", "Clipperz/PM/DataModel/RecordField.js", "Clipperz/PM/DataModel/RecordVersion.js", "Clipperz/PM/DataModel/DirectLogin.js", "Clipperz/PM/DataModel/DirectLoginReference.js", "Clipperz/PM/DataModel/DirectLoginInput.js", "Clipperz/PM/DataModel/DirectLoginBinding.js", "Clipperz/PM/DataModel/OneTimePasswordManager.js", "Clipperz/PM/DataModel/OneTimePassword.js", "Clipperz/YUI/IBLayoutManager.js", "Clipperz/YUI/IBLayoutRegion.js", "Clipperz/YUI/Drawer.js", "Clipperz/YUI/Collapser.js", "Clipperz/YUI/MessageBox.js", "Clipperz/YUI/DomHelper.js", "Clipperz/PM/Main.js" ], "css": [ "yui-extensions/reset-min.css", "yui-extensions/core.css", "yui-extensions/basic-dialog.css", "yui-extensions/button.css", "clipperz/clipperz.css", "clipperz/compact.css", "clipperz/ytheme-clipperz.css" ], "staticResources": [ "accountDeleted.html", "error.html", "logout.html", "static.css" ] } diff --git a/frontend/gamma/js/Clipperz/Crypto/AES_2.js b/frontend/gamma/js/Clipperz/Crypto/AES_2.js new file mode 100644 index 0000000..1627f39 --- a/dev/null +++ b/frontend/gamma/js/Clipperz/Crypto/AES_2.js @@ -0,0 +1,843 @@ +/* + +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/. + +*/ + +try { if (typeof(Clipperz.ByteArray) == 'undefined') { throw ""; }} catch (e) { + throw "Clipperz.Crypto.AES_2 depends on Clipperz.ByteArray!"; +} + +// Dependency commented to avoid a circular reference +//try { if (typeof(Clipperz.Crypto.PRNG) == 'undefined') { throw ""; }} catch (e) { +// throw "Clipperz.Crypto.AES_2 depends on Clipperz.Crypto.PRNG!"; +//} + +if (typeof(Clipperz.Crypto.AES_2) == 'undefined') { Clipperz.Crypto.AES_2 = {}; } + +//############################################################################# + +Clipperz.Crypto.AES_2.DeferredExecutionContext = function(args) { + args = args || {}; + + this._key = args.key; + this._message = args.message; + this._result = args.message.clone(); + this._nonce = args.nonce; + this._messageLength = this._message.length(); + + this._messageArray = this._message.arrayValues(); + this._resultArray = this._result.arrayValues(); + this._nonceArray = this._nonce.arrayValues(); + + this._executionStep = 0; + +// this._elaborationChunkSize = 1024; // 4096; // 16384; // 4096; + this._elaborationChunks = 10; + this._pauseTime = 0.02; // 0.02 // 0.2; + + return this; +} + +Clipperz.Crypto.AES_2.DeferredExecutionContext.prototype = MochiKit.Base.update(null, { + + 'key': function() { + return this._key; + }, + + 'message': function() { + return this._message; + }, + + 'messageLength': function() { + return this._messageLength; + }, + + 'result': function() { + return new Clipperz.ByteArray(this.resultArray()); + }, + + 'nonce': function() { + return this._nonce; + }, + + 'messageArray': function() { + return this._messageArray; + }, + + 'resultArray': function() { + return this._resultArray; + }, + + 'nonceArray': function() { + return this._nonceArray; + }, + + 'elaborationChunkSize': function() { +// return Clipperz.Crypto.AES_2.DeferredExecution.chunkSize; +// return this._elaborationChunkSize; + return (this._elaborationChunks * 1024); + }, + + 'executionStep': function() { + return this._executionStep; + }, + + 'setExecutionStep': function(aValue) { + this._executionStep = aValue; + }, + + 'tuneExecutionParameters': function (anElapsedTime) { +//var originalChunks = this._elaborationChunks; + if (anElapsedTime > 0) { + this._elaborationChunks = Math.round(this._elaborationChunks * ((anElapsedTime + 1000)/(anElapsedTime * 2))); + } +//Clipperz.log("tuneExecutionParameters - elapsedTime: " + anElapsedTime + /*originalChunks,*/ " chunks # " + this._elaborationChunks + " [" + this._executionStep + " / " + this._messageLength + "]"); + }, + + 'pause': function(aValue) { +// return MochiKit.Async.wait(Clipperz.Crypto.AES_2.DeferredExecution.pauseTime, aValue); + return MochiKit.Async.wait(this._pauseTime, aValue); + }, + + 'isDone': function () { + return (this._executionStep >= this._messageLength); + }, + + //----------------------------------------------------------------------------- + __syntaxFix__: "syntax fix" + +}); + +//############################################################################# + +Clipperz.Crypto.AES_2.Key = function(args) { + args = args || {}; + + this._key = args.key; + this._keySize = args.keySize || this.key().length(); + + if (this.keySize() == 128/8) { + this._b = 176; + this._numberOfRounds = 10; + } else if (this.keySize() == 256/8) { + this._b = 240; + this._numberOfRounds = 14; + } else { + Clipperz.logError("AES unsupported key size: " + (this.keySize() * 8) + " bits"); + throw Clipperz.Crypto.AES_2.exception.UnsupportedKeySize; + } + + this._stretchedKey = null; + + return this; +} + +Clipperz.Crypto.AES_2.Key.prototype = MochiKit.Base.update(null, { + + 'asString': function() { + return "Clipperz.Crypto.AES_2.Key (" + this.key().toHexString() + ")"; + }, + + //----------------------------------------------------------------------------- + + 'key': function() { + return this._key; + }, + + 'keySize': function() { + return this._keySize; + }, + + 'b': function() { + return this._b; + }, + + 'numberOfRounds': function() { + return this._numberOfRounds; + }, + //========================================================================= + + 'keyScheduleCore': function(aWord, aRoundConstantsIndex) { + var result; + var sbox; + + sbox = Clipperz.Crypto.AES_2.sbox(); + + result = [ sbox[aWord[1]] ^ Clipperz.Crypto.AES_2.roundConstants()[aRoundConstantsIndex], + sbox[aWord[2]], + sbox[aWord[3]], + sbox[aWord[0]] ]; + + return result; + }, + + //----------------------------------------------------------------------------- + + 'xorWithPreviousStretchValues': function(aKey, aWord, aPreviousWordIndex) { + var result; + var i,c; + + result = []; + c = 4; + for (i=0; i<c; i++) { + result[i] = aWord[i] ^ aKey.byteAtIndex(aPreviousWordIndex + i); + } + + return result; + }, + + //----------------------------------------------------------------------------- + + 'sboxShakeup': function(aWord) { + var result; + var sbox; + var i,c; + + result = []; + sbox = Clipperz.Crypto.AES_2.sbox(); + c =4; + for (i=0; i<c; i++) { + result[i] = sbox[aWord[i]]; + } + + return result; + }, + + //----------------------------------------------------------------------------- + + 'stretchKey': function(aKey) { + var currentWord; + var keyLength; + var previousStretchIndex; + var i,c; + + keyLength = aKey.length(); + previousStretchIndex = keyLength - this.keySize(); + + currentWord = [ aKey.byteAtIndex(keyLength - 4), + aKey.byteAtIndex(keyLength - 3), + aKey.byteAtIndex(keyLength - 2), + aKey.byteAtIndex(keyLength - 1) ]; + currentWord = this.keyScheduleCore(currentWord, keyLength / this.keySize()); + + if (this.keySize() == 256/8) { + c = 8; + } else if (this.keySize() == 128/8){ + c = 4; + } + + for (i=0; i<c; i++) { + if (i == 4) { + // fifth streatch word + currentWord = this.sboxShakeup(currentWord); + } + + currentWord = this.xorWithPreviousStretchValues(aKey, currentWord, previousStretchIndex + (i*4)); + aKey.appendBytes(currentWord); + } + + return aKey; + }, + + //----------------------------------------------------------------------------- + + 'stretchedKey': function() { + if (this._stretchedKey == null) { + var stretchedKey; + + stretchedKey = this.key().clone(); + + while (stretchedKey.length() < this.keySize()) { + stretchedKey.appendByte(0); + } + + while (stretchedKey.length() < this.b()) { + stretchedKey = this.stretchKey(stretchedKey); + } + + this._stretchedKey = stretchedKey.split(0, this.b()); + } + + return this._stretchedKey; + }, + + //========================================================================= + __syntaxFix__: "syntax fix" +}); + +//############################################################################# + +Clipperz.Crypto.AES_2.State = function(args) { + args = args || {}; + + this._data = args.block.slice(0); + this._key = args.key; + + return this; +} + +Clipperz.Crypto.AES_2.State.prototype = MochiKit.Base.update(null, { + + 'key': function() { + return this._key; + }, + + //----------------------------------------------------------------------------- + + 'data': function() { + return this._data; + }, + + 'setData': function(aValue) { + this._data = aValue; + }, + + //========================================================================= + + 'addRoundKey': function(aRoundNumber) { + // each byte of the state is combined with the round key; each round key is derived from the cipher key using a key schedule. + var data; + var stretchedKey; + var firstStretchedKeyIndex; + var i,c; + + data = this.data(); + stretchedKey = this.key().stretchedKey(); + firstStretchedKeyIndex = aRoundNumber * (128/8); + c = 128/8; + for (i=0; i<c; i++) { + data[i] = data[i] ^ stretchedKey.byteAtIndex(firstStretchedKeyIndex + i); + } + }, + + //----------------------------------------------------------------------------- + + 'subBytes': function() { + // a non-linear substitution step where each byte is replaced with another according to a lookup table. + var i,c; + var data; + var sbox; + + data = this.data(); + sbox = Clipperz.Crypto.AES_2.sbox(); + + c = 16; + for (i=0; i<c; i++) { + data[i] = sbox[data[i]]; + } + }, + + //----------------------------------------------------------------------------- + + 'shiftRows': function() { + // a transposition step where each row of the state is shifted cyclically a certain number of steps. + var newValue; + var data; + var shiftMapping; + var i,c; + + newValue = new Array(16); + data = this.data(); + shiftMapping = Clipperz.Crypto.AES_2.shiftRowMapping(); +// [0, 5, 10, 15, 4, 9, 14, 3, 8, 13, 2, 7, 12, 1, 6, 11]; + c = 16; + for (i=0; i<c; i++) { + newValue[i] = data[shiftMapping[i]]; + } + for (i=0; i<c; i++) { + data[i] = newValue[i]; + } + }, + + //----------------------------------------------------------------------------- +/* + 'mixColumnsWithValues': function(someValues) { + var result; + var a; + var i,c; + + c = 4; + result = []; + a = []; + for (i=0; i<c; i++) { + a[i] = []; + a[i][1] = someValues[i] + if ((a[i][1] & 0x80) == 0x80) { + a[i][2] = (a[i][1] << 1) ^ 0x11b; + } else { + a[i][2] = a[i][1] << 1; + } + + a[i][3] = a[i][2] ^ a[i][1]; + } + + for (i=0; i<c; i++) { + var x; + + x = Clipperz.Crypto.AES_2.mixColumnsMatrix()[i]; + result[i] = a[0][x[0]] ^ a[1][x[1]] ^ a[2][x[2]] ^ a[3][x[3]]; + } + + return result; + }, + + 'mixColumns': function() { + // a mixing operation which operates on the columns of the state, combining the four bytes in each column using a linear transformation. + var data; + var i, c; + + data = this.data(); + c = 4; + for(i=0; i<c; i++) { + var blockIndex; + var mixedValues; + + blockIndex = i * 4; + mixedValues = this.mixColumnsWithValues([ data[blockIndex + 0], + data[blockIndex + 1], + data[blockIndex + 2], + data[blockIndex + 3]]); + data[blockIndex + 0] = mixedValues[0]; + data[blockIndex + 1] = mixedValues[1]; + data[blockIndex + 2] = mixedValues[2]; + data[blockIndex + 3] = mixedValues[3]; + } + }, +*/ + + 'mixColumns': function() { + // a mixing operation which operates on the columns of the state, combining the four bytes in each column using a linear transformation. + var data; + var i, c; + var a_1; + var a_2; + + a_1 = new Array(4); + a_2 = new Array(4); + + data = this.data(); + c = 4; + for(i=0; i<c; i++) { + var blockIndex; + var ii, cc; + + blockIndex = i * 4; + + cc = 4; + for (ii=0; ii<cc; ii++) { + var value; + + value = data[blockIndex + ii]; + a_1[ii] = value; + a_2[ii] = (value & 0x80) ? ((value << 1) ^ 0x011b) : (value << 1); + } + + data[blockIndex + 0] = a_2[0] ^ a_1[1] ^ a_2[1] ^ a_1[2] ^ a_1[3]; + data[blockIndex + 1] = a_1[0] ^ a_2[1] ^ a_1[2] ^ a_2[2] ^ a_1[3]; + data[blockIndex + 2] = a_1[0] ^ a_1[1] ^ a_2[2] ^ a_1[3] ^ a_2[3]; + data[blockIndex + 3] = a_1[0] ^ a_2[0] ^ a_1[1] ^ a_1[2] ^ a_2[3]; + } + }, + + //========================================================================= + + 'spinRound': function(aRoundNumber) { + this.addRoundKey(aRoundNumber); + this.subBytes(); + this.shiftRows(); + this.mixColumns(); + }, + + 'spinLastRound': function() { + this.addRoundKey(this.key().numberOfRounds() - 1); + this.subBytes(); + this.shiftRows(); + this.addRoundKey(this.key().numberOfRounds()); + }, + + //========================================================================= + + 'encrypt': function() { + var i,c; + + c = this.key().numberOfRounds() - 1; + for (i=0; i<c; i++) { + this.spinRound(i); + } + + this.spinLastRound(); + }, + + //========================================================================= + __syntaxFix__: "syntax fix" +}); + +//############################################################################# + +Clipperz.Crypto.AES_2.VERSION = "0.1"; +Clipperz.Crypto.AES_2.NAME = "Clipperz.Crypto.AES_2"; + +MochiKit.Base.update(Clipperz.Crypto.AES_2, { + +// http://www.cs.eku.edu/faculty/styer/460/Encrypt/JS-AES.html +// http://en.wikipedia.org/wiki/Advanced_Encryption_Standard +// http://en.wikipedia.org/wiki/Rijndael_key_schedule +// http://en.wikipedia.org/wiki/Rijndael_S-box + + '__repr__': function () { + return "[" + this.NAME + " " + this.VERSION + "]"; + }, + + 'toString': function () { + return this.__repr__(); + }, + + //============================================================================= + + '_sbox': null, + 'sbox': function() { + if (Clipperz.Crypto.AES_2._sbox == null) { + Clipperz.Crypto.AES_2._sbox = [ +0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b, 0xfe, 0xd7, 0xab, 0x76, +0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0, 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0, +0xb7, 0xfd, 0x93, 0x26, 0x36, 0x3f, 0xf7, 0xcc, 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15, +0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a, 0x07, 0x12, 0x80, 0xe2, 0xeb, 0x27, 0xb2, 0x75, +0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0, 0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84, +0x53, 0xd1, 0x00, 0xed, 0x20, 0xfc, 0xb1, 0x5b, 0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf, +0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, 0x45, 0xf9, 0x02, 0x7f, 0x50, 0x3c, 0x9f, 0xa8, +0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5, 0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2, +0xcd, 0x0c, 0x13, 0xec, 0x5f, 0x97, 0x44, 0x17, 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73, +0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, 0x46, 0xee, 0xb8, 0x14, 0xde, 0x5e, 0x0b, 0xdb, +0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c, 0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79, +0xe7, 0xc8, 0x37, 0x6d, 0x8d, 0xd5, 0x4e, 0xa9, 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08, +0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6, 0xe8, 0xdd, 0x74, 0x1f, 0x4b, 0xbd, 0x8b, 0x8a, +0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e, 0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e, +0xe1, 0xf8, 0x98, 0x11, 0x69, 0xd9, 0x8e, 0x94, 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf, +0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 0x41, 0x99, 0x2d, 0x0f, 0xb0, 0x54, 0xbb, 0x16 + ]; + } + + return Clipperz.Crypto.AES_2._sbox; + }, + + //----------------------------------------------------------------------------- + // + // 0 4 8 12 0 4 8 12 + // 1 5 9 13 => 5 9 13 1 + // 2 6 10 14 10 14 2 6 + // 3 7 11 15 15 3 7 11 + // + '_shiftRowMapping': null, + 'shiftRowMapping': function() { + if (Clipperz.Crypto.AES_2._shiftRowMapping == null) { + Clipperz.Crypto.AES_2._shiftRowMapping = [0, 5, 10, 15, 4, 9, 14, 3, 8, 13, 2, 7, 12, 1, 6, 11]; + } + + return Clipperz.Crypto.AES_2._shiftRowMapping; + }, + + //----------------------------------------------------------------------------- + + '_mixColumnsMatrix': null, + 'mixColumnsMatrix': function() { + if (Clipperz.Crypto.AES_2._mixColumnsMatrix == null) { + Clipperz.Crypto.AES_2._mixColumnsMatrix = [ [2, 3, 1 ,1], + [1, 2, 3, 1], + [1, 1, 2, 3], + [3, 1, 1, 2] ]; + } + + return Clipperz.Crypto.AES_2._mixColumnsMatrix; + }, + + '_roundConstants': null, + 'roundConstants': function() { + if (Clipperz.Crypto.AES_2._roundConstants == null) { + Clipperz.Crypto.AES_2._roundConstants = [ , 1, 2, 4, 8, 16, 32, 64, 128, 27, 54, 108, 216, 171, 77, 154]; +// Clipperz.Crypto.AES_2._roundConstants = [ , 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a]; + } + + return Clipperz.Crypto.AES_2._roundConstants; + }, + + //============================================================================= + + 'incrementNonce': function(nonce) { + var i; + var done; + + done = false; + i = nonce.length - 1; + + while ((i>=0) && (done == false)) { + var currentByteValue; + + currentByteValue = nonce[i]; + + if (currentByteValue == 0xff) { + nonce[i] = 0; + if (i>= 0) { + i --; + } else { + done = true; + } + } else { + nonce[i] = currentByteValue + 1; + done = true; + } + } + }, + + //----------------------------------------------------------------------------- + + 'encryptBlock': function(aKey, aBlock) { + var result; + var state; + + state = new Clipperz.Crypto.AES_2.State({block:aBlock, key:aKey}); +//is(state.data(), 'before'); + state.encrypt(); + result = state.data(); + + return result; + }, + + //----------------------------------------------------------------------------- + + 'encryptBlocks': function(aKey, aMessage, aNonce) { + var result; + var nonce; + var self; + var messageIndex; + var messageLength; + var blockSize; + + self = Clipperz.Crypto.AES_2; + blockSize = 128/8; + messageLength = aMessage.length; + nonce = aNonce; + + result = aMessage; + messageIndex = 0; + while (messageIndex < messageLength) { + var encryptedBlock; + var i,c; + + encryptedBlock = self.encryptBlock(aKey, nonce); + + if ((messageLength - messageIndex) > blockSize) { + c = blockSize; + } else { + c = messageLength - messageIndex; + } + + for (i=0; i<c; i++) { + result[messageIndex + i] = result[messageIndex + i] ^ encryptedBlock[i]; + } + + messageIndex += blockSize; +// nonce = self.incrementNonce(nonce); + self.incrementNonce(nonce) + } + + return result; + }, + + //----------------------------------------------------------------------------- + + 'encrypt': function(aKey, someData, aNonce) { + var result; + var nonce; + var encryptedData; + var key; + + key = new Clipperz.Crypto.AES_2.Key({key:aKey}); + nonce = aNonce ? aNonce.clone() : Clipperz.Crypto.PRNG.defaultRandomGenerator().getRandomBytes(128/8); + + encryptedData = Clipperz.Crypto.AES_2.encryptBlocks(key, someData.arrayValues(), nonce.arrayValues()); + + result = nonce.appendBytes(encryptedData); + + return result; + }, + + //----------------------------------------------------------------------------- + + 'decrypt': function(aKey, someData) { + var result; + var nonce; + var encryptedData; + var decryptedData; + var dataIterator; + var key; + + key = new Clipperz.Crypto.AES_2.Key({key:aKey}); + + encryptedData = someData.arrayValues(); + nonce = encryptedData.slice(0, (128/8)); + encryptedData = encryptedData.slice(128/8); + decryptedData = Clipperz.Crypto.AES_2.encryptBlocks(key, encryptedData, nonce); + + result = new Clipperz.ByteArray(decryptedData); + + return result; + }, + + //============================================================================= + + 'deferredEncryptExecutionChunk': function(anExecutionContext) { + var result; + var nonce; + var self; + var messageIndex; + var messageLength; + var blockSize; + var executionLimit; + var startTime, endTime; + + self = Clipperz.Crypto.AES_2; + startTime = new Date(); + blockSize = 128/8; + messageLength = anExecutionContext.messageArray().length; + nonce = anExecutionContext.nonceArray(); + result = anExecutionContext.resultArray(); + + messageIndex = anExecutionContext.executionStep(); + executionLimit = messageIndex + anExecutionContext.elaborationChunkSize(); + executionLimit = Math.min(executionLimit, messageLength); + + while (messageIndex < executionLimit) { + var encryptedBlock; + var i,c; + +//console.log("+++ nonce: [" + nonce + "]") + encryptedBlock = self.encryptBlock(anExecutionContext.key(), nonce); + + if ((executionLimit - messageIndex) > blockSize) { + c = blockSize; + } else { + c = executionLimit - messageIndex; + } + + for (i=0; i<c; i++) { + result[messageIndex + i] = result[messageIndex + i] ^ encryptedBlock[i]; + } + + messageIndex += blockSize; +// nonce = self.incrementNonce(nonce); + self.incrementNonce(nonce); + } + anExecutionContext.setExecutionStep(messageIndex); + endTime = new Date(); + anExecutionContext.tuneExecutionParameters(endTime - startTime); + + return anExecutionContext; + }, + + //----------------------------------------------------------------------------- + + 'deferredEncryptBlocks': function(anExecutionContext) { + var deferredResult; + +//console.log("executionContext", anExecutionContext) +//console.log(" --- nonce: " + anExecutionContext.nonceArray()) + if (! anExecutionContext.isDone()) { + deferredResult = Clipperz.Async.callbacks("Clipperz.Crypto.AES_2.deferredEncryptBloks", [ + Clipperz.Crypto.AES_2.deferredEncryptExecutionChunk, + MochiKit.Base.method(anExecutionContext, 'pause'), + Clipperz.Crypto.AES_2.deferredEncryptBlocks + ], {trace:false}, anExecutionContext); + } else { + deferredResult = MochiKit.Async.succeed(anExecutionContext); + } + + return deferredResult; + }, + + //----------------------------------------------------------------------------- + + 'deferredEncrypt': function(aKey, someData, aNonce) { + var deferredResult; + var executionContext; + var result; + var nonce; + var key; + + key = new Clipperz.Crypto.AES_2.Key({key:aKey}); + nonce = aNonce ? aNonce.clone() : Clipperz.Crypto.PRNG.defaultRandomGenerator().getRandomBytes(128/8); + + executionContext = new Clipperz.Crypto.AES_2.DeferredExecutionContext({key:key, message:someData, nonce:nonce}); + + deferredResult = new Clipperz.Async.Deferred("AES.deferredEncrypt"); + deferredResult.addCallback(Clipperz.Crypto.AES_2.deferredEncryptBlocks); + deferredResult.addCallback(function(anExecutionContext) { + var result; + + result = anExecutionContext.nonce().clone(); + result.appendBytes(anExecutionContext.resultArray()); + + return result; + }); + deferredResult.callback(executionContext) + + return deferredResult; + }, + + //----------------------------------------------------------------------------- + + 'deferredDecrypt': function(aKey, someData) { + var deferredResult + var nonce; + var message; + var key; + + key = new Clipperz.Crypto.AES_2.Key({key:aKey}); + nonce = someData.split(0, (128/8)); +//console.log("nonce: [" + nonce.arrayValues() + "]") + message = someData.split(128/8); +//console.log("message: [" + message.arrayValues() + "]") + executionContext = new Clipperz.Crypto.AES_2.DeferredExecutionContext({key:key, message:message, nonce:nonce}); + + deferredResult = new Clipperz.Async.Deferred("AES.deferredDecrypt"); + deferredResult.addCallback(Clipperz.Crypto.AES_2.deferredEncryptBlocks); + deferredResult.addCallback(function(anExecutionContext) { + return anExecutionContext.result(); + }); + deferredResult.callback(executionContext); + + return deferredResult; + }, + + //----------------------------------------------------------------------------- + __syntaxFix__: "syntax fix" + +}); + +//############################################################################# + +//Clipperz.Crypto.AES_2.DeferredExecution = { +// 'chunkSize': 16384, // 4096, // 1024 4096 8192 16384 32768; +// 'pauseTime': 0.02 // 0.2 +//} + +Clipperz.Crypto.AES_2.exception = { + 'UnsupportedKeySize': new MochiKit.Base.NamedError("Clipperz.Crypto.AES_2.exception.UnsupportedKeySize") +}; diff --git a/frontend/gamma/js/Clipperz/PM/Crypto.js b/frontend/gamma/js/Clipperz/PM/Crypto.js index cd10e33..7edf17f 100644 --- a/frontend/gamma/js/Clipperz/PM/Crypto.js +++ b/frontend/gamma/js/Clipperz/PM/Crypto.js @@ -1,508 +1,546 @@ /* 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/. */ if (typeof(Clipperz) == 'undefined') { Clipperz = {}; } if (typeof(Clipperz.PM) == 'undefined') { Clipperz.PM = {}; } if (typeof(Clipperz.PM.Crypto) == 'undefined') { Clipperz.PM.Crypto = {}; } Clipperz.PM.Crypto.VERSION = "0.2"; Clipperz.PM.Crypto.NAME = "Clipperz.PM.Crypto"; Clipperz.PM.Crypto.encryptingFunctions = {}; MochiKit.Base.update(Clipperz.PM.Crypto, { '__repr__': function () { return "[" + this.NAME + " " + this.VERSION + "]"; }, //------------------------------------------------------------------------- 'toString': function () { return this.__repr__(); }, //------------------------------------------------------------------------- /* 'communicationProtocol': { 'currentVersion': '0.2', 'versions': { '0.1': Clipperz.PM.Connection.SRP['1.0'], //Clipperz.Crypto.SRP.versions['1.0'].Connection, '0.2': Clipperz.PM.Connection.SRP['1.1'] //Clipperz.Crypto.SRP.versions['1.1'].Connection }, 'fallbackVersions': { 'current': '0.1', '0.2': '0.1', '0.1': null } }, */ //------------------------------------------------------------------------- 'encryptingFunctions': { - 'currentVersion': '0.3', + 'currentVersion': '0.4', 'versions': { //##################################################################### '0.1': { 'encrypt': function(aKey, aValue) { return Clipperz.Crypto.Base.encryptUsingSecretKey(aKey, Clipperz.Base.serializeJSON(aValue)); }, 'deferredEncrypt': function(aKey, aValue) { var deferredResult; deferredResult = new Clipperz.Async.Deferred("Crypto[0.1].deferredEncrypt"); deferredResult.addCallback(Clipperz.PM.Crypto.encryptingFunctions.versions['0.1'].encrypt, aKey, aValue); deferredResult.callback(); return deferredResult; }, 'decrypt': function(aKey, aValue) { var result; if (aValue != null) { result = Clipperz.Base.evalJSON(Clipperz.Crypto.Base.decryptUsingSecretKey(aKey, aValue)); } else { result = null; } return result; }, 'deferredDecrypt': function(aKey, aValue) { var deferredResult; deferredResult = new Clipperz.Async.Deferred("Crypto.[0.1].deferredDecrypt"); deferredResult.addCallback(Clipperz.PM.Crypto.encryptingFunctions.versions['0.1'].decrypt, aKey, aValue); deferredResult.callback(); return deferredResult; }, 'hash': function(aValue) { var result; var strngResult; stringResult = Clipperz.Crypto.Base.computeHashValue(aValue.asString()); // !!!!!!! result = new Clipperz.ByteArray("0x" + stringResult); return result; }, 'deriveKey': function(aStringValue) { return Clipperz.Crypto.Base.computeHashValue(aStringValue); } }, //##################################################################### '0.2': { 'encrypt': function(aKey, aValue, aNonce) { var result; var key, value; var dataToEncrypt; var encryptedData; key = Clipperz.Crypto.SHA.sha_d256(new Clipperz.ByteArray(aKey)); value = new Clipperz.ByteArray(Clipperz.Base.serializeJSON(aValue)); dataToEncrypt = Clipperz.Crypto.SHA.sha_d256(value).appendBlock(value); encryptedData = Clipperz.Crypto.AES.encrypt(key, dataToEncrypt, aNonce); result = encryptedData.toBase64String(); return result; }, 'deferredEncrypt': function(aKey, aValue, aNonce) { var deferredResult; var key, value; var dataToEncrypt; // var encryptedData; key = Clipperz.Crypto.SHA.sha_d256(new Clipperz.ByteArray(aKey)); value = new Clipperz.ByteArray(Clipperz.Base.serializeJSON(aValue)); dataToEncrypt = Clipperz.Crypto.SHA.sha_d256(value).appendBlock(value); deferredResult = new Clipperz.Async.Deferred("Crypto[0.2].deferredEncrypt") deferredResult.addCallback(Clipperz.Crypto.AES.deferredEncrypt, key, dataToEncrypt, aNonce); deferredResult.addCallback(function(aResult) { return aResult.toBase64String(); }) deferredResult.callback(); return deferredResult; }, 'decrypt': function(aKey, aValue) { var result; if (aValue != null) { var key, value; var decryptedData; var decryptedValue; key = Clipperz.Crypto.SHA.sha_d256(new Clipperz.ByteArray(aKey)); value = new Clipperz.ByteArray().appendBase64String(aValue); decryptedData = Clipperz.Crypto.AES.decrypt(key, value); decryptedValue = decryptedData.split((256/8)); try { result = Clipperz.Base.evalJSON(decryptedValue.asString()); } catch (exception) { Clipperz.logError("Error while decrypting data [1]"); throw Clipperz.Crypto.Base.exception.CorruptedMessage; } } else { result = null; } return result; }, 'deferredDecrypt': function(aKey, aValue) { var result; if (aValue != null) { var deferredResult; var key, value; // var decryptedData; key = Clipperz.Crypto.SHA.sha_d256(new Clipperz.ByteArray(aKey)); value = new Clipperz.ByteArray().appendBase64String(aValue); deferredResult = new Clipperz.Async.Deferred("Crypto.[0.2].deferredDecrypt"); deferredResult.addCallback(Clipperz.Crypto.AES.deferredDecrypt, key, value); deferredResult.addCallback(function(aResult) { var result; var decryptedData; decryptedData = aResult.split((256/8)); try { result = Clipperz.Base.evalJSON(decryptedData.asString()); } catch (exception) { Clipperz.logError("Error while decrypting data [2]"); throw Clipperz.Crypto.Base.exception.CorruptedMessage; } return result; }) deferredResult.callback(); result = deferredResult; } else { result = MochiKit.Async.succeed(null); } return result; }, 'hash': Clipperz.Crypto.SHA.sha_d256, 'deriveKey': function(aStringValue) { var byteData; var result; byteData = new Clipperz.ByteArray(aStringValue); result = Clipperz.Crypto.SHA.sha_d256(byteData); return result; } }, //##################################################################### '0.3': { 'encrypt': function(aKey, aValue, aNonce) { var result; var key, value; var data; var dataToEncrypt; var encryptedData; key = Clipperz.Crypto.SHA.sha_d256(new Clipperz.ByteArray(aKey)); value = Clipperz.Base.serializeJSON(aValue); data = new Clipperz.ByteArray(value); encryptedData = Clipperz.Crypto.AES.encrypt(key, data, aNonce); result = encryptedData.toBase64String(); return result; }, 'deferredEncrypt': function(aKey, aValue, aNonce) { var deferredResult; var key, value; var data; var dataToEncrypt; var encryptedData; key = Clipperz.Crypto.SHA.sha_d256(new Clipperz.ByteArray(aKey)); value = Clipperz.Base.serializeJSON(aValue); data = new Clipperz.ByteArray(value); deferredResult = new Clipperz.Async.Deferred("Crypto[0.3].deferredEncrypt") deferredResult.addCallback(Clipperz.Crypto.AES.deferredEncrypt, key, data, aNonce); deferredResult.addCallback(function(aResult) { return aResult.toBase64String(); }) deferredResult.callback(); return deferredResult; }, 'decrypt': function(aKey, aValue) { var result; if (aValue != null) { var key, value; var decryptedData; key = Clipperz.Crypto.SHA.sha_d256(new Clipperz.ByteArray(aKey)); value = new Clipperz.ByteArray().appendBase64String(aValue); decryptedData = Clipperz.Crypto.AES.decrypt(key, value); value = decryptedData.asString(); try { result = Clipperz.Base.evalJSON(value); } catch (exception) { Clipperz.logError("Error while decrypting data [3]"); throw Clipperz.Crypto.Base.exception.CorruptedMessage; } } else { result = null; } return result; }, 'deferredDecrypt': function(aKey, aValue) { var deferredResult; deferredResult = new Clipperz.Async.Deferred("Crypto[0.3].deferredDecrypt", {trace: false}); // now = new Date; if (aValue != null) { var key, value; // var decryptedData; key = Clipperz.Crypto.SHA.sha_d256(new Clipperz.ByteArray(aKey)); value = new Clipperz.ByteArray().appendBase64String(aValue); deferredResult.addCallback(Clipperz.Crypto.AES.deferredDecrypt, key, value); deferredResult.addCallback(MochiKit.Async.wait, 0.1); deferredResult.addCallback(function(aResult) { return aResult.asString(); }); deferredResult.addCallback(MochiKit.Async.wait, 0.1); deferredResult.addCallback(Clipperz.Base.evalJSON); deferredResult.addErrback(function(anError) { +console.log("PIPPO_1", anError) Clipperz.logError("Error while decrypting data [4]"); throw Clipperz.Crypto.Base.exception.CorruptedMessage; }) } else { deferredResult.addCallback(function() { return null; }); } deferredResult.callback(); return deferredResult; }, 'hash': Clipperz.Crypto.SHA.sha_d256, 'deriveKey': function(aStringValue) { var byteData; var result; byteData = new Clipperz.ByteArray(aStringValue); result = Clipperz.Crypto.SHA.sha_d256(byteData); return result; } - }, //##################################################################### -/* + '0.4': { 'encrypt': function(aKey, aValue, aNonce) { var result; var key, value; var data; var dataToEncrypt; var encryptedData; -//Clipperz.logDebug(">>> [" + (new Date()).valueOf() + "] Clipperz.PM.Crypto.versions[0.3].encrypt"); key = Clipperz.Crypto.SHA.sha_d256(new Clipperz.ByteArray(aKey)); -//Clipperz.logDebug("--- [" + (new Date()).valueOf() + "] Clipperz.PM.Crypto.versions[0.3].encrypt - 1"); value = Clipperz.Base.serializeJSON(aValue); -//Clipperz.logDebug("--- [" + (new Date()).valueOf() + "] Clipperz.PM.Crypto.versions[0.3].encrypt - 2"); -/ * -//Clipperz.logDebug("--> encrypt.fullSize: " + value.length); - value = value.replace(/":{"label":"/g, '":{l:"'); - value = value.replace(/":{"key":"/g, '":{k:"'); - value = value.replace(/":{"notes":"/g, '":{n:"'); - value = value.replace(/":{"record":"/g, '":{r:"'); - value = value.replace(/", "label":"/g, '",l:"'); - value = value.replace(/", "favicon":"/g, '",f:"'); -//Clipperz.logDebug("<-- encrypt.compressed: " + value.length); -* / data = new Clipperz.ByteArray(value); -//Clipperz.logDebug("--- [" + (new Date()).valueOf() + "] Clipperz.PM.Crypto.versions[0.3].encrypt - 3"); - encryptedData = Clipperz.Crypto.AES.encrypt(key, data, aNonce); -//Clipperz.logDebug("--- [" + (new Date()).valueOf() + "] Clipperz.PM.Crypto.versions[0.3].encrypt - 4"); + encryptedData = Clipperz.Crypto.AES_2.encrypt(key, data, aNonce); result = encryptedData.toBase64String(); -//Clipperz.logDebug("<<< [" + (new Date()).valueOf() + "] Clipperz.PM.Crypto.versions[0.3].encrypt"); return result; }, + 'deferredEncrypt': function(aKey, aValue, aNonce) { + var deferredResult; + var key, value; + var data; + var dataToEncrypt; + var encryptedData; + + key = Clipperz.Crypto.SHA.sha_d256(new Clipperz.ByteArray(aKey)); + value = Clipperz.Base.serializeJSON(aValue); + data = new Clipperz.ByteArray(value); + + deferredResult = new Clipperz.Async.Deferred("Crypto[0.4].deferredEncrypt") + deferredResult.addCallback(Clipperz.Crypto.AES_2.deferredEncrypt, key, data, aNonce); + deferredResult.addCallback(function(aResult) { + return aResult.toBase64String(); + }) + deferredResult.callback(); + + return deferredResult; + }, + 'decrypt': function(aKey, aValue) { var result; if (aValue != null) { var key, value; var decryptedData; key = Clipperz.Crypto.SHA.sha_d256(new Clipperz.ByteArray(aKey)); value = new Clipperz.ByteArray().appendBase64String(aValue); - decryptedData = Clipperz.Crypto.AES.decrypt(key, value); + decryptedData = Clipperz.Crypto.AES_2.decrypt(key, value); value = decryptedData.asString(); -/ * - value = value.replace(/":{l:"/g, '":{"label":"'); - value = value.replace(/":{k:"/g, '":{"key":"'); - value = value.replace(/":{n:"/g, '":{"notes":"'); - value = value.replace(/":{r:"/g, '":{"record":"'); - value = value.replace(/",l:"/g, '", "label":"'); - value = value.replace(/",f:"/g, '", "favicon":"'); -* / try { result = Clipperz.Base.evalJSON(value); } catch (exception) { - Clipperz.logError("Error while decrypting data"); + console.log("PIPPO_2", anError) + Clipperz.logError("Error while decrypting data [4]"); throw Clipperz.Crypto.Base.exception.CorruptedMessage; } - - } else { result = null; } return result; }, - 'hash': Clipperz.Crypto.SHA.sha_d256 + 'deferredDecrypt': function(aKey, aValue) { + var deferredResult; + + deferredResult = new Clipperz.Async.Deferred("Crypto[0.4].deferredDecrypt", {trace: false}); + + if (aValue != null) { + var key, value; + + key = Clipperz.Crypto.SHA.sha_d256(new Clipperz.ByteArray(aKey)); + value = new Clipperz.ByteArray().appendBase64String(aValue); + + deferredResult.addCallback(Clipperz.Crypto.AES_2.deferredDecrypt, key, value); + deferredResult.addCallback(MochiKit.Async.wait, 0.1); + deferredResult.addCallback(function(aResult) { + return aResult.asString(); + }); + deferredResult.addCallback(MochiKit.Async.wait, 0.1); + deferredResult.addCallback(Clipperz.Base.evalJSON); + deferredResult.addErrback(function(anError) { + Clipperz.logError("Error while decrypting data [4]"); + throw Clipperz.Crypto.Base.exception.CorruptedMessage; + }) + } else { + deferredResult.addCallback(function() { + return null; + }); + } + deferredResult.callback(); + + return deferredResult; + }, + + 'hash': Clipperz.Crypto.SHA.sha_d256, + + 'deriveKey': function(aStringValue) { + var byteData; + var result; + + byteData = new Clipperz.ByteArray(aStringValue); + result = Clipperz.Crypto.SHA.sha_d256(byteData); + + return result; + } }, -*/ + //##################################################################### __syntaxFix__: "syntax fix" } }, //------------------------------------------------------------------------- 'encrypt': function(aKey, aValue, aVersion) { return Clipperz.PM.Crypto.encryptingFunctions.versions[aVersion].encrypt(aKey, aValue); }, 'deferredEncrypt': function(someParameters) { return Clipperz.PM.Crypto.encryptingFunctions.versions[someParameters['version']].deferredEncrypt(someParameters['key'], someParameters['value']); }, //......................................................................... 'decrypt': function(aKey, aValue, aVersion) { return Clipperz.PM.Crypto.encryptingFunctions.versions[aVersion].decrypt(aKey, aValue); }, 'deferredDecrypt': function(someParameters) { return Clipperz.PM.Crypto.encryptingFunctions.versions[someParameters['version']].deferredDecrypt(someParameters['key'], someParameters['value']); }, //------------------------------------------------------------------------- 'hash': function(aValue) { return Clipperz.PM.Crypto.encryptingFunctions.versions[Clipperz.PM.Crypto.encryptingFunctions.currentVersion]['hash'](aValue); }, //------------------------------------------------------------------------- 'randomKey': function() { return Clipperz.Crypto.PRNG.defaultRandomGenerator().getRandomBytes(32).toHexString().substring(2); }, //------------------------------------------------------------------------- 'deriveKey': function(aValue) { return Clipperz.PM.Crypto.encryptingFunctions.versions[Clipperz.PM.Crypto.encryptingFunctions.currentVersion].deriveKey(aValue); }, //------------------------------------------------------------------------- 'passwordEntropy': function(aValue) { var result; var bitPerChar; bitPerChar = 4; if (/[a-z]/.test(aValue)) { bitPerChar ++; } if (/[A-Z]/.test(aValue)) { bitPerChar ++; } if (/[^a-zA-Z0-9]/.test(aValue)) { bitPerChar ++; } result = aValue.length * bitPerChar; return result; }, //------------------------------------------------------------------------- 'nullValue': '####', //------------------------------------------------------------------------- __syntaxFix__: "syntax fix" }); //***************************************************************************** //MochiKit.Base.update(Clipperz.PM.Connection.communicationProtocol.versions, { // 'current': Clipperz.PM.Connection.communicationProtocol.versions[Clipperz.PM.Connection.communicationProtocol.currentVersion] //}); MochiKit.Base.update(Clipperz.PM.Crypto.encryptingFunctions.versions, { 'current': Clipperz.PM.Crypto.encryptingFunctions.versions[Clipperz.PM.Crypto.encryptingFunctions.currentVersion] }); //***************************************************************************** diff --git a/frontend/gamma/js/Clipperz/PM/DataModel/User.js b/frontend/gamma/js/Clipperz/PM/DataModel/User.js index fd18faf..b94fe4c 100644 --- a/frontend/gamma/js/Clipperz/PM/DataModel/User.js +++ b/frontend/gamma/js/Clipperz/PM/DataModel/User.js @@ -1,810 +1,810 @@ /* 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/. */ if (typeof(Clipperz) == 'undefined') { Clipperz = {}; } if (typeof(Clipperz.PM) == 'undefined') { Clipperz.PM = {}; } if (typeof(Clipperz.PM.DataModel) == 'undefined') { Clipperz.PM.DataModel = {}; } //############################################################################# Clipperz.PM.DataModel.User = function (args) { args = args || {}; Clipperz.PM.DataModel.User.superclass.constructor.apply(this, arguments); this._username = args.username || null; this._getPassphraseFunction = args.getPassphraseFunction || null; this._data = null; this._connection = null; this._connectionVersion = 'current'; this._serverData = null; // this._serverLockValue = null; this._transientState = null; this._deferredLocks = { 'passphrase': new MochiKit.Async.DeferredLock(), 'serverData': new MochiKit.Async.DeferredLock(), // 'recordsIndex': new MochiKit.Async.DeferredLock(), // 'directLoginsIndex': new MochiKit.Async.DeferredLock() // 'preferences': new MochiKit.Async.DeferredLock() // 'oneTimePasswords': new MochiKit.Async.DeferredLock() '__syntaxFix__': 'syntax fix' }; return this; } Clipperz.Base.extend(Clipperz.PM.DataModel.User, Object, { 'toString': function () { return "Clipperz.PM.DataModel.User - " + this.username(); }, //------------------------------------------------------------------------- 'username': function () { return this._username; }, 'setUsername': function (aValue) { this._username = aValue; }, //------------------------------------------------------------------------- 'displayName': function() { return "" + this.username() + ""; }, //------------------------------------------------------------------------- 'data': function () { if (this._data == null) { this._data = new Clipperz.KeyValueObjectStore(/*{'name':'User.data [1]'}*/); }; return this._data; }, //------------------------------------------------------------------------- /* 'serverLockValue': function () { return this._serverLockValue; }, 'setServerLockValue': function (aValue) { this._serverLockValue = aValue; }, */ //------------------------------------------------------------------------- 'transientState': function () { if (this._transientState == null) { this._transientState = {} } return this._transientState; }, 'resetTransientState': function (isCommitting) { this._transientState = null; }, //------------------------------------------------------------------------- 'deferredLockForSection': function(aSectionName) { return this._deferredLocks[aSectionName]; }, //------------------------------------------------------------------------- 'getPassphrase': function() { var deferredResult; deferredResult = new Clipperz.Async.Deferred("User.getPassphrase", {trace:false}); deferredResult.acquireLock(this.deferredLockForSection('passphrase')); deferredResult.addMethod(this.data(), 'deferredGetOrSet', 'passphrase', this.getPassphraseFunction()); deferredResult.releaseLock(this.deferredLockForSection('passphrase')); deferredResult.callback(); return deferredResult; }, 'getPassphraseFunction': function () { return this._getPassphraseFunction; }, //------------------------------------------------------------------------- 'getCredentials': function () { return Clipperz.Async.collectResults("User; get username and passphrase", { 'username': MochiKit.Base.method(this, 'username'), 'password': MochiKit.Base.method(this, 'getPassphrase') }, {trace:false})(); }, //------------------------------------------------------------------------- 'changePassphrase': function (aNewValue) { return this.updateCredentials(this.username(), aNewValue); }, //......................................................................... 'updateCredentials': function (aUsername, aPassphrase) { var deferredResult; deferredResult = new Clipperz.Async.Deferred("User.updateCredentials", {trace:false}); // deferredResult.addMethod(this, 'getPassphrase'); // deferredResult.setValue('currentPassphrase'); deferredResult.addMethod(this.connection(), 'ping'); deferredResult.addMethod(this, 'setUsername', aUsername) deferredResult.acquireLock(this.deferredLockForSection('passphrase')); deferredResult.addMethod(this.data(), 'deferredGetOrSet', 'passphrase', aPassphrase); deferredResult.releaseLock(this.deferredLockForSection('passphrase')); // deferredResult.getValue('currentPassphrase'); deferredResult.addMethod(this, 'prepareRemoteDataWithKey', aPassphrase); deferredResult.addMethod(this.connection(), 'updateCredentials', aUsername, aPassphrase); deferredResult.callback(); return deferredResult; }, //------------------------------------------------------------------------- 'initialSetupWithNoData': function () { this._serverData = { 'version': '0.1', 'statistics': "", 'header': { 'data': null, 'version': Clipperz.PM.Crypto.encryptingFunctions.currentVersion, 'recordsIndex': new Clipperz.PM.DataModel.User.Header.RecordIndex({ 'retrieveKeyFunction': MochiKit.Base.method(this, 'getPassphrase'), 'recordsData': {'data':null, 'index':{}}, 'recordsStats': null, 'directLoginsData': {'data':null, 'index':{}}, 'encryptedDataVersion': Clipperz.PM.Crypto.encryptingFunctions.currentVersion, 'retrieveRecordDetailFunction': MochiKit.Base.method(this, 'getRecordDetail') }), 'preferences': new Clipperz.PM.DataModel.User.Header.Preferences({ 'name': 'preferences', 'retrieveKeyFunction': MochiKit.Base.method(this, 'getPassphrase') }), 'oneTimePasswords': new Clipperz.PM.DataModel.User.Header.OneTimePasswords({ 'name': 'preferences', 'retrieveKeyFunction': MochiKit.Base.method(this, 'getPassphrase') }) } }; // this._serverLockValue = Clipperz.PM.Crypto.randomKey(); }, //......................................................................... 'registerAsNewAccount': function () { var deferredResult; deferredResult = new Clipperz.Async.Deferred("User.registerAsNewAccount", {trace:false}); deferredResult.addCallbackPass(MochiKit.Signal.signal, Clipperz.Signal.NotificationCenter, 'updateProgress', {'extraSteps':3}); deferredResult.addMethod(this, 'initialSetupWithNoData') deferredResult.addMethod(this, 'getPassphrase'); deferredResult.addMethod(this, 'prepareRemoteDataWithKey'); deferredResult.addCallbackPass(MochiKit.Signal.signal, Clipperz.Signal.NotificationCenter, 'advanceProgress'); deferredResult.addMethod(this.connection(), 'register'); // deferredResult.addCallback(MochiKit.Base.itemgetter('lock')); // deferredResult.addMethod(this, 'setServerLockValue'); deferredResult.addCallbackPass(MochiKit.Signal.signal, Clipperz.Signal.NotificationCenter, 'userSuccessfullyRegistered'); // deferredResult.addErrback (MochiKit.Base.method(this, 'handleRegistrationFailure')); deferredResult.callback(); return deferredResult; }, //------------------------------------------------------------------------- 'login': function () { var deferredResult; deferredResult = new Clipperz.Async.Deferred("User.login", {trace:false}); deferredResult.addCallbackPass(MochiKit.Signal.signal, Clipperz.Signal.NotificationCenter, 'updateProgress', {'extraSteps':3}); deferredResult.addMethod(this, 'getPassphrase'); deferredResult.addCallback(Clipperz.PM.DataModel.OneTimePassword.isValidOneTimePasswordValue); deferredResult.addCallback(Clipperz.Async.deferredIf("Is the passphrase an OTP", [ MochiKit.Base.partial(MochiKit.Signal.signal, Clipperz.Signal.NotificationCenter, 'updateProgress', {'extraSteps':1}), MochiKit.Base.method(this, 'getCredentials'), MochiKit.Base.method(this.connection(), 'redeemOneTimePassword'), MochiKit.Base.method(this.data(), 'setValue', 'passphrase') ], [])); deferredResult.addErrback(MochiKit.Base.method(this, 'getPassphrase')); deferredResult.addMethod(this.connection(), 'login', false); deferredResult.addCallbackPass(MochiKit.Signal.signal, Clipperz.Signal.NotificationCenter, 'userSuccessfullyLoggedIn'); deferredResult.addErrback (MochiKit.Base.method(this, 'handleConnectionFallback')); deferredResult.callback(); return deferredResult; }, //......................................................................... 'handleConnectionFallback': function(aValue) { var result; if (aValue instanceof MochiKit.Async.CancelledError) { result = aValue; } else { this.setConnectionVersion(Clipperz.PM.Connection.communicationProtocol.fallbackVersions[this.connectionVersion()]); if (this.connectionVersion() != null) { result = new Clipperz.Async.Deferred("User.handleConnectionFallback - retry"); result.addMethod(this, 'login'); result.callback(); } else { result = Clipperz.Async.callbacks("User.handleConnectionFallback - failed", [ MochiKit.Base.method(this.data(), 'removeValue', 'passphrase'), MochiKit.Base.method(this, 'setConnectionVersion', 'current'), MochiKit.Base.partial(MochiKit.Signal.signal, Clipperz.Signal.NotificationCenter, 'userLoginFailed'), MochiKit.Base.partial(MochiKit.Async.fail, Clipperz.PM.DataModel.User.exception.LoginFailed) ], {trace:false}); } } return result; }, //------------------------------------------------------------------------- 'lock': function () { return Clipperz.Async.callbacks("User.lock", [ MochiKit.Base.method(this, 'deleteAllCleanTextData') ], {trace:false}); }, //------------------------------------------------------------------------- 'logout': function () { return Clipperz.Async.callbacks("User.logout", [ MochiKit.Base.method(this, 'deleteAllCleanTextData'), MochiKit.Base.method(this.connection(), 'logout') ], {trace:false}); }, //------------------------------------------------------------------------- 'headerFormatVersion': function(anHeader) { var result; if (anHeader.charAt(0) == '{') { var headerData; headerData = Clipperz.Base.evalJSON(anHeader); result = headerData['version']; } else { result = 'LEGACY'; } return result; }, //------------------------------------------------------------------------- 'unpackServerData': function (someServerData) { var unpackedData; var headerVersion; var recordsIndex; var preferences; var oneTimePasswords; // this.setServerLockValue(someServerData['lock']); headerVersion = this.headerFormatVersion(someServerData['header']); switch (headerVersion) { case 'LEGACY': var legacyHeader; legacyHeader = new Clipperz.PM.DataModel.User.Header.Legacy({ 'retrieveKeyFunction': MochiKit.Base.method(this, 'getPassphrase'), 'remoteData': { 'data': someServerData['header'], 'version': someServerData['version'], 'recordsStats': someServerData['recordsStats'] }, // 'encryptedDataKeypath': 'data', // 'encryptedVersionKeypath': 'version', 'retrieveRecordDetailFunction': MochiKit.Base.method(this, 'getRecordDetail') }); recordsIndex = legacyHeader; preferences = legacyHeader; oneTimePasswords = legacyHeader; break; case '0.1': var headerData; headerData = Clipperz.Base.evalJSON(someServerData['header']); recordsIndex = new Clipperz.PM.DataModel.User.Header.RecordIndex({ 'retrieveKeyFunction': MochiKit.Base.method(this, 'getPassphrase'), 'recordsData': headerData['records'], 'recordsStats': someServerData['recordsStats'], 'directLoginsData': headerData['directLogins'], 'encryptedDataVersion': someServerData['version'], 'retrieveRecordDetailFunction': MochiKit.Base.method(this, 'getRecordDetail') }); // Still missing a test case that actually fais with the old version of the code, where the check for undefined was missing if (typeof(headerData['preferences']) != 'undefined') { preferences = new Clipperz.PM.DataModel.User.Header.Preferences({ 'name': 'preferences', 'retrieveKeyFunction': MochiKit.Base.method(this, 'getPassphrase'), 'remoteData': { 'data': headerData['preferences']['data'], 'version': someServerData['version'] } }); } else { preferences = new Clipperz.PM.DataModel.User.Header.Preferences({ 'name': 'preferences', 'retrieveKeyFunction': MochiKit.Base.method(this, 'getPassphrase') }); } if (typeof(headerData['oneTimePasswords']) != 'undefined') { oneTimePasswords = new Clipperz.PM.DataModel.User.Header.OneTimePasswords({ 'name': 'preferences', 'retrieveKeyFunction': MochiKit.Base.method(this, 'getPassphrase'), 'remoteData': { 'data': headerData['oneTimePasswords']['data'], 'version': someServerData['version'] } }); } else { oneTimePasswords = new Clipperz.PM.DataModel.User.Header.OneTimePasswords({ 'name': 'preferences', 'retrieveKeyFunction': MochiKit.Base.method(this, 'getPassphrase') }); } break; } unpackedData = { 'version': someServerData['version'], 'statistics': someServerData['statistics'], 'header': { 'data': someServerData['header'], 'version': headerVersion, 'recordsIndex': recordsIndex, 'preferences': preferences, 'oneTimePasswords': oneTimePasswords } }; this._serverData = unpackedData; return this._serverData; }, //------------------------------------------------------------------------- 'getServerData': function() { var deferredResult; deferredResult = new Clipperz.Async.Deferred("User.getServerData", {trace:false}); deferredResult.acquireLock(this.deferredLockForSection('serverData')); deferredResult.addCallback(MochiKit.Base.bind(function(aResult) { var innerDeferredResult; innerDeferredResult = new Clipperz.Async.Deferred("User.getUserDetails.innerDeferred", {trace:false}); if (this._serverData == null) { innerDeferredResult.addCallbackPass(MochiKit.Signal.signal, this, 'loadingUserDetails'); innerDeferredResult.addMethod(this.connection(), 'message', 'getUserDetails'); innerDeferredResult.addMethod(this, 'unpackServerData'); innerDeferredResult.addCallbackPass(MochiKit.Signal.signal, this, 'loadedUserDetails'); } innerDeferredResult.addCallback(MochiKit.Base.bind(function () { return this._serverData; },this)); innerDeferredResult.callback(); return innerDeferredResult; }, this)); deferredResult.releaseLock(this.deferredLockForSection('serverData')); deferredResult.callback(); return deferredResult; }, //------------------------------------------------------------------------- 'connectionVersion': function() { return this._connectionVersion; }, 'setConnectionVersion': function(aValue) { if (this._connectionVersion != aValue) { this.resetConnection(); } this._connectionVersion = aValue; }, //------------------------------------------------------------------------- 'connection': function() { if ((this._connection == null) && (this.connectionVersion() != null) ){ this._connection = new Clipperz.PM.Connection.communicationProtocol.versions[this.connectionVersion()]({ getCredentialsFunction: MochiKit.Base.method(this, 'getCredentials') }); } return this._connection; }, 'resetConnection': function(aValue) { if (this._connection != null) { this._connection.reset(); } this._connection = null; }, //========================================================================= 'getHeaderIndex': function (aKey) { return Clipperz.Async.callbacks("User.getHeaderIndex", [ MochiKit.Base.method(this, 'getServerData'), MochiKit.Base.itemgetter('header'), MochiKit.Base.itemgetter(aKey) ], {trace:false}) }, //========================================================================= 'getRecords': function () { return Clipperz.Async.callbacks("User.getRecords", [ MochiKit.Base.method(this, 'getHeaderIndex', 'recordsIndex'), MochiKit.Base.methodcaller('records'), MochiKit.Base.values ], {trace:false}); }, 'recordWithLabel': function (aLabel) { return Clipperz.Async.callbacks("User.recordWithLabel", [ MochiKit.Base.method(this, 'getRecords'), MochiKit.Base.partial(Clipperz.Async.deferredFilter, function (aRecord) { return Clipperz.Async.callbacks("User.recordWithLabel - check record label", [ MochiKit.Base.methodcaller('label'), MochiKit.Base.partial(MochiKit.Base.operator.eq, aLabel) ], {trace:false}, aRecord); }), function (someFilteredResults) { var result; switch (someFilteredResults.length) { case 0: result = null; break; case 1: result = someFilteredResults[0]; break; default: WTF = TODO; break; } return result; } ], {trace:false}); }, //------------------------------------------------------------------------- 'getRecord': function (aRecordReference) { return Clipperz.Async.callbacks("User.getRecord", [ MochiKit.Base.method(this, 'getHeaderIndex', 'recordsIndex'), MochiKit.Base.methodcaller('records'), MochiKit.Base.itemgetter(aRecordReference), Clipperz.Async.deferredIf("record != null", [ MochiKit.Base.operator.identity ], [ function () { throw "Record does not exists"} ]) ], {trace:false}); }, //------------------------------------------------------------------------- 'getRecordDetail': function (aRecordReference) { return this.connection().message('getRecordDetail', {reference: aRecordReference}); }, //------------------------------------------------------------------------- 'deleteRecord': function (aRecord) { return Clipperz.Async.callbacks("User.deleteRecord", [ MochiKit.Base.method(this, 'getHeaderIndex', 'recordsIndex'), MochiKit.Base.methodcaller('deleteRecord', aRecord) ], {trace:false}); }, //------------------------------------------------------------------------- 'createNewRecord': function () { return Clipperz.Async.callbacks("User.createNewRecord", [ MochiKit.Base.method(this, 'getHeaderIndex', 'recordsIndex'), MochiKit.Base.methodcaller('createNewRecord') ], {trace:false}); }, //========================================================================= 'getDirectLogins': function() { var deferredResult; deferredResult = new Clipperz.Async.Deferred("User.getDirectLogins", {trace:false}); deferredResult.addMethod(this, 'getRecords'); deferredResult.addCallback(MochiKit.Base.map, MochiKit.Base.compose(MochiKit.Base.values, MochiKit.Base.methodcaller('directLogins'))); deferredResult.addCallback(MochiKit.Base.flattenArray); deferredResult.callback(); return deferredResult; }, //========================================================================= 'getOneTimePasswords': function () { return Clipperz.Async.callbacks("User.getOneTimePasswords", [ MochiKit.Base.method(this, 'getHeaderIndex', 'oneTimePasswords'), MochiKit.Base.methodcaller('oneTimePasswords'), MochiKit.Base.values ], {trace:false}); }, //========================================================================= 'invokeMethodNamedOnHeader': function (aMethodName, aValue) { return Clipperz.Async.collectResults("User.invokeMethodNamedOnHeader [" + aMethodName + "]", { 'recordIndex': [ MochiKit.Base.method(this, 'getHeaderIndex', 'recordsIndex'), MochiKit.Base.methodcaller(aMethodName, aValue) ], 'preferences': [ MochiKit.Base.method(this, 'getHeaderIndex', 'preferences'), MochiKit.Base.methodcaller(aMethodName, aValue) ], 'oneTimePasswords': [ MochiKit.Base.method(this, 'getHeaderIndex', 'oneTimePasswords'), MochiKit.Base.methodcaller(aMethodName, aValue) ]//, // 'statistics': [ // MochiKit.Base.method(this, 'getStatistics'), // MochiKit.Base.methodcaller(aMethodName, aValue) // ] }, {trace:false})(); }, //------------------------------------------------------------------------- 'invokeMethodNamedOnRecords': function (aMethodName, aValue) { return Clipperz.Async.callbacks("User.invokeMethodNamedOnRecords[" + aMethodName + "]", [ MochiKit.Base.method(this, 'getRecords'), MochiKit.Base.partial(MochiKit.Base.map, MochiKit.Base.methodcaller(aMethodName, aValue)), Clipperz.Async.collectAll ], {trace:false}); }, //========================================================================= 'hasPendingChanges': function () { var deferredResult; deferredResult = new Clipperz.Async.Deferred("User.hasPendingChanges", {trace:false}); deferredResult.collectResults({ 'header': [ MochiKit.Base.method(this, 'invokeMethodNamedOnHeader', 'hasPendingChanges'), MochiKit.Base.values ], 'records': MochiKit.Base.method(this, 'invokeMethodNamedOnRecords', 'hasPendingChanges') }); deferredResult.addCallback(Clipperz.Async.or); deferredResult.callback(); // recordsIndex = legacyHeader; // preferences = legacyHeader; // oneTimePasswords = legacyHeader; return deferredResult; }, //========================================================================= 'commitTransientState': function () { return Clipperz.Async.callbacks("User.commitTransientState", [ MochiKit.Base.method(this, 'invokeMethodNamedOnHeader', 'commitTransientState'), MochiKit.Base.method(this, 'invokeMethodNamedOnRecords', 'commitTransientState'), MochiKit.Base.method(this, 'transientState'), // MochiKit.Base.itemgetter('lock'), // MochiKit.Base.method(this, 'setServerLockValue'), MochiKit.Base.method(this, 'resetTransientState', true) ], {trace:false}); }, //------------------------------------------------------------------------- 'revertChanges': function () { return Clipperz.Async.callbacks("User.revertChanges", [ MochiKit.Base.method(this, 'invokeMethodNamedOnHeader', 'revertChanges'), MochiKit.Base.method(this, 'invokeMethodNamedOnRecords', 'revertChanges'), MochiKit.Base.method(this, 'resetTransientState', false) ], {trace:false}); }, //========================================================================= 'deleteAllCleanTextData': function () { return Clipperz.Async.callbacks("User.deleteAllCleanTextData", [ MochiKit.Base.method(this, 'invokeMethodNamedOnRecords', 'deleteAllCleanTextData'), MochiKit.Base.method(this, 'invokeMethodNamedOnHeader', 'deleteAllCleanTextData'), MochiKit.Base.method(this.data(), 'removeAllData'), MochiKit.Base.method(this, 'resetTransientState', false) ], {trace:false}); }, //------------------------------------------------------------------------- 'hasAnyCleanTextData': function () { var deferredResult; deferredResult = new Clipperz.Async.Deferred("User.hasAnyCleanTextData", {trace:false}); deferredResult.collectResults({ 'header': [ MochiKit.Base.method(this, 'invokeMethodNamedOnHeader', 'hasAnyCleanTextData'), MochiKit.Base.values ], 'records': MochiKit.Base.method(this, 'invokeMethodNamedOnRecords', 'hasAnyCleanTextData'), 'data': MochiKit.Base.bind(function () { return MochiKit.Async.succeed(! this.data().isEmpty()); }, this), 'transientState': MochiKit.Base.bind(function () { return MochiKit.Async.succeed(MochiKit.Base.keys(this.transientState()).length != 0); }, this) }); deferredResult.addCallback(Clipperz.Async.or); deferredResult.callback(); return deferredResult; }, //========================================================================= 'prepareRemoteDataWithKey': function (aKey /*, aCurrentKey*/) { var deferredResult; var result; result = {}; deferredResult = new Clipperz.Async.Deferred("User.prepareRemoteDataWithKey", {trace:false}); deferredResult.addMethod(this, 'invokeMethodNamedOnHeader', 'prepareRemoteDataWithKey', aKey /*, aCurrentKey*/); deferredResult.addCallback(MochiKit.Base.bind(function (aResult, someHeaderPackedData) { var header; header = {}; header['records'] = someHeaderPackedData['recordIndex']['records']; header['directLogins'] = someHeaderPackedData['recordIndex']['directLogins']; - header['preferences'] = {'data': someHeaderPackedData['preferences']['data']}; // this._serverData['header']['preferences']; // Clipperz.Base.evalJSON(this._serverData['header']['data'])['preferences']; // ??????????? - header['oneTimePasswords'] = {'data': someHeaderPackedData['oneTimePasswords']['data']}; // this._serverData['header']['oneTimePasswords']; // Clipperz.Base.evalJSON(this._serverData['header']['data'])['oneTimePasswords']; // ??????????? + header['preferences'] = {'data': someHeaderPackedData['preferences']['data']}; + header['oneTimePasswords'] = {'data': someHeaderPackedData['oneTimePasswords']['data']}; header['version'] = '0.1'; aResult['header'] = Clipperz.Base.serializeJSON(header); aResult['statistics'] = this._serverData['statistics']; // "someHeaderPackedData['statistics']['data']"; return aResult; }, this), result); deferredResult.addCallback(Clipperz.Async.setItem, result, 'version', Clipperz.PM.Crypto.encryptingFunctions.currentVersion); // deferredResult.addCallback(Clipperz.Async.setItem, result, 'lock', this.serverLockValue()); deferredResult.callback(); return deferredResult; }, //========================================================================= 'saveChanges': function () { var deferredResult; var messageParameters; messageParameters = {}; deferredResult = new Clipperz.Async.Deferred("User.saveChangaes", {trace:false}); deferredResult.addMethod(this, 'getHeaderIndex', 'recordsIndex'); deferredResult.addCallback(MochiKit.Base.methodcaller('prepareRemoteDataForChangedRecords')); deferredResult.addCallback(Clipperz.Async.setItem, messageParameters, 'records'); deferredResult.addCallbackPass(MochiKit.Signal.signal, Clipperz.Signal.NotificationCenter, 'advanceProgress'); deferredResult.addMethod(this, 'getPassphrase'); deferredResult.addMethod(this, 'prepareRemoteDataWithKey'); deferredResult.addCallback(Clipperz.Async.setItem, messageParameters, 'user'); deferredResult.addCallbackPass(MochiKit.Signal.signal, Clipperz.Signal.NotificationCenter, 'advanceProgress'); deferredResult.addCallback(MochiKit.Async.succeed, messageParameters); deferredResult.addMethod(this.connection(), 'message', 'saveChanges'); deferredResult.addCallback(MochiKit.Base.update, this.transientState()) deferredResult.addCallbackPass(MochiKit.Signal.signal, Clipperz.Signal.NotificationCenter, 'advanceProgress'); deferredResult.addMethod(this, 'commitTransientState'); deferredResult.addCallbackPass(MochiKit.Signal.signal, Clipperz.Signal.NotificationCenter, 'advanceProgress'); deferredResult.addCallbackPass(MochiKit.Signal.signal, Clipperz.Signal.NotificationCenter, 'userDataSuccessfullySaved'); deferredResult.addErrbackPass(MochiKit.Base.method(this, 'revertChanges')); deferredResult.addErrbackPass(MochiKit.Signal.signal, Clipperz.Signal.NotificationCenter, 'failureWhileSavingUserData'); deferredResult.callback(); return deferredResult; }, //========================================================================= __syntaxFix__: "syntax fix" }); //----------------------------------------------------------------------------- Clipperz.PM.DataModel.User.registerNewAccount = function (anUsername, aPassphraseFunction) { var deferredResult; var user; user = new Clipperz.PM.DataModel.User({'username':anUsername, 'getPassphraseFunction':aPassphraseFunction}); deferredResult = new Clipperz.Async.Deferred("Clipperz.PM.DataModel.User.registerNewAccount", {trace:false}); deferredResult.addMethod(user, 'registerAsNewAccount'); deferredResult.addMethod(user, 'login'); deferredResult.addCallback(MochiKit.Async.succeed, user); deferredResult.callback(); return deferredResult; } //----------------------------------------------------------------------------- Clipperz.PM.DataModel.User.exception = { LoginFailed: new MochiKit.Base.NamedError("Clipperz.PM.DataModel.User.exception.LoginFailed"), CredentialUpgradeFailed: new MochiKit.Base.NamedError("Clipperz.PM.DataModel.User.exception.CredentialUpgradeFailed") }; //----------------------------------------------------------------------------- diff --git a/frontend/gamma/js/Clipperz/PM/Proxy/Proxy.Offline.DataStore.js b/frontend/gamma/js/Clipperz/PM/Proxy/Proxy.Offline.DataStore.js index 326022c..b806cb7 100644 --- a/frontend/gamma/js/Clipperz/PM/Proxy/Proxy.Offline.DataStore.js +++ b/frontend/gamma/js/Clipperz/PM/Proxy/Proxy.Offline.DataStore.js @@ -1,788 +1,788 @@ /* 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/. */ try { if (typeof(Clipperz.PM.Proxy.Offline) == 'undefined') { throw ""; }} catch (e) { throw "Clipperz.PM.Proxy.Offline.DataStore depends on Clipperz.PM.Proxy.Offline!"; } //============================================================================= Clipperz.PM.Proxy.Offline.DataStore = function(args) { args = args || {}; this._data = args.data || (typeof(_clipperz_dump_data_) != 'undefined' ? _clipperz_dump_data_ : null); this._isReadOnly = (typeof(args.readOnly) == 'undefined' ? true : args.readOnly); this._shouldPayTolls = args.shouldPayTolls || false; this._tolls = {}; this._currentStaticConnection = null; return this; } Clipperz.Base.extend(Clipperz.PM.Proxy.Offline.DataStore, Object, { //------------------------------------------------------------------------- 'isReadOnly': function () { return this._isReadOnly; }, //------------------------------------------------------------------------- 'shouldPayTolls': function() { return this._shouldPayTolls; }, //------------------------------------------------------------------------- 'data': function () { return this._data; }, //------------------------------------------------------------------------- 'tolls': function () { return this._tolls; }, //========================================================================= 'resetData': function() { this._data = { 'users': { 'catchAllUser': { __masterkey_test_value__: 'masterkey', s: '112233445566778899aabbccddeeff00112233445566778899aabbccddeeff00', v: '112233445566778899aabbccddeeff00112233445566778899aabbccddeeff00' } } }; }, //------------------------------------------------------------------------- 'setupWithEncryptedData': function(someData) { this._data = Clipperz.Base.deepClone(someData); }, //------------------------------------------------------------------------- 'setupWithData': function(someData) { var deferredResult; var resultData; var i, c; //Clipperz.log(">>> Proxy.Test.setupWithData"); resultData = this._data; deferredResult = new Clipperz.Async.Deferred("Proxy.Test.seupWithData", {trace:false}); c = someData['users'].length; for (i=0; i<c; i++) { var newConnection; var recordConfiguration; deferredResult.addMethod(this, 'userSerializedEncryptedData', someData['users'][i]); deferredResult.addCallback(MochiKit.Base.bind(function(aUserSerializationContext) { resultData['users'][aUserSerializationContext['credentials']['C']] = { 's': aUserSerializationContext['credentials']['s'], 'v': aUserSerializationContext['credentials']['v'], 'version': aUserSerializationContext['data']['connectionVersion'], 'userDetails': aUserSerializationContext['encryptedData']['user']['header'], 'userDetailsVersion': aUserSerializationContext['encryptedData']['user']['version'], 'statistics': aUserSerializationContext['encryptedData']['user']['statistics'], 'lock': aUserSerializationContext['encryptedData']['user']['lock'], 'records': this.rearrangeRecordsData(aUserSerializationContext['encryptedData']['records']) } }, this)); } deferredResult.addCallback(MochiKit.Base.bind(function() { this._data = resultData; }, this)); deferredResult.callback(); //Clipperz.log("<<< Proxy.Test.setupWithData"); return deferredResult; }, //========================================================================= 'getTollForRequestType': function (aRequestType) { var result; var targetValue; var cost; targetValue = Clipperz.Crypto.PRNG.defaultRandomGenerator().getRandomBytes(32).toHexString().substring(2); switch (aRequestType) { case 'REGISTER': cost = 5; break; case 'CONNECT': cost = 5; break; case 'MESSAGE': cost = 2; break; } result = { requestType: aRequestType, targetValue: targetValue, cost: cost } if (this.shouldPayTolls()) { this.tolls()[targetValue] = result; } return result; }, //------------------------------------------------------------------------- 'checkToll': function (aFunctionName, someParameters) { if (this.shouldPayTolls()) { var localToll; var tollParameters; tollParameters = someParameters['toll']; localToll = this.tolls()[tollParameters['targetValue']]; if (localToll != null) { if (! Clipperz.PM.Toll.validate(tollParameters['targetValue'], tollParameters['toll'], localToll['cost'])) { throw "Toll value too low."; }; } else { throw "Missing toll"; } } }, //========================================================================= 'currentStaticConnection': function () { if (this._currentStaticConnection == null) { this._currentStaticConnection = {}; } return this._currentStaticConnection; }, //------------------------------------------------------------------------- 'getConnectionForRequest': function (aFunctionName, someParameters) { var result; if (this.shouldPayTolls()) { if ((typeof(someParameters['toll']) != 'undefined') && (typeof(someParameters['toll']['targetValue']) != 'undefined')) { result = this.tolls()[someParameters['toll']['targetValue']]['connection']; if (typeof(result) == 'undefined') { result = {}; } } else { result = {}; } } else { result = this.currentStaticConnection(); } return result; }, //------------------------------------------------------------------------- 'storeConnectionForRequestWithConnectionAndResponse': function (aFunctionName, someParameters, aConnection, aResponse) { if (this.shouldPayTolls()) { if ((typeof(aResponse['toll']) != 'undefined') && (typeof(aResponse['toll']['targetValue']) != 'undefined') && (typeof(this.tolls()[aResponse['toll']['targetValue']]) != 'undefined') ) { this.tolls()[aResponse['toll']['targetValue']]['connection'] = aConnection; } } }, //========================================================================= 'processMessage': function (aFunctionName, someParameters) { var result; var connection; connection = this.getConnectionForRequest(aFunctionName, someParameters); switch(aFunctionName) { case 'knock': result = this._knock(connection, someParameters); break; case 'registration': this.checkToll(aFunctionName, someParameters); result = this._registration(connection, someParameters.parameters); break; case 'handshake': this.checkToll(aFunctionName, someParameters); result = this._handshake(connection, someParameters.parameters); break; case 'message': this.checkToll(aFunctionName, someParameters); result = this._message(connection, someParameters.parameters); break; case 'logout': this._currentStaticConnection = null; result = this._logout(connection, someParameters.parameters); break; } this.storeConnectionForRequestWithConnectionAndResponse(aFunctionName, someParameters, connection, result); return MochiKit.Async.succeed(result); }, //========================================================================= '_knock': function(aConnection, someParameters) { var result; result = { toll: this.getTollForRequestType(someParameters['requestType']) } return result; }, //------------------------------------------------------------------------- '_registration': function(aConnection, someParameters) { if (this.isReadOnly() == false) { if (typeof(this.data()['users'][someParameters['credentials']['C']]) == 'undefined') { this.data()['users'][someParameters['credentials']['C']] = { 's': someParameters['credentials']['s'], 'v': someParameters['credentials']['v'], 'version': someParameters['credentials']['version'], - 'lock': Clipperz.Crypto.Base.generateRandomSeed(), +// 'lock': Clipperz.Crypto.Base.generateRandomSeed(), 'userDetails': someParameters['user']['header'], 'statistics': someParameters['user']['statistics'], 'userDetailsVersion': someParameters['user']['version'], 'records': {} } } else { throw "user already exists"; } } else { throw Clipperz.PM.Proxy.Offline.DataStore.exception.ReadOnly; } result = { result: { 'lock': this.data()['users'][someParameters['credentials']['C']]['lock'], 'result': 'done' }, toll: this.getTollForRequestType('CONNECT') } return result; }, //------------------------------------------------------------------------- '_handshake': function(aConnection, someParameters) { var result; var nextTollRequestType; result = {}; if (someParameters.message == "connect") { var userData; var randomBytes; var v; userData = this.data()['users'][someParameters.parameters.C]; if ((typeof(userData) != 'undefined') && (userData['version'] == someParameters.version)) { aConnection['userData'] = userData; aConnection['C'] = someParameters.parameters.C; } else { aConnection['userData'] = this.data()['users']['catchAllUser']; } randomBytes = Clipperz.Crypto.Base.generateRandomSeed(); aConnection['b'] = new Clipperz.Crypto.BigInt(randomBytes, 16); v = new Clipperz.Crypto.BigInt(aConnection['userData']['v'], 16); aConnection['B'] = v.add(Clipperz.Crypto.SRP.g().powerModule(aConnection['b'], Clipperz.Crypto.SRP.n())); aConnection['A'] = someParameters.parameters.A; result['s'] = aConnection['userData']['s']; result['B'] = aConnection['B'].asString(16); nextTollRequestType = 'CONNECT'; } else if (someParameters.message == "credentialCheck") { var v, u, S, A, K, M1; v = new Clipperz.Crypto.BigInt(aConnection['userData']['v'], 16); u = new Clipperz.Crypto.BigInt(Clipperz.PM.Crypto.encryptingFunctions.versions[someParameters.version].hash(new Clipperz.ByteArray(aConnection['B'].asString(10))).toHexString(), 16); A = new Clipperz.Crypto.BigInt(aConnection['A'], 16); S = (A.multiply(v.powerModule(u, Clipperz.Crypto.SRP.n()))).powerModule(aConnection['b'], Clipperz.Crypto.SRP.n()); K = Clipperz.PM.Crypto.encryptingFunctions.versions[someParameters.version].hash(new Clipperz.ByteArray(S.asString(10))).toHexString().slice(2); M1 = Clipperz.PM.Crypto.encryptingFunctions.versions[someParameters.version].hash(new Clipperz.ByteArray(A.asString(10) + aConnection['B'].asString(10) + K)).toHexString().slice(2); if (someParameters.parameters.M1 == M1) { var M2; M2 = Clipperz.PM.Crypto.encryptingFunctions.versions[someParameters.version].hash(new Clipperz.ByteArray(A.asString(10) + someParameters.parameters.M1 + K)).toHexString().slice(2); result['M2'] = M2; } else { throw new Error("Client checksum verification failed! Expected <" + M1 + ">, received <" + someParameters.parameters.M1 + ">.", "Error"); } nextTollRequestType = 'MESSAGE'; } else if (someParameters.message == "oneTimePassword") { var otpData; otpData = this.data()['onetimePasswords'][someParameters.parameters.oneTimePasswordKey]; try { if (typeof(otpData) != 'undefined') { if (otpData['status'] == 'ACTIVE') { if (otpData['key_checksum'] == someParameters.parameters.oneTimePasswordKeyChecksum) { result = { 'data': otpData['data'], 'version': otpData['version'] } otpData['status'] = 'REQUESTED'; } else { otpData['status'] = 'DISABLED'; throw "The requested One Time Password has been disabled, due to a wrong keyChecksum"; } } else { throw "The requested One Time Password was not active"; } } else { throw "The requested One Time Password has not been found" } } catch (exception) { result = { 'data': Clipperz.PM.Crypto.randomKey(), 'version': Clipperz.PM.Connection.communicationProtocol.currentVersion } } nextTollRequestType = 'CONNECT'; } else { Clipperz.logError("Clipperz.PM.Proxy.Test.handshake - unhandled message: " + someParameters.message); } result = { result: result, toll: this.getTollForRequestType(nextTollRequestType) } return result; }, //------------------------------------------------------------------------- '_message': function(aConnection, someParameters) { var result; result = {}; //===================================================================== // // R E A D - O N L Y M e t h o d s // //===================================================================== if (someParameters.message == 'getUserDetails') { var recordsStats; var recordReference; recordsStats = {}; for (recordReference in aConnection['userData']['records']) { recordsStats[recordReference] = { 'updateDate': aConnection['userData']['records'][recordReference]['updateDate'] } } result['header'] = this.userDetails(aConnection); result['statistics'] = this.statistics(aConnection); result['maxNumberOfRecords'] = aConnection['userData']['maxNumberOfRecords']; result['version'] = aConnection['userData']['userDetailsVersion']; result['recordsStats'] = recordsStats; if (this.isReadOnly() == false) { var lock; if (typeof(aConnection['userData']['lock']) == 'undefined') { aConnection['userData']['lock'] = "<<LOCK>>"; } result['lock'] = aConnection['userData']['lock']; } //===================================================================== } else if (someParameters.message == 'getRecordDetail') { /* var recordData; var currentVersionData; recordData = this.userData()['records'][someParameters['parameters']['reference']]; result['reference'] = someParameters['parameters']['reference']; result['data'] = recordData['data']; result['version'] = recordData['version']; result['creationData'] = recordData['creationDate']; result['updateDate'] = recordData['updateDate']; result['accessDate'] = recordData['accessDate']; currentVersionData = recordData['versions'][recordData['currentVersion']]; result['currentVersion'] = {}; result['currentVersion']['reference'] = recordData['currentVersion']; result['currentVersion']['version'] = currentVersionData['version']; result['currentVersion']['header'] = currentVersionData['header']; result['currentVersion']['data'] = currentVersionData['data']; result['currentVersion']['creationData'] = currentVersionData['creationDate']; result['currentVersion']['updateDate'] = currentVersionData['updateDate']; result['currentVersion']['accessDate'] = currentVersionData['accessDate']; if (typeof(currentVersionData['previousVersion']) != 'undefined') { result['currentVersion']['previousVersionKey'] = currentVersionData['previousVersionKey']; result['currentVersion']['previousVersion'] = currentVersionData['previousVersion']; } */ MochiKit.Base.update(result, aConnection['userData']['records'][someParameters['parameters']['reference']]); result['reference'] = someParameters['parameters']['reference']; //===================================================================== // // R E A D - W R I T E M e t h o d s // //===================================================================== } else if (someParameters.message == 'upgradeUserCredentials') { if (this.isReadOnly() == false) { var parameters; var credentials; parameters = someParameters['parameters']; credentials = parameters['credentials']; if ((credentials['C'] == null) || (credentials['s'] == null) || (credentials['v'] == null) || (credentials['version'] != Clipperz.PM.Connection.communicationProtocol.currentVersion) ) { result = Clipperz.PM.DataModel.User.exception.CredentialUpgradeFailed; } else { var oldCValue; oldCValue = aConnection['C']; this.data()['users'][credentials['C']] = aConnection['userData']; aConnection['C'] = credentials['C']; aConnection['userData']['s'] = credentials['s']; aConnection['userData']['v'] = credentials['v']; aConnection['userData']['version'] = credentials['version']; aConnection['userData']['userDetails'] = parameters['user']['header']; aConnection['userData']['userDetailsVersion'] = parameters['user']['version']; aConnection['userData']['statistics'] = parameters['user']['statistics']; aConnection['userData']['lock'] = parameters['user']['lock']; delete this.data()['users'][oldCValue]; result = {result:"done", parameters:parameters}; } } else { throw Clipperz.PM.Proxy.Offline.DataStore.exception.ReadOnly; } //===================================================================== /* } else if (someParameters.message == 'updateData') { if (this.isReadOnly() == false) { var i, c; if (this.userData()['lock'] != someParameters['parameters']['user']['lock']) { throw "the lock attribute is not processed correctly" } this.userData()['userDetails'] = someParameters['parameters']['user']['header']; this.userData()['statistics'] = someParameters['parameters']['user']['statistics']; this.userData()['userDetailsVersions'] = someParameters['parameters']['user']['version']; c = someParameters['parameters']['records'].length; for (i=0; i<c; i++) { var currentRecord; var currentRecordData; currentRecordData = someParameters['parameters']['records'][i]; currentRecord = this.userData()['records'][currentRecordData['record']['reference']]; if (currentRecord == null) { } currentRecord['data'] = currentRecordData['record']['data']; currentRecord['version'] = currentRecordData['record']['version']; currentRecord['currentVersion'] = currentRecordData['currentRecordVersion']['reference']; currentRecord['versions'][currentRecordData['currentRecordVersion']['reference']] = { 'data': currentRecordData['currentRecordVersion']['data'], 'version': currentRecordData['currentRecordVersion']['version'], 'previousVersion': currentRecordData['currentRecordVersion']['previousVersion'], 'previousVersionKey': currentRecordData['currentRecordVersion']['previousVersionKey'] } } this.userData()['lock'] = Clipperz.PM.Crypto.randomKey(); result['lock'] = this.userData()['lock']; result['result'] = 'done'; } else { throw Clipperz.PM.Proxy.Offline.DataStore.exception.ReadOnly; } */ //===================================================================== } else if (someParameters.message == 'saveChanges') { if (this.isReadOnly() == false) { var i, c; if (aConnection['userData']['lock'] != someParameters['parameters']['user']['lock']) { throw "the lock attribute is not processed correctly" } aConnection['userData']['userDetails'] = someParameters['parameters']['user']['header']; aConnection['userData']['statistics'] = someParameters['parameters']['user']['statistics']; - aConnection['userData']['userDetailsVersions'] = someParameters['parameters']['user']['version']; + aConnection['userData']['userDetailsVersion'] = someParameters['parameters']['user']['version']; c = someParameters['parameters']['records']['updated'].length; for (i=0; i<c; i++) { var currentRecord; var currentRecordData; currentRecordData = someParameters['parameters']['records']['updated'][i]; currentRecord = aConnection['userData']['records'][currentRecordData['record']['reference']]; if ( (typeof(aConnection['userData']['records'][currentRecordData['record']['reference']]) == 'undefined') && (typeof(currentRecordData['currentRecordVersion']) == 'undefined') ) { throw "Record added without a recordVersion"; } if (currentRecord == null) { currentRecord = {}; currentRecord['versions'] = {}; currentRecord['creationDate'] = Clipperz.PM.Date.formatDateWithUTCFormat(new Date()); currentRecord['accessDate'] = Clipperz.PM.Date.formatDateWithUTCFormat(new Date()); aConnection['userData']['records'][currentRecordData['record']['reference']] = currentRecord; } currentRecord['data'] = currentRecordData['record']['data']; currentRecord['version'] = currentRecordData['record']['version']; currentRecord['updateDate'] = Clipperz.PM.Date.formatDateWithUTCFormat(new Date()); if (typeof(currentRecordData['currentRecordVersion']) != 'undefined') { currentRecord['currentVersion'] = currentRecordData['currentRecordVersion']['reference']; currentRecord['versions'][currentRecordData['currentRecordVersion']['reference']] = { 'data': currentRecordData['currentRecordVersion']['data'], 'version': currentRecordData['currentRecordVersion']['version'], 'previousVersion': currentRecordData['currentRecordVersion']['previousVersion'], 'previousVersionKey': currentRecordData['currentRecordVersion']['previousVersionKey'], 'creationDate': Clipperz.PM.Date.formatDateWithUTCFormat(new Date()), 'updateDate': Clipperz.PM.Date.formatDateWithUTCFormat(new Date()), 'accessDate': Clipperz.PM.Date.formatDateWithUTCFormat(new Date()) } } } c = someParameters['parameters']['records']['deleted'].length; for (i=0; i<c; i++) { var currentRecordReference; currentRecordReference = someParameters['parameters']['records']['deleted'][i]; delete aConnection['userData']['records'][currentRecordReference]; } aConnection['userData']['lock'] = Clipperz.PM.Crypto.randomKey(); result['lock'] = aConnection['userData']['lock']; result['result'] = 'done'; } else { throw Clipperz.PM.Proxy.Offline.DataStore.exception.ReadOnly; } //===================================================================== // // U N H A N D L E D M e t h o d // //===================================================================== } else { Clipperz.logError("Clipperz.PM.Proxy.Test.message - unhandled message: " + someParameters.message); } result = { result: result, toll: this.getTollForRequestType('MESSAGE') } // return MochiKit.Async.succeed(result); return result; }, //------------------------------------------------------------------------- '_logout': function(someParameters) { // return MochiKit.Async.succeed({result: 'done'}); return {result: 'done'}; }, //========================================================================= //######################################################################### 'isTestData': function(aConnection) { return (typeof(aConnection['userData']['__masterkey_test_value__']) != 'undefined'); }, 'userDetails': function(aConnection) { var result; if (this.isTestData(aConnection)) { var serializedHeader; var version; //Clipperz.logDebug("### test data"); version = aConnection['userData']['userDetailsVersion']; serializedHeader = Clipperz.Base.serializeJSON(aConnection['userData']['userDetails']); result = Clipperz.PM.Crypto.encryptingFunctions.versions[version].encrypt(aConnection['userData']['__masterkey_test_value__'], serializedHeader); } else { //Clipperz.logDebug("### NOT test data"); result = aConnection['userData']['userDetails']; } return result; }, 'statistics': function(aConnection) { var result; if (aConnection['userData']['statistics'] != null) { if (this.isTestData(aConnection)) { var serializedStatistics; var version; version = aConnection['userData']['userDetailsVersion']; serializedStatistics = Clipperz.Base.serializeJSON(aConnection['userData']['statistics']); result = Clipperz.PM.Crypto.encryptingFunctions.versions[version].encrypt(aConnection['userData']['__masterkey_test_value__'], serializedStatistics); } else { result = aConnection['userData']['statistics']; } } else { result = null; } return result; }, /* 'userSerializedEncryptedData': function(someData) { var deferredResult; var deferredContext; deferredContext = { 'data': someData }; deferredResult = new Clipperz.Async.Deferred('Proxy.Test.serializeUserEncryptedData', {trace:false}); deferredResult.addCallback(MochiKit.Base.bind(function(aDeferredContext) { aDeferredContext['user'] = this.createUserUsingConfigurationData(aDeferredContext['data']); return aDeferredContext; }, this)); deferredResult.addCallback(function(aDeferredContext) { // return aDeferredContext['user'].encryptedDataUsingVersion(aDeferredContext['data']['version']); return aDeferredContext['user'].serializedDataUsingVersion(MochiKit.Base.values(aDeferredContext['user'].records()), aDeferredContext['data']['version']); }); deferredResult.addCallback(function(aUserEncryptedData) { deferredContext['encryptedData'] = aUserEncryptedData; return deferredContext; }); deferredResult.addCallback(function(aDeferredContext) { var connection; connection = new Clipperz.PM.Connection.communicationProtocol.versions[aDeferredContext['data']['connectionVersion']]() aDeferredContext['credentials'] = connection.serverSideUserCredentials(aDeferredContext['user'].username(),aDeferredContext['user'].passphrase()); return aDeferredContext; }); // deferredResult.addCallback(function(aDeferredContext) { // return aDeferredContext['user'].serializedDataUsingVersion(MochiKit.Base.values(aDeferredContext['user'].records()), aDeferredContext['data']['version']); // }, deferredContext); // deferredResult.addCallback(function(aUserSerializedData) { // }); // // deferredResult.addCallback(MochiKit.Async.succeed, deferredContext); deferredResult.callback(deferredContext); return deferredResult; }, 'createUserUsingConfigurationData': function(someData) { var result; var user; var recordLabel; user = new Clipperz.PM.DataModel.User(); user.initForTests(); user.setUsername(someData['username']); user.setPassphrase(someData['passphrase']); for (recordLabel in someData['records']) { var recordData; var record; var i, c; recordData = someData['records'][recordLabel]; record = new Clipperz.PM.DataModel.Record({user:user, label:recordLabel}); record.setNotes(recordData['notes']); c = recordData['fields'].length; for (i=0; i<c; i++) { var recordField; recordField = new Clipperz.PM.DataModel.RecordField(); recordField.setLabel(recordData['fields'][i]['name']); recordField.setValue(recordData['fields'][i]['value']); recordField.setType(recordData['fields'][i]['type']); record.addField(recordField); } user.addRecord(record, true); } result = user; return result; }, */ //========================================================================= __syntaxFix__: "syntax fix" }); Clipperz.PM.Proxy.Offline.DataStore['exception'] = { 'ReadOnly': new MochiKit.Base.NamedError("Clipperz.PM.Proxy.Offline.DataStore.exception.ReadOnly") };
\ No newline at end of file diff --git a/frontend/gamma/js/Clipperz/PM/Proxy/Proxy.Test.js b/frontend/gamma/js/Clipperz/PM/Proxy/Proxy.Test.js index d459726..1a860c5 100644 --- a/frontend/gamma/js/Clipperz/PM/Proxy/Proxy.Test.js +++ b/frontend/gamma/js/Clipperz/PM/Proxy/Proxy.Test.js @@ -1,156 +1,161 @@ /* 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/. */ if (typeof(Clipperz) == 'undefined') { Clipperz = {}; } if (typeof(Clipperz.PM) == 'undefined') { Clipperz.PM = {}; } if (typeof(Clipperz.PM.Proxy) == 'undefined') { Clipperz.PM.Proxy = {}; } //============================================================================= Clipperz.PM.Proxy.Test = function(args) { Clipperz.PM.Proxy.Test.superclass.constructor.call(this, args); args = args || {}; this._expectedRequests = (args.shouldCheckExpectedRequests === true) ? [] : null; this._isExpectingRequests = true; this._unexpectedRequests = []; this.dataStore().resetData(); return this; } Clipperz.Base.extend(Clipperz.PM.Proxy.Test, Clipperz.PM.Proxy.Offline, { 'toString': function() { return "Clipperz.PM.Proxy.Test"; }, //========================================================================= 'expectedRequests': function () { return this._expectedRequests; }, //------------------------------------------------------------------------- 'shouldCheckExpectedRequests': function () { return (this._expectedRequests != null); }, 'setShouldCheckExpectedRequests': function(aValue) { if (aValue) { this._expectedRequests = aValue; } else { this._expectedRequests = null; } }, //------------------------------------------------------------------------- 'shouldNotReceiveAnyFurtherRequest': function () { this._isExpectingRequests = false; }, 'mayReceiveMoreRequests': function () { this._isExpectingRequests = true; this.resetUnexpectedRequests(); }, 'isExpectingRequests': function () { return this._isExpectingRequests; }, //------------------------------------------------------------------------- 'unexpectedRequests': function () { return this._unexpectedRequests; }, 'resetUnexpectedRequests': function () { this._unexpectedRequests = []; }, //------------------------------------------------------------------------- 'testExpectedRequestParameters': function (aPath, anActualRequest, anExpectedRequest) { var aKey; for (aKey in anExpectedRequest) { if (typeof(anActualRequest[aKey]) == 'undefined') { throw "the expected paramter [" + aKey + "] is missing from the actual request"; } if (typeof(anExpectedRequest[aKey]) == 'object') { this.testExpectedRequestParameters(aPath + "." + aKey, anActualRequest[aKey], anExpectedRequest[aKey]) } else { if (! anExpectedRequest[aKey](anActualRequest[aKey])) { throw "wrong value for paramter [" + aKey + "]; got '" + anActualRequest[aKey] + "'"; } } } }, //------------------------------------------------------------------------- 'checkRequest': function(aFunctionName, someParameters) { if (this.shouldCheckExpectedRequests()) { var expectedRequest; expectedRequest = this.expectedRequests().pop(); if (expectedRequest == null) { throw "Proxy.Test.sentMessage: no expected result specified. Got request '" + aFunctionName + "': " + someParameters; } try { if (aFunctionName != expectedRequest.functionName) { throw "wrong function name. Got '" + aFunctionName + "', expected '" + expectedRequest.request.functionName + "'"; } this.testExpectedRequestParameters("parameters", someParameters, expectedRequest.parameters); } catch(exception) { throw "Proxy.Test.sentMessage[" + expectedRequest.name + "]: " + exception; } } }, //========================================================================= 'sendMessage': function(aFunctionName, someParameters) { var result; if (this.isExpectingRequests() == false) { // throw Clipperz.PM.Connection.exception.UnexpectedRequest; Clipperz.log("UNEXPECTED REQUEST " + aFunctionName /* + ": " + Clipperz.Base.serializeJSON(someParameters) */); this.unexpectedRequests().push({'functionName':aFunctionName, 'someParameters': someParameters}); }; +//if (aFunctionName == 'knock') { +// console.log(">>> send message - " + aFunctionName, someParameters); +//} else { +// console.log(">>> SEND MESSAGE - " + aFunctionName + " [" + someParameters['parameters']['message'] + "]", someParameters['parameters']['parameters']); +//} this.checkRequest(aFunctionName, someParameters); result = Clipperz.PM.Proxy.Test.superclass.sendMessage.call(this, aFunctionName, someParameters); return result; }, //========================================================================= __syntaxFix__: "syntax fix" }); diff --git a/frontend/gamma/properties/gamma.properties.json b/frontend/gamma/properties/gamma.properties.json index d00e03a..1bc9e27 100644 --- a/frontend/gamma/properties/gamma.properties.json +++ b/frontend/gamma/properties/gamma.properties.json @@ -1,191 +1,192 @@ { "copyright.values": { "mochikit.repository": "https://github.com/mochi/mochikit.git", "mochikit.version": "fe8d17bb9ac0a4e5ad4a8d5c2c94a6fac1c92d75" }, "html.template": "index_template.html", "js": [ "MochiKit/Base.js", "MochiKit/Iter.js", "-- MochiKit/Logging.js", "-- MochiKit/DateTime.js", "MochiKit/Format.js", "MochiKit/Async.js", "MochiKit/DOM.js", "MochiKit/Style.js", "-- MochiKit/LoggingPane.js", "MochiKit/Color.js", "MochiKit/Signal.js", "MochiKit/Position.js", "MochiKit/Selector.js", "MochiKit/Visual.js", "JSON/json2.js", "Clipperz/YUI/Utils.js", "Clipperz/YUI/DomHelper.js", "Clipperz/ByteArray.js", "Clipperz/Base.js", "Clipperz/Async.js", "Clipperz/CSVProcessor.js", "Clipperz/KeePassExportProcessor.js", "Clipperz/Date.js", "Clipperz/DOM.js", "Clipperz/Logging.js", "Clipperz/Signal.js", "Clipperz/Style.js", "Clipperz/Visual.js", "Clipperz/Set.js", "-- Clipperz/Profile.js", "Clipperz/KeyValueObjectStore.js", "Clipperz/Crypto/SHA.js", "Clipperz/Crypto/AES.js", + "Clipperz/Crypto/AES_2.js", "Clipperz/Crypto/PRNG.js", "Clipperz/Crypto/BigInt.js", "Clipperz/Crypto/Base.js", "Clipperz/Crypto/SRP.js", "Clipperz/Crypto/RSA.js", "Clipperz/PM/Strings/Strings_defaults.js", "Clipperz/PM/Strings/Strings_en-US.js", "-- # Clipperz/PM/Strings/Strings_en-GB.js", "-- # Clipperz/PM/Strings/Strings_en-CA.js", "-- Clipperz/PM/Strings/Strings_it-IT.js", "-- Clipperz/PM/Strings/Strings_pt-BR.js", "-- # Clipperz/PM/Strings/Strings_pt-PT.js", "-- Clipperz/PM/Strings/Strings_ja-JP.js", "-- Clipperz/PM/Strings/Strings_zh-CN.js", "-- Clipperz/PM/Strings/Strings_es-ES.js", "-- Clipperz/PM/Strings/Strings_fr-FR.js", "-- # Clipperz/PM/Strings/Strings_de-DE.js", "-- # Clipperz/PM/Strings/Strings_el-GR.js", "-- # Clipperz/PM/Strings/Strings_ru-RU.js", "-- # Clipperz/PM/Strings/Strings_he-IL.js", "Clipperz/PM/Strings.js", "-- Clipperz/PM/Strings/MessagePanelConfigurations.js", "Clipperz/PM/Date.js", "Clipperz/PM/Toll.js", "Clipperz/PM/Proxy.js", "Clipperz/PM/Proxy/Proxy.JSON.js", "Clipperz/PM/Proxy/Proxy.Offline.js", "Clipperz/PM/Proxy/Proxy.Offline.DataStore.js", "Clipperz/PM/Connection.js", "Clipperz/PM/Crypto.js", "Clipperz/PM/BookmarkletProcessor.js", "Clipperz/PM/DataModel/EncryptedRemoteObject.js", "Clipperz/PM/DataModel/User.js", "Clipperz/PM/DataModel/User.Header.Legacy.js", "Clipperz/PM/DataModel/User.Header.RecordIndex.js", "Clipperz/PM/DataModel/User.Header.Preferences.js", "Clipperz/PM/DataModel/User.Header.OneTimePasswords.js", "Clipperz/PM/DataModel/Record.js", "Clipperz/PM/DataModel/Record.Version.js", "Clipperz/PM/DataModel/Record.Version.Field.js", "Clipperz/PM/DataModel/DirectLogin.js", "Clipperz/PM/DataModel/DirectLoginInput.js", "Clipperz/PM/DataModel/DirectLoginBinding.js", "Clipperz/PM/DataModel/DirectLoginFormValue.js", "Clipperz/PM/DataModel/OneTimePassword.js", "Clipperz/PM/UI/Canvas/Marks/exclamationMark.js", "Clipperz/PM/UI/Canvas/Marks/questionMark.js", "Clipperz/PM/UI/Canvas/Marks/info.js", "Clipperz/PM/UI/Canvas/Features/store.js", "Clipperz/PM/UI/Canvas/Features/protect.js", "Clipperz/PM/UI/Canvas/Features/directLogin.js", "Clipperz/PM/UI/Canvas/Features/share.js", "Clipperz/PM/UI/Canvas/Star/normal.js", "Clipperz/PM/UI/Canvas/CoverActions/look.js", "Clipperz/PM/UI/Canvas/CoverActions/download.js", "Clipperz/PM/UI/Canvas/Tips/open.js", "Clipperz/PM/UI/Canvas/Tips/close.js", "Clipperz/PM/UI/Canvas/RegisterButton/normal.js", "Clipperz/PM/UI/Canvas/Logo/normal.js", "Clipperz/PM/UI/Canvas/GraphicFunctions.js", "Clipperz/PM/UI/Common/Components/BaseComponent.js", "Clipperz/PM/UI/Common/Components/Button.js", "Clipperz/PM/UI/Common/Components/ComponentSlot.js", "Clipperz/PM/UI/Common/Components/FaviconComponent.js", "Clipperz/PM/UI/Common/Components/PasswordEntropyDisplay.js", "Clipperz/PM/UI/Common/Components/ProgressBar.js", "Clipperz/PM/UI/Common/Components/SimpleMessagePanel.js", "Clipperz/PM/UI/Common/Components/MessagePanelWithProgressBar.js", "Clipperz/PM/UI/Common/Components/TabPanelComponent.js", "Clipperz/PM/UI/Common/Components/Tooltip.js", "Clipperz/PM/UI/Common/Components/TranslatorWidget.js", "Clipperz/PM/UI/Common/Controllers/DirectLoginRunner.js", "Clipperz/PM/UI/Common/Controllers/ProgressBarController.js", "Clipperz/PM/UI/Common/Controllers/TabPanelController.js", "Clipperz/PM/UI/Common/Controllers/WizardController.js", "Clipperz/PM/UI/Web/Components/Page.js", "Clipperz/PM/UI/Web/Components/PageHeader.js", "Clipperz/PM/UI/Web/Components/PageFooter.js", "Clipperz/PM/UI/Web/Components/LoginPage.js", "Clipperz/PM/UI/Web/Components/LoginForm.js", "Clipperz/PM/UI/Web/Components/LoginProgress.js", "Clipperz/PM/UI/Web/Components/AppPage.js", "Clipperz/PM/UI/Web/Components/UserInfoBox.js", "Clipperz/PM/UI/Web/Components/TabSidePanel.js", "Clipperz/PM/UI/Web/Components/GridComponent.js", "Clipperz/PM/UI/Web/Components/ColumnManager.js", "Clipperz/PM/UI/Web/Components/TextColumnManager.js", "Clipperz/PM/UI/Web/Components/FaviconColumnManager.js", "Clipperz/PM/UI/Web/Components/ImageColumnManager.js", "Clipperz/PM/UI/Web/Components/DateColumnManager.js", "Clipperz/PM/UI/Web/Components/LinkColumnManager.js", "Clipperz/PM/UI/Web/Components/DirectLoginColumnManager.js", "Clipperz/PM/UI/Web/Components/DirectLoginsColumnManager.js", "Clipperz/PM/UI/Web/Components/DeleteObjectColumnManager.js", "Clipperz/PM/UI/Web/Components/CreateNewCardSplashComponent.js", "Clipperz/PM/UI/Web/Components/AccountPanel.js", "Clipperz/PM/UI/Web/Components/DataPanel.js", "Clipperz/PM/UI/Web/Components/ToolsPanel.js", "Clipperz/PM/UI/Web/Components/RulerComponent.js", "Clipperz/PM/UI/Web/Components/CardDialogComponent.js", "Clipperz/PM/UI/Web/Components/CardDialogRecordFieldComponent.js", "Clipperz/PM/UI/Web/Components/CardDialogRecordDirectLoginComponent.js", "Clipperz/PM/UI/Web/Components/DirectLoginEditingComponent.js", "Clipperz/PM/UI/Web/Components/DirectLoginEditingBindingComponent.js", "Clipperz/PM/UI/Web/Components/DirectLoginEditingFormValueComponent.js", "Clipperz/PM/UI/Web/Components/BookmarkletComponent.js", "Clipperz/PM/UI/Web/Components/UnlockPasswordComponent.js", "Clipperz/PM/UI/Web/Components/NewUserCreationComponent.js", "Clipperz/PM/UI/Web/Components/PasswordTooltip.js", "Clipperz/PM/UI/Web/Controllers/MainController.js", "Clipperz/PM/UI/Web/Controllers/LoginController.js", "Clipperz/PM/UI/Web/Controllers/AppController.js", "Clipperz/PM/UI/Web/Controllers/FilterController.js", "Clipperz/PM/UI/Web/Controllers/GridController.js", "Clipperz/PM/UI/Web/Controllers/CardsController.js", "Clipperz/PM/UI/Web/Controllers/DirectLoginsController.js", "Clipperz/PM/UI/Web/Controllers/CardDialogController.js", "Clipperz/PM/UI/Web/Controllers/DirectLoginWizardController.js", "Clipperz/PM/UI/Web/Controllers/NewUserWizardController.js", "main.js" ], "css": [ "web.css" ] } diff --git a/frontend/gamma/properties/mobile.properties.json b/frontend/gamma/properties/mobile.properties.json index 0127ce6..2b3b49d 100644 --- a/frontend/gamma/properties/mobile.properties.json +++ b/frontend/gamma/properties/mobile.properties.json @@ -1,156 +1,165 @@ { "copyright.values": { "mochikit.repository": "https://github.com/mochi/mochikit.git", "mochikit.version": "fe8d17bb9ac0a4e5ad4a8d5c2c94a6fac1c92d75" }, "html.template": "mobile_template.html", "js": [ "MochiKit/Base.js", "MochiKit/Iter.js", - "MochiKit/Logging.js", + "-- MochiKit/Logging.js", "MochiKit/DateTime.js", "MochiKit/Format.js", "MochiKit/Async.js", "MochiKit/DOM.js", "MochiKit/Style.js", - "MochiKit/LoggingPane.js", + "-- MochiKit/LoggingPane.js", "-- MochiKit/Color.js", "MochiKit/Signal.js", "-- MochiKit/Position.js", "MochiKit/Selector.js", "-- MochiKit/Visual.js", - "JSON/json2.js", + "-- JSON/json2.js", "Clipperz/YUI/Utils.js", "Clipperz/YUI/DomHelper.js", "Clipperz/ByteArray.js", "Clipperz/Base.js", "Clipperz/Async.js", "-- Clipperz/CSVProcessor.js", "-- Clipperz/KeePassExportProcessor.js", "Clipperz/Date.js", "Clipperz/DOM.js", "Clipperz/Logging.js", "Clipperz/Signal.js", "-- Clipperz/Style.js", "-- Clipperz/Visual.js", "Clipperz/Set.js", "Clipperz/KeyValueObjectStore.js", "Clipperz/Crypto/SHA.js", "Clipperz/Crypto/AES.js", + "Clipperz/Crypto/AES_2.js", "Clipperz/Crypto/PRNG.js", "Clipperz/Crypto/BigInt.js", "Clipperz/Crypto/Base.js", "Clipperz/Crypto/SRP.js", "Clipperz/Crypto/RSA.js", "Clipperz/PM/Strings/Strings_defaults.js", "Clipperz/PM/Strings/Strings_en-US.js", "-- # Clipperz/PM/Strings/Strings_en-GB.js", "-- # Clipperz/PM/Strings/Strings_en-CA.js", "-- Clipperz/PM/Strings/Strings_it-IT.js", "-- Clipperz/PM/Strings/Strings_pt-BR.js", "-- # Clipperz/PM/Strings/Strings_pt-PT.js", "-- Clipperz/PM/Strings/Strings_ja-JP.js", "-- Clipperz/PM/Strings/Strings_zh-CN.js", "-- Clipperz/PM/Strings/Strings_es-ES.js", "-- Clipperz/PM/Strings/Strings_fr-FR.js", "-- # Clipperz/PM/Strings/Strings_de-DE.js", "-- # Clipperz/PM/Strings/Strings_el-GR.js", "-- # Clipperz/PM/Strings/Strings_ru-RU.js", "-- # Clipperz/PM/Strings/Strings_he-IL.js", "Clipperz/PM/Strings.js", "-- Clipperz/PM/Strings/MessagePanelConfigurations.js", "Clipperz/PM/Date.js", "Clipperz/PM/Toll.js", "Clipperz/PM/Proxy.js", "Clipperz/PM/Proxy/Proxy.JSON.js", "-- Clipperz/PM/Proxy/Proxy.OfflineCache.js", "Clipperz/PM/Proxy/Proxy.Offline.js", "Clipperz/PM/Proxy/Proxy.Offline.DataStore.js", "Clipperz/PM/Connection.js", "Clipperz/PM/Crypto.js", "Clipperz/PM/PIN.js", "Clipperz/PM/DataModel/EncryptedRemoteObject.js", "Clipperz/PM/DataModel/User.js", "Clipperz/PM/DataModel/User.Header.Legacy.js", "Clipperz/PM/DataModel/User.Header.RecordIndex.js", "Clipperz/PM/DataModel/User.Header.Preferences.js", "Clipperz/PM/DataModel/User.Header.OneTimePasswords.js", "Clipperz/PM/DataModel/Record.js", "Clipperz/PM/DataModel/Record.Version.js", "Clipperz/PM/DataModel/Record.Version.Field.js", "Clipperz/PM/DataModel/DirectLogin.js", "Clipperz/PM/DataModel/DirectLoginInput.js", "Clipperz/PM/DataModel/DirectLoginBinding.js", "Clipperz/PM/DataModel/DirectLoginFormValue.js", "Clipperz/PM/DataModel/OneTimePassword.js", + "JQuery/1.9.1/jquery.js", + "Clipperz/PM/UI/Mobile/CustomizeJQueryMobile.js", + "JQuery/Mobile/1.3.0-rc.1/jquery.mobile.js", + "-- Zepto/zepto.js", "-- Zepto/ajax.js", "-- Zepto/assets.js", "-- Zepto/data.js", "-- Zepto/detect.js", "-- Zepto/event.js", "-- Zepto/form.js", "-- Zepto/fx.js", "-- Zepto/fx_methods.js", "-- Zepto/gesture.js", "-- Zepto/polyfill.js", "-- Zepto/selector.js", "-- Zepto/stack.js", "-- Zepto/touch.js", "-- JQTouch/jqtouch.js", "-- Bootstrap/bootstrap-affix.js", "-- Bootstrap/bootstrap-alert.js", "-- Bootstrap/bootstrap-button.js", "-- Bootstrap/bootstrap-carousel.js", "-- Bootstrap/bootstrap-collapse.js", "-- Bootstrap/bootstrap-dropdown.js", "-- Bootstrap/bootstrap-modal.js", "-- Bootstrap/bootstrap-popover.js", "-- Bootstrap/bootstrap-scrollspy.js", "-- Bootstrap/bootstrap-tab.js", "-- Bootstrap/bootstrap-tooltip.js", "-- Bootstrap/bootstrap-transition.js", "-- Bootstrap/bootstrap-typeahead.js", - "Clipperz/PM/UI/Common/Components/BaseComponent.js", + "-- Clipperz/PM/UI/Common/Components/BaseComponent.js", "-- Clipperz/PM/UI/Common/Components/Button.js", - "Clipperz/PM/UI/Common/Components/ComponentSlot.js", + "-- Clipperz/PM/UI/Common/Components/ComponentSlot.js", "-- Clipperz/PM/UI/Common/Components/PasswordEntropyDisplay.js", - "Clipperz/PM/UI/Common/Components/ProgressBar.js", + "-- Clipperz/PM/UI/Common/Components/ProgressBar.js", "-- Clipperz/PM/UI/Common/Components/SimpleMessagePanel.js", "-- Clipperz/PM/UI/Common/Components/MessagePanelWithProgressBar.js", "-- Clipperz/PM/UI/Common/Components/TabPanelComponent.js", "-- Clipperz/PM/UI/Common/Components/Tooltip.js", "-- Clipperz/PM/UI/Common/Components/TranslatorWidget.js", - "Clipperz/PM/UI/Common/Controllers/DirectLoginRunner.js", - "Clipperz/PM/UI/Common/Controllers/ProgressBarController.js", + "-- Clipperz/PM/UI/Common/Controllers/DirectLoginRunner.js", + "-- Clipperz/PM/UI/Common/Controllers/ProgressBarController.js", "-- Clipperz/PM/UI/Common/Controllers/TabPanelController.js", + "Clipperz/PM/UI/Mobile/Components/BaseComponent.js", + "Clipperz/PM/UI/Mobile/Components/Overlay.js", "Clipperz/PM/UI/Mobile/Components/LoginForm.js", "Clipperz/PM/UI/Mobile/Components/CardList.js", + "Clipperz/PM/UI/Mobile/Components/Preferences.js", "-- Clipperz/PM/UI/Mobile/Components/CardDetail.js", "Clipperz/PM/UI/Mobile/Controllers/MainController.js", "main.mobile.js" ], "css": [ + "jquery.mobile-1.3.0-rc.1.css", "mobile.css" ] }
\ No newline at end of file diff --git a/frontend/gamma/tests/tests/Clipperz/Crypto/AES_2.html b/frontend/gamma/tests/tests/Clipperz/Crypto/AES_2.html new file mode 100644 index 0000000..8f922fb --- a/dev/null +++ b/frontend/gamma/tests/tests/Clipperz/Crypto/AES_2.html @@ -0,0 +1,57 @@ +<!-- + +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/. + +--> + +<html> +<head> + <title>Clipperz.Crypto.AES_2 - tests</title> + + <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> + + <script type="text/javascript" src="../../../../js/MochiKit/MochiKit.js"></script> + <script type="text/javascript" src="../../../SimpleTest/SimpleTest.js"></script> + <link rel="stylesheet" type="text/css" href="../../../SimpleTest/test.css"> + + <script type='text/javascript' src='../../../../js/JSON/json2.js'></script> + + <script type='text/javascript' src='../../../../js/Clipperz/YUI/Utils.js'></script> + <script type='text/javascript' src='../../../../js/Clipperz/YUI/DomHelper.js'></script> + <script type='text/javascript' src='../../../../js/Clipperz/Base.js'></script> + <script type='text/javascript' src='../../../../js/Clipperz/ByteArray.js'></script> + <script type='text/javascript' src='../../../../js/Clipperz/Async.js'></script> + <script type='text/javascript' src='../../../../js/Clipperz/Logging.js'></script> + <script type='text/javascript' src='../../../../js/Clipperz/Crypto/Base.js'></script> + <script type='text/javascript' src='../../../../js/Clipperz/Crypto/BigInt.js'></script> + <script type='text/javascript' src='../../../../js/Clipperz/Crypto/AES.js'></script> + <script type='text/javascript' src='../../../../js/Clipperz/Crypto/AES_2.js'></script> + <script type='text/javascript' src='../../../../js/Clipperz/Crypto/SHA.js'></script> + <script type='text/javascript' src='../../../../js/Clipperz/Crypto/PRNG.js'></script> + + <script type="text/javascript" src="../../../SimpleTest/SimpleTest.Async.js"></script> + +</head> +<body> +<pre id="test"> +<script type="text/javascript" src="AES_2.test.js"></script> +</pre> +</body> +</html> diff --git a/frontend/gamma/tests/tests/Clipperz/Crypto/AES_2.test.js b/frontend/gamma/tests/tests/Clipperz/Crypto/AES_2.test.js new file mode 100644 index 0000000..f753747 --- a/dev/null +++ b/frontend/gamma/tests/tests/Clipperz/Crypto/AES_2.test.js @@ -0,0 +1,85 @@ +/* + +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/. + +*/ + +function testEncryptedData (tool, keyValue, encryptedText, expectedCleanText, someTestArgs) { + key = Clipperz.Crypto.SHA.sha_d256(new Clipperz.ByteArray(keyValue)); + value = new Clipperz.ByteArray().appendBase64String(encryptedText); + + deferredResult = new Clipperz.Async.Deferred("pythonCompatibility_test", someTestArgs); + deferredResult.addCallback(Clipperz.Crypto.AES_2.deferredDecrypt, key, value); + deferredResult.addCallback(function(aResult) { + return aResult.asString(); + }); + deferredResult.addTest(expectedCleanText, tool); + deferredResult.callback(); + + return deferredResult; +} + +//============================================================================= + +var tests = { + + 'incrementNonce_test': function (someTestArgs) { + var nonce; + + nonce = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] + Clipperz.Crypto.AES_2.incrementNonce(nonce) + SimpleTest.eq(nonce, [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1], "increment 0 based nonce"); + + nonce = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1] + Clipperz.Crypto.AES_2.incrementNonce(nonce) + SimpleTest.eq(nonce, [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2], "increment '1' nonce"); + + nonce = [58,231,19,199,48,86,154,169,188,141,46,196,83,34,37,89] + Clipperz.Crypto.AES_2.incrementNonce(nonce) + SimpleTest.eq(nonce, [58,231,19,199,48,86,154,169,188,141,46,196,83,34,37,90], "increment '1' nonce"); + return + }, + + 'pythonCompatibility_test': function (someTestArgs) { + var keyValue = "clipperz" + var cleanText = "Lorem īpsum dōlōr siÞ ǽmēt, stet voluptatum ei eum, quō pērfecto lobortis eā, vel ċu deserūisse comprehēƿsam. Eu sed cībō veniam effīciendi, Þe legere ðominġ est, ðuō ċu saperet inermis pērfeċto. Vim ei essent consetētūr, quo etīam saepē æpeirian in, et atqūi velīÞ sǣepe his? Æn porrō putanÞ sinġulis mei, ēx sonet noster mea, tē alterum praesent percipitur qūo. ViÞaē neċessitatibus ne vim, per ex communē sentēntiǣe! Qui stet ǽdhūċ uÞ." + +// def testEncrypt (keyValue, cleanText): +// key = keyDerivation(keyValue) +// iv = random.getrandbits(128) +// ctr = Crypto.Util.Counter.new(128, initial_value=iv) +// cipher = AES.new(key, Crypto.Cipher.AES.MODE_CTR, counter=ctr) +// encryptedValue = cipher.encrypt(cleanText.encode('utf-8')) +// data = base64.b64encode(base64.b16decode(hex(iv).upper()[2:-1]) + encryptedValue) +// +// return data + + var pythonEncryptedData = "9AFIXRO2nY0mkLJI6Xd4bd+Ov1g+kYUh73nICEVUM8OGt5FnfV/w2BfmTvdMGZjs+rF8w0ksrS9Ny8j2+2zPUUrKnVRXO6eGVPSN5VfuYFSHucV98msINH0FpOZHftuKCuJkB/orjQhoIbj9SXT0yUwB3b4R2bk48Br7R8G2bhxqrHRmnYQn22AQVA83UstNvCOdXT7ArfwJZbVSSMkdmvcziZ8ObMvaH+FXD/K8i7dzS1yP03MMBtIkYN8PnyUMS2uAHKiR11jGuha9QfXjLJlWUQWZgNB9NKyOKf7tN+OgtAoWmHmKlpTshfwbfFD8wBPR0kkhR0cC+7queIjpCDnBJ+Nod78zWgPDR8g64sph7OB686HkP03cO66aH/LNuAt03gxaVyE8ufvoStRjlIthOuys5xYWP+hTFYDC7OhCOLKvhZoY4Tr/FP+TjporX3ivCJUEEvwvXeftAxFVRl4JDin0ys0iPTQ7QlbtVa+iep2n9FUG1NOn5boD9y+iw64UJAcex4MqEIdpCHne9LjpiqshcwLmfEeLlFab28LHnvYPGkXDrSRjCujx8ZmmTw96sAIDqER8p1AqaSojwvONYBGrq+f5/f4xjzZJAknMmxYEN14Phbxc8WEhpe5omWdB80C1Kv6CLsoQnGAIshURSZryToXL" + return testEncryptedData("python", keyValue, pythonEncryptedData, cleanText, someTestArgs) + }, + + //------------------------------------------------------------------------- + 'syntaxFix': MochiKit.Base.noop +} + +//============================================================================= + +Clipperz.Crypto.PRNG.defaultRandomGenerator().fastEntropyAccumulationForTestingPurpose(); +SimpleTest.runDeferredTests("Clipperz.Crypto.AES_2", tests, {trace:false}); diff --git a/frontend/gamma/tests/tests/Clipperz/Crypto/index.html b/frontend/gamma/tests/tests/Clipperz/Crypto/index.html index 5ee8b8c..0679739 100644 --- a/frontend/gamma/tests/tests/Clipperz/Crypto/index.html +++ b/frontend/gamma/tests/tests/Clipperz/Crypto/index.html @@ -1,53 +1,54 @@ <!-- 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/. --> <html> <head> <title>Clipperz.Crypto.* - tests</title> <script type="text/javascript" src="../../../../js/MochiKit/MochiKit.js"></script> <script type="text/javascript" src="../../../SimpleTest/TestRunner.js"></script> </head> <body> <script> TestRunner.runTests( 'AES.html', +// 'AES_2.html', 'AES.performance.html', 'Base.html', 'BigInt.html', // 'ECC.B283.deferred.html', // 'ECC.BinaryField.FiniteField.html', // 'ECC.BinaryField.FiniteField.B283.html', // 'ECC.BinaryField.Value.html', //# 'ECC.K283.deferred.html', 'PRNG.html', // 'RSA.html', 'SHA.html', 'SRP.html', 'Usage.html' ); </script> </body> </html>
\ No newline at end of file diff --git a/frontend/gamma/tests/tests/Clipperz/PM/Crypto_v0_4.html b/frontend/gamma/tests/tests/Clipperz/PM/Crypto_v0_4.html new file mode 100644 index 0000000..1ed863a --- a/dev/null +++ b/frontend/gamma/tests/tests/Clipperz/PM/Crypto_v0_4.html @@ -0,0 +1,60 @@ +<!-- + +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/. + +--> + +<html> +<head> + <title>Clipperz.PM.Crypto [0.4] - tests</title> + + <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> + + <script type="text/javascript" src="../../../../js/MochiKit/MochiKit.js"></script> + <script type="text/javascript" src="../../../SimpleTest/SimpleTest.js"></script> + <link rel="stylesheet" type="text/css" href="../../../SimpleTest/test.css"> + + <script type='text/javascript' src='../../../../js/JSON/json2.js'></script> + + <script type='text/javascript' src='../../../../js/Clipperz/YUI/Utils.js'></script> + <script type='text/javascript' src='../../../../js/Clipperz/YUI/DomHelper.js'></script> + <script type='text/javascript' src='../../../../js/Clipperz/Base.js'></script> + <script type='text/javascript' src='../../../../js/Clipperz/ByteArray.js'></script> + <script type='text/javascript' src='../../../../js/Clipperz/Async.js'></script> + <script type='text/javascript' src='../../../../js/Clipperz/Logging.js'></script> + <script type='text/javascript' src='../../../../js/Clipperz/Crypto/Base.js'></script> + <script type='text/javascript' src='../../../../js/Clipperz/Crypto/BigInt.js'></script> + <script type='text/javascript' src='../../../../js/Clipperz/Crypto/AES.js'></script> + <script type='text/javascript' src='../../../../js/Clipperz/Crypto/AES_2.js'></script> + <script type='text/javascript' src='../../../../js/Clipperz/Crypto/SHA.js'></script> + <script type='text/javascript' src='../../../../js/Clipperz/Crypto/PRNG.js'></script> + <script type='text/javascript' src='../../../../js/Clipperz/PM/Proxy.js'></script> + <script type='text/javascript' src='../../../../js/Clipperz/PM/Connection.js'></script> + <script type='text/javascript' src='../../../../js/Clipperz/PM/Crypto.js'></script> + + <script type="text/javascript" src="../../../SimpleTest/SimpleTest.Async.js"></script> + +</head> +<body> +<pre id="test"> +<script type="text/javascript" src="Crypto_v0_4.test.js"></script> +</pre> +</body> +</html> diff --git a/frontend/gamma/tests/tests/Clipperz/PM/Crypto_v0_4.test.js b/frontend/gamma/tests/tests/Clipperz/PM/Crypto_v0_4.test.js new file mode 100644 index 0000000..ecfbec3 --- a/dev/null +++ b/frontend/gamma/tests/tests/Clipperz/PM/Crypto_v0_4.test.js @@ -0,0 +1,50 @@ +/* + +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/. + +*/ + +var tests = { + + 'decryptDataEncryptedUsingPythonLibrary_test': function (someTestArgs) { + var deferredResult; + + passphrase = 'trustno1'; + encryptedData = 'OucTxzBWmqm8jS7EUyIlWUWDPSFKvulL5iM4WwLPbNVIH7jtaK9pmzpm9w5ioVy2/tyebVwWr36t7QXSBOPwUPo2SlGmARCozA=='; + + deferredResult = new Clipperz.Async.Deferred("decryptDataEncryptedUsingPythonLibrary_test", someTestArgs); + deferredResult.addCallback(Clipperz.PM.Crypto.deferredDecrypt, {key:passphrase, value:encryptedData, version:'0.4'}); + deferredResult.addCallback(MochiKit.Base.itemgetter('message')); + deferredResult.addTest("The quick brown fox jumps over the lazy dog", "expected value"); + + deferredResult.callback(); + + return deferredResult; + + }, + + //------------------------------------------------------------------------- + 'syntaxFix': MochiKit.Base.noop +} + +//============================================================================= + +Clipperz.Crypto.PRNG.defaultRandomGenerator().fastEntropyAccumulationForTestingPurpose(); +SimpleTest.runDeferredTests("Clipperz.PM.Crypto [0.4]", tests, {trace:false}); diff --git a/frontend/gamma/tests/tests/Clipperz/PM/DataModel/DirectLogin.html b/frontend/gamma/tests/tests/Clipperz/PM/DataModel/DirectLogin.html index 73b8225..74d1a07 100644 --- a/frontend/gamma/tests/tests/Clipperz/PM/DataModel/DirectLogin.html +++ b/frontend/gamma/tests/tests/Clipperz/PM/DataModel/DirectLogin.html @@ -1,98 +1,99 @@ <!-- 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/. --> <html> <head> <title>Clipperz.PM.DataModel.DirectLogin - test</title> <script type="text/javascript" src="../../../../../js/MochiKit/MochiKit.js"></script> <script type="text/javascript" src="../../../../SimpleTest/SimpleTest.js"></script> <link rel="stylesheet" type="text/css" href="../../../../SimpleTest/test.css"> <script type='text/javascript' src='../../../../../js/JSON/json2.js'></script> <script type='text/javascript' src='../../../../../js/Clipperz/YUI/Utils.js'></script> <script type='text/javascript' src='../../../../../js/Clipperz/Base.js'></script> <script type='text/javascript' src='../../../../../js/Clipperz/Date.js'></script> <script type='text/javascript' src='../../../../../js/Clipperz/ByteArray.js'></script> <script type='text/javascript' src='../../../../../js/Clipperz/Logging.js'></script> <script type='text/javascript' src='../../../../../js/Clipperz/Async.js'></script> <script type='text/javascript' src='../../../../../js/Clipperz/Signal.js'></script> <script type='text/javascript' src='../../../../../js/Clipperz/KeyValueObjectStore.js'></script> <script type='text/javascript' src='../../../../../js/Clipperz/Crypto/Base.js'></script> <script type='text/javascript' src='../../../../../js/Clipperz/Crypto/BigInt.js'></script> <script type='text/javascript' src='../../../../../js/Clipperz/Crypto/AES.js'></script> + <script type='text/javascript' src='../../../../../js/Clipperz/Crypto/AES_2.js'></script> <script type='text/javascript' src='../../../../../js/Clipperz/Crypto/SHA.js'></script> <script type='text/javascript' src='../../../../../js/Clipperz/Crypto/PRNG.js'></script> <script type='text/javascript' src='../../../../../js/Clipperz/Crypto/SRP.js'></script> <script type='text/javascript' src='../../../../../js/Clipperz/PM/Toll.js'></script> <script type='text/javascript' src='../../../../../js/Clipperz/PM/Proxy.js'></script> <script type='text/javascript' src='../../../../../js/Clipperz/PM/Proxy/Proxy.Offline.js'></script> <script type='text/javascript' src='../../../../../js/Clipperz/PM/Proxy/Proxy.Test.js'></script> <script type='text/javascript' src='../../../../../js/Clipperz/PM/Proxy/Proxy.Offline.DataStore.js'></script> <script type='text/javascript' src='../../../../../js/Clipperz/PM/Connection.js'></script> <script type='text/javascript' src='../../../../../js/Clipperz/PM/Crypto.js'></script> <script type='text/javascript' src='../../../../../js/Clipperz/PM/Strings.js'></script> <script type='text/javascript' src='../../../../../js/Clipperz/PM/Strings/Strings_en-US.js'></script> <script type='text/javascript' src='../../../../../js/Clipperz/PM/Date.js'></script> <script type='text/javascript' src='../../../../../js/Clipperz/PM/DataModel/EncryptedRemoteObject.js'></script> <script type='text/javascript' src='../../../../../js/Clipperz/PM/DataModel/Record.js'></script> <script type='text/javascript' src='../../../../../js/Clipperz/PM/DataModel/Record.Version.js'></script> <script type='text/javascript' src='../../../../../js/Clipperz/PM/DataModel/Record.Version.Field.js'></script> <script type='text/javascript' src='../../../../../js/Clipperz/PM/DataModel/DirectLogin.js'></script> <script type='text/javascript' src='../../../../../js/Clipperz/PM/DataModel/DirectLoginInput.js'></script> <script type='text/javascript' src='../../../../../js/Clipperz/PM/DataModel/DirectLoginBinding.js'></script> <script type='text/javascript' src='../../../../../js/Clipperz/PM/DataModel/User.js'></script> <script type='text/javascript' src='../../../../../js/Clipperz/PM/DataModel/User.Header.Legacy.js'></script> <script type='text/javascript' src='../../../../../js/Clipperz/PM/DataModel/User.Header.RecordIndex.js'></script> <script type='text/javascript' src='../../../../../js/Clipperz/PM/DataModel/User.Header.Preferences.js'></script> <script type='text/javascript' src='../../../../../js/Clipperz/PM/DataModel/User.Header.OneTimePasswords.js'></script> <script type='text/javascript' src='../../../../../js/Clipperz/PM/DataModel/OneTimePassword.js'></script> <script type="text/javascript" src="../../../../SimpleTest/SimpleTest.Async.js"></script> <script> Clipperz_IEisBroken = false; </script> <!--[if IE]><script> Clipperz_IEisBroken = true; Clipperz_normalizedNewLine = '\x0d\x0a'; </script><![endif]--> </head> <body> <pre id="test"> <script> Clipperz.PM.Strings.Languages.setSelectedLanguage('en-us'); </script> <script type="text/javascript" src="User.data.js"></script> <script type="text/javascript" src="User.data.old.js"></script> <script type="text/javascript" src="DirectLogin.test.js"></script> </pre> </body> </html> diff --git a/frontend/gamma/tests/tests/Clipperz/PM/DataModel/EncryptedRemoteObject.html b/frontend/gamma/tests/tests/Clipperz/PM/DataModel/EncryptedRemoteObject.html index a711ba9..c264ff7 100644 --- a/frontend/gamma/tests/tests/Clipperz/PM/DataModel/EncryptedRemoteObject.html +++ b/frontend/gamma/tests/tests/Clipperz/PM/DataModel/EncryptedRemoteObject.html @@ -1,61 +1,62 @@ <!-- 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/. --> <html> <head> <title>Clipperz.PM.DataModel.EncryptedRemoteObject - test</title> <script type="text/javascript" src="../../../../../js/MochiKit/MochiKit.js"></script> <script type="text/javascript" src="../../../../SimpleTest/SimpleTest.js"></script> <link rel="stylesheet" type="text/css" href="../../../../SimpleTest/test.css"> <script type='text/javascript' src='../../../../../js/JSON/json2.js'></script> <script type='text/javascript' src='../../../../../js/Clipperz/YUI/Utils.js'></script> <script type='text/javascript' src='../../../../../js/Clipperz/Base.js'></script> <script type='text/javascript' src='../../../../../js/Clipperz/ByteArray.js'></script> <script type='text/javascript' src='../../../../../js/Clipperz/Logging.js'></script> <script type='text/javascript' src='../../../../../js/Clipperz/Async.js'></script> <script type='text/javascript' src='../../../../../js/Clipperz/Signal.js'></script> <script type='text/javascript' src='../../../../../js/Clipperz/KeyValueObjectStore.js'></script> <script type='text/javascript' src='../../../../../js/Clipperz/Crypto/Base.js'></script> <script type='text/javascript' src='../../../../../js/Clipperz/Crypto/BigInt.js'></script> <script type='text/javascript' src='../../../../../js/Clipperz/Crypto/AES.js'></script> + <script type='text/javascript' src='../../../../../js/Clipperz/Crypto/AES_2.js'></script> <script type='text/javascript' src='../../../../../js/Clipperz/Crypto/SHA.js'></script> <script type='text/javascript' src='../../../../../js/Clipperz/Crypto/PRNG.js'></script> <script type='text/javascript' src='../../../../../js/Clipperz/Crypto/SRP.js'></script> <script type='text/javascript' src='../../../../../js/Clipperz/PM/Proxy.js'></script> <script type='text/javascript' src='../../../../../js/Clipperz/PM/Connection.js'></script> <script type='text/javascript' src='../../../../../js/Clipperz/PM/Crypto.js'></script> <script type='text/javascript' src='../../../../../js/Clipperz/PM/DataModel/EncryptedRemoteObject.js'></script> <script type="text/javascript" src="../../../../SimpleTest/SimpleTest.Async.js"></script> </head> <body> <pre id="test"> <script type="text/javascript" src="EncryptedRemoteObject.test.js"></script> </pre> </body> </html> diff --git a/frontend/gamma/tests/tests/Clipperz/PM/DataModel/Record.html b/frontend/gamma/tests/tests/Clipperz/PM/DataModel/Record.html index 0332008..4d6bc5d 100644 --- a/frontend/gamma/tests/tests/Clipperz/PM/DataModel/Record.html +++ b/frontend/gamma/tests/tests/Clipperz/PM/DataModel/Record.html @@ -1,93 +1,94 @@ <!-- 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/. --> <html> <head> <title>Clipperz.PM.DataModel.Record - test</title> <script type="text/javascript" src="../../../../../js/MochiKit/MochiKit.js"></script> <script type="text/javascript" src="../../../../SimpleTest/SimpleTest.js"></script> <link rel="stylesheet" type="text/css" href="../../../../SimpleTest/test.css"> <script type='text/javascript' src='../../../../../js/JSON/json2.js'></script> <script type='text/javascript' src='../../../../../js/Clipperz/YUI/Utils.js'></script> <script type='text/javascript' src='../../../../../js/Clipperz/Base.js'></script> <script type='text/javascript' src='../../../../../js/Clipperz/Date.js'></script> <script type='text/javascript' src='../../../../../js/Clipperz/ByteArray.js'></script> <script type='text/javascript' src='../../../../../js/Clipperz/Logging.js'></script> <script type='text/javascript' src='../../../../../js/Clipperz/Async.js'></script> <script type='text/javascript' src='../../../../../js/Clipperz/Signal.js'></script> <script type='text/javascript' src='../../../../../js/Clipperz/KeyValueObjectStore.js'></script> <script type='text/javascript' src='../../../../../js/Clipperz/Crypto/Base.js'></script> <script type='text/javascript' src='../../../../../js/Clipperz/Crypto/BigInt.js'></script> <script type='text/javascript' src='../../../../../js/Clipperz/Crypto/AES.js'></script> + <script type='text/javascript' src='../../../../../js/Clipperz/Crypto/AES_2.js'></script> <script type='text/javascript' src='../../../../../js/Clipperz/Crypto/SHA.js'></script> <script type='text/javascript' src='../../../../../js/Clipperz/Crypto/PRNG.js'></script> <script type='text/javascript' src='../../../../../js/Clipperz/Crypto/SRP.js'></script> <script type='text/javascript' src='../../../../../js/Clipperz/PM/Toll.js'></script> <script type='text/javascript' src='../../../../../js/Clipperz/PM/Strings.js'></script> <script type='text/javascript' src='../../../../../js/Clipperz/PM/Strings/Strings_en-US.js'></script> <script type='text/javascript' src='../../../../../js/Clipperz/PM/Date.js'></script> <script type='text/javascript' src='../../../../../js/Clipperz/PM/Proxy.js'></script> <script type='text/javascript' src='../../../../../js/Clipperz/PM/Proxy/Proxy.Offline.js'></script> <script type='text/javascript' src='../../../../../js/Clipperz/PM/Proxy/Proxy.Test.js'></script> <script type='text/javascript' src='../../../../../js/Clipperz/PM/Proxy/Proxy.Offline.DataStore.js'></script> <script type='text/javascript' src='../../../../../js/Clipperz/PM/Connection.js'></script> <script type='text/javascript' src='../../../../../js/Clipperz/PM/Crypto.js'></script> <script type='text/javascript' src='../../../../../js/Clipperz/PM/Strings.js'></script> <script type='text/javascript' src='../../../../../js/Clipperz/PM/Strings/Strings_en-US.js'></script> <script type='text/javascript' src='../../../../../js/Clipperz/PM/Date.js'></script> <script type='text/javascript' src='../../../../../js/Clipperz/PM/DataModel/EncryptedRemoteObject.js'></script> <script type='text/javascript' src='../../../../../js/Clipperz/PM/DataModel/Record.js'></script> <script type='text/javascript' src='../../../../../js/Clipperz/PM/DataModel/Record.Version.js'></script> <script type='text/javascript' src='../../../../../js/Clipperz/PM/DataModel/Record.Version.Field.js'></script> <script type='text/javascript' src='../../../../../js/Clipperz/PM/DataModel/DirectLogin.js'></script> <script type='text/javascript' src='../../../../../js/Clipperz/PM/DataModel/DirectLoginInput.js'></script> <script type='text/javascript' src='../../../../../js/Clipperz/PM/DataModel/DirectLoginBinding.js'></script> <script type='text/javascript' src='../../../../../js/Clipperz/PM/DataModel/DirectLoginFormValue.js'></script> <script type='text/javascript' src='../../../../../js/Clipperz/PM/DataModel/User.js'></script> <script type='text/javascript' src='../../../../../js/Clipperz/PM/DataModel/User.Header.Legacy.js'></script> <script type='text/javascript' src='../../../../../js/Clipperz/PM/DataModel/User.Header.RecordIndex.js'></script> <script type='text/javascript' src='../../../../../js/Clipperz/PM/DataModel/User.Header.Preferences.js'></script> <script type='text/javascript' src='../../../../../js/Clipperz/PM/DataModel/User.Header.OneTimePasswords.js'></script> <script type='text/javascript' src='../../../../../js/Clipperz/PM/DataModel/OneTimePassword.js'></script> <script type="text/javascript" src="../../../../SimpleTest/SimpleTest.Async.js"></script> </head> <body> <pre id="test"> <script> Clipperz.PM.Strings.Languages.setSelectedLanguage('en-us'); </script> <script type="text/javascript" src="DirectLoginConfigurations.data.js"></script> <script type="text/javascript" src="User.data.js"></script> <script type="text/javascript" src="Record.test.js"></script> </pre> </body> </html> diff --git a/frontend/gamma/tests/tests/Clipperz/PM/DataModel/Record.test.js b/frontend/gamma/tests/tests/Clipperz/PM/DataModel/Record.test.js index 3478743..af1ffe8 100644 --- a/frontend/gamma/tests/tests/Clipperz/PM/DataModel/Record.test.js +++ b/frontend/gamma/tests/tests/Clipperz/PM/DataModel/Record.test.js @@ -1,1280 +1,1288 @@ /* 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(); var tests = { //------------------------------------------------------------------------- 'recordUseOf_retrieveIndexDataFunction_and_getRemoteDataFunction_test': function (someTestArgs) { var deferredResult; var record; //console.log("#### new Clipperz.PM.DataModel.Record [5]"); record = new Clipperz.PM.DataModel.Record({ 'reference': '<<< record reference >>>', 'retrieveKeyFunction': MochiKit.Base.noop, 'retrieveRemoteDataFunction': function (aRecordReference) { SimpleTest.is(aRecordReference, '<<< record reference >>>', "Record correctly passes its record reference when asking for encrypted data"); return MochiKit.Async.succeed({ // fake server payload 'data': "#### fake encrypted data ####", 'version': "0.x", 'currentVersion': { 'reference': "<<< fake record version reference >>>", 'data': "#### fake encrypted data ####", 'version': "0.x" } }); }, 'updateDate': "Thu, 10 May 2007 13:01:21 UTC", // 'encryptedDataKeypath': 'data', // 'encryptedVersionKeypath': 'version', 'retrieveIndexDataFunction': function (aRecordReference) { SimpleTest.is(aRecordReference, '<<< record reference >>>', "Record correctly passes its record reference when asking for index data"); return MochiKit.Async.succeed({ key: '<< key >>', label: '<< label >>', notes: '<< notes >>' }); }, 'updateIndexDataFunction': MochiKit.Base.noop }); deferredResult = new Clipperz.Async.Deferred("recordUseOf_retrieveIndexDataFunction_and_getEncryptedDataFunction_test", someTestArgs); deferredResult.addMethod(record, 'label'); deferredResult.addTest('<< label >>', "Record returns the right value for label"); deferredResult.addMethod(record, 'notes'); deferredResult.addTest('<< notes >>', "Record returns the right value for notes - even the legacy one, stored on the header"); deferredResult.addMethod(record, 'getRemoteData'); deferredResult.addCallback(Clipperz.Async.Test.isDeeply({ 'data': "#### fake encrypted data ####", 'version': "0.x", 'currentVersion': { 'reference': "<<< fake record version reference >>>", 'data': "#### fake encrypted data ####", 'version': "0.x" } }, "Record returns the expected encrypted data")); deferredResult.callback(); return deferredResult; }, //------------------------------------------------------------------------- 'createRecordWithoutAllRequiredParameters_test': function (someTestArgs) { var record; try { //console.log("#### new Clipperz.PM.DataModel.Record [6]"); record = new Clipperz.PM.DataModel.Record({reference:'--'}); SimpleTest.ok(false, "creating a record without all parameters should raise an exception"); } catch(exception) { // SimpleTest.is(exception.name, "Clipperz.Base.exception.MandatoryParameter", "creating a record without all parameters raises an exception"); SimpleTest.ok(/Clipperz\.Base\.exception\.MandatoryParameter.*/.test(exception.name), "creating a record without all parameters raises an exception"); } }, //------------------------------------------------------------------------- 'recordFromOldData_version_0.1_test': function (someTestArgs) { var deferredResult; var proxy; var user; var recordID; //console.log("#### new Clipperz.PM.DataModel.Record [7]"); /* record = new Clipperz.PM.DataModel.Record({ 'reference': '05aad20ee399b11ddc923e601fcd1d096233634f2ad4c55db4f6435e5f9cc17a', 'retrieveKeyFunction': MochiKit.Base.partial(MochiKit.Async.succeed, 'e038652297f981d5ca917d88fa2c4c3251a12c0fa41bf7313a4d24a9738fe6c6'), 'retrieveRemoteDataFunction': MochiKit.Base.partial(MochiKit.Async.succeed, { 'data': '4ec19a7093534e7dcf7c796b889283c6cec224b1895720ba3ff43ce091dc72c61fd5ea56def418ba3f15239f73228c6c8558585311f5e6673efe57482a1f9c9fe71e921576989eace671ec543685e3ad8f976bbfa4c2dbc629fab936c227d4fd4da3a1561ea79e553bae7b758ff91762572c1448a2d18bec797e12721238ef5ba18ddf1fba8ae773a8debe1040b3b158220aec6be9c7190687139f589a30d9c8887792fd7040e3c7cf3f9999fb9dde1f9f334d17c996996d538a7e374ac93135acafdaf5fce738a1702182897b63d2cb8e308b94156473cba63dcc557d17dcbdb55fcff63d9ba5edf68c42855052e34207d6fabe94fe024c3db616b45f494da42c62224d3897e320080072cc442d4212e7b1e8d5b3d9e3c25d48f4e7c37112ef4c6b2c0c8aff0bd3ce05694370e4378701463dde26c7c0322f8a9eb5a724106039b16b35050a9a9b5717b2eec803efa962b88b9655742f5e7b180ea567449671fb5a2ce563d8b47bc25705821938192eae420391c208182a788dd06fb6448b9858a4104a14efd7717671c65cd08fd979a4da7c01712bc5d4e949a10ef1ea65caf1f07cee34b063bab01bfb7a59047fef30c3059ea652f1c92b9e72aac515ac8851756703772e1fa05384ee7f0d5c7a3c', 'version': '0.1', 'currentVersion': { 'reference': '05aad20ee399b11ddc923e601fcd1d096233634f2ad4c55db4f6435e5f9cc17a', 'data': '4ec19a7093534e7dcf7c796b889283c6cec224b1895720ba3ff43ce091dc72c61fd5ea56def418ba3f15239f73228c6c8558585311f5e6673efe57482a1f9c9fe71e921576989eace671ec543685e3ad8f976bbfa4c2dbc629fab936c227d4fd4da3a1561ea79e553bae7b758ff91762572c1448a2d18bec797e12721238ef5ba18ddf1fba8ae773a8debe1040b3b158220aec6be9c7190687139f589a30d9c8887792fd7040e3c7cf3f9999fb9dde1f9f334d17c996996d538a7e374ac93135acafdaf5fce738a1702182897b63d2cb8e308b94156473cba63dcc557d17dcbdb55fcff63d9ba5edf68c42855052e34207d6fabe94fe024c3db616b45f494da42c62224d3897e320080072cc442d4212e7b1e8d5b3d9e3c25d48f4e7c37112ef4c6b2c0c8aff0bd3ce05694370e4378701463dde26c7c0322f8a9eb5a724106039b16b35050a9a9b5717b2eec803efa962b88b9655742f5e7b180ea567449671fb5a2ce563d8b47bc25705821938192eae420391c208182a788dd06fb6448b9858a4104a14efd7717671c65cd08fd979a4da7c01712bc5d4e949a10ef1ea65caf1f07cee34b063bab01bfb7a59047fef30c3059ea652f1c92b9e72aac515ac8851756703772e1fa05384ee7f0d5c7a3c', 'version': '0.1' } }), 'retrieveIndexDataFunction': MochiKit.Base.partial(MochiKit.Async.succeed, { // 'key': 'e038652297f981d5ca917d88fa2c4c3251a12c0fa41bf7313a4d24a9738fe6c6', 'label': '<< label >>', 'notes': '<< notes >>' }), 'updateIndexDataFunction': MochiKit.Base.noop, 'updateDate': 'Mon Oct 02 10:01:52 CEST 2006' }); */ proxy = new Clipperz.PM.Proxy.Test({shouldPayTolls:false, isDefault:true, readOnly:false}); user = new Clipperz.PM.DataModel.User({username:'test', getPassphraseFunction:function () { return 'test';}}); recordID = "05aad20ee399b11ddc923e601fcd1d096233634f2ad4c55db4f6435e5f9cc17a"; deferredResult = new Clipperz.Async.Deferred("recordFromOldData_version_0.1_test", someTestArgs); deferredResult.addMethod(proxy.dataStore(), 'setupWithEncryptedData', testData['test_test_someExtraOldData']); deferredResult.addMethod(user, 'login'); deferredResult.addMethod(user, 'getRecord', recordID); deferredResult.addMethodcaller('hasAnyCleanTextData'); deferredResult.addTest(false, "When first loaded, the record has no clean text data"); deferredResult.addMethod(user, 'getRecord', recordID); deferredResult.addMethodcaller('label'); deferredResult.addTest("Card encoded with an old algorithm", "Record returns the right value for label"); deferredResult.addMethod(user, 'getRecord', recordID); deferredResult.addMethodcaller('notes'); deferredResult.addTest("", "Record returns the right value for notes - even the legacy one, stored on the header"); deferredResult.addMethod(user, 'getRecord', recordID); deferredResult.addMethodcaller('hasAnyCleanTextData'); deferredResult.addTest(true, "After reading some values, the record has some clean text data"); deferredResult.addMethod(user, 'getRecord', recordID); deferredResult.addMethodcaller('fields'); deferredResult.addCallback(function (someFields) { SimpleTest.is(MochiKit.Base.values(someFields).length, 6, "the card has 6 fields"); }); deferredResult.callback(); return deferredResult; }, //------------------------------------------------------------------------- 'removeDirectLogin': function (someTestArgs) { var deferredResult; var proxy; var user; var recordID = 'd5f700b9c3367c39551ea49e00a9ab20dae09dd79d46047b983fc7c4bfaa050d'; // YAHOO (4) var directLoginID = 'dba0db679802f0e6aa6d0b7a6aaf42350aabc5f057409edd99a268a92ebb6496'; proxy = new Clipperz.PM.Proxy.Test({shouldPayTolls:false, isDefault:true, readOnly:false}); user = new Clipperz.PM.DataModel.User({username:'joe', getPassphraseFunction:function () { return 'clipperz';}}); user2 = new Clipperz.PM.DataModel.User({username:'joe', getPassphraseFunction:function () { return 'clipperz';}}); deferredResult = new Clipperz.Async.Deferred("Record.test.removeDirectLogin", someTestArgs); deferredResult.addMethod(proxy.dataStore(), 'setupWithEncryptedData', testData['joe_clipperz_offline_copy_data']); deferredResult.addMethod(user, 'login'); + + deferredResult.addMethod(user, 'getRecord', recordID); + deferredResult.addMethodcaller('directLogins'); + deferredResult.addCallback(MochiKit.Base.keys); + deferredResult.addCallback(MochiKit.Base.itemgetter('length')); + deferredResult.addTest(4, "The record initially has 4 direct logins"); + deferredResult.addMethod(user, 'getRecord', recordID); deferredResult.addMethodcaller('directLogins'); deferredResult.addCallback(MochiKit.Base.itemgetter(directLoginID)); deferredResult.addMethodcaller('remove'); deferredResult.addMethod(user, 'getRecord', recordID); deferredResult.addMethodcaller('hasPendingChanges'); deferredResult.addTest(true, "removing a direct login to a record should result in pending changes on the record"); deferredResult.addMethod(user, 'saveChanges'); + deferredResult.addMethod(user, 'hasPendingChanges'); deferredResult.addTest(false, "after saving there should be not any pending changes"); deferredResult.addMethod(user, 'getRecord', recordID); deferredResult.addMethodcaller('directLogins'); deferredResult.addCallback(MochiKit.Base.keys); deferredResult.addCallback(MochiKit.Base.itemgetter('length')); deferredResult.addTest(3, "after saving changes, the record should have only 3 direct logins"); deferredResult.addMethod(user2, 'login'); deferredResult.addMethod(user2, 'getRecord', recordID); deferredResult.addMethodcaller('directLogins'); deferredResult.addCallback(MochiKit.Base.keys); deferredResult.addCallback(MochiKit.Base.itemgetter('length')); deferredResult.addTest(3, "also reloading all the data with a new user, the direct logins should always be 3"); deferredResult.callback(); return deferredResult; }, //------------------------------------------------------------------------- 'removeDirectLoginAndRevertChanges': function (someTestArgs) { var deferredResult; var proxy; var user; var recordID = 'd5f700b9c3367c39551ea49e00a9ab20dae09dd79d46047b983fc7c4bfaa050d'; var directLoginID = 'dba0db679802f0e6aa6d0b7a6aaf42350aabc5f057409edd99a268a92ebb6496'; proxy = new Clipperz.PM.Proxy.Test({shouldPayTolls:false, isDefault:true, readOnly:false}); user = new Clipperz.PM.DataModel.User({username:'joe', getPassphraseFunction:function () { return 'clipperz';}}); deferredResult = new Clipperz.Async.Deferred("Record.test.removeDirectLoginAndRevertChanges", someTestArgs); deferredResult.addMethod(proxy.dataStore(), 'setupWithEncryptedData', testData['joe_clipperz_offline_copy_data']); deferredResult.addMethod(user, 'login'); deferredResult.addMethod(user, 'getDirectLogins'); deferredResult.addCallback(MochiKit.Base.itemgetter('length')); deferredResult.addTest(22, "the user has 22 initially"); deferredResult.addMethod(user, 'getRecord', recordID); deferredResult.addMethodcaller('directLogins'); deferredResult.addCallback(MochiKit.Base.keys); deferredResult.addCallback(MochiKit.Base.itemgetter('length')); deferredResult.addTest(4, "the selected record has 4 direct logins"); deferredResult.addMethod(user, 'getRecord', recordID); deferredResult.addMethodcaller('directLogins'); deferredResult.addCallback(MochiKit.Base.itemgetter(directLoginID)); deferredResult.addMethodcaller('remove'); deferredResult.addMethod(user, 'getRecord', recordID); deferredResult.addMethodcaller('hasPendingChanges'); deferredResult.addTest(true, "removing a direct login to a record should result in pending changes on the record"); deferredResult.addMethod(user, 'revertChanges'); deferredResult.addMethod(user, 'hasPendingChanges'); deferredResult.addTest(false, "after reverting the changes, the user should not have pending changes"); deferredResult.addMethod(user, 'getDirectLogins'); deferredResult.addCallback(MochiKit.Base.itemgetter('length')); deferredResult.addTest(22, "after reverting the changes, the user should still have 22 direct logins"); deferredResult.addMethod(user, 'getRecord', recordID); deferredResult.addMethodcaller('directLogins'); deferredResult.addCallback(MochiKit.Base.keys); deferredResult.addCallback(MochiKit.Base.itemgetter('length')); deferredResult.addTest(4, "after reverting the changes, the record should still have 4 direct logins"); deferredResult.callback(); return deferredResult; }, //------------------------------------------------------------------------- 'addDirectLoginAndRevertChanges': function (someTestArgs) { var deferredResult; var proxy; var user, user2; var recordID = 'd5f700b9c3367c39551ea49e00a9ab20dae09dd79d46047b983fc7c4bfaa050d'; // YAHOO (4) var directLoginReference; proxy = new Clipperz.PM.Proxy.Test({shouldPayTolls:false, isDefault:true, readOnly:false}); user = new Clipperz.PM.DataModel.User({username:'joe', getPassphraseFunction:function () { return 'clipperz';}}); user2 = new Clipperz.PM.DataModel.User({username:'joe', getPassphraseFunction:function () { return 'clipperz';}}); deferredResult = new Clipperz.Async.Deferred("Record.test.addDirectLoginAndRevertChanges", someTestArgs); deferredResult.addMethod(proxy.dataStore(), 'setupWithEncryptedData', testData['joe_clipperz_offline_copy_data']); deferredResult.addMethod(user, 'login'); deferredResult.addMethod(user, 'getRecord', recordID); deferredResult.setValue('record'); deferredResult.addMethodcaller('directLogins'); deferredResult.addCallback(MochiKit.Base.keys); deferredResult.addCallback(MochiKit.Base.itemgetter('length')); deferredResult.addTest(4, "the record, when initially loaded, has 4 direct logins"); deferredResult.getValue('record'); deferredResult.addMethodcaller('createNewDirectLogin'); deferredResult.setValue('directLogin'); deferredResult.getValue('directLogin'); deferredResult.addMethodcaller('setLabel', "New direct login"); deferredResult.getValue('directLogin'); deferredResult.addMethodcaller('setBookmarkletConfiguration', '{"page": {"title": "Parallels Account"}, "form": {"attributes": {"action": "https://www.parallels.com/account/", "method": "post"}, "inputs": [{"type": "text", "name": "Email", "value": ""}, {"type": "password", "name": "Password", "value": ""}]}, "version": "0.2.3"}'); deferredResult.addMethod(user, 'revertChanges'); //deferredResult.addCallback(function () { console.log("###################################"); }); deferredResult.addMethod(user, 'hasPendingChanges'); deferredResult.addTest(false, "after reverting the changes, the user should NOT have pending changes"); deferredResult.getValue('record'); deferredResult.addMethodcaller('hasPendingChanges'); deferredResult.addTest(false, "after reverting the changes, the record should NOT have pending changes"); deferredResult.addMethod(user2, 'login'); deferredResult.addMethod(user2, 'getRecord', recordID); deferredResult.setValue('record_2'); deferredResult.addMethodcaller('directLogins'); deferredResult.addCallback(MochiKit.Base.keys); deferredResult.addCallback(MochiKit.Base.itemgetter('length')); deferredResult.addTest(4, "the record, when reloaded from scratch, has still 4 direct logins"); deferredResult.callback(); return deferredResult; }, //------------------------------------------------------------------------- 'addDirectLoginAndSaveChanges': function (someTestArgs) { var deferredResult; var proxy; var user, user2; var recordID = 'd5f700b9c3367c39551ea49e00a9ab20dae09dd79d46047b983fc7c4bfaa050d'; // YAHOO (4) var directLoginReference; proxy = new Clipperz.PM.Proxy.Test({shouldPayTolls:false, isDefault:true, readOnly:false}); user = new Clipperz.PM.DataModel.User({username:'joe', getPassphraseFunction:function () { return 'clipperz';}}); user2 = new Clipperz.PM.DataModel.User({username:'joe', getPassphraseFunction:function () { return 'clipperz';}}); deferredResult = new Clipperz.Async.Deferred("Record.test.addDirectLoginAndSaveChanges", someTestArgs); deferredResult.addMethod(proxy.dataStore(), 'setupWithEncryptedData', testData['joe_clipperz_offline_copy_data']); deferredResult.addMethod(user, 'login'); deferredResult.addMethod(user, 'getRecord', recordID); deferredResult.addMethodcaller('hasAnyCleanTextData'); deferredResult.addTest(false, "When first loaded, the record has no clean text data [2]"); deferredResult.addMethod(user, 'getRecord', recordID); deferredResult.setValue('record'); deferredResult.addMethodcaller('directLogins'); deferredResult.addCallback(MochiKit.Base.keys); deferredResult.addCallback(MochiKit.Base.itemgetter('length')); deferredResult.addTest(4, "the selected record has 4 direct logins"); deferredResult.addMethod(user, 'getRecord', recordID); deferredResult.addMethodcaller('hasAnyCleanTextData'); deferredResult.addTest(false, "Still no clean text data is stored on the record, as all accessed data are stored on the index"); deferredResult.addMethod(user, 'hasAnyCleanTextData'); deferredResult.addTest(true, "the user has some clean text data"); deferredResult.getValue('record'); deferredResult.addMethodcaller('createNewDirectLogin'); deferredResult.setValue('directLogin'); deferredResult.getValue('directLogin'); deferredResult.addMethodcaller('label'); deferredResult.addTest(null, "The label of a initially created direct login is empty"); deferredResult.getValue('directLogin'); deferredResult.addMethodcaller('bookmarkletConfiguration'); deferredResult.addTest('', "The bookmaraklet configuration of a initially created direct login is empty"); deferredResult.getValue('directLogin'); deferredResult.addMethodcaller('bindings'); deferredResult.addCallback(Clipperz.Async.Test.isDeeply({}, "The bindings of a initially created direct login is empty")); deferredResult.getValue('directLogin'); deferredResult.addMethodcaller('setLabel', "New direct login"); deferredResult.getValue('directLogin'); deferredResult.addMethodcaller('setBookmarkletConfiguration', directLoginConfigurations['Parallels']); deferredResult.getValue('directLogin'); deferredResult.addMethodcaller('bindings'); deferredResult.addCallback(MochiKit.Base.itemgetter('Email')); deferredResult.addMethodcaller('setFieldKey', '4cfaf1e782086e7527bd0e0cc82b67eb773e8157ad0c5babe516f7bc945a02a9'); // "userID" deferredResult.getValue('directLogin'); deferredResult.addMethodcaller('bindings'); deferredResult.addCallback(MochiKit.Base.itemgetter('Password')); deferredResult.addMethodcaller('setFieldKey', 'ef2dee54322bf401540657d469e158a50e9228bc0a192a31d2e3ee56a77e565b'); // "password" deferredResult.getValue('directLogin'); deferredResult.addMethodcaller('favicon'), deferredResult.addTest('http://www.parallels.com/favicon.ico', "the original favicon is the expected one"), deferredResult.getValue('directLogin'); deferredResult.addMethodcaller('reference'); deferredResult.addCallback(function (aReference) { directLoginReference = aReference; }); deferredResult.addMethod(user, 'hasPendingChanges'); deferredResult.addTest(true, "after adding a new direct login, the user should have pending changes"); deferredResult.getValue('record'); deferredResult.addMethodcaller('hasPendingChanges'); deferredResult.addTest(true, "after adding a new direct login, the record should have pending changes"); deferredResult.getValue('record'); deferredResult.addMethodcaller('directLogins'); deferredResult.addCallback(MochiKit.Base.keys); deferredResult.addCallback(MochiKit.Base.itemgetter('length')); deferredResult.addTest(5, "after adding a new direct login, the record has now 5 direct logins"); deferredResult.addMethod(user, 'saveChanges'); deferredResult.addMethod(user, 'hasPendingChanges'); deferredResult.addTest(false, "after saving the changes, the user should NOT have pending changes"); deferredResult.addMethod(user2, 'login'); deferredResult.addMethod(user2, 'getRecord', recordID); deferredResult.setValue('record_2'); deferredResult.addMethodcaller('directLogins'); deferredResult.addCallback(MochiKit.Base.keys); deferredResult.addCallback(MochiKit.Base.itemgetter('length')); deferredResult.addTest(5, "the record, when reloaded from scratch, has still 5 direct logins"); deferredResult.getValue('record_2'); deferredResult.addMethodcaller('directLogins'); deferredResult.addCallback(MochiKit.Base.values); deferredResult.addCallback(MochiKit.Base.itemgetter('4')); // TODO: accessing directLogins by index is not really nice deferredResult.setValue('directLogin_2'); deferredResult.addMethodcaller('label'); deferredResult.addTest('New direct login', "The label of the direct login has been correctly saved"); deferredResult.getValue('directLogin_2'); deferredResult.addMethodcaller('bindings'); deferredResult.addCallback(MochiKit.Base.itemgetter('Email')); deferredResult.addMethodcaller('field'); deferredResult.addMethodcaller('value'); deferredResult.addTest('joe.clipperz', "The value bound to the direct login 'Email' field is correct"); deferredResult.getValue('directLogin_2'); deferredResult.addMethodcaller('bindings'); deferredResult.addCallback(MochiKit.Base.itemgetter('Password')); deferredResult.addMethodcaller('field'); deferredResult.addMethodcaller('value'); deferredResult.addTest('enfvDG1RxAsl', "The value bound to the direct login 'Password' field is correct"); deferredResult.callback(); return deferredResult; }, //------------------------------------------------------------------------- 'readDirectLoginAttributes': function (someTestArgs) { var deferredResult; var proxy; var user; var recordID = '2977aa5f99a9f6e5596c1bd7871e82d7328c3716c9ef8ba349ae65f10d97924e'; var directLoginID = '03251dc1cbc5398789e4c4b45c52cfac3fcd8c1a4f19a81fa68fc6feae31d55c'; proxy = new Clipperz.PM.Proxy.Test({shouldPayTolls:false, isDefault:true, readOnly:false}); user = new Clipperz.PM.DataModel.User({username:'joe', getPassphraseFunction:function () { return 'clipperz';}}); deferredResult = new Clipperz.Async.Deferred("Record.test.readDirectLoginAttributes", someTestArgs); deferredResult.addMethod(proxy.dataStore(), 'setupWithEncryptedData', testData['joe_clipperz_offline_copy_with_multipleRecordVersions_data']); deferredResult.addMethod(user, 'login'); deferredResult.addMethod(user, 'getRecord', recordID); deferredResult.addMethodcaller('directLogins'); deferredResult.addCallback(MochiKit.Base.itemgetter('03251dc1cbc5398789e4c4b45c52cfac3fcd8c1a4f19a81fa68fc6feae31d55c')); deferredResult.setValue('directLogin'); deferredResult.getValue('directLogin'); deferredResult.addMethodcaller('inputs'); deferredResult.addCallback(MochiKit.Base.keys); deferredResult.addCallback(MochiKit.Base.itemgetter('length')); deferredResult.addTest(13, "Amazon direct login has 13 inputs"); deferredResult.getValue('directLogin'); deferredResult.addMethodcaller('inputs'); deferredResult.addCallback(MochiKit.Base.values); deferredResult.addCallback(MochiKit.Base.filter, MochiKit.Base.methodcaller('needsFormValue')); deferredResult.addCallback(MochiKit.Base.itemgetter('length')); deferredResult.addTest(1, "Amazon direct login has 1 field needing a form value"); deferredResult.getValue('directLogin'); deferredResult.addMethodcaller('inputs'); deferredResult.addCallback(MochiKit.Base.values); deferredResult.addCallback(MochiKit.Base.filter, MochiKit.Base.methodcaller('needsBinding')); deferredResult.addCallback(MochiKit.Base.itemgetter('length')); deferredResult.addTest(2, "Amazon direct login has 2 field needing a binding"); deferredResult.getValue('directLogin'); deferredResult.addMethodcaller('bindings'); deferredResult.addCallback(MochiKit.Base.keys); deferredResult.addCallback(MochiKit.Base.itemgetter('length')); deferredResult.addTest(2, "Amazon direct login has just two bindings"); deferredResult.getValue('directLogin'); deferredResult.addMethodcaller('bindings'); deferredResult.addCallback(MochiKit.Base.itemgetter('email')); deferredResult.addMethodcaller('fieldKey'); deferredResult.addTest('5e822c34aaf1a9fbc0b52585c1915f3a3758abd51923a4d35ae85373bbb839c2', "Amazon direct login 'email' binding points to the correct field"); deferredResult.getValue('directLogin'); deferredResult.addMethodcaller('bindings'); deferredResult.addCallback(MochiKit.Base.itemgetter('password')); deferredResult.setValue('passwordBinding'); deferredResult.addMethodcaller('fieldKey'); deferredResult.addTest('01e4bb6dcf054f312c535de8160bcf50bdccd664bdc05721b10d4e69583765f7', "Amazon direct login 'password' binding points to the correct field"); deferredResult.getValue('passwordBinding'); deferredResult.addMethodcaller('field'); deferredResult.addMethodcaller('label'); deferredResult.addTest('password', "Amazon direct login 'password' binding points to the 'password' field"); deferredResult.getValue('directLogin'); deferredResult.addMethodcaller('formValues'); deferredResult.addCallback(MochiKit.Base.keys); deferredResult.addCallback(MochiKit.Base.itemgetter('length')); deferredResult.addTest(1, "Amazon direct login has just one formValue"); deferredResult.getValue('directLogin'); deferredResult.addMethodcaller('formValues'); deferredResult.addCallback(MochiKit.Base.itemgetter('action')); deferredResult.addMethodcaller('value'); deferredResult.addTest('sign-in', "Amazon direct 'action' formValue is set to 'sign-in'"); deferredResult.callback(); return deferredResult; }, //------------------------------------------------------------------------- 'editDirectLoginLabel': function (someTestArgs) { var deferredResult; var proxy; var user; var oldLabel; var newLabel; var recordID = 'd5f700b9c3367c39551ea49e00a9ab20dae09dd79d46047b983fc7c4bfaa050d'; var directLoginID = 'dba0db679802f0e6aa6d0b7a6aaf42350aabc5f057409edd99a268a92ebb6496'; oldLabel = "Yahoo! Mail"; newLabel = "YAHOO! Mail"; proxy = new Clipperz.PM.Proxy.Test({shouldPayTolls:false, isDefault:true, readOnly:false}); user = new Clipperz.PM.DataModel.User({username:'joe', getPassphraseFunction:function () { return 'clipperz';}}); deferredResult = new Clipperz.Async.Deferred("Record.test.editDirectLoginLabel", someTestArgs); deferredResult.addMethod(proxy.dataStore(), 'setupWithEncryptedData', testData['joe_clipperz_offline_copy_data']); deferredResult.addMethod(user, 'login'); deferredResult.addMethod(user, 'getRecord', recordID); deferredResult.addMethodcaller('directLogins'); deferredResult.addCallback(MochiKit.Base.itemgetter(directLoginID)); deferredResult.addMethodcaller('label'); deferredResult.addTest(oldLabel, "the current label of the direct login"); deferredResult.addMethod(user, 'getRecord', recordID); deferredResult.addMethodcaller('directLogins'); deferredResult.addCallback(MochiKit.Base.itemgetter(directLoginID)); deferredResult.addMethodcaller('setLabel', newLabel); deferredResult.addMethod(user, 'hasPendingChanges'); deferredResult.addTest(true, "changing the label of a direct login should trigger some changes"); deferredResult.addMethod(user, 'getRecord', recordID); deferredResult.addMethodcaller('hasPendingChanges'); deferredResult.addTest(true, "changing the label of a direct login should trigger some changes also on the record itself"); deferredResult.addMethod(user, 'getRecord', recordID); deferredResult.addMethodcaller('directLogins'); deferredResult.addCallback(MochiKit.Base.itemgetter(directLoginID)); deferredResult.addMethodcaller('hasPendingChanges'); deferredResult.addTest(true, "changing the label of a direct login should trigger some changes also on the directLogin itself"); deferredResult.callback(); return deferredResult; }, //------------------------------------------------------------------------- 'editDirectLoginFormValueAndRestoreChanges': function (someTestArgs) { var deferredResult; var proxy; var user; var recordID = 'd5f700b9c3367c39551ea49e00a9ab20dae09dd79d46047b983fc7c4bfaa050d'; var directLoginID = 'dba0db679802f0e6aa6d0b7a6aaf42350aabc5f057409edd99a268a92ebb6496'; proxy = new Clipperz.PM.Proxy.Test({shouldPayTolls:false, isDefault:true, readOnly:false}); user = new Clipperz.PM.DataModel.User({username:'joe', getPassphraseFunction:function () { return 'clipperz';}}); deferredResult = new Clipperz.Async.Deferred("Record.test.editDirectLoginFormValueAndRestoreChanges", someTestArgs); deferredResult.addMethod(proxy.dataStore(), 'setupWithEncryptedData', testData['joe_clipperz_offline_copy_data']); deferredResult.addMethod(user, 'login'); deferredResult.addMethod(user, 'getRecord', recordID); deferredResult.addMethodcaller('directLogins'); deferredResult.addCallback(MochiKit.Base.itemgetter(directLoginID)); deferredResult.setValue('directLogin'); deferredResult.addMethodcaller('formValues'); deferredResult.addCallback(MochiKit.Base.itemgetter('.persistent')); deferredResult.addMethodcaller('value'); deferredResult.addTest(null, "original formValue value matches"); deferredResult.getValue('directLogin'); deferredResult.addMethodcaller('formValues'); deferredResult.addCallback(MochiKit.Base.itemgetter('.persistent')) deferredResult.addMethodcaller('setValue', 'y'); deferredResult.getValue('directLogin'); deferredResult.addMethodcaller('formValues'); deferredResult.addCallback(MochiKit.Base.itemgetter('.persistent')) deferredResult.addMethodcaller('value'); deferredResult.addTest('y', "the newly set value is retained"); deferredResult.addMethod(user, 'hasPendingChanges'); deferredResult.addTest(true, "changing the label of a direct login should trigger some changes"); deferredResult.addMethod(user, 'getRecord', recordID); deferredResult.addMethodcaller('hasPendingChanges'); deferredResult.addTest(true, "changing the label of a direct login should trigger some changes also on the record itself"); deferredResult.addMethod(user, 'getRecord', recordID); deferredResult.addMethodcaller('directLogins'); deferredResult.addCallback(MochiKit.Base.itemgetter(directLoginID)); deferredResult.addMethodcaller('hasPendingChanges'); deferredResult.addTest(true, "changing the label of a direct login should trigger some changes also on the directLogin itself"); deferredResult.addMethod(user, 'revertChanges'); deferredResult.getValue('directLogin'); deferredResult.addMethodcaller('formValues'); deferredResult.addCallback(MochiKit.Base.itemgetter('.persistent')) deferredResult.addMethodcaller('value'); deferredResult.addTest(null, "the old formValue value is correctly restored"); deferredResult.callback(); return deferredResult; }, //------------------------------------------------------------------------- 'editDirectLoginConfigurationAndRevertChanges': function (someTestArgs) { var deferredResult; var proxy; var user; var recordID = 'd5f700b9c3367c39551ea49e00a9ab20dae09dd79d46047b983fc7c4bfaa050d'; var directLoginID = 'dba0db679802f0e6aa6d0b7a6aaf42350aabc5f057409edd99a268a92ebb6496'; proxy = new Clipperz.PM.Proxy.Test({shouldPayTolls:false, isDefault:true, readOnly:false}); user = new Clipperz.PM.DataModel.User({username:'joe', getPassphraseFunction:function () { return 'clipperz';}}); deferredResult = new Clipperz.Async.Deferred("Record.test.editDirectLoginConfigurationAndRevertChanges", someTestArgs); deferredResult.addMethod(proxy.dataStore(), 'setupWithEncryptedData', testData['joe_clipperz_offline_copy_data']); deferredResult.addMethod(user, 'login'); deferredResult.addMethod(user, 'getRecord', recordID); deferredResult.addMethodcaller('directLogins'); deferredResult.addCallback(MochiKit.Base.itemgetter(directLoginID)); deferredResult.addCallback(function (aDirectLogin) { // var newBookmarkletConfiguration; // newBookmarkletConfiguration = '{\n \"page\": {\n \"title\": \"Yahoo! Mail\"\n },\n \"form\": {\n \"attributes\": {\n \"action\": \"https://login.yahoo.com/config/login?\",\n \"method\": \"post\"\n },\n \"inputs\": [\n {\n \"type\": \"text\",\n \"name\": \"login\",\n \"value\": \"\"\n },\n {\n \"type\": \"password\",\n \"name\": \"passwd\",\n \"value\": \"\"\n },\n {\n \"type\": \"checkbox\",\n \"name\": \".persistent\",\n \"value\": \"y\"\n }\n ]\n },\n \"version\": \"0.2\"\n}'; return Clipperz.Async.callbacks("Record.test.editDirectLoginConfiguration [inner call]", [ MochiKit.Base.method(aDirectLogin, 'bookmarkletConfiguration'), Clipperz.Async.Test.is(directLoginConfigurations['Yahoo! Mail'], "the current bookmarkletConfiguration"), MochiKit.Base.method(aDirectLogin, 'favicon'), Clipperz.Async.Test.is('http://login.yahoo.com/favicon.ico', "the original favicon is the expected one"), MochiKit.Base.method(aDirectLogin, 'setBookmarkletConfiguration', directLoginConfigurations['Parallels']), MochiKit.Base.method(aDirectLogin, 'favicon'), Clipperz.Async.Test.is('http://login.yahoo.com/favicon.ico', "the original favicon is the expected one"), MochiKit.Base.method(aDirectLogin, 'hasPendingChanges'), Clipperz.Async.Test.ok("changing the configuration should trigger the pending changes on the direct login"), MochiKit.Base.method(aDirectLogin.record(), 'hasPendingChanges'), Clipperz.Async.Test.ok("changing the configuration should trigger the pending changes also on the record"), MochiKit.Base.method(user, 'hasPendingChanges'), Clipperz.Async.Test.ok("changing the configuration should trigger the pending changes also on the user"), MochiKit.Base.method(aDirectLogin, 'revertChanges'), MochiKit.Base.method(aDirectLogin, 'hasPendingChanges'), Clipperz.Async.Test.fail("reverting changes should reset pending changes on the direct login"), MochiKit.Base.method(aDirectLogin.record(), 'hasPendingChanges'), Clipperz.Async.Test.fail("reverting changes should reset pending changes also on the record"), MochiKit.Base.method(user, 'hasPendingChanges'), Clipperz.Async.Test.fail("reverting changes should reset pending changes also on the user"), MochiKit.Base.noop ], someTestArgs); }) deferredResult.callback(); return deferredResult; }, //------------------------------------------------------------------------- 'editDirectLoginConfiguration_keepingTheSameStructure_AndSaveChanges': function (someTestArgs) { var deferredResult; var proxy; var user; var user2; var newBookmarkletConfiguration; var recordID = 'd5f700b9c3367c39551ea49e00a9ab20dae09dd79d46047b983fc7c4bfaa050d'; var directLoginID = 'dba0db679802f0e6aa6d0b7a6aaf42350aabc5f057409edd99a268a92ebb6496'; proxy = new Clipperz.PM.Proxy.Test({shouldPayTolls:false, isDefault:true, readOnly:false}); user = new Clipperz.PM.DataModel.User({username:'joe', getPassphraseFunction:function () { return 'clipperz';}}); user2 = new Clipperz.PM.DataModel.User({username:'joe', getPassphraseFunction:function () { return 'clipperz';}}); newBookmarkletConfiguration = '{\n \"page\": {\n \"title\": \"Yahoo! Mail\"\n },\n \"form\": {\n \"attributes\": {\n \"action\": \"https://login.yahoo.com/config/login?\",\n \"method\": \"post\"\n },\n \"inputs\": [\n {\n \"type\": \"text\",\n \"name\": \"login\",\n \"value\": \"\"\n },\n {\n \"type\": \"password\",\n \"name\": \"passwd\",\n \"value\": \"\"\n },\n {\n \"type\": \"checkbox\",\n \"name\": \".persistent\",\n \"value\": \"y\"\n }\n ]\n },\n \"version\": \"0.2\"\n}'; deferredResult = new Clipperz.Async.Deferred("Record.test.editDirectLoginConfiguration_keepingTheSameStructure_AndSaveChanges", someTestArgs); deferredResult.addMethod(proxy.dataStore(), 'setupWithEncryptedData', testData['joe_clipperz_offline_copy_data']); deferredResult.addMethod(user, 'login'); deferredResult.addMethod(user, 'getRecord', recordID); deferredResult.addMethodcaller('directLogins'); deferredResult.addCallback(MochiKit.Base.itemgetter(directLoginID)); deferredResult.addCallback(function (aDirectLogin) { return Clipperz.Async.callbacks("Record.test.editDirectLoginConfiguration_keepingTheSameStructure_AndSaveChanges [inner call 1]", [ MochiKit.Base.method(aDirectLogin, 'bookmarkletConfiguration'), Clipperz.Async.Test.is(directLoginConfigurations['Yahoo! Mail'], "the current bookmarkletConfiguration (1)"), MochiKit.Base.method(aDirectLogin, 'inputs'), MochiKit.Base.keys, MochiKit.Base.itemgetter('length'), Clipperz.Async.Test.is(26, "The original direct login had 26 inputs"), MochiKit.Base.method(aDirectLogin, 'bindings'), MochiKit.Base.keys, MochiKit.Base.itemgetter('length'), Clipperz.Async.Test.is(2, "The original direct login had 2 inputs"), MochiKit.Base.method(aDirectLogin, 'bindings'), MochiKit.Base.itemgetter('login'), MochiKit.Base.methodcaller('field'), MochiKit.Base.methodcaller('reference'), Clipperz.Async.Test.is('4cfaf1e782086e7527bd0e0cc82b67eb773e8157ad0c5babe516f7bc945a02a9', "the original 'login' direct login binding points to the correct field"), MochiKit.Base.method(aDirectLogin, 'formValues'), MochiKit.Base.keys, MochiKit.Base.itemgetter('length'), Clipperz.Async.Test.is(1, "The original direct login had 1 form values"), MochiKit.Base.method(aDirectLogin, 'formValues'), MochiKit.Base.itemgetter('.persistent'), MochiKit.Base.methodcaller('type'), Clipperz.Async.Test.is('checkbox', "the original formValue has the expected type"), MochiKit.Base.method(aDirectLogin, 'formValues'), MochiKit.Base.itemgetter('.persistent'), MochiKit.Base.methodcaller('value'), Clipperz.Async.Test.is(null, "the original formValue is correct (1)"), MochiKit.Base.method(aDirectLogin, 'formValues'), MochiKit.Base.itemgetter('.persistent'), MochiKit.Base.methodcaller('setValue', 'y'), MochiKit.Base.method(aDirectLogin, 'setBookmarkletConfiguration', newBookmarkletConfiguration), MochiKit.Base.method(user, 'saveChanges'), MochiKit.Base.method(aDirectLogin, 'bindings'), MochiKit.Base.itemgetter('login'), MochiKit.Base.methodcaller('field'), MochiKit.Base.methodcaller('reference'), Clipperz.Async.Test.is('4cfaf1e782086e7527bd0e0cc82b67eb773e8157ad0c5babe516f7bc945a02a9', "the 'login' binding is still valid after the new configuration is set"), MochiKit.Base.method(aDirectLogin, 'hasPendingChanges'), Clipperz.Async.Test.fail("reverting changes should reset pending changes on the direct login (2)"), MochiKit.Base.method(aDirectLogin.record(), 'hasPendingChanges'), Clipperz.Async.Test.fail("reverting changes should reset pending changes also on the record (2)"), MochiKit.Base.method(user, 'hasPendingChanges'), Clipperz.Async.Test.fail("reverting changes should reset pending changes also on the user (2)"), MochiKit.Base.noop ], someTestArgs); }) deferredResult.addMethod(user2, 'login'); deferredResult.addMethod(user2, 'getRecord', recordID); deferredResult.addMethodcaller('directLogins'); deferredResult.addCallback(MochiKit.Base.itemgetter(directLoginID)); deferredResult.addCallback(function (aDirectLogin) { return Clipperz.Async.callbacks("Record.test.editDirectLoginConfiguration_keepingTheSameStructure_AndSaveChanges [inner call 2]", [ MochiKit.Base.method(aDirectLogin, 'bookmarkletConfiguration'), Clipperz.Async.Test.is(newBookmarkletConfiguration, "the direct login has the new bookmarkletConfiguration even after being reloaded"), MochiKit.Base.method(aDirectLogin, 'inputs'), MochiKit.Base.keys, MochiKit.Base.itemgetter('length'), Clipperz.Async.Test.is(3, "The new direct login has 3 inputs"), MochiKit.Base.method(aDirectLogin, 'bindings'), MochiKit.Base.keys, MochiKit.Base.itemgetter('length'), Clipperz.Async.Test.is(2, "The new direct login had 2 inputs"), MochiKit.Base.method(aDirectLogin, 'bindings'), MochiKit.Base.itemgetter('login'), MochiKit.Base.methodcaller('field'), MochiKit.Base.methodcaller('reference'), Clipperz.Async.Test.is('4cfaf1e782086e7527bd0e0cc82b67eb773e8157ad0c5babe516f7bc945a02a9', "the new 'login' direct login binding still points to the correct field"), MochiKit.Base.method(aDirectLogin, 'formValues'), MochiKit.Base.keys, MochiKit.Base.itemgetter('length'), Clipperz.Async.Test.is(1, "The new direct login had 1 form values (1)"), MochiKit.Base.method(aDirectLogin, 'formValues'), MochiKit.Base.itemgetter('.persistent'), MochiKit.Base.methodcaller('value'), Clipperz.Async.Test.is(null, "the formValue is still correctly set"), MochiKit.Base.noop ], someTestArgs); }); deferredResult.callback(); return deferredResult; }, //------------------------------------------------------------------------- 'editDirectLoginConfiguration_changingTheStructure_AndSaveChanges': function (someTestArgs) { var deferredResult; var proxy; var user; var user2; var recordID = 'd5f700b9c3367c39551ea49e00a9ab20dae09dd79d46047b983fc7c4bfaa050d'; var directLoginID = 'dba0db679802f0e6aa6d0b7a6aaf42350aabc5f057409edd99a268a92ebb6496'; proxy = new Clipperz.PM.Proxy.Test({shouldPayTolls:false, isDefault:true, readOnly:false}); user = new Clipperz.PM.DataModel.User({username:'joe', getPassphraseFunction:function () { return 'clipperz';}}); user2 = new Clipperz.PM.DataModel.User({username:'joe', getPassphraseFunction:function () { return 'clipperz';}}); deferredResult = new Clipperz.Async.Deferred("Record.test.editDirectLoginConfiguration_changingTheStructure_AndSaveChanges", someTestArgs); deferredResult.addMethod(proxy.dataStore(), 'setupWithEncryptedData', testData['joe_clipperz_offline_copy_data']); deferredResult.addMethod(user, 'login'); deferredResult.addMethod(user, 'getRecord', recordID); deferredResult.addMethodcaller('directLogins'); deferredResult.addCallback(MochiKit.Base.itemgetter(directLoginID)); deferredResult.addCallback(function (aDirectLogin) { return Clipperz.Async.callbacks("Record.test.editDirectLoginConfiguration_changingTheStructure_AndSaveChanges [inner call 1]", [ MochiKit.Base.method(aDirectLogin, 'bookmarkletConfiguration'), Clipperz.Async.Test.is(directLoginConfigurations['Yahoo! Mail'], "the current bookmarkletConfiguration (2)"), MochiKit.Base.method(aDirectLogin, 'inputs'), MochiKit.Base.keys, MochiKit.Base.itemgetter('length'), Clipperz.Async.Test.is(26, "The original direct login had 26 inputs"), MochiKit.Base.method(aDirectLogin, 'bindings'), MochiKit.Base.keys, MochiKit.Base.itemgetter('length'), Clipperz.Async.Test.is(2, "The original direct login had 2 inputs"), MochiKit.Base.method(aDirectLogin, 'bindings'), MochiKit.Base.itemgetter('login'), MochiKit.Base.methodcaller('field'), MochiKit.Base.methodcaller('reference'), Clipperz.Async.Test.is('4cfaf1e782086e7527bd0e0cc82b67eb773e8157ad0c5babe516f7bc945a02a9', "the original 'login' direct login binding points to the correct field"), MochiKit.Base.method(aDirectLogin, 'formValues'), MochiKit.Base.keys, MochiKit.Base.itemgetter('length'), Clipperz.Async.Test.is(1, "The original direct login had 1 form values"), MochiKit.Base.method(aDirectLogin, 'formValues'), MochiKit.Base.itemgetter('.persistent'), MochiKit.Base.methodcaller('value'), Clipperz.Async.Test.is(null, "the original formValue is correct (2)"), MochiKit.Base.method(aDirectLogin, 'setBookmarkletConfiguration', directLoginConfigurations['Parallels']), MochiKit.Base.method(user, 'saveChanges'), MochiKit.Base.method(aDirectLogin, 'inputs'), MochiKit.Base.keys, MochiKit.Base.itemgetter('length'), Clipperz.Async.Test.is(2, "The new direct login has 2 inputs"), MochiKit.Base.method(aDirectLogin, 'formValues'), MochiKit.Base.keys, MochiKit.Base.itemgetter('length'), Clipperz.Async.Test.is(0, "The new direct login has no form values"), MochiKit.Base.method(aDirectLogin, 'bindings'), MochiKit.Base.keys, MochiKit.Base.itemgetter('length'), Clipperz.Async.Test.is(2, "The new direct login has 2 inputs"), MochiKit.Base.method(aDirectLogin, 'bindings'), MochiKit.Base.itemgetter('login'), Clipperz.Async.Test.is(null, "the 'login' binding should not exist within the new configuration"), MochiKit.Base.method(aDirectLogin, 'bindings'), MochiKit.Base.itemgetter('passwd'), Clipperz.Async.Test.is(null, "the 'passwd' binding should not exist within the new configuration"), MochiKit.Base.method(aDirectLogin, 'bindings'), MochiKit.Base.itemgetter('Email'), Clipperz.Async.Test.ok("the 'Email' binding should exist within the new configuration"), MochiKit.Base.method(aDirectLogin, 'bindings'), MochiKit.Base.itemgetter('Password'), Clipperz.Async.Test.ok("the 'Password' binding should exist within the new configuration"), MochiKit.Base.method(aDirectLogin, 'bindings'), MochiKit.Base.itemgetter('Email'), MochiKit.Base.methodcaller('field'), Clipperz.Async.Test.is(null, "the 'Email' binding should not point to any field, yet"), MochiKit.Base.method(aDirectLogin, 'hasPendingChanges'), Clipperz.Async.Test.fail("reverting changes should reset pending changes on the direct login (2)"), MochiKit.Base.method(aDirectLogin.record(), 'hasPendingChanges'), Clipperz.Async.Test.fail("reverting changes should reset pending changes also on the record (2)"), MochiKit.Base.method(user, 'hasPendingChanges'), Clipperz.Async.Test.fail("reverting changes should reset pending changes also on the user (2)"), MochiKit.Base.noop ], someTestArgs); }) deferredResult.addMethod(user2, 'login'); deferredResult.addMethod(user2, 'getRecord', recordID); deferredResult.addMethodcaller('directLogins'); deferredResult.addCallback(MochiKit.Base.itemgetter(directLoginID)); deferredResult.addCallback(function (aDirectLogin) { return Clipperz.Async.callbacks("Record.test.editDirectLoginConfiguration_changingTheStructure_AndSaveChanges [inner call 2]", [ MochiKit.Base.method(aDirectLogin, 'bookmarkletConfiguration'), Clipperz.Base.evalJSON, MochiKit.Base.itemgetter('form'), Clipperz.Async.Test.isDeeply(Clipperz.Base.evalJSON(directLoginConfigurations['Parallels'])['form'], "the direct login has the new bookmarkletConfiguration even after being reloaded"), MochiKit.Base.method(aDirectLogin, 'inputs'), MochiKit.Base.keys, MochiKit.Base.itemgetter('length'), Clipperz.Async.Test.is(2, "The new -reloaded- direct login has 2 inputs"), MochiKit.Base.method(aDirectLogin, 'bindings'), MochiKit.Base.keys, MochiKit.Base.itemgetter('length'), Clipperz.Async.Test.is(2, "The new direct login had 2 inputs"), MochiKit.Base.method(aDirectLogin, 'bindings'), MochiKit.Base.itemgetter('login'), Clipperz.Async.Test.is(null, "the 'login' binding should not exist within the new configuration"), MochiKit.Base.method(aDirectLogin, 'formValues'), MochiKit.Base.keys, MochiKit.Base.itemgetter('length'), Clipperz.Async.Test.is(0, "The new direct login has no form values (2)"), MochiKit.Base.noop ], someTestArgs); }); deferredResult.callback(); return deferredResult; }, //------------------------------------------------------------------------- 'editFieldValueAndRestoreIt': function (someTestArgs) { var deferredResult; var proxy; var user; var recordID = 'd5f700b9c3367c39551ea49e00a9ab20dae09dd79d46047b983fc7c4bfaa050d'; proxy = new Clipperz.PM.Proxy.Test({shouldPayTolls:false, isDefault:true, readOnly:false}); user = new Clipperz.PM.DataModel.User({username:'joe', getPassphraseFunction:function () { return 'clipperz';}}); deferredResult = new Clipperz.Async.Deferred("Record.test.editValueAndRestoreIt", someTestArgs); deferredResult.addMethod(proxy.dataStore(), 'setupWithEncryptedData', testData['joe_clipperz_offline_copy_data']); deferredResult.addMethod(user, 'login'); deferredResult.addMethod(user, 'getRecord', recordID); deferredResult.addMethodcaller('fields'); deferredResult.addCallback(MochiKit.Base.itemgetter('4cfaf1e782086e7527bd0e0cc82b67eb773e8157ad0c5babe516f7bc945a02a9')); deferredResult.addMethodcaller('value'); deferredResult.addTest('joe.clipperz', "the current field value is 'joe.clipperz'"); deferredResult.addMethod(user, 'getRecord', recordID); deferredResult.addMethodcaller('fields'); deferredResult.addCallback(MochiKit.Base.itemgetter('4cfaf1e782086e7527bd0e0cc82b67eb773e8157ad0c5babe516f7bc945a02a9')); deferredResult.addMethodcaller('setValue', 'fake.clipperz'); deferredResult.addMethod(user, 'getRecord', recordID); deferredResult.addMethodcaller('hasPendingChanges'); deferredResult.addTest(true, "changing the value of a field should trigger pending changes"); deferredResult.addMethod(user, 'getRecord', recordID); deferredResult.addMethodcaller('fields'); deferredResult.addCallback(MochiKit.Base.itemgetter('4cfaf1e782086e7527bd0e0cc82b67eb773e8157ad0c5babe516f7bc945a02a9')); deferredResult.addMethodcaller('setValue', 'joe.clipperz'); deferredResult.addMethod(user, 'getRecord', recordID); deferredResult.addMethodcaller('hasPendingChanges'); deferredResult.addTest(false, "restoring the value of a field should revert pending changes"); deferredResult.callback(); return deferredResult; }, //------------------------------------------------------------------------- 'accessFieldValues': function (someTestArgs) { var deferredResult; var proxy; var user; var recordID = 'd5f700b9c3367c39551ea49e00a9ab20dae09dd79d46047b983fc7c4bfaa050d'; proxy = new Clipperz.PM.Proxy.Test({shouldPayTolls:false, isDefault:true, readOnly:false}); user = new Clipperz.PM.DataModel.User({username:'joe', getPassphraseFunction:function () { return 'clipperz';}}); deferredResult = new Clipperz.Async.Deferred("Record.test.accessFieldValues", someTestArgs); deferredResult.addMethod(proxy.dataStore(), 'setupWithEncryptedData', testData['joe_clipperz_offline_copy_data']); deferredResult.addMethod(user, 'login'); deferredResult.addMethod(user, 'getRecord', recordID); deferredResult.addMethodcaller('fieldWithLabel', 'userID'); deferredResult.addMethodcaller('value'); deferredResult.addTest('joe.clipperz', "the current field value is 'joe.clipperz'"); deferredResult.callback(); return deferredResult; }, //------------------------------------------------------------------------- 'editFieldValueAndSaveIt': function (someTestArgs) { var deferredResult; var proxy; var user, user2; var recordID = '2977aa5f99a9f6e5596c1bd7871e82d7328c3716c9ef8ba349ae65f10d97924e'; var passwordFieldID = '01e4bb6dcf054f312c535de8160bcf50bdccd664bdc05721b10d4e69583765f7'; proxy = new Clipperz.PM.Proxy.Test({shouldPayTolls:false, isDefault:true, readOnly:false}); user = new Clipperz.PM.DataModel.User({username:'joe', getPassphraseFunction:function () { return 'clipperz';}}); user2 = new Clipperz.PM.DataModel.User({username:'joe', getPassphraseFunction:function () { return 'clipperz';}}); deferredResult = new Clipperz.Async.Deferred("Record.test.editValueAndRestoreIt", someTestArgs); // deferredResult.addMethod(proxy.dataStore(), 'setupWithEncryptedData', testData['joe_clipperz_offline_copy_data']); deferredResult.addMethod(proxy.dataStore(), 'setupWithEncryptedData', testData['joe_clipperz_offline_copy_with_multipleRecordVersions_data']); deferredResult.addMethod(user, 'login'); deferredResult.addMethod(user, 'getRecord', recordID); deferredResult.addMethodcaller('getVersions'); deferredResult.addCallback(MochiKit.Base.keys); deferredResult.addCallback(MochiKit.Base.itemgetter('length')); deferredResult.addTest(5, "the selected record has 5 versions"); deferredResult.addMethod(user, 'getRecord', recordID); deferredResult.addMethodcaller('fields'); deferredResult.addCallback(MochiKit.Base.itemgetter(passwordFieldID)); deferredResult.collectResults({ 'label': MochiKit.Base.methodcaller('label'), 'value': MochiKit.Base.methodcaller('value') }); deferredResult.addTest({'label': 'password', 'value': 'HRRd7ycaFVG6'}, "the current field label and value match", true); deferredResult.addMethod(user, 'getRecord', recordID); deferredResult.addMethodcaller('fields'); deferredResult.addCallback(MochiKit.Base.itemgetter(passwordFieldID)); deferredResult.addMethodcaller('setValue', '<<pippo>>'); deferredResult.addMethod(user, 'getRecord', recordID); deferredResult.addMethodcaller('hasPendingChanges'); deferredResult.addTest(true, "changing the value of a field should trigger pending changes"); deferredResult.addMethod(user, 'saveChanges'); deferredResult.addMethod(user, 'hasPendingChanges'); deferredResult.addTest(false, "after saving, there should be no pending changes"); deferredResult.addMethod(user, 'getRecord', recordID); deferredResult.addMethodcaller('getVersions'); deferredResult.addCallback(MochiKit.Base.keys); deferredResult.addCallback(MochiKit.Base.itemgetter('length')); deferredResult.addTest(6, "the selected record, after saving a new version, has now 6 versions"); deferredResult.addMethod(user2, 'login'); deferredResult.addMethod(user2, 'getRecord', recordID); deferredResult.addMethodcaller('getVersions'); deferredResult.addCallback(MochiKit.Base.keys); deferredResult.addCallback(MochiKit.Base.itemgetter('length')); deferredResult.addTest(6, "the selected record - reloaded from the db - has 6 versions"); deferredResult.addMethod(user2, 'getRecord', recordID); deferredResult.addMethodcaller('fields'); deferredResult.addCallback(MochiKit.Base.itemgetter(passwordFieldID)); deferredResult.collectResults({ 'label': MochiKit.Base.methodcaller('label'), 'value': MochiKit.Base.methodcaller('value') }); deferredResult.addTest({'label': 'password', 'value': '<<pippo>>'}, "the current field label and value match", true); /* deferredResult.addCallback(function (aValue) { console.log("FIELDS", aValue); return aValue}); deferredResult.addMethod(user, 'getRecord', recordID); deferredResult.addMethodcaller('fields'); deferredResult.addCallback(MochiKit.Base.itemgetter('4cfaf1e782086e7527bd0e0cc82b67eb773e8157ad0c5babe516f7bc945a02a9')); deferredResult.addMethodcaller('setValue', 'joe.clipperz'); deferredResult.addMethod(user, 'getRecord', recordID); deferredResult.addMethodcaller('hasPendingChanges'); deferredResult.addTest(false, "restoring the value of a field should revert pending changes"); */ deferredResult.callback(); return deferredResult; }, //------------------------------------------------------------------------- 'editNotesAndRestoreIt': function (someTestArgs) { var deferredResult; var proxy; var user; var recordID = 'd5f700b9c3367c39551ea49e00a9ab20dae09dd79d46047b983fc7c4bfaa050d'; proxy = new Clipperz.PM.Proxy.Test({shouldPayTolls:false, isDefault:true, readOnly:false}); user = new Clipperz.PM.DataModel.User({username:'joe', getPassphraseFunction:function () { return 'clipperz';}}); deferredResult = new Clipperz.Async.Deferred("Record.test.editNotesAndRestoreIt", someTestArgs); deferredResult.addMethod(proxy.dataStore(), 'setupWithEncryptedData', testData['joe_clipperz_offline_copy_data']); deferredResult.addMethod(user, 'login'); deferredResult.addMethod(user, 'getRecord', recordID); deferredResult.addMethodcaller('notes'); deferredResult.addTest('', "the current note is the empty string even if nothing is set on the record"); deferredResult.addMethod(user, 'getRecord', recordID); deferredResult.addMethodcaller('setNotes', ''); deferredResult.addMethod(user, 'getRecord', recordID); deferredResult.addMethodcaller('hasPendingChanges'); deferredResult.addTest(false, "setting notes to an empty string should be the same has not having the notes altogether"); deferredResult.callback(); return deferredResult; }, //------------------------------------------------------------------------- 'loadAllRecordVersions': function (someTestArgs) { var deferredResult; var proxy; var user; var recordID = '2977aa5f99a9f6e5596c1bd7871e82d7328c3716c9ef8ba349ae65f10d97924e'; proxy = new Clipperz.PM.Proxy.Test({shouldPayTolls:false, isDefault:true, readOnly:false}); user = new Clipperz.PM.DataModel.User({username:'joe', getPassphraseFunction:function () { return 'clipperz';}}); deferredResult = new Clipperz.Async.Deferred("Record.test.loadAllRecordVersions", someTestArgs); deferredResult.addMethod(proxy.dataStore(), 'setupWithEncryptedData', testData['joe_clipperz_offline_copy_with_multipleRecordVersions_data']); deferredResult.addMethod(user, 'login'); deferredResult.addMethod(user, 'getRecord', recordID); deferredResult.addMethodcaller('label'); deferredResult.addTest('Amazon.com', "the selected record is the expected one"); deferredResult.addMethod(user, 'getRecord', recordID); deferredResult.addMethodcaller('getVersions'); deferredResult.addCallback(MochiKit.Base.keys); deferredResult.addCallback(MochiKit.Base.itemgetter('length')); deferredResult.addTest(5, "the 'Amazon' record has 5 versions"); deferredResult.addMethod(user, 'getRecord', recordID); deferredResult.addMethodcaller('getCurrentRecordVersion'); deferredResult.addMethodcaller('fields'); deferredResult.addCallback(MochiKit.Base.keys); deferredResult.addCallback(MochiKit.Base.itemgetter('length')); deferredResult.addTest(3, "the current version of 'Amazon' record has 3 fields"); deferredResult.callback(); return deferredResult; }, //------------------------------------------------------------------------- 'createDirectLoginAndDeleteItAfterward': function (someTestArgs) { var deferredResult; var proxy; var user, user2; var recordID = 'd5f700b9c3367c39551ea49e00a9ab20dae09dd79d46047b983fc7c4bfaa050d'; // YAHOO (4) var directLoginReference; proxy = new Clipperz.PM.Proxy.Test({shouldPayTolls:false, isDefault:true, readOnly:false}); user = new Clipperz.PM.DataModel.User({username:'joe', getPassphraseFunction:function () { return 'clipperz';}}); user2 = new Clipperz.PM.DataModel.User({username:'joe', getPassphraseFunction:function () { return 'clipperz';}}); deferredResult = new Clipperz.Async.Deferred("Record.test.addDirectLoginAndRevertChanges", someTestArgs); deferredResult.addMethod(proxy.dataStore(), 'setupWithEncryptedData', testData['joe_clipperz_offline_copy_data']); deferredResult.addMethod(user, 'login'); deferredResult.addMethod(user, 'getRecord', recordID); deferredResult.setValue('record'); deferredResult.addMethodcaller('directLogins'); deferredResult.addCallback(MochiKit.Base.keys); deferredResult.addCallback(MochiKit.Base.itemgetter('length')); deferredResult.addTest(4, "the record, when initially loaded, has 4 direct logins"); deferredResult.getValue('record'); deferredResult.addMethodcaller('createNewDirectLogin'); deferredResult.setValue('directLogin'); deferredResult.getValue('directLogin'); deferredResult.addMethodcaller('setLabel', "New direct login"); deferredResult.getValue('directLogin'); deferredResult.addMethodcaller('setBookmarkletConfiguration', '{"page": {"title": "Parallels Account"}, "form": {"attributes": {"action": "https://www.parallels.com/account/", "method": "post"}, "inputs": [{"type": "text", "name": "Email", "value": ""}, {"type": "password", "name": "Password", "value": ""}]}, "version": "0.2.3"}'); deferredResult.getValue('directLogin'); deferredResult.addMethodcaller('remove'); deferredResult.addMethod(user, 'hasPendingChanges'); deferredResult.addTest(false, "after reverting the changes, the user should NOT have pending changes"); deferredResult.callback(); return deferredResult; }, //------------------------------------------------------------------------- 'syntaxFix': MochiKit.Base.noop }; //############################################################################# SimpleTest.runDeferredTests("Clipperz.PM.DataModel.Record", tests, {trace:false}); diff --git a/frontend/gamma/tests/tests/Clipperz/PM/DataModel/User.html b/frontend/gamma/tests/tests/Clipperz/PM/DataModel/User.html index 793f763..3a0eda8 100644 --- a/frontend/gamma/tests/tests/Clipperz/PM/DataModel/User.html +++ b/frontend/gamma/tests/tests/Clipperz/PM/DataModel/User.html @@ -1,101 +1,102 @@ <!-- 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/. --> <html> <head> <title>Clipperz.PM.DataModel.User - test</title> <script type="text/javascript" src="../../../../../js/MochiKit/MochiKit.js"></script> <script type="text/javascript" src="../../../../SimpleTest/SimpleTest.js"></script> <link rel="stylesheet" type="text/css" href="../../../../SimpleTest/test.css"> <script type='text/javascript' src='../../../../../js/JSON/json2.js'></script> <script type='text/javascript' src='../../../../../js/Clipperz/YUI/Utils.js'></script> <script type='text/javascript' src='../../../../../js/Clipperz/Base.js'></script> <script type='text/javascript' src='../../../../../js/Clipperz/Date.js'></script> <script type='text/javascript' src='../../../../../js/Clipperz/ByteArray.js'></script> <script type='text/javascript' src='../../../../../js/Clipperz/Logging.js'></script> <script type='text/javascript' src='../../../../../js/Clipperz/Async.js'></script> <script type='text/javascript' src='../../../../../js/Clipperz/Signal.js'></script> <script type='text/javascript' src='../../../../../js/Clipperz/KeyValueObjectStore.js'></script> <script type='text/javascript' src='../../../../../js/Clipperz/Crypto/Base.js'></script> <script type='text/javascript' src='../../../../../js/Clipperz/Crypto/BigInt.js'></script> <script type='text/javascript' src='../../../../../js/Clipperz/Crypto/AES.js'></script> + <script type='text/javascript' src='../../../../../js/Clipperz/Crypto/AES_2.js'></script> <script type='text/javascript' src='../../../../../js/Clipperz/Crypto/SHA.js'></script> <script type='text/javascript' src='../../../../../js/Clipperz/Crypto/PRNG.js'></script> <script type='text/javascript' src='../../../../../js/Clipperz/Crypto/SRP.js'></script> <script type='text/javascript' src='../../../../../js/Clipperz/PM/Toll.js'></script> <script type='text/javascript' src='../../../../../js/Clipperz/PM/Proxy.js'></script> <script type='text/javascript' src='../../../../../js/Clipperz/PM/Proxy/Proxy.Offline.js'></script> <script type='text/javascript' src='../../../../../js/Clipperz/PM/Proxy/Proxy.Test.js'></script> <script type='text/javascript' src='../../../../../js/Clipperz/PM/Proxy/Proxy.Offline.DataStore.js'></script> <script type='text/javascript' src='../../../../../js/Clipperz/PM/Connection.js'></script> <script type='text/javascript' src='../../../../../js/Clipperz/PM/Crypto.js'></script> <script type='text/javascript' src='../../../../../js/Clipperz/PM/UI/Common/Controllers/DirectLoginRunner.js'></script> <script type='text/javascript' src='../../../../../js/Clipperz/PM/Strings.js'></script> <script type='text/javascript' src='../../../../../js/Clipperz/PM/Strings/Strings_en-US.js'></script> <script type='text/javascript' src='../../../../../js/Clipperz/PM/Date.js'></script> <script type='text/javascript' src='../../../../../js/Clipperz/PM/DataModel/EncryptedRemoteObject.js'></script> <script type='text/javascript' src='../../../../../js/Clipperz/PM/DataModel/Record.js'></script> <script type='text/javascript' src='../../../../../js/Clipperz/PM/DataModel/Record.Version.js'></script> <script type='text/javascript' src='../../../../../js/Clipperz/PM/DataModel/Record.Version.Field.js'></script> <script type='text/javascript' src='../../../../../js/Clipperz/PM/DataModel/DirectLogin.js'></script> <script type='text/javascript' src='../../../../../js/Clipperz/PM/DataModel/DirectLoginInput.js'></script> <script type='text/javascript' src='../../../../../js/Clipperz/PM/DataModel/DirectLoginBinding.js'></script> <script type='text/javascript' src='../../../../../js/Clipperz/PM/DataModel/DirectLoginFormValue.js'></script> <script type='text/javascript' src='../../../../../js/Clipperz/PM/DataModel/User.js'></script> <script type='text/javascript' src='../../../../../js/Clipperz/PM/DataModel/User.Header.Legacy.js'></script> <script type='text/javascript' src='../../../../../js/Clipperz/PM/DataModel/User.Header.RecordIndex.js'></script> <script type='text/javascript' src='../../../../../js/Clipperz/PM/DataModel/User.Header.Preferences.js'></script> <script type='text/javascript' src='../../../../../js/Clipperz/PM/DataModel/User.Header.OneTimePasswords.js'></script> <script type='text/javascript' src='../../../../../js/Clipperz/PM/DataModel/OneTimePassword.js'></script> <script type="text/javascript" src="../../../../SimpleTest/SimpleTest.Async.js"></script> <script> Clipperz_IEisBroken = false; </script> <!--[if IE]><script> Clipperz_IEisBroken = true; Clipperz_normalizedNewLine = '\x0d\x0a'; </script><![endif]--> </head> <body> <pre id="test"> <script> Clipperz.PM.Strings.Languages.setSelectedLanguage('en-us'); </script> <script type="text/javascript" src="User.data.js"></script> <script type="text/javascript" src="User.data.old.js"></script> <script type="text/javascript" src="User.test.js"></script> </pre> </body> </html> diff --git a/frontend/gamma/tests/tests/Clipperz/PM/DataModel/User.test.js b/frontend/gamma/tests/tests/Clipperz/PM/DataModel/User.test.js index 45f3297..545580f 100644 --- a/frontend/gamma/tests/tests/Clipperz/PM/DataModel/User.test.js +++ b/frontend/gamma/tests/tests/Clipperz/PM/DataModel/User.test.js @@ -1,2077 +1,2077 @@ /* 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(); var tests = { //------------------------------------------------------------------------- 'invertIndex_test': function (someTestArgs) { var testIndex; var invertedIndex; testIndex = { 'key1': 'value1', 'key2': 'value2', 'key3': 'value3', 'key4': 'value4', 'key5': 'value5' }; invertedIndex = Clipperz.PM.DataModel.User.Header.RecordIndex.invertIndex(testIndex); SimpleTest.is(MochiKit.Base.keys(invertedIndex).length, MochiKit.Base.keys(testIndex).length, "the inverted index has the same number of elements as the original index"); SimpleTest.is(invertedIndex['value1'], 'key1', "the first element has been correctly inverted"); SimpleTest.is(invertedIndex['value2'], 'key2', "the second element has been correctly inverted"); SimpleTest.is(invertedIndex['value3'], 'key3', "the third element has been correctly inverted"); SimpleTest.is(invertedIndex['value4'], 'key4', "the forth element has been correctly inverted"); SimpleTest.is(invertedIndex['value5'], 'key5', "the fifth element has been correctly inverted"); return MochiKit.Async.succeed('done'); }, //------------------------------------------------------------------------- 'joe_clipperz_offline_copy_test': function(someTestArgs) { var deferredResult; var proxy; var user; proxy = new Clipperz.PM.Proxy.Test({shouldPayTolls:true, isDefault:true}); user = new Clipperz.PM.DataModel.User({username:'joe', getPassphraseFunction:function () { return 'clipperz';}}); deferredResult = new Clipperz.Async.Deferred("joe_clipperz_offline_copy_test", someTestArgs); deferredResult.addMethod(proxy.dataStore(), 'setupWithEncryptedData', testData['joe_clipperz_offline_copy_data']); deferredResult.addMethod(user, 'login'); deferredResult.addMethod(user, 'getRecords'); deferredResult.addCallback(function (someRecords) { is(someRecords.length, 20, "joe_clipperz_offline_copy_test - joe has 20 records"); }); deferredResult.addMethod(user, 'getRecords'); deferredResult.addCallback(MochiKit.Base.map, MochiKit.Base.methodcaller('label')); deferredResult.addCallback(Clipperz.Async.collectAll); deferredResult.addCallback(MochiKit.Base.methodcaller('sort')); deferredResult.addCallback(function (someSortedLabels) { SimpleTest.is(someSortedLabels.length, 20, "We got all the labels"); SimpleTest.is(someSortedLabels[0], "Amazon.com", "The first label is correct"); SimpleTest.is(someSortedLabels[1], "American Airlines", "The second label is correct"); SimpleTest.is(someSortedLabels[2], "Bloglines", "The third label is correct"); SimpleTest.is(someSortedLabels[3], "Digg", "The fourth label is correct"); SimpleTest.is(someSortedLabels[4], "Example Attack", "The fifth label is correct"); SimpleTest.is(someSortedLabels[5], "Expedia.com", "The sixth label is correct"); SimpleTest.is(someSortedLabels[6], "Google Account", "The seventh label is correct"); SimpleTest.is(someSortedLabels[7], "Home burglar alarm", "The eighth label is correct"); SimpleTest.is(someSortedLabels[8], "Jaiku", "The ninth label is correct"); SimpleTest.is(someSortedLabels[9], "LinkedIn", "The 10th label is correct"); SimpleTest.is(someSortedLabels[10], "Lufthansa", "The 11th label is correct"); SimpleTest.is(someSortedLabels[11], "Microsoft Office CD Key", "The 12th label is correct"); SimpleTest.is(someSortedLabels[12], "MyBlogLog", "The 13th label is correct"); SimpleTest.is(someSortedLabels[13], "MySpace", "The 14th label is correct"); SimpleTest.is(someSortedLabels[14], "SAP - Login", "The 15th label is correct"); SimpleTest.is(someSortedLabels[15], "The New York Times", "The 16th label is correct"); SimpleTest.is(someSortedLabels[16], "Web password", "The 17th label is correct"); SimpleTest.is(someSortedLabels[17], "Web password", "The 18th label is correct"); SimpleTest.is(someSortedLabels[18], "Yahoo! Account", "The 19th label is correct"); SimpleTest.is(someSortedLabels[19], "del.icio.us", "The 20th label is correct"); }); deferredResult.callback(); return deferredResult; }, //------------------------------------------------------------------------- 'joe_clipperz_offline_copy_getDirectLogins_test': function(someTestArgs) { var deferredResult; var proxy; var user; proxy = new Clipperz.PM.Proxy.Test({shouldPayTolls:true, isDefault:true}); user = new Clipperz.PM.DataModel.User({username:'joe', getPassphraseFunction:function () { return 'clipperz';}}); deferredResult = new Clipperz.Async.Deferred("joe_clipperz_offline_copy_getDirectLogins_test", someTestArgs); deferredResult.addMethod(proxy.dataStore(), 'setupWithEncryptedData', testData['joe_clipperz_offline_copy_data']); deferredResult.addMethod(user, 'login'); deferredResult.addMethod(user, 'getDirectLogins'); deferredResult.addCallback(function (someDirectLogins) { SimpleTest.is(someDirectLogins.length, 22, "joe has 22 direct logins"); }); deferredResult.addMethod(user, 'getDirectLogins'); deferredResult.addCallback(MochiKit.Base.map, MochiKit.Base.methodcaller('label')); deferredResult.addCallback(Clipperz.Async.collectAll); deferredResult.addCallback(MochiKit.Base.methodcaller('sort')); deferredResult.addCallback(function (someSortedLabels) { SimpleTest.is(someSortedLabels.length, 22, "We got all the labels"); SimpleTest.is(someSortedLabels[0], "Amazon.com", "The first label is correct"); SimpleTest.is(someSortedLabels[1], "American Airlines", "The second label is correct"); SimpleTest.is(someSortedLabels[2], "Bloglines", "The third label is correct"); SimpleTest.is(someSortedLabels[3], "Digg", "The fourth label is correct"); SimpleTest.is(someSortedLabels[4], "Example Attack", "The 5th label is correct"); SimpleTest.is(someSortedLabels[5], "Expedia.com", "The 6th label is correct"); SimpleTest.is(someSortedLabels[6], "Flickr", "The 7th label is correct"); SimpleTest.is(someSortedLabels[7], "Google Account", "The 8th label is correct"); SimpleTest.is(someSortedLabels[8], "Google Calendar", "The 9th label is correct"); SimpleTest.is(someSortedLabels[9], "Google Docs", "The 10th label is correct"); SimpleTest.is(someSortedLabels[10], "Google Mail", "The 11th label is correct"); SimpleTest.is(someSortedLabels[11], "Jaiku", "The 12th label is correct"); SimpleTest.is(someSortedLabels[12], "LinkedIn", "The 13th label is correct"); SimpleTest.is(someSortedLabels[13], "Lufthansa", "The 14th label is correct"); SimpleTest.is(someSortedLabels[14], "My Yahoo!", "The 15th label is correct"); SimpleTest.is(someSortedLabels[15], "MyBlogLog", "The 16th label is correct"); SimpleTest.is(someSortedLabels[16], "MySpace", "The 17th label is correct"); SimpleTest.is(someSortedLabels[17], "SAP - Login", "The 18th label is correct"); SimpleTest.is(someSortedLabels[18], "SAP - Login", "The 19th label is correct"); SimpleTest.is(someSortedLabels[19], "The New York Times", "The 20th label is correct"); SimpleTest.is(someSortedLabels[20], "Yahoo! Groups", "The 21st label is correct"); SimpleTest.is(someSortedLabels[21], "Yahoo! Mail", "The 22nd label is correct"); }); deferredResult.callback(); return deferredResult; }, //------------------------------------------------------------------------- 'getCredentials_test': function (someTestArgs) { var deferredResult; var user; user = new Clipperz.PM.DataModel.User({username:'joe', getPassphraseFunction:function () { return 'clipperz';}}); deferredResult = new Clipperz.Async.Deferred("getCredentials_test", someTestArgs); deferredResult.addMethod(user, 'getCredentials'); deferredResult.addCallback(function(aResult) { SimpleTest.is(aResult.username, 'joe', "the username of the credentaials is correct"); SimpleTest.is(aResult.password, 'clipperz', "the password of the credentaials is correct"); }) deferredResult.callback(); return deferredResult; }, //------------------------------------------------------------------------- 'loginWithOfflineData_test': function (someTestArgs) { var deferredResult; var user; var proxy; proxy = new Clipperz.PM.Proxy.Test({shouldPayTolls:true, isDefault:true}); user = new Clipperz.PM.DataModel.User({username:'joe', getPassphraseFunction:function () { return 'clipperz';}}); deferredResult = new Clipperz.Async.Deferred("loginWithOfflineData_test", someTestArgs); deferredResult.addMethod(proxy.dataStore(), 'setupWithEncryptedData', testData['joe_clipperz_offline_copy_data']); deferredResult.addMethod(user, 'login'); deferredResult.addCallback(function(aResult) { SimpleTest.is(aResult.result, 'done', "successfully logged in"); }) deferredResult.callback(); return deferredResult; }, //------------------------------------------------------------------------- 'getRecords_fromOfflineData_OLD_test': function (someTestArgs) { var deferredResult; var user; var proxy; proxy = new Clipperz.PM.Proxy.Test({shouldPayTolls:true, isDefault:true}); user = new Clipperz.PM.DataModel.User({username:'joe', getPassphraseFunction:function () { return 'clipperz';}}); deferredResult = new Clipperz.Async.Deferred("getRecords_fromOfflineData_OLD_test", someTestArgs); deferredResult.addMethod(proxy.dataStore(), 'setupWithEncryptedData', testData['OLD_joe_clipperz_offline_copy_data']); deferredResult.addMethod(user, 'login'); deferredResult.addCallback(function(aResult) { SimpleTest.is(aResult.result, 'done', "successfully logged in"); }); deferredResult.addMethod(user, 'getRecords'); deferredResult.addCallback(function(someRecords) { SimpleTest.is(someRecords.length, 15, "the OLD test user has just 15 records"); }); deferredResult.addMethod(user, 'getRecords'); deferredResult.addCallback(MochiKit.Base.map, MochiKit.Base.methodcaller('label')); deferredResult.addCallback(Clipperz.Async.collectAll); deferredResult.addCallback(MochiKit.Base.methodcaller('sort')); deferredResult.addCallback(function (someSortedLabels) { SimpleTest.is(someSortedLabels.length, 15, "We got all the labels"); SimpleTest.is(someSortedLabels[0], "Amazon.com", "The first label is correct"); SimpleTest.is(someSortedLabels[1], "American Airlines", "The second label is correct"); SimpleTest.is(someSortedLabels[2], "Bloglines", "The third label is correct"); SimpleTest.is(someSortedLabels[3], "Digg", "The fourth label is correct"); SimpleTest.is(someSortedLabels[4], "Expedia.com", "The fifth label is correct"); SimpleTest.is(someSortedLabels[5], "Google Account", "The sixth label is correct"); SimpleTest.is(someSortedLabels[6], "Home burglar alarm","The seventh label is correct"); }); /* */ deferredResult.callback(); return deferredResult; }, //------------------------------------------------------------------------- 'getDirectLogins_fromOfflineData_OLD_test': function (someTestArgs) { var deferredResult; var user; var proxy; proxy = new Clipperz.PM.Proxy.Test({shouldPayTolls:true, isDefault:true}); user = new Clipperz.PM.DataModel.User({username:'joe', getPassphraseFunction:function () { return 'clipperz';}}); deferredResult = new Clipperz.Async.Deferred("getRecords_fromOfflineData_OLD_test", someTestArgs); deferredResult.addMethod(proxy.dataStore(), 'setupWithEncryptedData', testData['OLD_joe_clipperz_offline_copy_data']); deferredResult.addMethod(user, 'login'); deferredResult.addCallback(function(aResult) { SimpleTest.is(aResult.result, 'done', "successfully logged in"); }); deferredResult.addMethod(user, 'getDirectLogins'); deferredResult.addCallback(function(someDirectLogins) { SimpleTest.is(someDirectLogins.length, 17, "the OLD test user has 17 direct logins"); }); deferredResult.addMethod(user, 'getDirectLogins'); deferredResult.addCallback(MochiKit.Base.map, MochiKit.Base.methodcaller('label')); deferredResult.addCallback(Clipperz.Async.collectAll); deferredResult.addCallback(MochiKit.Base.methodcaller('sort')); deferredResult.addCallback(function (someSortedLabels) { SimpleTest.is(someSortedLabels.length, 17, "We got all the labels"); SimpleTest.is(someSortedLabels[0], "Amazon.com", "The first label is correct"); SimpleTest.is(someSortedLabels[1], "American Airlines", "The second label is correct"); SimpleTest.is(someSortedLabels[2], "Bloglines", "The third label is correct"); SimpleTest.is(someSortedLabels[3], "Digg", "The fourth label is correct"); SimpleTest.is(someSortedLabels[4], "Expedia.com", "The fifth label is correct"); SimpleTest.is(someSortedLabels[5], "Flickr", "The sixth label is correct"); SimpleTest.is(someSortedLabels[6], "Google Calendar", "The seventh label is correct"); SimpleTest.is(someSortedLabels[7], "Google Docs", "The 8th label is correct"); SimpleTest.is(someSortedLabels[8], "Google Mail", "The 9th label is correct"); SimpleTest.is(someSortedLabels[9], "LinkedIn", "The 10th label is correct"); SimpleTest.is(someSortedLabels[10], "Lufthansa", "The 11th label is correct"); SimpleTest.is(someSortedLabels[11], "My Yahoo!", "The 12th label is correct"); SimpleTest.is(someSortedLabels[12], "MyBlogLog", "The 13th label is correct"); SimpleTest.is(someSortedLabels[13], "MySpace", "The 14th label is correct"); SimpleTest.is(someSortedLabels[14], "The New York Times", "The 15th label is correct"); SimpleTest.is(someSortedLabels[15], "Yahoo! Groups", "The 16th label is correct"); SimpleTest.is(someSortedLabels[16], "Yahoo! Mail", "The 17th label is correct"); }); deferredResult.callback(); return deferredResult; }, //------------------------------------------------------------------------- 'sortRecords_test': function (someTestArgs) { var deferredResult; var proxy; var user; var caseInsensitiveCompare; caseInsensitiveCompare = function (aValue, bValue) { return MochiKit.Base.compare(aValue.toLowerCase(), bValue.toLowerCase()); }; proxy = new Clipperz.PM.Proxy.Test({shouldPayTolls:true, isDefault:true}); user = new Clipperz.PM.DataModel.User({username:'joe', getPassphraseFunction:function () { return 'clipperz';}}); deferredResult = new Clipperz.Async.Deferred("sortRecords_test", someTestArgs); deferredResult.addMethod(proxy.dataStore(), 'setupWithEncryptedData', testData['joe_clipperz_offline_copy_data']); deferredResult.addMethod(user, 'login'); deferredResult.addMethod(user, 'getRecords'); deferredResult.addCallback(Clipperz.Async.deferredSort, function (aRecord, bRecord) { return Clipperz.Async.deferredCompare(MochiKit.Base.compare, aRecord.label(), bRecord.label()); }); deferredResult.addCallback(MochiKit.Base.itemgetter('0')); deferredResult.addCallback(MochiKit.Base.methodcaller('label')); deferredResult.addTest("Amazon.com", "Sorting the records themselves (by labels), the first one is 'Amazon.com'"); deferredResult.addMethod(user, 'getRecords'); deferredResult.addCallback(Clipperz.Async.deferredSort, function (aRecord, bRecord) { return Clipperz.Async.deferredCompare(MochiKit.Base.compare, aRecord.label(), bRecord.label()); }); deferredResult.addCallback(MochiKit.Base.itemgetter('5')); deferredResult.addCallback(MochiKit.Base.methodcaller('label')); deferredResult.addTest("Expedia.com", "Sorting the records themselves (by labels), the sixth element is 'Expedia.com'"); deferredResult.addMethod(user, 'getRecords'); deferredResult.addCallback(Clipperz.Async.deferredSort, function (aRecord, bRecord) { return Clipperz.Async.deferredCompare(MochiKit.Base.compare, aRecord.label(), bRecord.label()); }); deferredResult.addCallback(MochiKit.Base.itemgetter('19')); deferredResult.addCallback(MochiKit.Base.methodcaller('label')); deferredResult.addTest("del.icio.us", "Sorting the records themselves (by labels), the 20th element is 'del.icio.us'"); deferredResult.addMethod(user, 'getRecords'); deferredResult.addCallback(Clipperz.Async.deferredSort, function (aRecord, bRecord) { return Clipperz.Async.deferredCompare(caseInsensitiveCompare, aRecord.label(), bRecord.label()); }); deferredResult.addCallback(MochiKit.Base.itemgetter('3')); deferredResult.addCallback(MochiKit.Base.methodcaller('label')); deferredResult.addTest("del.icio.us", "Sorting with case insensitive mode (by labels), the fourth record is 'del.ico.us'"); deferredResult.addMethod(user, 'getRecords'); deferredResult.addCallback(Clipperz.Async.deferredSort, function (aRecord, bRecord) { return Clipperz.Async.deferredCompare(caseInsensitiveCompare, aRecord.label(), bRecord.label()); }); deferredResult.addCallback(MochiKit.Base.itemgetter('19')); deferredResult.addCallback(MochiKit.Base.methodcaller('label')); deferredResult.addTest("Yahoo! Account", "Sorting with case insensitive mode (by labels), the 20th record is 'Yahoo! Account'"); deferredResult.callback(); return deferredResult; }, //------------------------------------------------------------------------- 'accessToSingleRecord_test': function (someTestArgs) { var deferredResult; var proxy; var user; proxy = new Clipperz.PM.Proxy.Test({shouldPayTolls:true, isDefault:true}); user = new Clipperz.PM.DataModel.User({username:'joe', getPassphraseFunction:function () { return 'clipperz';}}); deferredResult = new Clipperz.Async.Deferred("sortRecords_test", someTestArgs); deferredResult.addMethod(proxy.dataStore(), 'setupWithEncryptedData', testData['joe_clipperz_offline_copy_data']); deferredResult.addMethod(user, 'login'); deferredResult.addMethod(user, 'getRecord', '13a5e52976337ab210903cd04872588e1b21fb72bc183e91aa25c494b8138551'); deferredResult.addCallback(MochiKit.Base.methodcaller('label')); deferredResult.addTest("Amazon.com", "Sorting the records themselves (by labels), the first one is 'Amazon.com'"); deferredResult.callback(); return deferredResult; }, //------------------------------------------------------------------------- 'accessToSingleRecordContent_test': function (someTestArgs) { var deferredResult; var proxy; var user; proxy = new Clipperz.PM.Proxy.Test({shouldPayTolls:true, isDefault:true}); user = new Clipperz.PM.DataModel.User({username:'joe', getPassphraseFunction:function () { return 'clipperz';}}); deferredResult = new Clipperz.Async.Deferred("sortRecords_test", someTestArgs); deferredResult.addMethod(proxy.dataStore(), 'setupWithEncryptedData', testData['joe_clipperz_offline_copy_data']); deferredResult.addMethod(user, 'login'); deferredResult.addMethod(user, 'getRecord', '13a5e52976337ab210903cd04872588e1b21fb72bc183e91aa25c494b8138551'); deferredResult.addCallback(MochiKit.Base.methodcaller('fields')); deferredResult.addCallback(function (someRecordFields) { SimpleTest.is(MochiKit.Base.keys(someRecordFields).length, 2, "The number of fields of the Amazon.com record matches"); return someRecordFields; }); deferredResult.addCallback(MochiKit.Base.itemgetter('5e822c34aaf1a9fbc0b52585c1915f3a3758abd51923a4d35ae85373bbb839c2')); deferredResult.collectResults({ 'label': MochiKit.Base.methodcaller('label'), 'value': MochiKit.Base.methodcaller('value') }) deferredResult.addCallback(function (someValues) { SimpleTest.is(someValues['label'], 'email', "the first field label matches"); SimpleTest.is(someValues['value'], 'joe@clipperz.com', "the first field value matches"); }); deferredResult.callback(); return deferredResult; }, //------------------------------------------------------------------------- 'modifyRecordLabelAndCheckForPendingChanges_test': function (someTestArgs) { var deferredResult; var proxy; var user; proxy = new Clipperz.PM.Proxy.Test({shouldPayTolls:true, isDefault:true}); user = new Clipperz.PM.DataModel.User({username:'joe', getPassphraseFunction:function () { return 'clipperz';}}); deferredResult = new Clipperz.Async.Deferred("modifyRecordAndCheckForPendingChanges_test", someTestArgs); deferredResult.addMethod(proxy.dataStore(), 'setupWithEncryptedData', testData['joe_clipperz_offline_copy_data']); deferredResult.addMethod(user, 'login'); deferredResult.addMethod(user, 'getRecord', '13a5e52976337ab210903cd04872588e1b21fb72bc183e91aa25c494b8138551'); deferredResult.addCallback(MochiKit.Base.methodcaller('label')); deferredResult.addTest("Amazon.com", "This is the record the test was expecting"); deferredResult.addMethod(user, 'getRecord', '13a5e52976337ab210903cd04872588e1b21fb72bc183e91aa25c494b8138551'); deferredResult.addCallback(MochiKit.Base.methodcaller('setLabel', "New label")); deferredResult.addMethod(user, 'hasPendingChanges'); deferredResult.addTest(true, "setting a label on one of the user's record, trigger the 'hasPendingChanges' flag"); deferredResult.addMethod(user, 'getRecord', '13a5e52976337ab210903cd04872588e1b21fb72bc183e91aa25c494b8138551'); deferredResult.addCallback(MochiKit.Base.methodcaller('label')); deferredResult.addTest("New label", "once set the new label value, I can still get back its value"); deferredResult.addMethod(user, 'revertChanges'); deferredResult.addMethod(user, 'hasPendingChanges'); deferredResult.addTest(false, "reverting changes should return to the original state"); deferredResult.addMethod(user, 'getRecord', '13a5e52976337ab210903cd04872588e1b21fb72bc183e91aa25c494b8138551'); deferredResult.addCallback(MochiKit.Base.methodcaller('label')); deferredResult.addTest("Amazon.com", "The label of the record is restored to its initial value"); deferredResult.callback(); return deferredResult; }, //------------------------------------------------------------------------- 'modifyRecordFieldsAndCheckForPendingChanges_test': function (someTestArgs) { var deferredResult; var proxy; var user; proxy = new Clipperz.PM.Proxy.Test({shouldPayTolls:true, isDefault:true}); user = new Clipperz.PM.DataModel.User({username:'joe', getPassphraseFunction:function () { return 'clipperz';}}); deferredResult = new Clipperz.Async.Deferred("modifyRecordFieldsAndCheckForPendingChanges_test", someTestArgs); deferredResult.addMethod(proxy.dataStore(), 'setupWithEncryptedData', testData['joe_clipperz_offline_copy_data']); deferredResult.addMethod(user, 'login'); deferredResult.addMethod(user, 'getRecord', '13a5e52976337ab210903cd04872588e1b21fb72bc183e91aa25c494b8138551'); deferredResult.addCallback(MochiKit.Base.methodcaller('fields')); deferredResult.addCallback(MochiKit.Base.itemgetter('5e822c34aaf1a9fbc0b52585c1915f3a3758abd51923a4d35ae85373bbb839c2')); deferredResult.addCallback(MochiKit.Base.methodcaller('value')); deferredResult.addTest("joe@clipperz.com", "The value of the record field is correct"); deferredResult.addMethod(user, 'getRecord', '13a5e52976337ab210903cd04872588e1b21fb72bc183e91aa25c494b8138551'); deferredResult.addCallback(MochiKit.Base.methodcaller('fields')); deferredResult.addCallback(MochiKit.Base.itemgetter('5e822c34aaf1a9fbc0b52585c1915f3a3758abd51923a4d35ae85373bbb839c2')); deferredResult.addCallback(MochiKit.Base.methodcaller('setValue', 'joe@example.com')); deferredResult.addMethod(user, 'getRecord', '13a5e52976337ab210903cd04872588e1b21fb72bc183e91aa25c494b8138551'); deferredResult.addCallback(MochiKit.Base.methodcaller('fields')); deferredResult.addCallback(MochiKit.Base.itemgetter('5e822c34aaf1a9fbc0b52585c1915f3a3758abd51923a4d35ae85373bbb839c2')); deferredResult.addCallback(MochiKit.Base.methodcaller('value')); deferredResult.addTest("joe@example.com", "The record field correctly returns the newly updated value"); deferredResult.addMethod(user, 'hasPendingChanges'); deferredResult.addTest(true, "changing the value of a record's field trigger the 'hasPendingChanges' flag"); deferredResult.addMethod(user, 'revertChanges'); deferredResult.addMethod(user, 'hasPendingChanges'); deferredResult.addTest(false, "reverting changes should return to the original state"); deferredResult.addMethod(user, 'getRecord', '13a5e52976337ab210903cd04872588e1b21fb72bc183e91aa25c494b8138551'); deferredResult.addCallback(MochiKit.Base.methodcaller('fields')); deferredResult.addCallback(MochiKit.Base.itemgetter('5e822c34aaf1a9fbc0b52585c1915f3a3758abd51923a4d35ae85373bbb839c2')); deferredResult.addCallback(MochiKit.Base.methodcaller('value')); deferredResult.addTest("joe@clipperz.com", "The original value of the record field is returned after reverting the changes"); deferredResult.callback(); return deferredResult; }, //------------------------------------------------------------------------- 'modifyRecordNoteAndCheckForPendingChanges_test': function (someTestArgs) { var deferredResult; var proxy; var user; proxy = new Clipperz.PM.Proxy.Test({shouldPayTolls:true, isDefault:true}); user = new Clipperz.PM.DataModel.User({username:'joe', getPassphraseFunction:function () { return 'clipperz';}}); deferredResult = new Clipperz.Async.Deferred("modifyRecordNoteAndCheckForPendingChanges_test", someTestArgs); deferredResult.addMethod(proxy.dataStore(), 'setupWithEncryptedData', testData['joe_clipperz_offline_copy_data']); deferredResult.addMethod(user, 'login'); deferredResult.addMethod(user, 'getRecord', '084e23120544603f0297368fd3891a3818e0fe13488e2f2c6079913c8d1bed8d'); deferredResult.addCallback(MochiKit.Base.methodcaller('notes')); deferredResult.addTest("aproofofconcept\n<script>alert(\"nothing bad in here\");</script><script>alert(\"AAHHGGGH!\");</script>", "The value of the record note is correct"); deferredResult.addMethod(user, 'getRecord', '084e23120544603f0297368fd3891a3818e0fe13488e2f2c6079913c8d1bed8d'); deferredResult.addCallback(MochiKit.Base.methodcaller('setNotes', "A new note text")); deferredResult.addMethod(user, 'getRecord', '084e23120544603f0297368fd3891a3818e0fe13488e2f2c6079913c8d1bed8d'); deferredResult.addCallback(MochiKit.Base.methodcaller('notes')); deferredResult.addTest("A new note text", "The value of the record note has been updated"); deferredResult.addMethod(user, 'hasPendingChanges'); deferredResult.addTest(true, "changing the value of record's notes trigger the 'hasPendingChanges' flag"); deferredResult.addMethod(user, 'getRecord', '084e23120544603f0297368fd3891a3818e0fe13488e2f2c6079913c8d1bed8d'); deferredResult.addCallback(MochiKit.Base.methodcaller('hasPendingChanges')); deferredResult.addTest(true, "also the record should flat its pending changes on the note field"); deferredResult.addMethod(user, 'revertChanges'); deferredResult.addMethod(user, 'hasPendingChanges'); deferredResult.addTest(false, "reverting changes should return to the original state"); deferredResult.addMethod(user, 'getRecord', '084e23120544603f0297368fd3891a3818e0fe13488e2f2c6079913c8d1bed8d'); deferredResult.addCallback(MochiKit.Base.methodcaller('notes')); deferredResult.addTest("aproofofconcept\n<script>alert(\"nothing bad in here\");</script><script>alert(\"AAHHGGGH!\");</script>", "The value of the record note is restored to its initial value"); deferredResult.callback(); return deferredResult; }, //------------------------------------------------------------------------- 'loadUser_withoutPreferences_andTryToAccessThem_test': function (someTestArgs) { var deferredResult; var proxy; var user; proxy = new Clipperz.PM.Proxy.Test({shouldPayTolls:true, isDefault:true}); user = new Clipperz.PM.DataModel.User({username:'test', getPassphraseFunction:function () { return 'test';}}); deferredResult = new Clipperz.Async.Deferred("loadUser_withoutPreferences_andTryToAccessThem_test", someTestArgs); deferredResult.addMethod(proxy.dataStore(), 'setupWithEncryptedData', testData['test_test_offline_copy_data']); deferredResult.addMethod(user, 'login'); deferredResult.collectResults({ 'preferences': [ MochiKit.Base.method(user, 'getHeaderIndex', 'preferences'), MochiKit.Base.methodcaller('getDecryptedData') ], 'oneTimePasswords': [ MochiKit.Base.method(user, 'getHeaderIndex', 'oneTimePasswords'), MochiKit.Base.methodcaller('getDecryptedData') ] }); deferredResult.addCallback(function (someValues) { SimpleTest.is(Clipperz.Base.serializeJSON(someValues['preferences']), '{}', "The preferences are empty"); }); deferredResult.callback(); return deferredResult; }, //------------------------------------------------------------------------- 'modifyRecordTitleAndCheckForPendingChanges_test': function (someTestArgs) { var deferredResult; var proxy; var user; proxy = new Clipperz.PM.Proxy.Test({shouldPayTolls:true, isDefault:true}); user = new Clipperz.PM.DataModel.User({username:'test', getPassphraseFunction:function () { return 'test';}}); deferredResult = new Clipperz.Async.Deferred("modifyRecordTitleAndCheckForPendingChanges_test", someTestArgs); deferredResult.addMethod(proxy.dataStore(), 'setupWithEncryptedData', testData['test_test_offline_copy_data']); deferredResult.addMethod(user, 'login'); deferredResult.addMethod(user, 'getRecord', '8280842f41162b673335b63860637e8472e8bbff0efa2bc78b0dbc5e09712e13'); deferredResult.addCallback(MochiKit.Base.methodcaller('label')); deferredResult.addTest("Card 1", "The value of the record note is correct"); deferredResult.addMethod(user, 'getRecord', '8280842f41162b673335b63860637e8472e8bbff0efa2bc78b0dbc5e09712e13'); deferredResult.addCallback(MochiKit.Base.methodcaller('setLabel', "Edited card 1")); deferredResult.addMethod(user, 'getRecord', '8280842f41162b673335b63860637e8472e8bbff0efa2bc78b0dbc5e09712e13'); deferredResult.addCallback(MochiKit.Base.methodcaller('label')); deferredResult.addTest("Edited card 1", "The value of the record label has been updated"); deferredResult.addMethod(user, 'hasPendingChanges'); deferredResult.addTest(true, "changing the value of record's label trigger the 'hasPendingChanges' flag"); deferredResult.addMethod(user, 'getRecord', '8280842f41162b673335b63860637e8472e8bbff0efa2bc78b0dbc5e09712e13'); deferredResult.addCallback(MochiKit.Base.methodcaller('hasPendingChanges')); // deferredResult.addTest(true, "also the record should flag its pending changes on the label - 1"); deferredResult.addTest(false, "changing just the label (or any other attribute stored on the header) should not trigger the 'hasPendingChanges' flag"); deferredResult.addMethod(user, 'revertChanges'); deferredResult.addMethod(user, 'hasPendingChanges'); deferredResult.addTest(false, "reverting changes should return to the original state"); deferredResult.addMethod(user, 'getRecord', '8280842f41162b673335b63860637e8472e8bbff0efa2bc78b0dbc5e09712e13'); deferredResult.addCallback(MochiKit.Base.methodcaller('label')); deferredResult.addTest("Card 1", "The value of the record label is restored to its initial value"); deferredResult.callback(); return deferredResult; }, //------------------------------------------------------------------------- 'modifyRecordTitleAndCheckForPendingChanges_take2_test': function (someTestArgs) { var deferredResult; var proxy; var user; proxy = new Clipperz.PM.Proxy.Test({shouldPayTolls:true, isDefault:true}); user = new Clipperz.PM.DataModel.User({username:'test', getPassphraseFunction:function () { return 'test';}}); deferredResult = new Clipperz.Async.Deferred("modifyRecordTitleAndCheckForPendingChanges_take2_test", someTestArgs); deferredResult.addMethod(proxy.dataStore(), 'setupWithEncryptedData', testData['test_test_offline_copy_data']); deferredResult.addMethod(user, 'login'); deferredResult.addMethod(user, 'getRecord', '8280842f41162b673335b63860637e8472e8bbff0efa2bc78b0dbc5e09712e13'); deferredResult.addCallback(MochiKit.Base.methodcaller('label')); deferredResult.addTest("Card 1", "The value of the record note is correct"); deferredResult.addMethod(user, 'getRecord', '8280842f41162b673335b63860637e8472e8bbff0efa2bc78b0dbc5e09712e13'); deferredResult.addCallback(MochiKit.Base.methodcaller('setLabel', "Edited card 1")); deferredResult.addMethod(user, 'hasPendingChanges'); deferredResult.addTest(true, "changing the value of record's label trigger the 'hasPendingChanges' flag"); deferredResult.addMethod(user, 'getRecord', '8280842f41162b673335b63860637e8472e8bbff0efa2bc78b0dbc5e09712e13'); deferredResult.addCallback(MochiKit.Base.methodcaller('hasPendingChanges')); // deferredResult.addTest(true, "also the record should flag its pending changes on the label - 2"); deferredResult.addTest(false, "only the label has changed, and this should not trigger the 'hasPendingChanges' flag on the record as it is stored in the header"); // deferredResult.addCallback(Clipperz.log, "======================================================="); deferredResult.addMethod(user, 'getRecord', '8280842f41162b673335b63860637e8472e8bbff0efa2bc78b0dbc5e09712e13'); deferredResult.addCallback(MochiKit.Base.methodcaller('setLabel', "Card 1")); deferredResult.addMethod(user, 'hasPendingChanges'); deferredResult.addTest(false, "Setting the old value back should void all pending changes"); deferredResult.addMethod(user, 'getRecord', '8280842f41162b673335b63860637e8472e8bbff0efa2bc78b0dbc5e09712e13'); deferredResult.addCallback(MochiKit.Base.methodcaller('hasPendingChanges')); deferredResult.addTest(false, "also the record should not flag any pending changes, as the original value has been restored"); deferredResult.addMethod(user, 'getRecord', '8280842f41162b673335b63860637e8472e8bbff0efa2bc78b0dbc5e09712e13'); deferredResult.addCallback(MochiKit.Base.methodcaller('label')); deferredResult.addTest("Card 1", "The value of the record label is restored to its initial value"); deferredResult.callback(); return deferredResult; }, //------------------------------------------------------------------------- 'modifyRecordNoteAndThanResetOriginalValue_test': function (someTestArgs) { var deferredResult; var proxy; var user; proxy = new Clipperz.PM.Proxy.Test({shouldPayTolls:true, isDefault:true}); user = new Clipperz.PM.DataModel.User({username:'joe', getPassphraseFunction:function () { return 'clipperz';}}); deferredResult = new Clipperz.Async.Deferred("modifyRecordNoteAndThanResetOriginalValue_test", someTestArgs); deferredResult.addMethod(proxy.dataStore(), 'setupWithEncryptedData', testData['joe_clipperz_offline_copy_data']); deferredResult.addMethod(user, 'login'); deferredResult.addMethod(user, 'getRecord', '084e23120544603f0297368fd3891a3818e0fe13488e2f2c6079913c8d1bed8d'); deferredResult.addCallback(MochiKit.Base.methodcaller('notes')); deferredResult.addTest("aproofofconcept\n<script>alert(\"nothing bad in here\");</script><script>alert(\"AAHHGGGH!\");</script>", "The value of the record note is correct"); deferredResult.addMethod(user, 'getRecord', '084e23120544603f0297368fd3891a3818e0fe13488e2f2c6079913c8d1bed8d'); deferredResult.addCallback(MochiKit.Base.methodcaller('setNotes', "A new note text")); deferredResult.addMethod(user, 'hasPendingChanges'); deferredResult.addTest(true, "changing the value of record's notes trigger the 'hasPendingChanges' flag"); deferredResult.addMethod(user, 'getRecord', '084e23120544603f0297368fd3891a3818e0fe13488e2f2c6079913c8d1bed8d'); deferredResult.addCallback(MochiKit.Base.methodcaller('setNotes', "aproofofconcept\n<script>alert(\"nothing bad in here\");</script><script>alert(\"AAHHGGGH!\");</script>")); deferredResult.addMethod(user, 'hasPendingChanges'); deferredResult.addTest(false, "setting the field to its original value basically reset the change, like 'revertChanges' would have done"); deferredResult.callback(); return deferredResult; }, //------------------------------------------------------------------------- 'modifyRecordNoteAndCommitChanges_test': function (someTestArgs) { var deferredResult; var proxy; var user; var user2; var newNoteText; proxy = new Clipperz.PM.Proxy.Test({shouldPayTolls:true, isDefault:true, readOnly:false}); user = new Clipperz.PM.DataModel.User({username:'test', getPassphraseFunction:function () { return 'test';}}); user2 = new Clipperz.PM.DataModel.User({username:'test', getPassphraseFunction:function () { return 'test';}}); newNoteText = "A new note text"; deferredResult = new Clipperz.Async.Deferred("modifyRecordAndCommitChanges_test", someTestArgs); deferredResult.addMethod(proxy.dataStore(), 'setupWithEncryptedData', testData['test_test_offline_copy_data']); deferredResult.addMethod(user, 'login'); deferredResult.addMethod(user, 'getRecord', '8280842f41162b673335b63860637e8472e8bbff0efa2bc78b0dbc5e09712e13'); deferredResult.addCallback(MochiKit.Base.methodcaller('notes')); deferredResult.addTest("", "This is the original value of the notes"); deferredResult.addMethod(user, 'getRecord', '8280842f41162b673335b63860637e8472e8bbff0efa2bc78b0dbc5e09712e13'); deferredResult.addCallback(MochiKit.Base.methodcaller('setNotes', newNoteText)); deferredResult.addMethod(user, 'hasPendingChanges'); deferredResult.addTest(true, "changing the value of record's notes trigger the 'hasPendingChanges' flag"); deferredResult.addMethod(user, 'getRecord', '8280842f41162b673335b63860637e8472e8bbff0efa2bc78b0dbc5e09712e13'); deferredResult.addCallback(MochiKit.Base.methodcaller('hasPendingChanges')); deferredResult.addTest(true, "changing the value of record's notes trigger the 'hasPendingChanges' flag also on the record itself"); deferredResult.addMethod(user, 'saveChanges'); deferredResult.addMethod(user, 'hasPendingChanges'); deferredResult.addTest(false, "saving changes should return the user to a state with not changes pending - 1"); deferredResult.addMethod(user2, 'login'); deferredResult.addMethod(user2, 'getRecord', '8280842f41162b673335b63860637e8472e8bbff0efa2bc78b0dbc5e09712e13'); deferredResult.addCallback(MochiKit.Base.methodcaller('notes')); deferredResult.addTest(newNoteText, "It looks like the data edited was correctly stored and reloaded here"); deferredResult.callback(); return deferredResult; }, //------------------------------------------------------------------------- 'multipleModificationToRecordTitleAndCommitChanges_test': function (someTestArgs) { var deferredResult; var proxy; var user; var user2; var user3; var newRecordTitle; proxy = new Clipperz.PM.Proxy.Test({shouldPayTolls:true, isDefault:true, readOnly:false}); user = new Clipperz.PM.DataModel.User({username:'test', getPassphraseFunction:function () { return 'test';}}); user2 = new Clipperz.PM.DataModel.User({username:'test', getPassphraseFunction:function () { return 'test';}}); user3 = new Clipperz.PM.DataModel.User({username:'test', getPassphraseFunction:function () { return 'test';}}); newRecordTitle = "A nice new title here"; deferredResult = new Clipperz.Async.Deferred("multipleModificationToRecordTitleAndCommitChanges_test", someTestArgs); deferredResult.addMethod(proxy.dataStore(), 'setupWithEncryptedData', testData['test_test_offline_copy_data']); deferredResult.addMethod(user, 'login'); deferredResult.addMethod(user, 'getRecord', '8280842f41162b673335b63860637e8472e8bbff0efa2bc78b0dbc5e09712e13'); deferredResult.addCallback(MochiKit.Base.methodcaller('label')); deferredResult.addTest("Card 1", "This is the original value of the label"); deferredResult.addMethod(user, 'getRecord', '8280842f41162b673335b63860637e8472e8bbff0efa2bc78b0dbc5e09712e13'); deferredResult.addCallback(MochiKit.Base.methodcaller('setLabel', newRecordTitle)); deferredResult.addMethod(user, 'hasPendingChanges'); deferredResult.addTest(true, "changing the value of record's label trigger the 'hasPendingChanges' flag"); deferredResult.addMethod(user, 'saveChanges'); deferredResult.addMethod(user, 'hasPendingChanges'); deferredResult.addTest(false, "saving changes should return the user to a state with not changes pending - 2"); // FAIL deferredResult.addMethod(user2, 'login'); deferredResult.addMethod(user2, 'getRecord', '8280842f41162b673335b63860637e8472e8bbff0efa2bc78b0dbc5e09712e13'); deferredResult.addCallback(MochiKit.Base.methodcaller('label')); deferredResult.addTest(newRecordTitle, "It looks like the label edited was correctly stored and reloaded here"); deferredResult.addMethod(user2, 'getRecord', '8280842f41162b673335b63860637e8472e8bbff0efa2bc78b0dbc5e09712e13'); deferredResult.addCallback(MochiKit.Base.methodcaller('setLabel', newRecordTitle + "-" + newRecordTitle)); deferredResult.addMethod(user2, 'hasPendingChanges'); deferredResult.addTest(true, "changing again the value of record's label trigger the 'hasPendingChanges' flag also on the new user"); deferredResult.addMethod(user2, 'saveChanges'); deferredResult.addMethod(user2, 'hasPendingChanges'); deferredResult.addTest(false, "after committing the changes, the user has no pending changes"); // FAIL deferredResult.addMethod(user3, 'login'); deferredResult.addMethod(user3, 'getRecord', '8280842f41162b673335b63860637e8472e8bbff0efa2bc78b0dbc5e09712e13'); deferredResult.addCallback(MochiKit.Base.methodcaller('label')); deferredResult.addTest(newRecordTitle + "-" + newRecordTitle, "It looks like the label edited was correctly stored and reloaded here"); deferredResult.callback(); return deferredResult; }, //------------------------------------------------------------------------- 'saveChangesWithADeletedRecord_test': function (someTestArgs) { var deferredResult; var proxy; var user; proxy = new Clipperz.PM.Proxy.Test({shouldPayTolls:true, isDefault:true, readOnly:false}); user = new Clipperz.PM.DataModel.User({username:'test', getPassphraseFunction:function () { return 'test';}}); deferredResult = new Clipperz.Async.Deferred("saveChangesWithADeletedRecord_test", someTestArgs); deferredResult.addMethod(proxy.dataStore(), 'setupWithEncryptedData', testData['test_test_offline_copy_data']); deferredResult.addMethod(user, 'login'); deferredResult.addMethod(user, 'getRecords'); deferredResult.addCallback(MochiKit.Base.itemgetter('length')); deferredResult.addTest(1, "This account has oly a single card"); deferredResult.addMethod(user, 'getRecord', '8280842f41162b673335b63860637e8472e8bbff0efa2bc78b0dbc5e09712e13'); deferredResult.addCallback(MochiKit.Base.methodcaller('label')); deferredResult.addTest("Card 1", "This is the initial value of the label ..."); deferredResult.addMethod(user, 'getHeaderIndex', 'recordsIndex'); deferredResult.addCallback(MochiKit.Base.methodcaller('prepareRemoteDataForChangedRecords')); deferredResult.addCallback(function (aResult) { SimpleTest.ok(aResult['updated'] != null, "There updated key is not null"); SimpleTest.isDeeply(aResult['updated'], [], "There are no updated cards"); SimpleTest.ok(aResult['deleted'] != null, "There deleted key is not null"); SimpleTest.isDeeply(aResult['deleted'], [], "There are no deleted references"); return aResult; }) deferredResult.addMethod(user, 'revertChanges'); deferredResult.addMethod(user, 'getRecord', '8280842f41162b673335b63860637e8472e8bbff0efa2bc78b0dbc5e09712e13'); deferredResult.addMethod(user, 'deleteRecord'); deferredResult.addMethod(user, 'getHeaderIndex', 'recordsIndex'); deferredResult.addCallback(MochiKit.Base.methodcaller('prepareRemoteDataForChangedRecords')); deferredResult.addCallback(function (aResult) { SimpleTest.isDeeply(aResult['deleted'], ['8280842f41162b673335b63860637e8472e8bbff0efa2bc78b0dbc5e09712e13'], "The deleted record reference is correctly reported"); return aResult; }) deferredResult.addMethod(user, 'getRecord', '8280842f41162b673335b63860637e8472e8bbff0efa2bc78b0dbc5e09712e13'); deferredResult.shouldFail("accessing the deleted record reference should raise an exception"); deferredResult.addMethod(user, 'getRecord', '0000000000000000000000000000000000000000000000000000000000000000'); deferredResult.shouldFail("accessing a fake record reference should raise an exception"); deferredResult.addMethod(user, 'saveChanges'); deferredResult.addMethod(user, 'getRecords'); deferredResult.addCallback(MochiKit.Base.itemgetter('length')); deferredResult.addTest(0, "after deleting the only record, there should be no records bound to the user"); deferredResult.callback(); return deferredResult; }, //------------------------------------------------------------------------- 'revertingChangesAfterDeletingACard_test': function (someTestArgs) { var deferredResult; var proxy; var user; proxy = new Clipperz.PM.Proxy.Test({shouldPayTolls:true, isDefault:true, readOnly:false}); user = new Clipperz.PM.DataModel.User({username:'test', getPassphraseFunction:function () { return 'test';}}); deferredResult = new Clipperz.Async.Deferred("simpleSaveChanges_test", someTestArgs); deferredResult.addMethod(proxy.dataStore(), 'setupWithEncryptedData', testData['test_test_offline_copy_data']); deferredResult.addMethod(user, 'login'); deferredResult.addMethod(user, 'getRecord', '8280842f41162b673335b63860637e8472e8bbff0efa2bc78b0dbc5e09712e13'); deferredResult.addCallback(MochiKit.Base.methodcaller('label')); deferredResult.addTest("Card 1", "This is the initial value of the label ..."); deferredResult.addMethod(user, 'getHeaderIndex', 'recordsIndex'); deferredResult.addCallback(MochiKit.Base.methodcaller('prepareRemoteDataForChangedRecords')); deferredResult.addCallback(function (aResult) { SimpleTest.ok(aResult['updated'] != null, "There updated key is not null"); SimpleTest.isDeeply(aResult['updated'], [], "There are no updated cards"); SimpleTest.ok(aResult['deleted'] != null, "There deleted key is not null"); SimpleTest.isDeeply(aResult['deleted'], [], "There are no deleted references"); return aResult; }) deferredResult.addMethod(user, 'revertChanges'); deferredResult.addMethod(user, 'getRecord', '8280842f41162b673335b63860637e8472e8bbff0efa2bc78b0dbc5e09712e13'); deferredResult.addMethod(user, 'deleteRecord'); deferredResult.addMethod(user, 'getHeaderIndex', 'recordsIndex'); deferredResult.addCallback(MochiKit.Base.methodcaller('prepareRemoteDataForChangedRecords')); deferredResult.addCallback(function (aResult) { SimpleTest.isDeeply(aResult['deleted'], ['8280842f41162b673335b63860637e8472e8bbff0efa2bc78b0dbc5e09712e13'], "The deleted record reference is correctly reported"); return aResult; }) deferredResult.addMethod(user, 'getRecord', '8280842f41162b673335b63860637e8472e8bbff0efa2bc78b0dbc5e09712e13'); deferredResult.shouldFail("accessing the deleted record reference should raise an exception"); deferredResult.addMethod(user, 'getRecord', '0000000000000000000000000000000000000000000000000000000000000000'); deferredResult.shouldFail("accessing a fake record reference should raise an exception"); deferredResult.addMethod(user, 'revertChanges'); deferredResult.addMethod(user, 'getRecord', '8280842f41162b673335b63860637e8472e8bbff0efa2bc78b0dbc5e09712e13'); deferredResult.addCallback(SimpleTest.ok, true, "after reverting all changes, the deleted card is restored"); deferredResult.callback(); return deferredResult; }, //------------------------------------------------------------------------- 'lockUnlockAccountAfterDeletingACard_test': function (someTestArgs) { var deferredResult; var proxy; var user; var recordID; proxy = new Clipperz.PM.Proxy.Test({shouldPayTolls:true, isDefault:true, readOnly:false}); user = new Clipperz.PM.DataModel.User({username:'joe', getPassphraseFunction:function () { return 'clipperz';}}); recordID = 'eeda70e0392261967bda71c3764da78989c45bbd2bb7be6b941b90f81d9b81b5'; // recordID = '507f38b06d587d8889698ae1ebbba7ef8f0539b82550dd25779fd9ee88fc0c7a'; deferredResult = new Clipperz.Async.Deferred("lockUnlockAccountAfterDeletingACard_test", someTestArgs); deferredResult.addMethod(proxy.dataStore(), 'setupWithEncryptedData', testData['joe_clipperz_offline_copy_data']); deferredResult.addMethod(user, 'login'); deferredResult.addMethod(user, 'getRecords'); deferredResult.addCallback(MochiKit.Base.itemgetter('length')); deferredResult.addTest(20, "Initially the user has 20 cards"); deferredResult.addMethod(user, 'getDirectLogins'); deferredResult.addCallback(MochiKit.Base.itemgetter('length')); deferredResult.addTest(22, "Initially the user has 22 direct logins"); deferredResult.addMethod(user, 'getHeaderIndex', 'recordsIndex'); deferredResult.addMethodcaller('directLoginsData'); deferredResult.addMethodcaller('values'); deferredResult.addCallback(MochiKit.Base.values); deferredResult.addCallback(MochiKit.Base.itemgetter('length')); deferredResult.addTest(22, "There should be also 22 direct login references"); deferredResult.addMethod(user, 'getRecord', recordID); deferredResult.addMethodcaller('directLogins'); deferredResult.addCallback(MochiKit.Base.values); deferredResult.addCallback(MochiKit.Base.itemgetter('length')); deferredResult.addTest(4, "The selected record has 4 direct logins"); deferredResult.addMethod(user, 'getRecord', recordID); deferredResult.addMethod(user, 'deleteRecord'); deferredResult.addMethod(user, 'saveChanges'); deferredResult.addMethod(user, 'hasAnyCleanTextData'); deferredResult.addTest(true, "after saving changes, hasAnyCleanTextData should be true"); deferredResult.addMethod(user, 'deleteAllCleanTextData'); deferredResult.addMethod(user, 'hasAnyCleanTextData'); deferredResult.addTest(false, "after deleting all clean text data, hasAnyCleanTextData should be true"); deferredResult.addMethod(user, 'login'); deferredResult.addMethod(user, 'getRecords'); deferredResult.addCallback(MochiKit.Base.itemgetter('length')); deferredResult.addTest((20 - 1), "After deleting a card, only 19 are left"); deferredResult.addMethod(user, 'getDirectLogins'); deferredResult.addCallback(MochiKit.Base.itemgetter('length')); deferredResult.addTest((22 - 4), "Initially the user has 18 direct logins"); deferredResult.addMethod(user, 'getHeaderIndex', 'recordsIndex'); deferredResult.addMethodcaller('directLoginsData'); deferredResult.addMethodcaller('values'); deferredResult.addCallback(MochiKit.Base.values); deferredResult.addCallback(MochiKit.Base.itemgetter('length')); deferredResult.addTest((22 - 4), "Once deleted the card, there should be just 18 direct login references left"); deferredResult.addCallback(function () { SimpleTest.ok(true, "nothing wrong had happen 'till here"); }); deferredResult.callback(); return deferredResult; }, //------------------------------------------------------------------------- 'lockUnlockAccountAfterDeletingACard_2_test': function (someTestArgs) { var deferredResult; var proxy; var user; proxy = new Clipperz.PM.Proxy.Test({shouldPayTolls:true, isDefault:true, readOnly:false}); user = new Clipperz.PM.DataModel.User({username:'joe', getPassphraseFunction:function () { return 'clipperz';}}); deferredResult = new Clipperz.Async.Deferred("lockUnlockAccountAfterDeletingACard_2_test", someTestArgs); deferredResult.addMethod(proxy.dataStore(), 'setupWithEncryptedData', testData['joe_clipperz_offline_copy_data']); deferredResult.addMethod(user, 'login'); deferredResult.addMethod(user, 'getRecords'); deferredResult.addCallback(function (someRecords) { SimpleTest.is(someRecords.length, 20, "Initially the user has 20 cards"); }); deferredResult.addMethod(user, 'getDirectLogins'); deferredResult.addCallback(function (someDirectLogins) { SimpleTest.is(someDirectLogins.length, 22, "Initially the user has 42 direct logins"); }); deferredResult.addMethod(user, 'getHeaderIndex', 'recordsIndex'); deferredResult.addMethodcaller('directLoginsData'); deferredResult.addMethodcaller('values'); deferredResult.addCallback(MochiKit.Base.values); deferredResult.addCallback(function (someDirectLoginReferences) { SimpleTest.is(someDirectLoginReferences.length, 22, "There should be also 22 direct login references - 2"); }); deferredResult.addMethod(user, 'getRecord', '507f38b06d587d8889698ae1ebbba7ef8f0539b82550dd25779fd9ee88fc0c7a'); deferredResult.addMethodcaller('directLogins'); deferredResult.addCallback(MochiKit.Base.values); deferredResult.addCallback(function (someDirectLogins) { SimpleTest.is(someDirectLogins.length, 1, "The selected record has 4 direct logins"); }); deferredResult.addMethod(user, 'getRecord', '507f38b06d587d8889698ae1ebbba7ef8f0539b82550dd25779fd9ee88fc0c7a'); deferredResult.addMethod(user, 'deleteRecord'); deferredResult.addMethod(user, 'saveChanges'); deferredResult.addMethod(user, 'deleteAllCleanTextData'); deferredResult.addMethod(user, 'login'); deferredResult.addMethod(user, 'getRecords'); deferredResult.addCallback(function (someRecords) { SimpleTest.is(someRecords.length, (20 -1), "After deleting a card, only 19 are left - 2"); }); deferredResult.addMethod(user, 'getDirectLogins'); deferredResult.addCallback(function (someDirectLogins) { SimpleTest.is(someDirectLogins.length, (22 - 1), "Initially the user has 21 direct logins - 2"); }); deferredResult.addMethod(user, 'getHeaderIndex', 'recordsIndex'); deferredResult.addMethodcaller('directLoginsData'); deferredResult.addMethodcaller('values'); deferredResult.addCallback(MochiKit.Base.values); deferredResult.addCallback(function (someDirectLoginReferences) { SimpleTest.is(someDirectLoginReferences.length, (22 - 1), "Once deleted the card, there should be just 21 direct login references left"); }); deferredResult.addCallback(function () { SimpleTest.ok(true, "nothing wrong had happen 'till here - 2"); }); deferredResult.callback(); return deferredResult; }, //------------------------------------------------------------------------- 'simpleSaveChanges_test': function (someTestArgs) { var deferredResult; var proxy; var user; proxy = new Clipperz.PM.Proxy.Test({shouldPayTolls:true, isDefault:true, readOnly:false}); user = new Clipperz.PM.DataModel.User({username:'test', getPassphraseFunction:function () { return 'test';}}); deferredResult = new Clipperz.Async.Deferred("simpleSaveChanges_test", someTestArgs); deferredResult.addMethod(proxy.dataStore(), 'setupWithEncryptedData', testData['test_test_offline_copy_data']); deferredResult.addMethod(user, 'login'); deferredResult.addMethod(user, 'getRecord', '8280842f41162b673335b63860637e8472e8bbff0efa2bc78b0dbc5e09712e13'); deferredResult.addCallback(MochiKit.Base.methodcaller('label')); deferredResult.addTest("Card 1", "This is the initial value of the label ..."); deferredResult.addMethod(user, 'getRecord', '8280842f41162b673335b63860637e8472e8bbff0efa2bc78b0dbc5e09712e13'); deferredResult.addCallback(MochiKit.Base.methodcaller('setLabel', "New label for Card 1")); deferredResult.addMethod(user, 'getRecord', '8280842f41162b673335b63860637e8472e8bbff0efa2bc78b0dbc5e09712e13'); deferredResult.addCallback(MochiKit.Base.methodcaller('setNotes', "Setting just the label would not trigger the update of the record data and nothing will end up in the 'updated' list")); deferredResult.addMethod(user, 'getHeaderIndex', 'recordsIndex'); deferredResult.addCallback(MochiKit.Base.methodcaller('prepareRemoteDataForChangedRecords')); deferredResult.addCallback(function (aResult) { SimpleTest.is(aResult['updated'].length, 1, "The updadated record should be listed in the changes getting ready for commit"); return aResult; }) deferredResult.callback(); return deferredResult; }, //------------------------------------------------------------------------- 'saveChangesAndDataCaching_test': function (someTestArgs) { var deferredResult; var proxy; var user; var record_1; var record_2; record_1 = '062af892bcfba49ffcff05c56d99b7af2d508358e39c058c2e1fc83531436f80'; record_2 = '084e23120544603f0297368fd3891a3818e0fe13488e2f2c6079913c8d1bed8d'; proxy = new Clipperz.PM.Proxy.Test({shouldPayTolls:true, isDefault:true, readOnly:false}); user = new Clipperz.PM.DataModel.User({username:'joe', getPassphraseFunction:function () { return 'clipperz';}}); deferredResult = new Clipperz.Async.Deferred("saveChangesAndDataCaching_test", someTestArgs); deferredResult.addMethod(proxy.dataStore(), 'setupWithEncryptedData', testData['joe_clipperz_offline_copy_data']); deferredResult.addMethod(user, 'login'); deferredResult.addMethod(user, 'getRecord', record_1); deferredResult.addMethodcaller('hasLoadedRemoteData'); deferredResult.addTest(false, "The card data should have not been loaded yet"); deferredResult.addMethod(user, 'getRecord', record_2); deferredResult.addMethodcaller('hasLoadedRemoteData'); deferredResult.addTest(false, "Also the other card data should have not been loaded yet"); deferredResult.addMethod(user, 'getRecord', record_1); deferredResult.addMethodcaller('setLabel', "New title"); deferredResult.addMethod(user, 'getRecord', record_1); deferredResult.addMethodcaller('hasLoadedRemoteData'); deferredResult.addTest(false, "Changing just the label should not trigger the full loading of the card"); deferredResult.addMethod(user, 'getRecord', record_1); deferredResult.addMethodcaller('setNotes', "New note text"); deferredResult.addMethod(user, 'getRecord', record_1); deferredResult.addMethodcaller('hasLoadedRemoteData'); deferredResult.addTest(true, "Changing the notes should trigger the loading of the card"); deferredResult.addMethod(user, 'getRecord', record_2); deferredResult.addMethodcaller('hasLoadedRemoteData'); deferredResult.addTest(false, "Changing record_1 should not trigger the loading of record_2"); deferredResult.addMethod(user, 'hasPendingChanges'); deferredResult.addTest(true, "changing the value of record's label trigger the 'hasPendingChanges' flag"); deferredResult.addMethod(user, 'saveChanges'); deferredResult.addMethod(user, 'hasPendingChanges'); deferredResult.addTest(false, "saving changes should return the user to a state with not changes pending - 3"); deferredResult.addMethod(user, 'getRecord', record_1); deferredResult.addMethodcaller('hasLoadedRemoteData'); deferredResult.addTest(true, "After saving the changes, record_1 sould not have the remote data"); deferredResult.addMethod(user, 'getRecord', record_2); deferredResult.addMethodcaller('hasLoadedRemoteData'); deferredResult.addTest(false, "After saving, record_2 should still be NOT loaded"); deferredResult.callback(); return deferredResult; }, //------------------------------------------------------------------------- 'addNewRecordFieldAndSave_test': function (someTestArgs) { var deferredResult; var proxy; var user; proxy = new Clipperz.PM.Proxy.Test({shouldPayTolls:true, isDefault:true, readOnly:false}); user = new Clipperz.PM.DataModel.User({username:'test', getPassphraseFunction:function () { return 'test';}}); deferredResult = new Clipperz.Async.Deferred("simpleSaveChanges_test", someTestArgs); deferredResult.addMethod(proxy.dataStore(), 'setupWithEncryptedData', testData['test_test_offline_copy_data']); deferredResult.addMethod(user, 'login'); deferredResult.addMethod(user, 'getRecord', '8280842f41162b673335b63860637e8472e8bbff0efa2bc78b0dbc5e09712e13'); deferredResult.addMethodcaller('fields'); deferredResult.addCallback(function (someFields) { SimpleTest.is(MochiKit.Base.values(someFields).length, 3, "The record has initially 3 fields"); }); deferredResult.addMethod(user, 'getRecord', '8280842f41162b673335b63860637e8472e8bbff0efa2bc78b0dbc5e09712e13'); deferredResult.addCallback(MochiKit.Base.methodcaller('addField', {'label':"New field label", 'value':"New field value", 'isHidden':false})); deferredResult.addMethod(user, 'getRecord', '8280842f41162b673335b63860637e8472e8bbff0efa2bc78b0dbc5e09712e13'); deferredResult.addMethodcaller('hasPendingChanges'); deferredResult.addTest(true, "adding a field should mark the record as having pending changes"); deferredResult.addMethod(user, 'getRecord', '8280842f41162b673335b63860637e8472e8bbff0efa2bc78b0dbc5e09712e13'); deferredResult.addMethodcaller('fields'); deferredResult.addCallback(function (someFields) { SimpleTest.is(MochiKit.Base.values(someFields).length, 4, "The record has now 4 fields"); }); deferredResult.addMethod(user, 'saveChanges'); deferredResult.addMethod(user, 'hasPendingChanges'); deferredResult.addTest(false, "saving changes should return the user to a state with not changes pending - 4"); deferredResult.addMethod(user, 'hasAnyCleanTextData'); deferredResult.addTest(true, "after saving changes, hasAnyCleanTextData should be true"); //deferredResult.addCallback(function (aValue) { console.log(">>> #################################################"); return aValue}); deferredResult.addMethod(user, 'deleteAllCleanTextData'); //deferredResult.addCallback(function (aValue) { console.log("<<< #################################################"); return aValue}); deferredResult.addMethod(user, 'hasAnyCleanTextData'); deferredResult.addTest(false, "after deleting all clean text, hasAnyCleanTextData should be false"); deferredResult.callback(); return deferredResult; }, //------------------------------------------------------------------------- 'deleteRecordFieldAndSave_test': function (someTestArgs) { var deferredResult; var proxy; var user; var user2; proxy = new Clipperz.PM.Proxy.Test({shouldPayTolls:true, isDefault:true, readOnly:false}); user = new Clipperz.PM.DataModel.User({username:'test', getPassphraseFunction:function () { return 'test';}}); user2 = new Clipperz.PM.DataModel.User({username:'test', getPassphraseFunction:function () { return 'test';}}); deferredResult = new Clipperz.Async.Deferred("simpleSaveChanges_test", someTestArgs); deferredResult.addMethod(proxy.dataStore(), 'setupWithEncryptedData', testData['test_test_offline_copy_data']); deferredResult.addMethod(user, 'login'); deferredResult.addMethod(user, 'getRecord', '8280842f41162b673335b63860637e8472e8bbff0efa2bc78b0dbc5e09712e13'); deferredResult.addMethodcaller('fields'); deferredResult.addCallback(function (someFields) { SimpleTest.is(MochiKit.Base.values(someFields).length, 3, "The record has initially 3 fields"); }); deferredResult.collectResults({ 'record': MochiKit.Base.method(user, 'getRecord', '8280842f41162b673335b63860637e8472e8bbff0efa2bc78b0dbc5e09712e13'), 'field': [ MochiKit.Base.method(user, 'getRecord', '8280842f41162b673335b63860637e8472e8bbff0efa2bc78b0dbc5e09712e13'), MochiKit.Base.methodcaller('fields'), MochiKit.Base.values, MochiKit.Base.itemgetter('0') ] }) deferredResult.addCallback(function (someValues) { someValues['record'].removeField(someValues['field']); }); deferredResult.addMethod(user, 'getRecord', '8280842f41162b673335b63860637e8472e8bbff0efa2bc78b0dbc5e09712e13'); deferredResult.addMethodcaller('hasPendingChanges'); deferredResult.addTest(true, "removing a field should mark the record as having pending changes"); deferredResult.addMethod(user, 'getRecord', '8280842f41162b673335b63860637e8472e8bbff0efa2bc78b0dbc5e09712e13'); deferredResult.addMethodcaller('fields'); deferredResult.addCallback(function (someFields) { SimpleTest.is(MochiKit.Base.values(someFields).length, 2, "The record has now 2 fields"); }); deferredResult.addMethod(user, 'saveChanges'); deferredResult.addMethod(user, 'hasPendingChanges'); deferredResult.addTest(false, "saving changes should return the user to a state with not changes pending - 5"); //. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . deferredResult.addMethod(user2, 'login'); deferredResult.addMethod(user2, 'getRecord', '8280842f41162b673335b63860637e8472e8bbff0efa2bc78b0dbc5e09712e13'); deferredResult.addMethodcaller('fields'); deferredResult.addCallback(function (someFields) { SimpleTest.is(MochiKit.Base.values(someFields).length, 2, "Once saved, the record is left with just two fields"); }); deferredResult.callback(); return deferredResult; }, //------------------------------------------------------------------------- 'loadDirectLogin_test': function (someTestArgs) { var deferredResult; var proxy; var user; proxy = new Clipperz.PM.Proxy.Test({shouldPayTolls:true, isDefault:true}); user = new Clipperz.PM.DataModel.User({username:'joe', getPassphraseFunction:function () { return 'clipperz';}}); deferredResult = new Clipperz.Async.Deferred("loadDirectLogin_test", someTestArgs); deferredResult.addMethod(proxy.dataStore(), 'setupWithEncryptedData', testData['joe_clipperz_offline_copy_data']); deferredResult.addMethod(user, 'login'); deferredResult.addMethod(user, 'getRecord', '13a5e52976337ab210903cd04872588e1b21fb72bc183e91aa25c494b8138551'); deferredResult.addCallback(MochiKit.Base.methodcaller('directLogins')); deferredResult.addCallback(function (someDirectLogins) { SimpleTest.is(1, MochiKit.Base.keys(someDirectLogins).length, "the Amazon.com card has just one direct login"); }); deferredResult.addMethod(user, 'getRecord', '13a5e52976337ab210903cd04872588e1b21fb72bc183e91aa25c494b8138551'); deferredResult.addCallback(MochiKit.Base.methodcaller('hasPendingChanges')); deferredResult.addTest(false, "initially the record does not have any pending changes"); deferredResult.addMethod(user, 'getRecord', '13a5e52976337ab210903cd04872588e1b21fb72bc183e91aa25c494b8138551'); deferredResult.addCallback(MochiKit.Base.methodcaller('directLogins')); deferredResult.addCallback(MochiKit.Base.itemgetter('03251dc1cbc5398789e4c4b45c52cfac3fcd8c1a4f19a81fa68fc6feae31d55c')); // deferredResult.addCallback(MochiKit.Base.methodcaller('runDirectLogin', true)); deferredResult.addCallback(Clipperz.PM.UI.Common.Controllers.DirectLoginRunner.testDirectLogin); deferredResult.addMethod(user, 'getRecord', '13a5e52976337ab210903cd04872588e1b21fb72bc183e91aa25c494b8138551'); deferredResult.addCallback(MochiKit.Base.methodcaller('getFieldsValues')); deferredResult.addCallback(function (someFieldsValues) { SimpleTest.is(MochiKit.Base.keys(someFieldsValues).length, 2, "the Amazon.com card has just two fields"); }); deferredResult.addMethod(user, 'getRecord', '13a5e52976337ab210903cd04872588e1b21fb72bc183e91aa25c494b8138551'); deferredResult.addCallback(MochiKit.Base.methodcaller('hasPendingChanges')); deferredResult.addTest(false, "accessing fields values should not trigger the 'hasPendingChanges' flag"); deferredResult.callback(); return deferredResult; }, //------------------------------------------------------------------------- 'readingVeryOldCards_test': function (someTestArgs) { var deferredResult; var proxy; var user; proxy = new Clipperz.PM.Proxy.Test({shouldPayTolls:true, isDefault:true}); user = new Clipperz.PM.DataModel.User({username:'test', getPassphraseFunction:function () { return 'test';}}); deferredResult = new Clipperz.Async.Deferred("readingVeryOldCards_test", someTestArgs); deferredResult.addMethod(proxy.dataStore(), 'setupWithEncryptedData', testData['test_test_someExtraOldData']); deferredResult.addMethod(user, 'login'); deferredResult.addMethod(user, 'getRecord', '05aad20ee399b11ddc923e601fcd1d096233634f2ad4c55db4f6435e5f9cc17a'); deferredResult.addMethodcaller('label'); deferredResult.addTest('Card encoded with an old algorithm', 'the label of the selected record is the expected one'); deferredResult.addMethod(user, 'getRecord', '05aad20ee399b11ddc923e601fcd1d096233634f2ad4c55db4f6435e5f9cc17a'); deferredResult.addCallback(MochiKit.Base.methodcaller('fields')); deferredResult.addCallback(function (someFields) { SimpleTest.is(6, MochiKit.Base.keys(someFields).length, "the 'Card encoded with an old algorithm' card has six fields"); }); deferredResult.addMethod(user, 'getRecord', '05aad20ee399b11ddc923e601fcd1d096233634f2ad4c55db4f6435e5f9cc17a'); deferredResult.addMethodcaller('hasPendingChanges'); deferredResult.addTest(false, "accessing the card fields should not trigger the hasPendingChanges flag"); deferredResult.addMethod(user, 'getRecord', '05aad20ee399b11ddc923e601fcd1d096233634f2ad4c55db4f6435e5f9cc17a'); deferredResult.addCallback(MochiKit.Base.methodcaller('addField', {'label':"New field label", 'value':"New field value", 'isHidden':false})); deferredResult.addMethod(user, 'getRecord', '05aad20ee399b11ddc923e601fcd1d096233634f2ad4c55db4f6435e5f9cc17a'); deferredResult.addCallback(MochiKit.Base.methodcaller('fields')); deferredResult.addCallback(function (someFields) { SimpleTest.is(7, MochiKit.Base.keys(someFields).length, "adding a field shoult bring the total field count to 7"); }); deferredResult.addMethod(user, 'getRecord', '05aad20ee399b11ddc923e601fcd1d096233634f2ad4c55db4f6435e5f9cc17a'); deferredResult.addMethodcaller('hasPendingChanges'); deferredResult.addTest(true, "adding a field should mark the record as having pending changes - 2"); deferredResult.callback(); return deferredResult; }, //------------------------------------------------------------------------- 'addingNewEmptyRecordAndSaveChanges_test': function (someTestArgs) { var deferredResult; var proxy; var user; var newRecordReference; proxy = new Clipperz.PM.Proxy.Test({shouldPayTolls:true, isDefault:true, readOnly:false}); user = new Clipperz.PM.DataModel.User({username:'test', getPassphraseFunction:function () { return 'test';}}); user2 = new Clipperz.PM.DataModel.User({username:'test', getPassphraseFunction:function () { return 'test';}}); deferredResult = new Clipperz.Async.Deferred("addingNewEmptyRecordAndSaveChanges_test", someTestArgs); deferredResult.addMethod(proxy.dataStore(), 'setupWithEncryptedData', testData['test_test_someExtraOldData']); deferredResult.addMethod(user, 'login'); deferredResult.addMethod(user, 'getRecords'); deferredResult.addCallback(function (someRecords) { SimpleTest.is(MochiKit.Base.keys(someRecords).length, 1, "The user has initially just one record"); }); deferredResult.addMethod(user, 'createNewRecord'); deferredResult.addMethodcaller('reference'); deferredResult.addCallback(function (aNewRecordReference) { newRecordReference = aNewRecordReference; }) deferredResult.addMethod(user, 'getRecords'); deferredResult.addCallback(function (someRecords) { SimpleTest.is(MochiKit.Base.keys(someRecords).length, 2, "After having created a new record, the total should be updated accordingly"); }); deferredResult.addMethod(user, 'getRecord', '05aad20ee399b11ddc923e601fcd1d096233634f2ad4c55db4f6435e5f9cc17a'); deferredResult.addMethodcaller('hasPendingChanges'); deferredResult.addTest(false, "adding a new record should not trigger any changes on a sibling record"); deferredResult.addMethod(user, 'hasPendingChanges'); deferredResult.addTest(true, "adding a new record should trigger the 'has pending changes' flag on the user"); deferredResult.addMethod(user, 'saveChanges'); deferredResult.addMethod(user2, 'login'); deferredResult.addMethod(user2, 'getRecords'); deferredResult.addCallback(function (someRecords) { SimpleTest.is(MochiKit.Base.keys(someRecords).length, 1, "Reloading the data, just one record is available, as a brand new record without any changes should not be saved"); }); deferredResult.callback(); return deferredResult; }, //------------------------------------------------------------------------- 'addNewRecordAndSaveChanges_test': function (someTestArgs) { var deferredResult; var proxy; var user; proxy = new Clipperz.PM.Proxy.Test({shouldPayTolls:true, isDefault:true, readOnly:false}); user = new Clipperz.PM.DataModel.User({username:'test', getPassphraseFunction:function () { return 'test';}}); user2 = new Clipperz.PM.DataModel.User({username:'test', getPassphraseFunction:function () { return 'test';}}); deferredResult = new Clipperz.Async.Deferred("addNewRecordAndSaveChanges_test", someTestArgs); deferredResult.addMethod(proxy.dataStore(), 'setupWithEncryptedData', testData['test_test_someExtraOldData']); deferredResult.addMethod(user, 'login'); deferredResult.addMethod(user, 'getRecords'); deferredResult.addCallback(function (someRecords) { SimpleTest.is(MochiKit.Base.keys(someRecords).length, 1, "The user has initially just one record"); }); deferredResult.addMethod(user, 'createNewRecord'); deferredResult.addCallback(function (aNewRecord) { var innerDeferredResult; innerDeferredResult = new Clipperz.Async.Deferred("addNewRecordAndSaveChanges_test <internal>", {trace:false}); innerDeferredResult.addMethod(aNewRecord, 'label'); innerDeferredResult.addTest('', "The label of a brand new record should be the empty string"); innerDeferredResult.addMethod(aNewRecord, 'setLabel', "New record label"); innerDeferredResult.addMethod(aNewRecord, 'setNotes', "New record notes"); innerDeferredResult.addMethod(aNewRecord, 'addField', {'label':"Label 1", 'value':"Value 1", 'isHidden':false}); innerDeferredResult.addMethod(aNewRecord, 'addField', {'label':"Label 2", 'value':"Value 2", 'isHidden':false}); innerDeferredResult.addMethod(aNewRecord, 'addField', {'label':"Label 3", 'value':"Value 3", 'isHidden':true}); innerDeferredResult.addMethod(aNewRecord, 'addField', {'label':"Label 4", 'value':"Value 4", 'isHidden':false}); innerDeferredResult.callback(); return innerDeferredResult; }) deferredResult.addMethod(user, 'getRecords'); deferredResult.addCallback(function (someRecords) { SimpleTest.is(MochiKit.Base.keys(someRecords).length, 2, "After having created a new record, the total should be updated accordingly"); }); deferredResult.addMethod(user, 'getRecord', '05aad20ee399b11ddc923e601fcd1d096233634f2ad4c55db4f6435e5f9cc17a'); deferredResult.addMethodcaller('hasPendingChanges'); deferredResult.addTest(false, "adding a new record should not trigger any changes on a sibling record"); deferredResult.addMethod(user, 'hasPendingChanges'); deferredResult.addTest(true, "adding a new record should trigger the 'has pending changes' flag on the user"); deferredResult.addMethod(user, 'saveChanges'); deferredResult.addCallback(function () { var recordData var recordVersionData; recordData = MochiKit.Base.values(proxy.dataStore().data()['users']['9a984e219b07f9b645ef35f4de938b4741abe2e0b4adc88b40e9367170c91cc8']['records'])[1]; recordVersionData = MochiKit.Base.values(recordData['versions'])[0]; SimpleTest.is(recordVersionData['previousVersionKey'], Clipperz.PM.Crypto.nullValue, "The previous version key on the first version of a newly created record is equal to Clipperz.PM.Crypto.nullValue"); }); deferredResult.addMethod(user2, 'login'); deferredResult.addMethod(user2, 'getRecords'); deferredResult.addCallback(function (someRecords) { SimpleTest.is(someRecords.length, 2, "Reloading the data, two records are available."); return someRecords; }); deferredResult.addCallback(MochiKit.Base.itemgetter('1')); deferredResult.collectResults({ 'label': [ MochiKit.Base.methodcaller('label'), Clipperz.Async.Test.is("New record label", "The label is correct") ], 'notes': [ MochiKit.Base.methodcaller('notes'), Clipperz.Async.Test.is("New record notes", "The note is correct") ], 'fields': [ MochiKit.Base.methodcaller('fields'), function (someFields) { SimpleTest.is(MochiKit.Base.values(someFields).length, 4, "The fields are 4, as expected"); return someFields; } ] }) deferredResult.callback(); return deferredResult; }, //------------------------------------------------------------------------- 'addNewRecordAndTestNewRecordIndex_test': function (someTestArgs) { var deferredResult; var proxy; var user; proxy = new Clipperz.PM.Proxy.Test({shouldPayTolls:true, isDefault:true, readOnly:false}); user = new Clipperz.PM.DataModel.User({username:'joe', getPassphraseFunction:function () { return 'clipperz';}}); deferredResult = new Clipperz.Async.Deferred("addNewRecordAndTestNewRecordIndex_test", someTestArgs); deferredResult.addMethod(proxy.dataStore(), 'setupWithEncryptedData', testData['joe_clipperz_offline_copy_data']); deferredResult.addMethod(user, 'login'); deferredResult.addMethod(user, 'getRecords'); deferredResult.addCallback(function (someRecords) { SimpleTest.is(MochiKit.Base.keys(someRecords).length, 20, "The user has initially 20 records"); }); deferredResult.addMethod(user, 'createNewRecord'); deferredResult.addCallback(function (aNewRecord) { var innerDeferredResult; innerDeferredResult = new Clipperz.Async.Deferred("addNewRecordAndTestNewRecordIndex_test <internal>", {trace:false}); innerDeferredResult.addMethod(user, 'getHeaderIndex', 'recordsIndex'); innerDeferredResult.addMethodcaller('recordsIndex'); innerDeferredResult.addCallback(MochiKit.Base.itemgetter(aNewRecord.reference())); innerDeferredResult.addTest(20, "The index of the new record should be 20"); innerDeferredResult.callback(); return innerDeferredResult; }) deferredResult.callback(); return deferredResult; }, //------------------------------------------------------------------------- 'editRecordAndTestForChangesInPreferencesAndOTP_test': function (someTestArgs) { var deferredResult; var proxy; var user; var user_2; var originalPreferences; var originalOTPs; proxy = new Clipperz.PM.Proxy.Test({shouldPayTolls:true, isDefault:true, readOnly:false}); user = new Clipperz.PM.DataModel.User({username:'joe', getPassphraseFunction:function () { return 'clipperz';}}); user_2 = new Clipperz.PM.DataModel.User({username:'joe', getPassphraseFunction:function () { return 'clipperz';}}); deferredResult = new Clipperz.Async.Deferred("editRecordAndTestForChangesInPreferencesAndOTP_test", someTestArgs); deferredResult.addMethod(proxy.dataStore(), 'setupWithEncryptedData', testData['joe_clipperz_offline_copy_with_preferences_and_OTPs_data']); deferredResult.addMethod(user, 'login'); deferredResult.addMethod(user, 'getServerData'); deferredResult.collectResults({ 'preferences': [ MochiKit.Base.method(user, 'getHeaderIndex', 'preferences'), MochiKit.Base.methodcaller('getDecryptedData') ], 'oneTimePasswords': [ MochiKit.Base.method(user, 'getHeaderIndex', 'oneTimePasswords'), MochiKit.Base.methodcaller('getDecryptedData') ] }); deferredResult.addCallback(function (someValues) { //console.log("SOME VALUES", someValues); originalPreferences = Clipperz.Base.deepClone(someValues['preferences']); originalOTPs = Clipperz.Base.deepClone(someValues['oneTimePasswords']); SimpleTest.is(originalPreferences['preferredLanguage'], 'en-US', "Preference.language is ok"); SimpleTest.is(originalPreferences['shouldShowDonationPanel'], false, "Preference.shouldShowDonationPanel is ok"); SimpleTest.is(MochiKit.Base.keys(originalOTPs).length, 6, "the number of OTPs is as expected"); }); deferredResult.addMethod(user, 'getRecord', '35b30f9e923ce913365815d44cf344ce66cb71b636093b8ec55b8245d13df82b'); deferredResult.addCallback(MochiKit.Base.methodcaller('setLabel', "NEW LABEL")); deferredResult.addMethod(user, 'saveChanges'); deferredResult.addMethod(user_2, 'login'); deferredResult.addMethod(user_2, 'getServerData'); deferredResult.collectResults({ 'preferences': [ MochiKit.Base.method(user_2, 'getHeaderIndex', 'preferences'), MochiKit.Base.methodcaller('getDecryptedData') ], 'oneTimePasswords': [ MochiKit.Base.method(user_2, 'getHeaderIndex', 'oneTimePasswords'), MochiKit.Base.methodcaller('getDecryptedData') ] }); deferredResult.addCallback(function (someValues) { //console.log("SOME VALUES", someValues); // originalPreferences = Clipperz.Base.deepClone(someValues['preferences']); // originalOTPs = Clipperz.Base.deepClone(someValues['oneTimePasswords']); SimpleTest.is(someValues['preferences']['preferredLanguage'], originalPreferences['preferredLanguage'], "Preference.language is preserved"); SimpleTest.is(someValues['preferences']['shouldShowDonationPanel'], originalPreferences['shouldShowDonationPanel'], "Preference.shouldShowDonationPanel is preserved"); SimpleTest.is(MochiKit.Base.keys(someValues['oneTimePasswords']).length, MochiKit.Base.keys(originalOTPs).length, "the number of OTPs is preserved"); }); deferredResult.callback(); return deferredResult; }, //------------------------------------------------------------------------- 'addRecordAndSaveChangesMultipleTimes_test': function (someTestArgs) { var deferredResult; var proxy; var user; proxy = new Clipperz.PM.Proxy.Test({shouldPayTolls:true, isDefault:true, readOnly:false}); user = new Clipperz.PM.DataModel.User({username:'test', getPassphraseFunction:function () { return 'test';}}); user2 = new Clipperz.PM.DataModel.User({username:'test', getPassphraseFunction:function () { return 'test';}}); deferredResult = new Clipperz.Async.Deferred("addRecordAndSaveChangesMultipleTimes_test", someTestArgs); deferredResult.addMethod(proxy.dataStore(), 'setupWithEncryptedData', testData['test_test_someExtraOldData']); deferredResult.addMethod(user, 'login'); deferredResult.addMethod(user, 'getRecords'); deferredResult.addCallback(MochiKit.Base.itemgetter('length')); deferredResult.addTest(1, "The user has one record stored in its account"); deferredResult.addMethod(user, 'hasPendingChanges'); deferredResult.addTest(false, "After loading records, the user should have no pending changes"); deferredResult.addMethod(user, 'createNewRecord'); deferredResult.addCallback(function (aNewRecord) { var innerDeferredResult; innerDeferredResult = new Clipperz.Async.Deferred("addRecordAndSaveChangesMultipleTimes_test <internal [1]>", {trace:false}); innerDeferredResult.addMethod(aNewRecord, 'setLabel', "New record 1"); innerDeferredResult.addMethod(aNewRecord, 'addField', {'label':'record number', 'value':"1", 'isHidden':false}); innerDeferredResult.addMethod(aNewRecord, 'addField', {'label':'field count', 'value':"2", 'isHidden':false}); innerDeferredResult.callback(); return innerDeferredResult; }) deferredResult.addMethod(user, 'hasPendingChanges'); deferredResult.addTest(true, "Before saving, the user has pending changes"); deferredResult.addMethod(user, 'saveChanges'); deferredResult.addCallback(SimpleTest.ok, true, "Saving worked (apparently) fine"); deferredResult.addMethod(user, 'hasPendingChanges'); deferredResult.addTest(false, "After saving, the user has no pending changes"); deferredResult.addMethod(user, 'createNewRecord'); deferredResult.addCallback(function (aNewRecord) { var innerDeferredResult; innerDeferredResult = new Clipperz.Async.Deferred("addRecordAndSaveChangesMultipleTimes_test <internal [2]>", {trace:false}); innerDeferredResult.addMethod(aNewRecord, 'setLabel', "New record 2"); innerDeferredResult.addMethod(aNewRecord, 'addField', {'label':"record number", 'value':"2", 'isHidden':false}); innerDeferredResult.callback(); return innerDeferredResult; }) deferredResult.addMethod(user, 'saveChanges'); deferredResult.addMethod(user, 'getRecords'); deferredResult.addCallback(MochiKit.Base.itemgetter('length')); deferredResult.addTest(3, "After having created two new records, the total should be updated accordingly"); deferredResult.addMethod(user2, 'login'); deferredResult.addMethod(user2, 'getRecords'); deferredResult.addCallback(MochiKit.Base.itemgetter('length')); deferredResult.addTest(3, "Reloading the data, three records are available"); deferredResult.addMethod(user2, 'recordWithLabel', 'New record 1'); //deferredResult.addCallback(function (aValue) { console.log("RECORD with Label", aValue); return aValue; }); deferredResult.collectResults({ 'label': [ MochiKit.Base.methodcaller('label'), MochiKit.Base.partial(Clipperz.Async.Test.is, 'New record label', "The label is correct") ], 'notes': [ MochiKit.Base.methodcaller('notes'), Clipperz.Async.Test.is('', "The note of the new created record is empty") ], 'fields': [ MochiKit.Base.methodcaller('fields'), MochiKit.Base.values, MochiKit.Base.itemgetter('length'), Clipperz.Async.Test.is(2, "The new record has just one field, as expected") ], 'fieldValues_1': [ MochiKit.Base.methodcaller('fieldWithLabel', 'record number'), MochiKit.Base.methodcaller('value'), Clipperz.Async.Test.is('1', "The field value is as expected") ], 'fieldValues_2': [ MochiKit.Base.methodcaller('fieldWithLabel', 'field count'), MochiKit.Base.methodcaller('value'), Clipperz.Async.Test.is('2', "Also the second field value is as expected") ] }) deferredResult.callback(); return deferredResult; }, //------------------------------------------------------------------------- 'addNewRecordAndRevertChanges_test': function (someTestArgs) { var deferredResult; var proxy; var user, user2; proxy = new Clipperz.PM.Proxy.Test({shouldPayTolls:true, isDefault:true, readOnly:false}); user = new Clipperz.PM.DataModel.User({username:'test', getPassphraseFunction:function () { return 'test';}}); user2 = new Clipperz.PM.DataModel.User({username:'test', getPassphraseFunction:function () { return 'test';}}); deferredResult = new Clipperz.Async.Deferred("addNewRecordAndRevertChanges_test", someTestArgs); deferredResult.addMethod(proxy.dataStore(), 'setupWithEncryptedData', testData['test_test_someExtraOldData']); deferredResult.addMethod(user, 'login'); deferredResult.addMethod(user, 'getRecords'); deferredResult.addCallback(function (someRecords) { SimpleTest.is(MochiKit.Base.keys(someRecords).length, 1, "The user has initially just one record"); }); deferredResult.addMethod(user, 'createNewRecord'); deferredResult.addCallback(function (aNewRecord) { return Clipperz.Async.callbacks("addNewRecordAndRevertChanges_test <internal>", [ MochiKit.Base.method(aNewRecord, 'setLabel', "New record label"), MochiKit.Base.method(aNewRecord, 'setNotes', "New record notes"), MochiKit.Base.method(aNewRecord, 'addField', {'label':"Label 1", 'value':"Value 1", 'isHidden':false}), MochiKit.Base.method(aNewRecord, 'addField', {'label':"Label 2", 'value':"Value 2", 'isHidden':false}), MochiKit.Base.method(aNewRecord, 'addField', {'label':"Label 3", 'value':"Value 3", 'isHidden':true}), MochiKit.Base.method(aNewRecord, 'addField', {'label':"Label 4", 'value':"Value 4", 'isHidden':false}) ], {trace:false}); }) deferredResult.addMethod(user, 'getRecords'); deferredResult.addCallback(function (someRecords) { SimpleTest.is(MochiKit.Base.keys(someRecords).length, 2, "After having created a new record, the total should be updated accordingly"); }); deferredResult.addMethod(user, 'getRecord', '05aad20ee399b11ddc923e601fcd1d096233634f2ad4c55db4f6435e5f9cc17a'); deferredResult.addMethodcaller('hasPendingChanges'); deferredResult.addTest(false, "adding a new record should not trigger any changes on a sibling record"); deferredResult.addMethod(user, 'hasPendingChanges'); deferredResult.addTest(true, "adding a new record should trigger the 'has pending changes' flag on the user"); deferredResult.addMethod(user, 'revertChanges'); deferredResult.addMethod(user, 'hasPendingChanges'); deferredResult.addTest(false, "reverting changes shoud restore the previous state on the user"); deferredResult.addMethod(user2, 'login'); deferredResult.addMethod(user2, 'getRecords'); deferredResult.addCallback(function (someRecords) { SimpleTest.is(someRecords.length, 1, "Reloading the data, just one record is available."); return someRecords; }); deferredResult.callback(); return deferredResult; }, //------------------------------------------------------------------------- 'logout_test': function (someTestArgs) { var deferredResult; var proxy; var user; proxy = new Clipperz.PM.Proxy.Test({shouldPayTolls:true, isDefault:true, readOnly:false}); user = new Clipperz.PM.DataModel.User({username:'joe', getPassphraseFunction:function () { return 'clipperz';}}); deferredResult = new Clipperz.Async.Deferred("logout_test", someTestArgs); deferredResult.addMethod(proxy.dataStore(), 'setupWithEncryptedData', testData['joe_clipperz_offline_copy_with_preferences_and_OTPs_data']); deferredResult.addMethod(user, 'login'); deferredResult.addMethod(user, 'getRecords'); deferredResult.addCallback(function (someRecords) { SimpleTest.is(MochiKit.Base.keys(someRecords).length, 18, "The user has 18 records"); }); deferredResult.addMethod(user, 'logout'); deferredResult.shouldSucceed("Logging out should not trigger an exception"); deferredResult.callback(); return deferredResult; }, //------------------------------------------------------------------------- 'lock_test': function (someTestArgs) { var deferredResult; var proxy; var user; var returnPassword = function () { return MochiKit.Async.succeed('clipperz'); }; var failPassword = function () { throw "Unexpected access to the password"; }; var currentPasswordFunction = returnPassword; var passwordFunction = function () { return currentPasswordFunction(); }; proxy = new Clipperz.PM.Proxy.Test({shouldPayTolls:true, isDefault:true, readOnly:false}); user = new Clipperz.PM.DataModel.User({username:'joe', getPassphraseFunction:passwordFunction}); deferredResult = new Clipperz.Async.Deferred("lock_test", someTestArgs); deferredResult.addMethod(proxy.dataStore(), 'setupWithEncryptedData', testData['joe_clipperz_offline_copy_with_preferences_and_OTPs_data']); deferredResult.addMethod(user, 'login'); deferredResult.addMethod(user, 'getRecords'); deferredResult.addCallback(function (someRecords) { SimpleTest.is(MochiKit.Base.keys(someRecords).length, 18, "The user has 18 records"); }); deferredResult.addMethod(user, 'getDirectLogins'); deferredResult.addCallback(function (someDirectLogins) { SimpleTest.is(MochiKit.Base.keys(someDirectLogins).length, 22, "The user has 22 direct logins"); }); deferredResult.addMethod(proxy, 'shouldNotReceiveAnyFurtherRequest'); deferredResult.addCallback(function () { currentPasswordFunction = failPassword; }); deferredResult.addMethod(user, 'lock'); deferredResult.shouldSucceed("Locking out should not trigger an exception"); deferredResult.addMethod(proxy, 'unexpectedRequests'); deferredResult.addCallback(MochiKit.Base.itemgetter('length')); deferredResult.addTest(0, "The proxy should have not received any extra request"); //deferredResult.addCallback(function (aValue) { console.log("PROXY.unexpectedRequests", Clipperz.Base.serializeJSON(proxy.unexpectedRequests())); return aValue; }); deferredResult.addMethod(proxy, 'mayReceiveMoreRequests'); deferredResult.addCallback(function () { currentPasswordFunction = returnPassword; }); deferredResult.callback(); return deferredResult; }, //------------------------------------------------------------------------- 'registerNewUser_test': function (someTestArgs) { var deferredResult; var proxy; var user, user2; var username; var passphrase; username = "new"; passphrase = "user"; proxy = new Clipperz.PM.Proxy.Test({shouldPayTolls:true, isDefault:true, readOnly:false}); // user2 = new Clipperz.PM.DataModel.User({username:username, getPassphraseFunction:function () { return MochiKit.Async.succeed(passphrase);}}); user2 = new Clipperz.PM.DataModel.User({username:username, getPassphraseFunction:function () { return passphrase;}}); deferredResult = new Clipperz.Async.Deferred("registerNewUser_test", someTestArgs); deferredResult.addMethod(proxy.dataStore(), 'setupWithEncryptedData', testData['joe_clipperz_offline_copy_with_preferences_and_OTPs_data']); deferredResult.addCallback(Clipperz.PM.DataModel.User.registerNewAccount, username, function () { return MochiKit.Async.succeed(passphrase);}); deferredResult.setValue('user'); deferredResult.addMethodcaller('getRecords'); deferredResult.addCallback(function (someRecords) { SimpleTest.is(MochiKit.Base.keys(someRecords).length, 0, "The newly created user has no records"); }); deferredResult.getValue('user'); deferredResult.addMethodcaller('logout'); deferredResult.addMethod(user2, 'login'); deferredResult.addMethod(user2, 'getDirectLogins'); deferredResult.addCallback(function (someDirectLogins) { SimpleTest.is(MochiKit.Base.keys(someDirectLogins).length, 0, "The user has no direct logins"); }); deferredResult.callback(); return deferredResult; }, //------------------------------------------------------------------------- 'registerNewUserAndAddARecord_test': function (someTestArgs) { var deferredResult; var proxy; var user, user2; var username; var passphrase; username = "new"; passphrase = "user"; proxy = new Clipperz.PM.Proxy.Test({shouldPayTolls:true, isDefault:true, readOnly:false}); user2 = new Clipperz.PM.DataModel.User({username:username, getPassphraseFunction:function () { return passphrase;}}); - +console.log("PROXY", proxy); deferredResult = new Clipperz.Async.Deferred("registerNewUserAndAddARecord_test", someTestArgs); deferredResult.addMethod(proxy.dataStore(), 'setupWithEncryptedData', testData['joe_clipperz_offline_copy_with_preferences_and_OTPs_data']); deferredResult.addCallback(Clipperz.PM.DataModel.User.registerNewAccount, username, function () { return MochiKit.Async.succeed(passphrase);}); deferredResult.setValue('user'); deferredResult.addMethodcaller('getRecords'); deferredResult.addCallback(function (someRecords) { SimpleTest.is(MochiKit.Base.keys(someRecords).length, 0, "The newly created user has no records"); }); deferredResult.getValue('user'); deferredResult.addMethodcaller('createNewRecord'); deferredResult.addCallback(function (aNewRecord) { var innerDeferredResult; innerDeferredResult = new Clipperz.Async.Deferred("addRecordAndSaveChangesMultipleTimes_test <internal [1]>", {trace:false}); innerDeferredResult.addMethod(aNewRecord, 'setLabel', "New record 1"); innerDeferredResult.addMethod(aNewRecord, 'addField', {'label':'record number', 'value':"1", 'isHidden':false}); innerDeferredResult.addMethod(aNewRecord, 'addField', {'label':'field count', 'value':"2", 'isHidden':false}); innerDeferredResult.callback(); return innerDeferredResult; }) deferredResult.getValue('user'); deferredResult.addMethodcaller('saveChanges'); deferredResult.addCallback(SimpleTest.ok, true, "Saving worked (apparently) fine"); deferredResult.getValue('user'); deferredResult.addMethodcaller('logout'); deferredResult.addMethod(user2, 'login'); deferredResult.addMethod(user2, 'getRecords'); deferredResult.addCallback(function (someDirectLogins) { SimpleTest.is(MochiKit.Base.keys(someDirectLogins).length, 1, "The user - even after a brand new login - has the newly created record"); }); deferredResult.callback(); return deferredResult; }, //------------------------------------------------------------------------- 'changePassphrase_test': function (someTestArgs) { var deferredResult; var proxy; var user; var user2; var newPassphrase; newPassphrase = 'zreppilc'; proxy = new Clipperz.PM.Proxy.Test({shouldPayTolls:true, isDefault:true, readOnly:false}); user = new Clipperz.PM.DataModel.User({username:'joe', getPassphraseFunction:function () { return 'clipperz';}}); user2 = new Clipperz.PM.DataModel.User({username:'joe', getPassphraseFunction:function () { return newPassphrase;}}); deferredResult = new Clipperz.Async.Deferred("changePassphrase_test", someTestArgs); deferredResult.addMethod(proxy.dataStore(), 'setupWithEncryptedData', testData['joe_clipperz_offline_copy_data']); deferredResult.addMethod(user, 'login'); deferredResult.addMethod(user, 'getRecords'); deferredResult.addCallback(MochiKit.Base.itemgetter('length')); deferredResult.addTest(20, "This account has oly a single card"); deferredResult.addMethod(user, 'changePassphrase', newPassphrase); deferredResult.addMethod(user, 'logout'); deferredResult.addMethod(user2, 'login'); deferredResult.addMethod(user2, 'getRecords'); deferredResult.addCallback(MochiKit.Base.itemgetter('length')); deferredResult.addTest(20, "This account has oly a single card"); deferredResult.callback(); return deferredResult; }, //------------------------------------------------------------------------- /* 'rearrangeRecordFieldOrderAndSave_test': function (someTestArgs) { var deferredResult; var proxy; var user; proxy = new Clipperz.PM.Proxy.Test({shouldPayTolls:true, isDefault:true, readOnly:false}); user = new Clipperz.PM.DataModel.User({username:'test', getPassphraseFunction:function () { return 'test';}}); deferredResult = new Clipperz.Async.Deferred("simpleSaveChanges_test", someTestArgs); deferredResult.addMethod(proxy.dataStore(), 'setupWithEncryptedData', testData['test_test_offline_copy_data']); deferredResult.addMethod(user, 'login'); deferredResult.addMethod(user, 'getRecord', '8280842f41162b673335b63860637e8472e8bbff0efa2bc78b0dbc5e09712e13'); deferredResult.addMethodcaller('fields'); deferredResult.addCallback(function (someFields) { var fields; fields = MochiKit.Base.values(someFields); SimpleTest.is(fields.length, 3, "The record has initially 3 fields"); SimpleTest.is(fields[0].reference(), '6a84c414866dd6d266186f0255a595e9330fb34973c085a81a6e4906876c721b', "the first field is the expected one"); SimpleTest.is(fields[1].reference(), 'fde88847cdbae6f7ee7e38aca1a242492888ff430a79c997bc6ba4afd0540ca2', "the second field is the expected one"); SimpleTest.is(fields[2].reference(), 'bd4e3bb9d3497f63c4c3a507d4b80f489fdb57deb9d1b342a5e1cff65936a410', "the third field is the expected one"); }); // "6a84c414866dd6d266186f0255a595e9330fb34973c085a81a6e4906876c721b": { // "label":"Label 1","value":"Value 1","type":"TXT","hidden":false // }, // "fde88847cdbae6f7ee7e38aca1a242492888ff430a79c997bc6ba4afd0540ca2": { // "label":"Label 2","value":"Value 2","type":"PWD","hidden":true // }, // "bd4e3bb9d3497f63c4c3a507d4b80f489fdb57deb9d1b342a5e1cff65936a410": { // "label":"Label 3","value":"http://www.example.com","type":"URL","hidden":false // } deferredResult.addMethod(user, 'getRecord', '8280842f41162b673335b63860637e8472e8bbff0efa2bc78b0dbc5e09712e13'); deferredResult.addCallback(MochiKit.Base.methodcaller('sortFieldReference', [ 'bd4e3bb9d3497f63c4c3a507d4b80f489fdb57deb9d1b342a5e1cff65936a410', '6a84c414866dd6d266186f0255a595e9330fb34973c085a81a6e4906876c721b', 'bd4e3bb9d3497f63c4c3a507d4b80f489fdb57deb9d1b342a5e1cff65936a410' ])); deferredResult.addMethod(user, 'getRecord', '8280842f41162b673335b63860637e8472e8bbff0efa2bc78b0dbc5e09712e13'); deferredResult.addMethodcaller('hasPendingChanges'); deferredResult.addTest(true, "adding a field should mark the record as having pending changes"); deferredResult.addMethod(user, 'getRecord', '8280842f41162b673335b63860637e8472e8bbff0efa2bc78b0dbc5e09712e13'); deferredResult.addMethodcaller('fields'); deferredResult.addCallback(function (someFields) { SimpleTest.is(MochiKit.Base.values(someFields).length, 4, "The record has now 4 fields"); }); deferredResult.addMethod(user, 'saveChanges'); deferredResult.addMethod(user, 'hasPendingChanges'); deferredResult.addTest(false, "saving changes should return the user to a state with not changes pending - 4"); deferredResult.callback(); return deferredResult; }, */ //------------------------------------------------------------------------- 'syntaxFix': MochiKit.Base.noop }; //############################################################################# SimpleTest.runDeferredTests("Clipperz.PM.DataModel.User", tests, {trace:false}); diff --git a/frontend/gamma/tests/tests/Clipperz/PM/index.html b/frontend/gamma/tests/tests/Clipperz/PM/index.html index eeda692..6eb6622 100644 --- a/frontend/gamma/tests/tests/Clipperz/PM/index.html +++ b/frontend/gamma/tests/tests/Clipperz/PM/index.html @@ -1,52 +1,53 @@ <!-- 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/. --> <html> <head> <title>Clipperz.PM.* - tests</title> <script type="text/javascript" src="../../../../js/MochiKit/MochiKit.js"></script> <script type="text/javascript" src="../../../SimpleTest/TestRunner.js"></script> </head> <body> <script> TestRunner.runTests( // // This is still a complete mess. // // 'BookmarkletProcessor.html', 'Connection.html', 'Crypto.html', + 'Crypto_v0_4.html', // 'Crypto_other_implementation_comparison.html', 'Crypto_performanceEvaluation.html', // 'CryptoPerformance_ByteArrayArray.html', // 'CryptoPerformance_ByteArrayHex.html', // 'CryptoPerformance_ByteArrayString.html', 'Date.html', 'PIN.html', 'Proxy.html', 'Toll.html' ); </script> </body> </html>
\ No newline at end of file |