ActivityPub.convert bug fix: don't call postprocess_as2_actor without user

fixes https://console.cloud.google.com/errors/detail/CKmOubHj-8H84AE;time=P30D?project=bridgy-federated
pull/755/head
Ryan Barrett 2023-12-14 15:48:02 -08:00
rodzic 07177e7d93
commit b999cfe59a
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 6BE31FDF4776E9D4
2 zmienionych plików z 47 dodań i 10 usunięć

Wyświetl plik

@ -344,17 +344,18 @@ class ActivityPub(User, Protocol):
# special cases where obj or obj['object'] or obj['object']['object']
# are an actor
if as1.object_type(obj.as1) in as1.ACTOR_TYPES:
return postprocess_as2_actor(converted, user=from_user)
if from_user:
if as1.object_type(obj.as1) in as1.ACTOR_TYPES:
return postprocess_as2_actor(converted, user=from_user)
inner_obj = as1.get_object(obj.as1)
if as1.object_type(inner_obj) in as1.ACTOR_TYPES:
converted['object'] = postprocess_as2_actor(converted['object'],
user=from_user)
inner_obj = as1.get_object(obj.as1)
if as1.object_type(inner_obj) in as1.ACTOR_TYPES:
converted['object'] = postprocess_as2_actor(converted['object'],
user=from_user)
# eg Accept of a Follow
if from_user and from_user.is_web_url(as1.get_object(inner_obj).get('id')):
converted['object']['object'] = from_user.id_as(ActivityPub)
# eg Accept of a Follow
if from_user.is_web_url(as1.get_object(inner_obj).get('id')):
converted['object']['object'] = from_user.id_as(ActivityPub)
# convert!
return postprocess_as2(converted, orig_obj=orig_obj)
@ -676,7 +677,7 @@ def postprocess_as2(activity, orig_obj=None, wrap=True):
return util.trim_nulls(activity)
def postprocess_as2_actor(actor, user=None):
def postprocess_as2_actor(actor, user):
"""Prepare an AS2 actor object to be served or sent via ActivityPub.
Modifies actor in place.
@ -692,6 +693,7 @@ def postprocess_as2_actor(actor, user=None):
return actor
assert isinstance(actor, dict)
assert user
url = user.web_url()
urls = [u for u in util.get_list(actor, 'url') if u and not u.startswith('acct:')]

Wyświetl plik

@ -1707,6 +1707,9 @@ class ActivityPubUtilsTest(TestCase):
super().setUp()
self.user = self.make_user('user.com', cls=Web, has_hcard=True, obj_as2=ACTOR)
for obj in ACTOR_BASE, ACTOR_FAKE:
obj['publicKey']['publicKeyPem'] = self.user.public_pem().decode()
def test_put_validates_id(self, *_):
for bad in (
'',
@ -2063,6 +2066,38 @@ class ActivityPubUtilsTest(TestCase):
'to': [as2.PUBLIC_AUDIENCE],
}, ActivityPub.convert(obj))
def test_convert_actor_as2(self):
self.assert_equals(ACTOR, ActivityPub.convert(Object(as2=ACTOR)))
def test_convert_actor_as1_from_user(self):
obj = Object(our_as1={
'objectType': 'person',
'id': 'https://user.com/',
})
self.assert_equals(ACTOR_BASE, ActivityPub.convert(obj, from_user=self.user),
ignore=['endpoints', 'followers', 'following'])
def test_convert_actor_as1_no_from_user(self):
obj = Object(our_as1=ACTOR_AS1)
self.assert_equals(ACTOR, common.unwrap(ActivityPub.convert(obj)),
ignore=['to', 'attachment'])
def test_convert_follow_as1_no_from_user(self):
obj = Object(our_as1=as2.to_as1(FOLLOW))
self.assert_equals(FOLLOW, common.unwrap(ActivityPub.convert(obj)),
ignore=['to'])
def test_convert_profile_update_as1_no_from_user(self):
obj = Object(our_as1={
'objectType': 'activity',
'verb': 'update',
'object': ACTOR_AS1,
})
self.assert_equals({
'type': 'Update',
'object': ACTOR,
}, common.unwrap(ActivityPub.convert(obj)), ignore=['to', 'attachment'])
def test_convert_compact_actor_attributedTo_author(self):
obj = Object(our_as1={
'actor': {'id': 'baj'},