def test_decode_garbage(self): """ If too short to decode we should raise a unique exception that Will allow us to retry """ # Gave a length that was not a multiple of 4 with self.assertRaises(CodecException): message.decode(b'\x01' + # Version b'\x00\x00\x15' + # Length 21 b'\x00' * (message.HEADER_LEN - 3)) # Garbage AVPs with self.assertRaises(CodecException): message.decode(b'\x01' + # Version b'\x00\x00\x18' + # Length 24 b'\x00' * (message.HEADER_LEN))
def test_decode_validate_length(self): """ If too short to decode we should raise a unique exception that Will allow us to retry """ # Shorter than header by 1 with self.assertRaises(TooShortException): message.decode(b'\x01' + b'\x00' * (message.HEADER_LEN - 2)) # Header says 24 bytes but we give 23 with self.assertRaises(TooShortException): payload = ( b'\x01' + # Version b'\x00\x00\x18' + # Length 24 b'\x00' * (message.HEADER_LEN - 1)) self.assertEqual(len(payload), 23) message.decode(payload)
def _decode_check(self, msg, msg_bytes): decoded_msg = message.decode(msg_bytes) self.assertEqual(msg.header, decoded_msg.header) self.assertEqual(msg._avps, decoded_msg._avps)