def test_bad_option_length(self):
        with self.assertRaisesRegex(ValueError, 'embedded message has a different length'):
            LQRelayDataOption.parse(bytes.fromhex(
                '002f'  # Option type: OPTION_LQ_RELAY_DATA
                '003a'  # Option length: 58 (should be 59)
                '20010db8000000000000000000000002'  # Peer address: 2001:db8::2

                '0c'  # Message type: MSG_RELAY_FORW
                '00'  # Hop count: 0
                '20010db8000000000000000000000002'  # Link address: 2001:db8::2
                'fe800000000000000000000000000022'  # Peer address: fe80::22

                '0012'  # Option type: OPTION_INTERFACE_ID
                '0005'  # Option length: 5
                '4661322f33'  # Interface ID: 'Fa2/3'
            ))

        with self.assertRaisesRegex(ValueError, 'longer than the available buffer'):
            LQRelayDataOption.parse(bytes.fromhex(
                '002f'  # Option type: OPTION_LQ_RELAY_DATA
                '003c'  # Option length: 60 (should be 59)
                '20010db8000000000000000000000002'  # Peer address: 2001:db8::2

                '0c'  # Message type: MSG_RELAY_FORW
                '00'  # Hop count: 0
                '20010db8000000000000000000000002'  # Link address: 2001:db8::2
                'fe800000000000000000000000000022'  # Peer address: fe80::22

                '0012'  # Option type: OPTION_INTERFACE_ID
                '0005'  # Option length: 5
                '4661322f33'  # Interface ID: 'Fa2/3'
            ))
    def test_bad_option_length(self):
        with self.assertRaisesRegex(ValueError, "embedded message has a different length"):
            LQRelayDataOption.parse(
                bytes.fromhex(
                    "002f"  # Option type: OPTION_LQ_RELAY_DATA
                    "003a"  # Option length: 58 (should be 59)
                    "20010db8000000000000000000000002"  # Peer address: 2001:db8::2
                    "0c"  # Message type: MSG_RELAY_FORW
                    "00"  # Hop count: 0
                    "20010db8000000000000000000000002"  # Link address: 2001:db8::2
                    "fe800000000000000000000000000022"  # Peer address: fe80::22
                    "0012"  # Option type: OPTION_INTERFACE_ID
                    "0005"  # Option length: 5
                    "4661322f33"  # Interface ID: 'Fa2/3'
                )
            )

        with self.assertRaisesRegex(ValueError, "longer than the available buffer"):
            LQRelayDataOption.parse(
                bytes.fromhex(
                    "002f"  # Option type: OPTION_LQ_RELAY_DATA
                    "003c"  # Option length: 60 (should be 59)
                    "20010db8000000000000000000000002"  # Peer address: 2001:db8::2
                    "0c"  # Message type: MSG_RELAY_FORW
                    "00"  # Hop count: 0
                    "20010db8000000000000000000000002"  # Link address: 2001:db8::2
                    "fe800000000000000000000000000022"  # Peer address: fe80::22
                    "0012"  # Option type: OPTION_INTERFACE_ID
                    "0005"  # Option length: 5
                    "4661322f33"  # Interface ID: 'Fa2/3'
                )
            )
    def test_bad_option_length(self):
        with self.assertRaisesRegex(ValueError, 'length does not match the combined length'):
            LQRelayDataOption.parse(bytes.fromhex(
                '0030'  # Option type: OPTION_LQ_CLIENT_LINK
                '002f'  # Option length: 47 (should be 48)
                '20010db8000000000000000000000001'  # Link address: 2001:db8::2
                '20010db8000000000000000000000002'  # Link address: 2001:db8::2
                '20010db8000000000000000000000004'  # Link address: 2001:db8::2
            ))

        with self.assertRaisesRegex(ValueError, 'longer than the available buffer'):
            LQRelayDataOption.parse(bytes.fromhex(
                '0030'  # Option type: OPTION_LQ_CLIENT_LINK
                '0031'  # Option length: 49 (should be 48)
                '20010db8000000000000000000000001'  # Link address: 2001:db8::2
                '20010db8000000000000000000000002'  # Link address: 2001:db8::2
                '20010db8000000000000000000000004'  # Link address: 2001:db8::2
            ))
Пример #4
0
    def test_bad_option_length(self):
        with self.assertRaisesRegex(
                ValueError, 'length does not match the combined length'):
            LQRelayDataOption.parse(
                bytes.fromhex(
                    '0030'  # Option type: OPTION_LQ_CLIENT_LINK
                    '002f'  # Option length: 47 (should be 48)
                    '20010db8000000000000000000000001'  # Link address: 2001:db8::2
                    '20010db8000000000000000000000002'  # Link address: 2001:db8::2
                    '20010db8000000000000000000000004'  # Link address: 2001:db8::2
                ))

        with self.assertRaisesRegex(ValueError,
                                    'longer than the available buffer'):
            LQRelayDataOption.parse(
                bytes.fromhex(
                    '0030'  # Option type: OPTION_LQ_CLIENT_LINK
                    '0031'  # Option length: 49 (should be 48)
                    '20010db8000000000000000000000001'  # Link address: 2001:db8::2
                    '20010db8000000000000000000000002'  # Link address: 2001:db8::2
                    '20010db8000000000000000000000004'  # Link address: 2001:db8::2
                ))