From d538928fe626b7c7dc2547b60c15db2d20d0fed2 Mon Sep 17 00:00:00 2001 From: Ryan Barrett Date: Fri, 1 Dec 2023 13:06:59 -0800 Subject: [PATCH] activitypub.postprocess_as2_actor: bug fix for publicKey w/Web.ap_subdomain --- activitypub.py | 3 ++- tests/test_activitypub.py | 8 ++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/activitypub.py b/activitypub.py index 34db727..d04d2b5 100644 --- a/activitypub.py +++ b/activitypub.py @@ -701,7 +701,8 @@ def postprocess_as2_actor(actor, user=None): urls[0] = redirect_wrap(urls[0]) id = actor.get('id') - if not id or user.is_web_url(id): + user_id = user.key.id() + if not id or user.is_web_url(id) or unwrap(id) in (user_id, f'www.{user_id}'): id = actor['id'] = user.id_as(ActivityPub) actor['url'] = urls[0] if len(urls) == 1 else urls diff --git a/tests/test_activitypub.py b/tests/test_activitypub.py index 546de98..e7244ec 100644 --- a/tests/test_activitypub.py +++ b/tests/test_activitypub.py @@ -1884,6 +1884,14 @@ class ActivityPubUtilsTest(TestCase): }], }, user=self.user)['preferredUsername']) + def test_postprocess_as2_user_wrapped_id(self): + for id in 'http://fed.brid.gy/user.com', 'http://fed.brid.gy/www.user.com': + got = postprocess_as2_actor(as2.from_as1({ + 'objectType': 'person', + 'id': id, + }), user=self.user) + self.assert_equals('http://localhost/user.com', got['id']) + def test_postprocess_as2_mentions_into_cc(self): obj = copy.deepcopy(MENTION_OBJECT) del obj['cc']