activitypub.postprocess_as2_actor: handle user without handle

fixes https://console.cloud.google.com/errors/detail/CIT9-r3d-MKW5AE;time=P30D?project=bridgy-federated
as2-actor-ids
Ryan Barrett 2023-11-23 22:08:19 -08:00
rodzic dcd7081d48
commit db2668ffab
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 6BE31FDF4776E9D4
3 zmienionych plików z 28 dodań i 19 usunięć

Wyświetl plik

@ -738,7 +738,9 @@ def postprocess_as2_actor(actor, wrap=True):
# https://docs.joinmastodon.org/spec/webfinger/#mastodons-requirements-for-webfinger
# https://github.com/snarfed/bridgy-fed/issues/302#issuecomment-1324305460
# https://github.com/snarfed/bridgy-fed/issues/77
actor['preferredUsername'] = g.user.handle_as(ActivityPub).strip('@').split('@')[0]
handle = g.user.handle_as(ActivityPub)
if handle:
actor['preferredUsername'] = handle.strip('@').split('@')[0]
# Override the label for their home page to be "Web site"
for att in util.get_list(actor, 'attachment'):

Wyświetl plik

@ -79,10 +79,9 @@ class ATProto(User, Protocol):
@ndb.ComputedProperty
def handle(self):
"""Returns handle if the DID document includes one, otherwise None."""
did_obj = ATProto.load(self.key.id())
if did_obj:
handle, _, _ = parse_at_uri(
util.get_first(did_obj.raw, 'alsoKnownAs', ''))
if did_obj := ATProto.load(self.key.id()):
if aka := util.get_first(did_obj.raw, 'alsoKnownAs', ''):
handle, _, _ = parse_at_uri(aka)
if handle:
return handle

Wyświetl plik

@ -23,6 +23,7 @@ from .testutil import Fake, TestCase
import activitypub
from activitypub import ActivityPub, default_signature_user, postprocess_as2
from atproto import ATProto
import common
from models import Follower, Object
import protocol
@ -428,6 +429,13 @@ class ActivityPubTest(TestCase):
**ACTOR_FAKE,
}, got.json, ignore=['publicKeyPem'])
def test_actor_no_handle(self, *_):
self.store_object(id='did:plc:user', raw={'foo': 'bar'})
self.make_user('did:plc:user', cls=ATProto)
got = self.client.get('/ap/did:plc:user', base_url='https://atproto.brid.gy/')
self.assertEqual(200, got.status_code)
self.assertNotIn('preferredUsername', got.json)
def test_actor_handle_user_fetch_fails(self, _, __, ___):
got = self.client.get('/ap/fake/fake:handle:nope')
self.assertEqual(404, got.status_code)