def test_config_datatype(self): value = NTPServerAddressSubOption.config_datatype('2001:db8::1') self.assertEqual(value, IPv6Address('2001:db8::1')) with self.assertRaisesRegex(ValueError, 'routable IPv6 address'): NTPServerAddressSubOption.config_datatype('::') with self.assertRaisesRegex(ValueError, 'routable IPv6 address'): NTPServerAddressSubOption.config_datatype('::1') with self.assertRaisesRegex(ValueError, 'routable IPv6 address'): NTPServerAddressSubOption.config_datatype('fe80::1') with self.assertRaisesRegex(ValueError, 'routable IPv6 address'): NTPServerAddressSubOption.config_datatype('ff02::1')
def setUp(self): self.option_bytes = bytes.fromhex('0038004b' '0001001020010db8000000000000000000000001' '00020010ff12000000000000000000000000abcd' '00030011') + b'\x03ntp\x08steffann\x02nl\x00' + \ bytes.fromhex('ffff000a') + b'RandomData' self.option_object = NTPServersOption(options=[ NTPServerAddressSubOption(IPv6Address('2001:db8::1')), NTPMulticastAddressSubOption(IPv6Address('ff12::abcd')), NTPServerFQDNSubOption('ntp.steffann.nl.'), UnknownNTPSubOption(65535, b'RandomData'), ]) self.parse_option()
def setUp(self): self.option_bytes = bytes.fromhex('0001001020010db8000000000000000000000001') self.option_object = NTPServerAddressSubOption(IPv6Address('2001:db8::1')) self.parse_option()
def test_parse_wrong_type(self): with self.assertRaisesRegex(ValueError, 'does not contain NTPServerAddressSubOption data'): option = NTPServerAddressSubOption() option.load_from(b'00020010ff12000000000000000000000000abcd')
def test_bad_option_length(self): with self.assertRaisesRegex(ValueError, 'must have length 16'): NTPServerAddressSubOption.parse(bytes.fromhex('0001000f')) with self.assertRaisesRegex(ValueError, 'must have length 16'): NTPServerAddressSubOption.parse(bytes.fromhex('00010011'))