From 2a83cbb0d8bbe76ca8e6f66e28372a51fafa3c2f Mon Sep 17 00:00:00 2001 From: Ryan Barrett Date: Sat, 13 Jul 2024 12:46:53 -0700 Subject: [PATCH] Protocol.targets: bug fix for self replies this bug snuck in because of our special case handling of Fake and OtherFake in Protocol.targets. ugh. need to get rid of that, and elsewhere, eg ids.*. fixes #1179 --- protocol.py | 3 ++- tests/test_protocol.py | 38 +++++++++++++++++++++++--------------- 2 files changed, 25 insertions(+), 16 deletions(-) diff --git a/protocol.py b/protocol.py index e87c239..56b7d3d 100644 --- a/protocol.py +++ b/protocol.py @@ -1276,7 +1276,8 @@ class Protocol: to_protocols = [] if DEBUG and from_user.LABEL != 'eefake': # for unit tests to_protocols = [PROTOCOLS['fake'], PROTOCOLS['other']] - for label in (list(from_user.DEFAULT_ENABLED_PROTOCOLS) + for label in ([from_user.LABEL] + + list(from_user.DEFAULT_ENABLED_PROTOCOLS) + from_user.enabled_protocols): proto = PROTOCOLS[label] if proto.HAS_COPIES and (obj.type in ('update', 'delete', 'share') diff --git a/tests/test_protocol.py b/tests/test_protocol.py index cce6cc8..b189141 100644 --- a/tests/test_protocol.py +++ b/tests/test_protocol.py @@ -1425,35 +1425,43 @@ class ProtocolReceiveTest(TestCase): def test_create_self_reply_to_same_protocol_bridge_if_original_is_bridged(self): - # eve follows alice - eve = self.make_user('other:eve', cls=OtherFake, obj_id='other:eve') - Follower.get_or_create(to=self.alice, from_=eve) + # use eefake because Protocol.targets automatically adds fake and other + # to to_protocols. + # TODO: refactor tests to not do fake-to-fake delivery, then remove + # these special cases + user = self.make_user('eefake:user', cls=ExplicitEnableFake, + obj_id='eefake:user', enabled_protocols=['other']) - # alice replies to herself - self.store_object(id='fake:post', source_protocol='fake', + # eve follows user + eve = self.make_user('other:eve', cls=OtherFake, obj_id='other:eve') + Follower.get_or_create(to=user, from_=eve) + + # user replies to themselves + self.store_object(id='eefake:post', source_protocol='eefake', copies=[Target(protocol='other', uri='other:post')], our_as1={ 'objectType': 'note', - 'id': 'fake:post', - 'author': 'fake:alice', + 'id': 'eefake:post', + 'author': 'eefake:user', }) reply_as1 = { - 'id': 'fake:reply', + 'id': 'eefake:reply', 'objectType': 'note', - 'inReplyTo': 'fake:post', - 'author': 'fake:alice', + 'inReplyTo': 'eefake:post', + 'author': 'eefake:user', } - self.assertEqual(('OK', 202), Fake.receive_as1(reply_as1)) + self.assertEqual(('OK', 202), ExplicitEnableFake.receive_as1(reply_as1)) - copy = Target(protocol='other', uri='other:o:fa:fake:reply') - reply = self.assert_object('fake:reply', + copy = Target(protocol='other', uri='other:o:eefake:eefake:reply') + reply = self.assert_object('eefake:reply', type='note', + source_protocol='eefake', our_as1=reply_as1, copies=[copy], feed=[eve.key]) - self.assertEqual([('fake:reply#bridgy-fed-create', 'other:eve:target'), - ('fake:reply#bridgy-fed-create', 'other:post:target'), + self.assertEqual([('eefake:reply#bridgy-fed-create', 'other:eve:target'), + ('eefake:reply#bridgy-fed-create', 'other:post:target'), ], OtherFake.sent) def test_update_reply(self):