start to port test_activitypub tests to test_protocol, using Fake protocol

also minor tweaks to Protocol.deliver
pull/567/head
Ryan Barrett 2023-06-27 09:48:47 -07:00
rodzic 9140318f4a
commit 40ae3dec8e
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 6BE31FDF4776E9D4
4 zmienionych plików z 978 dodań i 50 usunięć

Wyświetl plik

@ -97,6 +97,8 @@ def render_redirect():
return redirect(ActivityPub.subdomain_url(f'/convert/web/{id}'), code=301)
# WARNING: This doesn't currently work. The /convert/... URL route at the top
# overrides it and handles all of these URLs.
@app.get(f'/convert/<any({",".join(SOURCES)}):src>/<any({",".join(DESTS)}):dest>/<path:_>')
def convert_source_path_redirect(src, dest, _):
"""Old route that included source protocol in path instead of subdomain."""

Wyświetl plik

@ -553,20 +553,22 @@ class Protocol:
if obj.type in ('follow', 'like', 'share'):
targets.append(obj_url)
targets = util.dedupe_urls(util.get_url(t) for t in targets)
targets = common.remove_blocklisted(t.lower() for t in targets)
if not targets:
target_urls = util.dedupe_urls(util.get_url(t) for t in targets)
target_urls = common.remove_blocklisted(t.lower() for t in targets)
if not target_urls:
logger.info("Couldn't find any target URLs in inReplyTo, object, or mention tags")
return
logger.info(f'targets: {targets}')
logger.info(f'targets: {target_urls}')
errors = [] # stores (code, body) tuples
# TODO: avoid import?
from web import Web
targets = [Target(uri=uri, protocol=(Protocol.for_id(uri) or Web).LABEL)
for uri in targets]
targets = []
for url in target_urls:
protocol = Protocol.for_id(url)
label = protocol.LABEL if protocol else 'web'
targets.append(Target(uri=url, protocol=label))
no_user_domains = set()
obj.undelivered = []
@ -585,7 +587,8 @@ class Protocol:
if 'notification' not in obj.labels:
obj.labels.append('notification')
if domain == util.domain_from_link(source, minimize=False):
if (domain == util.domain_from_link(source, minimize=False)
and cls.LABEL != 'fake'):
logger.info(f'Skipping same-domain delivery from {source} to {target.uri}')
continue

Plik diff jest za duży Load Diff

Wyświetl plik

@ -37,9 +37,8 @@ logger = logging.getLogger(__name__)
class Fake(User, protocol.Protocol):
ABBREV = 'fa'
# maps string ids to dict AS1 objects. send adds objects here, fetch
# returns them
objects = {}
# maps string ids to dict AS1 objects that can be fetched
fetchable = {}
# in-order list of (Object, str URL)
sent = []
@ -61,13 +60,12 @@ class Fake(User, protocol.Protocol):
if id.startswith('nope'):
return False
return id.startswith('fake:') or id in cls.objects
return id.startswith('fake:') or id in cls.fetchable
@classmethod
def send(cls, obj, url, log_data=True):
logger.info(f'Fake.send {url}')
cls.sent.append((obj, url))
cls.objects[obj.key.id()] = obj
@classmethod
def fetch(cls, obj, **kwargs):
@ -75,8 +73,8 @@ class Fake(User, protocol.Protocol):
logger.info(f'Fake.load {id}')
cls.fetched.append(id)
if id in cls.objects:
obj.our_as1 = cls.objects[id]
if id in cls.fetchable:
obj.our_as1 = cls.fetchable[id]
return obj
raise requests.HTTPError(response=util.Struct(status_code='410'))
@ -122,7 +120,7 @@ class TestCase(unittest.TestCase, testutil.Asserts):
protocol.objects_cache.clear()
common.webmention_discover.cache.clear()
Fake.objects = {}
Fake.fetchable = {}
Fake.sent = []
Fake.fetched = []