From 70da21a7f3ec1ec2c9987b50b807d5c555555f91 Mon Sep 17 00:00:00 2001 From: Ryan Barrett Date: Fri, 19 Apr 2024 13:16:48 -0700 Subject: [PATCH] Protocol.receive: send accepts for bot user follows --- protocol.py | 7 +++---- tests/test_activitypub.py | 4 ++-- tests/test_protocol.py | 19 ++++++++++++------- 3 files changed, 17 insertions(+), 13 deletions(-) diff --git a/protocol.py b/protocol.py index 3b5a3df..2f805ec 100644 --- a/protocol.py +++ b/protocol.py @@ -829,10 +829,9 @@ class Protocol: if obj.type == 'follow': proto = Protocol.for_bridgy_subdomain(inner_obj_id) if proto: - # follow of one of our protocol users; enable that protocol + # follow of one of our protocol users; enable that protocol. + # foll through so that we send an accept. from_user.enable_protocol(proto) - # TODO: accept - return 'OK', 200 from_cls.handle_follow(obj) @@ -927,7 +926,7 @@ class Protocol: # send accept. note that this is one accept for the whole # follow, even if it has multiple followees! - id = followee.id_as('activitypub') + f'/followers#accept-{follow.key.id()}' + id = f'{followee.key.id()}/followers#accept-{follow.key.id()}' accept = Object.get_or_create(id, our_as1={ 'id': id, 'objectType': 'activity', diff --git a/tests/test_activitypub.py b/tests/test_activitypub.py index 09aa47f..5d95b75 100644 --- a/tests/test_activitypub.py +++ b/tests/test_activitypub.py @@ -230,7 +230,7 @@ ACCEPT_FOLLOW['object'] = 'http://localhost/user.com' ACCEPT = { '@context': 'https://www.w3.org/ns/activitystreams', 'type': 'Accept', - 'id': 'http://localhost/user.com/followers#accept-https://mas.to/6d1a', + 'id': 'http://localhost/r/user.com/followers#accept-https://mas.to/6d1a', 'actor': 'http://localhost/user.com', 'object': { 'type': 'Follow', @@ -1096,7 +1096,7 @@ class ActivityPubTest(TestCase): self.assert_equals(('http://mas.to/inbox',), args) self.assert_equals({ 'type': 'Accept', - 'id': 'https://web.brid.gy/user.com/followers#accept-https://mas.to/6d1a', + 'id': 'https://web.brid.gy/r/user.com/followers#accept-https://mas.to/6d1a', 'actor': 'https://web.brid.gy/user.com', 'object': { 'type': 'Follow', diff --git a/tests/test_protocol.py b/tests/test_protocol.py index db411ee..3c784d4 100644 --- a/tests/test_protocol.py +++ b/tests/test_protocol.py @@ -1375,7 +1375,7 @@ class ProtocolReceiveTest(TestCase): delivered=['fake:user:target'], ) - accept_id = 'https://fa.brid.gy/ap/fake:user/followers#accept-fake:follow' + accept_id = 'fake:user/followers#accept-fake:follow' accept_as1 = { 'id': accept_id, 'objectType': 'activity', @@ -1597,9 +1597,8 @@ class ProtocolReceiveTest(TestCase): self.assertEqual(('OK', 202), OtherFake.receive_as1(follow_as1)) self.assertEqual(1, len(OtherFake.sent)) - self.assertEqual( - 'https://fa.brid.gy/ap/fake:alice/followers#accept-other:follow', - OtherFake.sent[0][0]) + self.assertEqual('fake:alice/followers#accept-other:follow', + OtherFake.sent[0][0]) self.assertEqual(1, len(Fake.sent)) self.assertEqual('other:follow', Fake.sent[0][0]) @@ -1778,7 +1777,7 @@ class ProtocolReceiveTest(TestCase): }], }, obj.key.get().our_as1) - def test_follow_and_block_protocol_user_adds_and_removes_enabled_protocols(self): + def test_follow_and_block_protocol_user_sets_enabled_protocols(self): follow = { 'objectType': 'activity', 'verb': 'follow', @@ -1803,14 +1802,20 @@ class ProtocolReceiveTest(TestCase): self.assertEqual([], user.enabled_protocols) # follow should add to enabled_protocols - self.assertEqual(('OK', 200), ExplicitEnableFake.receive_as1(follow)) + with self.assertRaises(NoContent): + ExplicitEnableFake.receive_as1(follow) user = user.key.get() self.assertEqual(['fake'], user.enabled_protocols) self.assertTrue(ExplicitEnableFake.is_enabled_to(Fake, user)) + self.assertEqual([ + ('https://fa.brid.gy//followers#accept-eefake:follow', + 'eefake:user:target'), + ], ExplicitEnableFake.sent) # another follow should be a noop follow['id'] += '2' - self.assertEqual(('OK', 200), ExplicitEnableFake.receive_as1(follow)) + with self.assertRaises(NoContent): + ExplicitEnableFake.receive_as1(follow) user = user.key.get() self.assertEqual(['fake'], user.enabled_protocols)