2023-01-15 02:33:32 +00:00
|
|
|
""" Test allowlists
|
|
|
|
"""
|
|
|
|
import pytest
|
|
|
|
|
|
|
|
from util import shim_argparse
|
|
|
|
from fediblockhole.const import DomainBlock
|
2023-01-22 02:05:44 +00:00
|
|
|
from fediblockhole.blocklists import Blocklist
|
2023-01-15 02:33:32 +00:00
|
|
|
from fediblockhole import fetch_allowlists, apply_allowlists
|
|
|
|
|
|
|
|
def test_cmdline_allow_removes_domain():
|
|
|
|
"""Test that -A <domain> removes entries from merged
|
|
|
|
"""
|
|
|
|
conf = shim_argparse(['-A', 'removeme.org'])
|
|
|
|
|
2023-01-22 02:05:44 +00:00
|
|
|
merged = Blocklist('test_allowlist.merged', {
|
2023-01-15 02:33:32 +00:00
|
|
|
'example.org': DomainBlock('example.org'),
|
2023-01-16 19:52:25 +00:00
|
|
|
'example2.org': DomainBlock('example2.org'),
|
2023-01-15 02:33:32 +00:00
|
|
|
'removeme.org': DomainBlock('removeme.org'),
|
|
|
|
'keepblockingme.org': DomainBlock('keepblockingme.org'),
|
2023-01-22 02:05:44 +00:00
|
|
|
})
|
2023-01-15 02:33:32 +00:00
|
|
|
|
|
|
|
merged = apply_allowlists(merged, conf, {})
|
|
|
|
|
|
|
|
with pytest.raises(KeyError):
|
|
|
|
merged['removeme.org']
|
|
|
|
|
|
|
|
def test_allowlist_removes_domain():
|
|
|
|
"""Test that an item in an allowlist removes entries from merged
|
|
|
|
"""
|
|
|
|
conf = shim_argparse()
|
|
|
|
|
2023-01-22 02:05:44 +00:00
|
|
|
merged = Blocklist('test_allowlist.merged', {
|
2023-01-15 02:33:32 +00:00
|
|
|
'example.org': DomainBlock('example.org'),
|
2023-01-16 19:52:25 +00:00
|
|
|
'example2.org': DomainBlock('example2.org'),
|
2023-01-15 02:33:32 +00:00
|
|
|
'removeme.org': DomainBlock('removeme.org'),
|
|
|
|
'keepblockingme.org': DomainBlock('keepblockingme.org'),
|
2023-01-22 02:05:44 +00:00
|
|
|
})
|
2023-01-15 02:33:32 +00:00
|
|
|
|
2023-01-22 02:05:44 +00:00
|
|
|
allowlists = [
|
|
|
|
Blocklist('test_allowlist', {
|
|
|
|
'removeme.org': DomainBlock('removeme.org', 'noop'),
|
|
|
|
})
|
|
|
|
]
|
2023-01-15 02:33:32 +00:00
|
|
|
|
|
|
|
merged = apply_allowlists(merged, conf, allowlists)
|
|
|
|
|
|
|
|
with pytest.raises(KeyError):
|
|
|
|
merged['removeme.org']
|
2023-01-16 19:52:25 +00:00
|
|
|
|
|
|
|
def test_allowlist_removes_tld():
|
|
|
|
"""Test that an item in an allowlist removes entries from merged
|
|
|
|
"""
|
|
|
|
conf = shim_argparse()
|
|
|
|
|
2023-01-22 02:05:44 +00:00
|
|
|
merged = Blocklist('test_allowlist.merged', {
|
2023-01-16 19:52:25 +00:00
|
|
|
'.cf': DomainBlock('.cf'),
|
|
|
|
'example.org': DomainBlock('example.org'),
|
|
|
|
'.tk': DomainBlock('.tk'),
|
|
|
|
'keepblockingme.org': DomainBlock('keepblockingme.org'),
|
2023-01-22 02:05:44 +00:00
|
|
|
})
|
2023-01-16 19:52:25 +00:00
|
|
|
|
2023-01-22 02:05:44 +00:00
|
|
|
allowlists = [
|
|
|
|
Blocklist('test_allowlist.list1', {
|
|
|
|
'.cf': DomainBlock('.cf', 'noop'),
|
|
|
|
'.tk': DomainBlock('.tk', 'noop'),
|
|
|
|
})
|
|
|
|
]
|
2023-01-16 19:52:25 +00:00
|
|
|
|
|
|
|
merged = apply_allowlists(merged, conf, allowlists)
|
|
|
|
|
|
|
|
with pytest.raises(KeyError):
|
|
|
|
merged['.cf']
|
|
|
|
|
|
|
|
with pytest.raises(KeyError):
|
|
|
|
merged['.tk']
|