Not so great value decoding code
This commit is contained in:
@@ -64,7 +64,7 @@ def num_tlv(num_type, num, length, expected=None):
|
||||
num_tlv(b"\x08\x06", 0xFFFF, 4), # rfc signed
|
||||
num_tlv(b"\x08\x06", 0x10000, 4), # rfc signed
|
||||
num_tlv(b"\x08\x06", 0xFFFFFFFF, 4, -1), # rfc signed
|
||||
num_tlv(b"\x08\x06", 0x80000000, 4, -268435458), # rfc signed
|
||||
num_tlv(b"\x08\x06", 0x80000000, 4, -2147483648), # rfc signed
|
||||
num_tlv(b"\x08\x06", 0x7FFFFFFF, 4, 2147483647), # rfc signed
|
||||
num_tlv(b"\x09\x0A", 0, 8), # rfc integer64
|
||||
num_tlv(b"\x09\x0A", 0xFF, 8), # rfc integer64
|
||||
@@ -74,22 +74,18 @@ def num_tlv(num_type, num, length, expected=None):
|
||||
num_tlv(b"\x09\x0A", 0xFFFFFFFF, 8), # rfc integer64
|
||||
num_tlv(b"\x09\x0A", 0x100000000, 8), # rfc integer64
|
||||
num_tlv(b"\x09\x0A", 0xFFFFFFFFFFFFFFFF, 8), # rfc integer64
|
||||
(b"\x0a\x06\xc0\xa8\x01\x08", IPv4Address("192.168.1.1")),
|
||||
(b"\x0b\x07\x10\xc4\xa8\x00\x00", IPv4Network("192.168.0.0/16")),
|
||||
(b"\x0a\x06\xc0\xa8\x01\x08", IPv4Address("192.168.1.8")),
|
||||
(b"\x0b\x07\x10\xc0\xa8\x00\x00", IPv4Network("192.168.0.0/16")),
|
||||
(
|
||||
b"\x0c\x12\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01",
|
||||
b"\x0c\x12\x20\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01",
|
||||
IPv6Address("2003::1"),
|
||||
),
|
||||
(
|
||||
b"\x0c\x13@\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
|
||||
IPv6Network("2003::0/64"),
|
||||
),
|
||||
(b"\x0c\x04@\x03", IPv6Network("2003::0/64")),
|
||||
(b"\x0a\x06\xc0\xa8\x01\x08", IPv4Address("192.168.1.1")),
|
||||
(
|
||||
b"\x0a\x13@\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
|
||||
b"\x0d\x14\x00\x40\x20\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
|
||||
IPv6Network("2003::0/64"),
|
||||
),
|
||||
(b"\x0c\x04\x20\x03", IPv6Address("2003::0")),
|
||||
(b"\x0d\x06\x00\x40\x20\x03", IPv6Network("2003::0/64")),
|
||||
],
|
||||
)
|
||||
def test_parse_attribute_rfc_and_vsa(radius_dictionary, attr_bytes, expected):
|
||||
@@ -98,8 +94,10 @@ def test_parse_attribute_rfc_and_vsa(radius_dictionary, attr_bytes, expected):
|
||||
assert len(attrs) == 1
|
||||
assert attrs[0].value == expected
|
||||
|
||||
vsa_length = (4 + len(attr_bytes)).to_bytes(1, "big")
|
||||
raw_packet = bytes(20) + b"\x1a" + vsa_length + "\x04\xd2" + attr_bytes
|
||||
vsa_length = (6 + len(attr_bytes)).to_bytes(1, "big")
|
||||
raw_packet = (
|
||||
bytes(20) + b"\x1a" + vsa_length + b"\x00\x00\x04\xd2" + attr_bytes
|
||||
)
|
||||
attrs = utils.parse_attributes(radius_dictionary, raw_packet)
|
||||
assert len(attrs) == 1
|
||||
assert attrs[0].value == expected
|
||||
|
||||
Reference in New Issue
Block a user