Example #1
0
def test_bad_port():
    try:
        E.encode_uri('http://foo.bar:buz')
    except E.MalformedUrlError as error:
        assert error.args == (
            "Invalid port number: invalid literal for int() with base 10: 'buz'",
        )
Example #2
0
def test_bad_domain_segment_too_long():
    try:
        E.encode_uri('http://foo.%s.bar' % ('x' * 64))
    except E.MalformedUrlError as error:
        assert error.args == (
            "Invalid hostname: label empty or too long: " +
            "'foo.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.bar'",
        )
Example #3
0
def test_bad_domain_segment_too_long():
    try:
        E.encode_uri('http://foo.%s.bar' % ('x' * 64))
    except E.MalformedUrlError as error:
        assert error.args == (
            "Invalid hostname: label empty or too long: " +
            "'foo.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.bar'",
        )
Example #4
0
def test_bad_domain_segment_too_long():
    try:
        E.encode_uri('http://foo.%s.bar' % ('x' * 64))
    except E.MalformedUrlError as error:
        if six.PY3:
            error_msg = ("Invalid hostname: encoding with 'IDNA' codec failed "
                         "(UnicodeError: label empty or too long): ")
        else:
            error_msg = 'Invalid hostname: label empty or too long: '

        assert error.args == (error_msg + repr(
            u"foo.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.bar"
        ), )
Example #5
0
def test_bad_domain_segment_too_long():
    try:
        E.encode_uri('http://foo.%s.bar' % ('x' * 64))
    except E.MalformedUrlError as error:
        if six.PY3:
            error_msg = (
                "Invalid hostname: encoding with 'IDNA' codec failed "
                "(UnicodeError: label empty or too long): "
            )
        else:
            error_msg = 'Invalid hostname: label empty or too long: '

        assert error.args == (
            error_msg +
            repr(u"foo.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.bar"),
        )
Example #6
0
def test_bad_domain_extra_dots():
    # We normalize this one ala Chrome browser
    assert E.encode_uri('http://..foo..com../.bar.') == 'http://foo.com/.bar.'
Example #7
0
def test_bad_domain_extra_dots():
    # We normalize this one ala Chrome browser
    assert E.encode_uri('http://..foo..com../.bar.') == 'http://foo.com/.bar.'
Example #8
0
def test_bad_port():
    try:
        E.encode_uri('http://foo.bar:buz')
    except E.MalformedUrlError as error:
        assert error.args == ("Invalid port number: invalid literal for int() with base 10: 'buz'",)