urlmatch: Improve port tests

This commit is contained in:
Florian Bruhin 2018-02-14 23:32:40 +01:00
parent c728d78bea
commit d266190518
2 changed files with 10 additions and 15 deletions

View File

@ -139,7 +139,7 @@ class UrlPattern:
'file': False, 'chrome': False, 'qute': False,
'about': False}
if not allows_ports[self._scheme] and self._port is not None:
raise ParseError("Ports unsupported with {} scheme".format(
raise ParseError("Ports are unsupported with {} scheme".format(
self._scheme))
def __repr__(self):

View File

@ -53,6 +53,14 @@ from qutebrowser.utils import urlmatch
("http://foo.*.bar/baz", "Invalid host wildcard"),
("http://fo.*.ba:123/baz", "Invalid host wildcard"),
("http://foo.*/bar", "Invalid host wildcard"),
# Chromium: PARSE_ERROR_INVALID_PORT
("http://foo:/", "Empty port"),
("http://*.foo:/", "Empty port"),
("http://foo:com/", "Invalid port"),
("http://foo:123456/", "Invalid port"),
("http://foo:80:80/monkey", "Invalid port"),
("chrome://foo:1234/bar", "Ports are unsupported with chrome scheme"),
])
def test_invalid_patterns(pattern, error):
with pytest.raises(urlmatch.ParseError, match=error):
@ -70,19 +78,6 @@ def test_invalid_patterns(pattern, error):
# FIXME Why is this valid in Chromium?
# ("file://foo:1234/bar", "*"),
])
def test_port_valid(pattern, port):
def test_port(pattern, port):
up = urlmatch.UrlPattern(pattern)
assert up._port == port
@pytest.mark.parametrize('pattern', [
"http://foo:/",
"http://*.foo:/",
"http://foo:com/",
"http://foo:123456/",
"http://foo:80:80/monkey",
"chrome://foo:1234/bar",
])
def test_port_invalid(pattern):
with pytest.raises(urlmatch.ParseError):
urlmatch.UrlPattern(pattern)