/* 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/. */ //============================================================================= testEvalJSON = function(aString, shouldFail, aDescription) { var result; if (shouldFail == true) { try { result = Clipperz.Base.evalJSON(aString); is(true, false, aDescription + ": vulnerability not caught"); //console.log(result); } catch(exception) { is(true, true, aDescription + ": vulnerability correctly caught"); } } else { try { result = Clipperz.Base.evalJSON(aString); is(true, true, aDescription + ": configuration correctly checked"); } catch(exception) { is(true, false, aDescription + ": configuration wrongly caught as malicious"); // console.log(exception); } } return result; } //============================================================================= var tests = { '001_test': function () { var stringToSplit; var splittedString; stringToSplit = "stringToSplit"; splittedString = Clipperz.Base.splitStringAtFixedTokenSize(stringToSplit, 2); is(splittedString.length, 7); is(splittedString[0], 'st'); is(splittedString[1], 'ri'); is(splittedString[2], 'ng'); is(splittedString[3], 'To'); is(splittedString[4], 'Sp'); is(splittedString[5], 'li'); is(splittedString[6], 't', "test that should pass"); stringToSplit = "stringToSplit"; splittedString = Clipperz.Base.splitStringAtFixedTokenSize(stringToSplit, 20); is(splittedString.length, 1); is(splittedString[0], 'stringToSplit'); stringToSplit = null; splittedString = Clipperz.Base.splitStringAtFixedTokenSize(stringToSplit, 20); is(splittedString.length, 0); }, //------------------------------------------------------------------------- '002_test': function () { var anObject; anObject = "String"; is(Clipperz.Base.objectType(anObject), 'string', "test on strings (1)"); anObject = new String("String"); is(Clipperz.Base.objectType(anObject), 'string', "test on strings (2)"); anObject = 120; is(Clipperz.Base.objectType(anObject), 'number', "test on numbers (1)"); anObject = new Number(120); is(Clipperz.Base.objectType(anObject), 'number', "test on numbers (2)"); anObject = true; is(Clipperz.Base.objectType(anObject), 'boolean', "test on booleans (1)"); anObject = new Boolean(true); is(Clipperz.Base.objectType(anObject), 'boolean', "test on booleans (2)"); anObject = new Date; is(Clipperz.Base.objectType(anObject), 'date', "test on dates"); anObject = new Error("test"); is(Clipperz.Base.objectType(anObject), 'error', "test on errors"); anObject = function() {}; is(Clipperz.Base.objectType(anObject), 'function', "test on functions"); anObject = new Object(); is(Clipperz.Base.objectType(anObject), 'object', "test on objects"); anObject = [1, 2, 3]; is(Clipperz.Base.objectType(anObject), 'array', "test on arrays"); }, //------------------------------------------------------------------------- '003_test': function () { var original, clone; original = { a: "a", b: "b" }; clone = Clipperz.Base.deepClone(original); is(MochiKit.Base.compare(original, clone), 0, "simple cloning return two equal objects"); clone.c = "c"; is(MochiKit.Base.compare(original, clone), -1, "changing an object leave the original object unchanged"); original = { a: "a", b: "b", nested: { a1: "a1", b1: "b1" } }; clone = Clipperz.Base.deepClone(original); is(MochiKit.Base.compare(original, clone), 0, "cloning of an object with nested values return two equal objects"); clone.nested.c1 = "c1"; is(MochiKit.Base.compare(original, clone), -1, "changing a nested value leave the original object unchanged"); }, //------------------------------------------------------------------------- '004_test': function () { var jsonString; jsonString = '{"page": {"title": "Example Attack"},"form": { "attributes": { "action": "javascript:opener.document.body.innerHTML = \'hacked!\';close();", "style": "-moz-binding:url(\'http://ha.ckers.org/xssmoz.xml#xss\')", "method": null }, "inputs": [{"type": "text", "name": "username", "value": ""}, {"type": "password", "name": "password", "value": ""}]},"version": "0.2.3" }'; testEvalJSON(jsonString, false, ""); // jsonString = '{"0":{"label":"