import importlib.util import struct import unittest from pathlib import Path spec = importlib.util.spec_from_file_location('packet_oracle', Path(__file__).with_name('packet-oracle.py')) oracle = importlib.util.module_from_spec(spec) spec.loader.exec_module(oracle) class PacketOracleTest(unittest.TestCase): def test_compression_pointer_preserves_question_cursor(self): message = b'\x03www\x07example\x03com\0' + b'\xc0\0' + b'\0\x01\0\x01' self.assertEqual(oracle.dns_name(message, 17), ('www.example.com', 19)) def test_compression_cycle_and_missing_pointer_byte_fail(self): for message in (b'\xc0\0', b'\xc0', b'\xc0\x02\xc0\0'): with self.subTest(message=message), self.assertRaises(ValueError): oracle.dns_name(message, 0) def test_truncated_pcap_record_is_not_exhaustion(self): header = struct.pack('