示例#1
0
def test_dns_sd_txt_parse_multiple():
    """Test that a TXT RDATA section with multiple keys can be parsed properly."""
    data = b"\x07foo=bar\x09spam=eggs"
    extra_data = data + b"\xDE\xAD\xBE\xEF" * 2
    with io.BytesIO(extra_data) as buffer:
        txt_dict = dns.parse_txt_dict(buffer, len(data))
        assert buffer.tell() == len(data)
        assert txt_dict == {"foo": b"bar", "spam": b"eggs"}
示例#2
0
def test_dns_sd_txt_parse_single():
    """Test that a TXT RDATA section with one key can be parsed properly."""
    data = b"\x07foo=bar"
    extra_data = data + b"\xDE\xAD\xBE\xEF" * 3
    with io.BytesIO(extra_data) as buffer:
        txt_dict = dns.parse_txt_dict(buffer, len(data))
        assert buffer.tell() == len(data)
        assert txt_dict == {"foo": b"bar"}
示例#3
0
def test_dns_sd_txt_parse_long():
    """Test that a TXT RDATA section with a long value can be parsed properly."""
    # If TXT records are being parsed the same way domain names are, this won't work as
    # the data is too long to fit in a label.
    data = b"\xCCfoo=" + b"\xCA\xFE" * 100
    extra_data = data + b"\xDE\xAD\xBE\xEF" * 3
    with io.BytesIO(extra_data) as buffer:
        txt_dict = dns.parse_txt_dict(buffer, len(data))
        assert buffer.tell() == len(data)
        assert txt_dict == {"foo": b"\xCA\xFE" * 100}
示例#4
0
def test_dns_sd_txt_parse_binary():
    """Test that a TXT RDATA section with a binary value can be parsed properly."""
    # 0xfeed can't be decoded as UTF-8 or ASCII, so it'll thrown an error if it's not
    # being treated as binary data.
    data = b"\x06foo=\xFE\xED"
    extra_data = data + b"\xDE\xAD\xBE\xEF" * 3
    with io.BytesIO(extra_data) as buffer:
        txt_dict = dns.parse_txt_dict(buffer, len(data))
        assert buffer.tell() == len(data)
        assert txt_dict == {"foo": b"\xFE\xED"}