public void testRecvNoAnnotations() { var msg = new Message(Message.MSG_CONNECT, new byte[] { 1, 2, 3, 4, 5 }, 42, 0, 0, null); var c = new ConnectionMock(); c.send(msg.to_bytes()); msg = Message.recv(c, null); Assert.AreEqual(0, c.RemainingLength); Assert.AreEqual(5, msg.data_size); Assert.AreEqual(new byte[] { 1, 2, 3, 4, 5 }, msg.data); Assert.AreEqual(0, msg.annotations_size); Assert.AreEqual(0, msg.annotations.Count); }
public void testRecvAnnotations() { var annotations = new Dictionary <string, byte[]>(); annotations["TEST"] = new byte[] { 10, 20, 30, 40, 50 }; var msg = new Message(Message.MSG_CONNECT, new byte[] { 1, 2, 3, 4, 5 }, this.serializer_id, 0, 0, annotations); var c = new ConnectionMock(); c.send(msg.to_bytes()); msg = Message.recv(c, null); Assert.AreEqual(0, c.RemainingLength); Assert.AreEqual(5, msg.data_size); Assert.AreEqual(new byte[] { 1, 2, 3, 4, 5 }, msg.data); Assert.AreEqual(new byte[] { 10, 20, 30, 40, 50 }, msg.annotations["TEST"]); Assert.IsTrue(msg.annotations.ContainsKey("HMAC")); }
public void testChecksum() { var msg = new Message(Message.MSG_RESULT, new byte[] { 1, 2, 3, 4 }, 42, 0, 1, null); var c = new ConnectionMock(); c.send(msg.to_bytes()); // corrupt the checksum bytes byte[] data = c.ReceivedData; data[Message.HEADER_SIZE - 2] = 0; data[Message.HEADER_SIZE - 1] = 0; c = new ConnectionMock(data); try { Message.recv(c, null); Assert.Fail("crash expected"); } catch (PyroException x) { Assert.IsTrue(x.Message.Contains("checksum")); } }
public void testRecvNoAnnotations() { var msg = new Message(Message.MSG_CONNECT, new byte[]{1,2,3,4,5}, 42, 0, 0, null); var c = new ConnectionMock(); c.send(msg.to_bytes()); msg = Message.recv(c, null); Assert.AreEqual(0, c.RemainingLength); Assert.AreEqual(5, msg.data_size); Assert.AreEqual(new byte[]{1,2,3,4,5}, msg.data); Assert.AreEqual(0, msg.annotations_size); Assert.AreEqual(0, msg.annotations.Count); }
public void testRecvAnnotations() { var annotations = new Dictionary<string, byte[]>(); annotations["TEST"] = new byte[]{10, 20,30,40,50}; var msg = new Message(Message.MSG_CONNECT, new byte[]{1,2,3,4,5}, this.serializer_id, 0, 0, annotations); var c = new ConnectionMock(); c.send(msg.to_bytes()); msg = Message.recv(c, null); Assert.AreEqual(0, c.RemainingLength); Assert.AreEqual(5, msg.data_size); Assert.AreEqual(new byte[]{1,2,3,4,5}, msg.data); Assert.AreEqual(new byte[]{10,20,30,40,50}, msg.annotations["TEST"]); Assert.IsTrue(msg.annotations.ContainsKey("HMAC")); }
public void testChecksum() { var msg = new Message(Message.MSG_RESULT, new byte[]{1,2,3,4}, 42, 0, 1, null); var c = new ConnectionMock(); c.send(msg.to_bytes()); // corrupt the checksum bytes byte[] data = c.ReceivedData; data[Message.HEADER_SIZE-2] = 0; data[Message.HEADER_SIZE-1] = 0; c = new ConnectionMock(data); try { Message.recv(c, null); Assert.Fail("crash expected"); } catch(PyroException x) { Assert.IsTrue(x.Message.Contains("checksum")); } }