// Setup dumb test wrapper var testsdiv = $('#tests'); function TEST(func, name) { var funcName = name === undefined ? func + "" : name; try { if (func()) testsdiv.append('
' + funcName + ' passed
'); else testsdiv.append('' + funcName + ' returned false
'); } catch (e) { testsdiv.append('' + funcName + ' threw ' + e + '
'); } } // Random tests to check my JS knowledge TEST(function() { return !objectContainsKeys({}); }); TEST(function() { return objectContainsKeys({ a: undefined }); }); TEST(function() { return objectContainsKeys({ a: null }); }); // Basic sanity-checks on the crypto library TEST(function() { var PushMessageProto = dcodeIO.ProtoBuf.loadProtoFile("IncomingPushMessageSignal.proto").build("textsecure.PushMessageContent"); var IncomingMessageProto = dcodeIO.ProtoBuf.loadProtoFile("IncomingPushMessageSignal.proto").build("textsecure.IncomingPushMessageSignal"); var text_message = new PushMessageProto(); text_message.body = "Hi Mom"; var server_message = {type: 0, // unencrypted source: "+19999999999", timestamp: 42, message: text_message.encode() }; crypto.handleIncomingPushMessageProto(server_message); return server_message.message.body == text_message.body && server_message.message.attachments.length == text_message.attachments.length && text_message.attachments.length == 0; }, 'Unencrypted PushMessageProto "decrypt"'); // TODO: Run through the test vectors for the axolotl ratchet