Merge pull request #4118 from DerJesko/master
Tests for ipv6 support in urlmatch
This commit is contained in:
commit
b962c5c4d9
@ -56,7 +56,7 @@ class Option:
|
|||||||
@attr.s
|
@attr.s
|
||||||
class Migrations:
|
class Migrations:
|
||||||
|
|
||||||
"""Nigrated options in configdata.yml.
|
"""Migrated options in configdata.yml.
|
||||||
|
|
||||||
Attributes:
|
Attributes:
|
||||||
renamed: A dict mapping old option names to new names.
|
renamed: A dict mapping old option names to new names.
|
||||||
|
@ -29,6 +29,8 @@ import ipaddress
|
|||||||
import fnmatch
|
import fnmatch
|
||||||
import urllib.parse
|
import urllib.parse
|
||||||
|
|
||||||
|
from PyQt5.QtCore import QUrl
|
||||||
|
|
||||||
from qutebrowser.utils import utils, qtutils
|
from qutebrowser.utils import utils, qtutils
|
||||||
|
|
||||||
|
|
||||||
@ -177,6 +179,15 @@ class UrlPattern:
|
|||||||
assert self._host is None
|
assert self._host is None
|
||||||
return
|
return
|
||||||
|
|
||||||
|
if parsed.netloc.startswith('['):
|
||||||
|
# Using QUrl parsing to minimize ipv6 addresses
|
||||||
|
url = QUrl()
|
||||||
|
url.setHost(parsed.hostname)
|
||||||
|
if not url.isValid():
|
||||||
|
raise ParseError(url.errorString())
|
||||||
|
self._host = url.host()
|
||||||
|
return
|
||||||
|
|
||||||
# FIXME what about multiple dots?
|
# FIXME what about multiple dots?
|
||||||
host_parts = parsed.hostname.rstrip('.').split('.')
|
host_parts = parsed.hostname.rstrip('.').split('.')
|
||||||
if host_parts[0] == '*':
|
if host_parts[0] == '*':
|
||||||
|
@ -84,6 +84,19 @@ from qutebrowser.utils import urlmatch
|
|||||||
|
|
||||||
# Additional tests
|
# Additional tests
|
||||||
("http://[", "Invalid IPv6 URL"),
|
("http://[", "Invalid IPv6 URL"),
|
||||||
|
("http://[fc2e:bb88::edac]:", "Invalid port: Port is empty"),
|
||||||
|
("http://[fc2e::bb88::edac]", 'Invalid IPv6 address; source was "fc2e::bb88::edac"; host = ""'),
|
||||||
|
("http://[fc2e:0e35:bb88::edac:fc2e:0e35:bb88:edac]", 'Invalid IPv6 address; source was "fc2e:0e35:bb88::edac:fc2e:0e35:bb88:edac"; host = ""'),
|
||||||
|
("http://[fc2e:0e35:bb88:af:edac:fc2e:0e35:bb88:edac]", 'Invalid IPv6 address; source was "fc2e:0e35:bb88:af:edac:fc2e:0e35:bb88:edac"; host = ""'),
|
||||||
|
("http://[127.0.0.1:fc2e::bb88:edac]", 'Invalid IPv6 address; source was "127.0.0.1:fc2e::bb88:edac'),
|
||||||
|
("http://[]:20", "Pattern without host"),
|
||||||
|
("http://[fc2e::bb88", "Invalid IPv6 URL"),
|
||||||
|
("http://[[fc2e::bb88:edac]", """Expected ']' to match '[' in hostname; source was "[fc2e::bb88:edac"; host = """""),
|
||||||
|
pytest.param("http://[fc2e::bb88:edac]]", "Invalid IPv6 URL", marks=pytest.mark.xfail(reason="https://bugs.python.org/issue34360")),
|
||||||
|
("http://[fc2e:bb88:edac]", 'Invalid IPv6 address; source was "fc2e:bb88:edac"; host = ""'),
|
||||||
|
("http://[fc2e:bb88:edac::z]", 'Invalid IPv6 address; source was "fc2e:bb88:edac::z"; host = ""'),
|
||||||
|
("http://[fc2e:bb88:edac::2]:2a2", "Invalid port: invalid literal for int() with base 10: '2a2'"),
|
||||||
|
|
||||||
])
|
])
|
||||||
def test_invalid_patterns(pattern, error):
|
def test_invalid_patterns(pattern, error):
|
||||||
with pytest.raises(urlmatch.ParseError, match=re.escape(error)):
|
with pytest.raises(urlmatch.ParseError, match=re.escape(error)):
|
||||||
@ -154,10 +167,16 @@ class TestMatchAllPagesForGivenScheme:
|
|||||||
|
|
||||||
@pytest.mark.parametrize('url, expected', [
|
@pytest.mark.parametrize('url, expected', [
|
||||||
("http://google.com", True),
|
("http://google.com", True),
|
||||||
|
("http://google.com:80", True),
|
||||||
|
("http://google.com.", True),
|
||||||
("http://yahoo.com", True),
|
("http://yahoo.com", True),
|
||||||
("http://google.com/foo", True),
|
("http://google.com/foo", True),
|
||||||
("https://google.com", False),
|
("https://google.com", False),
|
||||||
("http://74.125.127.100/search", True),
|
("http://74.125.127.100/search", True),
|
||||||
|
("http://[fc2e:0e35:bb88::edac]", True),
|
||||||
|
("http://[fc2e:e35:bb88::edac]", True),
|
||||||
|
("http://[fc2e:e35:bb88::127.0.0.1]", True),
|
||||||
|
("http://[::1]/bar", True),
|
||||||
])
|
])
|
||||||
def test_urls(self, up, url, expected):
|
def test_urls(self, up, url, expected):
|
||||||
assert up.matches(QUrl(url)) == expected
|
assert up.matches(QUrl(url)) == expected
|
||||||
@ -238,6 +257,10 @@ class TestMatchIpAddresses:
|
|||||||
@pytest.mark.parametrize('pattern, host, match_subdomains', [
|
@pytest.mark.parametrize('pattern, host, match_subdomains', [
|
||||||
("http://127.0.0.1/*", "127.0.0.1", False),
|
("http://127.0.0.1/*", "127.0.0.1", False),
|
||||||
("http://*.0.0.1/*", "0.0.1", True),
|
("http://*.0.0.1/*", "0.0.1", True),
|
||||||
|
("http://[::1]/*", "::1", False),
|
||||||
|
("http://[0::1]/*", "::1", False),
|
||||||
|
("http://[::01]/*", "::1", False),
|
||||||
|
("http://[0:0:0:0:20::1]/*", "::20:0:0:1", False),
|
||||||
])
|
])
|
||||||
def test_attrs(self, pattern, host, match_subdomains):
|
def test_attrs(self, pattern, host, match_subdomains):
|
||||||
up = urlmatch.UrlPattern(pattern)
|
up = urlmatch.UrlPattern(pattern)
|
||||||
|
Loading…
Reference in New Issue
Block a user