mitmproxy/test/netlib/test_utils.py
Aldo Cortesi 02acfb1242 Fix netlib.utils.is_valid_host
- Don't crash when passed an empty string. This translated into an actual core
crash, discovered while fuzzing with afl.
- Taking a slice of length one out of bytes returns an integer, so the check
for trailing period in this function never worked on Python3.
- Add unit tests.
2016-07-21 10:38:37 +12:00

20 lines
491 B
Python

# coding=utf-8
from netlib import utils, tutils
def test_is_valid_host():
assert not utils.is_valid_host(b"")
assert utils.is_valid_host(b"one.two")
assert not utils.is_valid_host(b"one"*255)
assert utils.is_valid_host(b"one.two.")
def test_bidi():
b = utils.BiDi(a=1, b=2)
assert b.a == 1
assert b.get_name(1) == "a"
assert b.get_name(5) is None
tutils.raises(AttributeError, getattr, b, "c")
tutils.raises(ValueError, utils.BiDi, one=1, two=1)