def test_get_unhandled_options(self): unanswered_options = self.ia_bundle.get_unhandled_options((IANAOption, IATAOption)) self.assertEqual(len(unanswered_options), 4) self.assertIn(IANAOption(b'0001'), unanswered_options) self.assertIn(IANAOption(b'0002'), unanswered_options) self.assertIn(IATAOption(b'0003'), unanswered_options) self.assertIn(IATAOption(b'0004'), unanswered_options)
def test_bad_option_length(self): with self.assertRaisesRegex(ValueError, 'shorter than the minimum length'): IATAOption.parse(bytes.fromhex('0004000041424344')) with self.assertRaisesRegex(ValueError, 'length does not match'): IATAOption.parse(bytes.fromhex('000400054142434400140000'))
def setUp(self): self.bundle = TransactionBundle(relayed_solicit_message, received_over_multicast=False) self.shallow_bundle = TransactionBundle(solicit_message, received_over_multicast=True) self.deep_bundle = TransactionBundle(RelayForwardMessage( hop_count=0, link_address=IPv6Address('2001:db8:ffff:2::1'), peer_address=IPv6Address('fe80::3631:c4ff:fe3c:b2f1'), options=[ RelayMessageOption(relayed_message=relayed_solicit_message), ]), received_over_multicast=False, marks=['some', 'marks']) self.ia_bundle = TransactionBundle(SolicitMessage(options=[ IANAOption(b'0001'), IANAOption(b'0002'), IATAOption(b'0003'), IATAOption(b'0004'), IAPDOption(b'0005'), IAPDOption(b'0006'), ]), received_over_multicast=False) self.option_handlers = [ InterfaceIdOptionHandler(), ]
def test_validate_IAID_uniqueness(self): # The first one should be fine self.message.options.append(IANAOption(iaid=b'test')) self.message.validate() # Adding a different type with the same IAID is allowed self.message.options.append(IATAOption(iaid=b'test')) self.message.validate() # But adding another one with the same IAID is not allowed self.message.options.append(IATAOption(iaid=b'test')) with self.assertRaisesRegex(ValueError, 'not unique'): self.message.validate()
def setUp(self): self.option_bytes = bytes.fromhex( '0004' # option_type: OPTION_IA_TA '003c' # option_length '41424344' # iaid: ABCD '0005' # option_type: OPTION_IAADDR '0018' # option_length '20010db8000000000000000000000001' # address: 2001:db8::1 '00000000' # preferred_lifetime '00000000' # valid_lifetime '000d' # option_type: OPTION_STATUS_CODE '0018' # option_length '0000' # status_code '45766572797468696e6720697320617765736f6d6521') # status_message self.option_object = IATAOption( iaid=b'ABCD', options=[ IAAddressOption(address=IPv6Address('2001:db8::1')), StatusCodeOption(status_code=STATUS_SUCCESS, status_message='Everything is awesome!') ]) self.parse_option()
def test_unanswered_iata_options(self): unanswered_options = self.ia_bundle.get_unhandled_options(IATAOption) self.assertEqual(len(unanswered_options), 2) self.assertIn(IATAOption(b'0003'), unanswered_options) self.assertIn(IATAOption(b'0004'), unanswered_options)
def test_bad_option_length(self): with self.assertRaisesRegex(ValueError, "length does not match"): IATAOption.parse(bytes.fromhex("0004000041424344"))