send follow accepts to protocols that support them

for #710
pull/737/head
Ryan Barrett 2023-11-27 16:32:22 -08:00
rodzic 8f7facda97
commit ee373095e2
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 6BE31FDF4776E9D4
2 zmienionych plików z 36 dodań i 2 usunięć

Wyświetl plik

@ -641,8 +641,13 @@ class Protocol:
actor_id = actor.get('id')
# handle activity!
if obj.type == 'accept': # eg in response to a Follow
return 'OK' # noop
# accept, eg in response to a follow. only send if the destination
# supports accepts.
if obj.type == 'accept':
to_cls = Protocol.for_id(inner_obj_id)
if not to_cls or not to_cls.HAS_FOLLOW_ACCEPTS:
return 'OK' # noop
elif obj.type == 'stop-following':
# TODO: unify with handle_follow?

Wyświetl plik

@ -1381,6 +1381,35 @@ class ProtocolReceiveTest(TestCase):
self.assertEqual([], Follower.query().fetch())
self.assertEqual([], Fake.sent)
def test_accept_noop(self, **extra):
eve = self.make_user('other:eve', cls=OtherFake)
accept_as1 = {
'id': 'other:accept',
'objectType': 'activity',
'verb': 'accept',
'actor': 'other:eve',
'object': 'fake:follow'
}
self.assertEqual('OK', OtherFake.receive_as1(accept_as1))
self.assertEqual([], Fake.sent)
self.assertEqual([], OtherFake.sent)
def test_accept_with_has_accepts_protocol(self, **extra):
OtherFake.fetchable['other:follow'] = {'id': 'other:follow'}
accept_as1 = {
'id': 'fake:accept',
'objectType': 'activity',
'verb': 'accept',
'actor': 'fake:alice',
'object': 'other:follow'
}
self.assertEqual(('OK', 202), Fake.receive_as1(accept_as1))
self.assertEqual([
('fake:accept', 'other:follow:target'),
], OtherFake.sent)
def test_stop_following(self):
follower = Follower.get_or_create(to=self.user, from_=self.alice)