Exemple #1
0
 def test_payload_without_padding(self):
     """Use a payload which isn't padded."""
     self.assertEqual(decode(b'\x00\x00\x00\x04ABCD'), b'ABCD')
     self.assertEqual(
         decode(
             b'\x00\x00\x01\x00aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'
         ),
         b'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'
     )
Exemple #2
0
 def test_payload_with_padding(self):
     """Use a payload which is padded."""
     self.assertEqual(
         decode(b'\x00\x00\x00\x04ABCDPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP'),
         b'ABCD')
     self.assertEqual(
         decode(
             b'\x00\x00\x00\x05AB\x00CDPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP'
         ), b'AB\x00CD')
     self.assertEqual(decode(b'\x00\x00\x00\x01PP'), b'P')
    def test_rountrip_with_padding(self):
        """Encode each test case with padding."""
        for data in all_test_cases():
            # Round up to the nearest 100
            multiplier = 100
            target_length = (int((len(data) + 4) / multiplier) + 1) * multiplier

            enc = encode(data, target_length)
            dec = decode(enc)
            self.assertEqual(data, dec)
Exemple #4
0
 def test_file_too_small(self):
     """Use a file shorter than the length header."""
     with self.assertRaises(ValueError):
         decode(b'\x00\x00\x00\x01')
     with self.assertRaises(ValueError):
         decode(b'\x00\x00\x00\x04ABC')
     with self.assertRaises(ValueError):
         decode(b'\x00\x00\x00\x08ABCDPPP')
Exemple #5
0
 def test_invalid_length(self):
     """Use an invalid length header."""
     with self.assertRaises(ValueError):
         decode(b'')
     with self.assertRaises(ValueError):
         decode(b'\xFF')
     with self.assertRaises(ValueError):
         decode(b'\x00\x00\x00')
Exemple #6
0
 def test_payload_with_weird_padding(self):
     """Use a payload which is padded with non-standard characters."""
     self.assertEqual(decode(b'\x00\x00\x00\x04ABCDABCD'), b'ABCD')
     self.assertEqual(decode(b'\x00\x00\x00\x01P\x00\x00\x00'), b'P')
Exemple #7
0
 def test_empty_payload(self):
     """Use an empty file."""
     self.assertEqual(decode(b'\x00\x00\x00\x00'), b'')
Exemple #8
0
 def test_roundtrip_without_padding(self):
     """Encode each test case without padding."""
     for data in all_test_cases():
         enc = encode(data, len(data) + 4)
         dec = decode(enc)
         self.assertEqual(data, dec)