kopia lustrzana https://github.com/snarfed/bridgy-fed
start to port test_activitypub tests to test_protocol, using Fake protocol
also minor tweaks to Protocol.deliverpull/567/head
rodzic
9140318f4a
commit
40ae3dec8e
|
@ -97,6 +97,8 @@ def render_redirect():
|
||||||
return redirect(ActivityPub.subdomain_url(f'/convert/web/{id}'), code=301)
|
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:_>')
|
@app.get(f'/convert/<any({",".join(SOURCES)}):src>/<any({",".join(DESTS)}):dest>/<path:_>')
|
||||||
def convert_source_path_redirect(src, dest, _):
|
def convert_source_path_redirect(src, dest, _):
|
||||||
"""Old route that included source protocol in path instead of subdomain."""
|
"""Old route that included source protocol in path instead of subdomain."""
|
||||||
|
|
21
protocol.py
21
protocol.py
|
@ -553,20 +553,22 @@ class Protocol:
|
||||||
if obj.type in ('follow', 'like', 'share'):
|
if obj.type in ('follow', 'like', 'share'):
|
||||||
targets.append(obj_url)
|
targets.append(obj_url)
|
||||||
|
|
||||||
targets = util.dedupe_urls(util.get_url(t) for t in targets)
|
target_urls = util.dedupe_urls(util.get_url(t) for t in targets)
|
||||||
targets = common.remove_blocklisted(t.lower() for t in targets)
|
target_urls = common.remove_blocklisted(t.lower() for t in targets)
|
||||||
if not targets:
|
if not target_urls:
|
||||||
logger.info("Couldn't find any target URLs in inReplyTo, object, or mention tags")
|
logger.info("Couldn't find any target URLs in inReplyTo, object, or mention tags")
|
||||||
return
|
return
|
||||||
|
|
||||||
logger.info(f'targets: {targets}')
|
logger.info(f'targets: {target_urls}')
|
||||||
|
|
||||||
errors = [] # stores (code, body) tuples
|
errors = [] # stores (code, body) tuples
|
||||||
|
|
||||||
# TODO: avoid import?
|
targets = []
|
||||||
from web import Web
|
for url in target_urls:
|
||||||
targets = [Target(uri=uri, protocol=(Protocol.for_id(uri) or Web).LABEL)
|
protocol = Protocol.for_id(url)
|
||||||
for uri in targets]
|
label = protocol.LABEL if protocol else 'web'
|
||||||
|
targets.append(Target(uri=url, protocol=label))
|
||||||
|
|
||||||
no_user_domains = set()
|
no_user_domains = set()
|
||||||
|
|
||||||
obj.undelivered = []
|
obj.undelivered = []
|
||||||
|
@ -585,7 +587,8 @@ class Protocol:
|
||||||
if 'notification' not in obj.labels:
|
if 'notification' not in obj.labels:
|
||||||
obj.labels.append('notification')
|
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}')
|
logger.info(f'Skipping same-domain delivery from {source} to {target.uri}')
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
|
Plik diff jest za duży
Load Diff
|
@ -37,9 +37,8 @@ logger = logging.getLogger(__name__)
|
||||||
class Fake(User, protocol.Protocol):
|
class Fake(User, protocol.Protocol):
|
||||||
ABBREV = 'fa'
|
ABBREV = 'fa'
|
||||||
|
|
||||||
# maps string ids to dict AS1 objects. send adds objects here, fetch
|
# maps string ids to dict AS1 objects that can be fetched
|
||||||
# returns them
|
fetchable = {}
|
||||||
objects = {}
|
|
||||||
|
|
||||||
# in-order list of (Object, str URL)
|
# in-order list of (Object, str URL)
|
||||||
sent = []
|
sent = []
|
||||||
|
@ -61,13 +60,12 @@ class Fake(User, protocol.Protocol):
|
||||||
if id.startswith('nope'):
|
if id.startswith('nope'):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
return id.startswith('fake:') or id in cls.objects
|
return id.startswith('fake:') or id in cls.fetchable
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def send(cls, obj, url, log_data=True):
|
def send(cls, obj, url, log_data=True):
|
||||||
logger.info(f'Fake.send {url}')
|
logger.info(f'Fake.send {url}')
|
||||||
cls.sent.append((obj, url))
|
cls.sent.append((obj, url))
|
||||||
cls.objects[obj.key.id()] = obj
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def fetch(cls, obj, **kwargs):
|
def fetch(cls, obj, **kwargs):
|
||||||
|
@ -75,8 +73,8 @@ class Fake(User, protocol.Protocol):
|
||||||
logger.info(f'Fake.load {id}')
|
logger.info(f'Fake.load {id}')
|
||||||
cls.fetched.append(id)
|
cls.fetched.append(id)
|
||||||
|
|
||||||
if id in cls.objects:
|
if id in cls.fetchable:
|
||||||
obj.our_as1 = cls.objects[id]
|
obj.our_as1 = cls.fetchable[id]
|
||||||
return obj
|
return obj
|
||||||
|
|
||||||
raise requests.HTTPError(response=util.Struct(status_code='410'))
|
raise requests.HTTPError(response=util.Struct(status_code='410'))
|
||||||
|
@ -122,7 +120,7 @@ class TestCase(unittest.TestCase, testutil.Asserts):
|
||||||
protocol.objects_cache.clear()
|
protocol.objects_cache.clear()
|
||||||
common.webmention_discover.cache.clear()
|
common.webmention_discover.cache.clear()
|
||||||
|
|
||||||
Fake.objects = {}
|
Fake.fetchable = {}
|
||||||
Fake.sent = []
|
Fake.sent = []
|
||||||
Fake.fetched = []
|
Fake.fetched = []
|
||||||
|
|
||||||
|
|
Ładowanie…
Reference in New Issue