Modify tests, localhost should never be blocked
This commit is contained in:
parent
c8db9e1c76
commit
3f37fcf8fa
@ -236,7 +236,7 @@ class HostBlocker:
|
|||||||
log.misc.error("Failed to parse: {!r}".format(line))
|
log.misc.error("Failed to parse: {!r}".format(line))
|
||||||
return False
|
return False
|
||||||
|
|
||||||
if '.' not in host and not host.endswith('.localdomain'):
|
if '.' in host and not host.endswith('.localdomain'):
|
||||||
self._blocked_hosts.add(host)
|
self._blocked_hosts.add(host)
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
@ -114,14 +114,14 @@ def create_blocklist(directory, blocked_hosts=BLOCKLIST_HOSTS,
|
|||||||
return name
|
return name
|
||||||
|
|
||||||
|
|
||||||
def assert_urls(host_blocker, blocked=BLOCKLIST_HOSTS,
|
def assert_urls(host_blocker, blocked=BLOCKLIST_HOSTS[1:],
|
||||||
whitelisted=WHITELISTED_HOSTS, urls_to_check=URLS_TO_CHECK):
|
whitelisted=WHITELISTED_HOSTS, urls_to_check=URLS_TO_CHECK):
|
||||||
"""Test if Urls to check are blocked or not by HostBlocker.
|
"""Test if Urls to check are blocked or not by HostBlocker.
|
||||||
|
|
||||||
Ensure URLs in 'blocked' and not in 'whitelisted' are blocked.
|
Ensure URLs in 'blocked' and not in 'whitelisted' are blocked.
|
||||||
All other URLs must not be blocked.
|
All other URLs must not be blocked.
|
||||||
"""
|
"""
|
||||||
whitelisted = list(whitelisted) + list(host_blocker.WHITELISTED)
|
whitelisted = list(whitelisted)
|
||||||
for str_url in urls_to_check:
|
for str_url in urls_to_check:
|
||||||
url = QUrl(str_url)
|
url = QUrl(str_url)
|
||||||
host = url.host()
|
host = url.host()
|
||||||
@ -341,7 +341,7 @@ def test_blocking_with_whitelist(config_stub, basedir, download_stub,
|
|||||||
"""Ensure hosts in content.host_blocking.whitelist are never blocked."""
|
"""Ensure hosts in content.host_blocking.whitelist are never blocked."""
|
||||||
# Simulate adblock_update has already been run
|
# Simulate adblock_update has already been run
|
||||||
# by creating a file named blocked-hosts,
|
# by creating a file named blocked-hosts,
|
||||||
# Exclude localhost from it, since localhost is in HostBlocker.WHITELISTED
|
# Exclude localhost from it, since localhost is never blocked by list
|
||||||
filtered_blocked_hosts = BLOCKLIST_HOSTS[1:]
|
filtered_blocked_hosts = BLOCKLIST_HOSTS[1:]
|
||||||
blocklist = create_blocklist(data_tmpdir,
|
blocklist = create_blocklist(data_tmpdir,
|
||||||
blocked_hosts=filtered_blocked_hosts,
|
blocked_hosts=filtered_blocked_hosts,
|
||||||
|
Loading…
Reference in New Issue
Block a user