From ca86534f21acb8465f5bbde60045810f40b40010 Mon Sep 17 00:00:00 2001 From: Ryan Barrett Date: Mon, 27 Jan 2025 16:47:33 -0800 Subject: [PATCH] Protocol.receive: when fetching actor, fetch profile id also update tests to test profile vs actor id with Fake users more --- protocol.py | 3 ++- tests/test_pages.py | 4 ++-- tests/test_protocol.py | 39 ++++++++++++++++++--------------------- tests/testutil.py | 1 + 4 files changed, 23 insertions(+), 24 deletions(-) diff --git a/protocol.py b/protocol.py index ed1dd9bd..8cbc97d1 100644 --- a/protocol.py +++ b/protocol.py @@ -1042,7 +1042,8 @@ def receive(from_cls, obj, authed_as=None, internal=False, received_at=None): if (actor and actor.keys() == set(['id']) and obj.type not in ('delete', 'undo')): logger.debug('Fetching actor so we have name, profile photo, etc') - actor_obj = from_cls.load(actor['id'], raise_=False) + actor_obj = from_cls.load(ids.profile_id(id=actor['id'], proto=from_cls), + raise_=False) if actor_obj and actor_obj.as1: obj.our_as1 = { **obj.as1, 'actor': { diff --git a/tests/test_pages.py b/tests/test_pages.py index 8813de62..a125621f 100644 --- a/tests/test_pages.py +++ b/tests/test_pages.py @@ -238,7 +238,7 @@ def test_update_profile(self): ['Updating profile from fake:handle:user...'], get_flashed_messages()) - self.assertEqual(['fake:profile:user', 'fake:user'], Fake.fetched) + self.assertEqual(['fake:profile:user'], Fake.fetched) actor['updated'] = '2022-01-02T03:04:05+00:00' self.assert_object('fake:profile:user', source_protocol='fake', our_as1=actor, @@ -248,7 +248,7 @@ def test_update_profile(self): 'objectType': 'activity', 'verb': 'update', 'id': 'fake:profile:user#bridgy-fed-update-2022-01-02T03:04:05+00:00', - 'actor': 'fake:user', + 'actor': {**actor, 'id': 'fake:user'}, 'object': actor, } self.assertEqual([('other:bob:target', update)], OtherFake.sent) diff --git a/tests/test_protocol.py b/tests/test_protocol.py index 13682a47..18645ab1 100644 --- a/tests/test_protocol.py +++ b/tests/test_protocol.py @@ -1518,11 +1518,7 @@ def test_create_post_use_instead(self): 'objectType': 'activity', 'verb': 'post', 'id': 'fake:post#bridgy-fed-create', - 'actor': { - 'objectType': 'person', - 'id': 'fake:user', - 'url': 'fake:user', - }, + 'actor': 'fake:user', 'object': note_as1, 'published': '2022-01-02T03:04:05+00:00', } @@ -1635,7 +1631,7 @@ def test_update_post_fetch_object(self): _, status = Fake.receive_as1(update) self.assertEqual(204, status) - self.assertEqual(['fake:post'], Fake.fetched) + self.assertEqual(['fake:profile:user', 'fake:post'], Fake.fetched) self.assert_object('fake:post', our_as1=post, type='note', @@ -1655,7 +1651,7 @@ def test_update_post_fetch_object_fails(self): with self.assertRaises(ErrorButDoNotRetryTask): Fake.receive_as1(update) - self.assertEqual(['fake:post'], Fake.fetched) + self.assertEqual(['fake:profile:user', 'fake:post'], Fake.fetched) self.assertIsNone(Object.get_by_id('fake:update')) def test_create_reply(self): @@ -2157,19 +2153,20 @@ def test_update_profile(self): self.make_followers() + actor = { + 'objectType': 'person', + 'id': 'fake:user', + 'displayName': 'Ms. ☕ Baz', + 'urls': [{'displayName': 'Ms. ☕ Baz', 'value': 'https://user.com/'}], + 'updated': '2022-01-02T03:04:05+00:00', + } id = 'fake:user#update-2022-01-02T03:04:05+00:00' update_as1 = { 'objectType': 'activity', 'verb': 'update', 'id': id, - 'actor': 'fake:user', - 'object': { - 'objectType': 'person', - 'id': 'fake:profile:user', - 'displayName': 'Ms. ☕ Baz', - 'urls': [{'displayName': 'Ms. ☕ Baz', 'value': 'https://user.com/'}], - 'updated': '2022-01-02T03:04:05+00:00', - }, + 'actor': actor, + 'object': {**actor, 'id': 'fake:profile:user'}, } Fake.receive_as1(update_as1) @@ -2427,11 +2424,11 @@ def test_follow_accept(self, _, **extra): self.assertEqual([('efake:follow:target', accept_as1)], ExplicitFake.sent) def test_stop_following(self): - follower = Follower.get_or_create(to=self.user, from_=self.alice) - self.user.obj.our_as1 = {'id': 'fake:user'} self.user.obj.put() + follower = Follower.get_or_create(to=self.user, from_=self.alice) + stop_as1 = { 'id': 'other:stop-following', 'objectType': 'activity', @@ -2462,12 +2459,12 @@ def test_stop_following_doesnt_exist(self): self.assertEqual([('fake:user:target', stop_following_as1)], Fake.sent) def test_stop_following_inactive(self): - follower = Follower.get_or_create(to=self.user, from_=self.alice, - status='inactive') - OtherFake.fetchable['other:alice'] = {} self.user.obj.our_as1 = {'id': 'fake:user'} self.user.obj.put() + follower = Follower.get_or_create(to=self.user, from_=self.alice, + status='inactive') + stop_following_as1 = { 'id': 'other:stop-following', 'objectType': 'activity', @@ -2690,7 +2687,7 @@ def test_resolve_ids_follow(self): self.assertEqual(('OK', 202), Fake.receive(obj, authed_as='fake:user')) self.assert_equals({ **follow, - 'actor': {'id': 'fake:user'}, + 'actor': 'fake:user', 'object': 'other:alice', }, Object.get_by_id('fake:follow').our_as1) diff --git a/tests/testutil.py b/tests/testutil.py index 9164b384..ed36bfb3 100644 --- a/tests/testutil.py +++ b/tests/testutil.py @@ -42,6 +42,7 @@ import router logger = logging.getLogger(__name__) +logging.getLogger('memcache').setLevel(logging.INFO) ATPROTO_KEY = arroba.util.new_key(2349823483510) # deterministic seed