From d724ae8cba492cf069fc5620c94c73e9c3b7349d Mon Sep 17 00:00:00 2001 From: Ryan Barrett Date: Wed, 25 Jan 2023 19:44:48 -0800 Subject: [PATCH] accept Updates to Person objects, do nothing with them fixes #387 --- activitypub.py | 6 ++++++ tests/test_activitypub.py | 31 ++++++++++++++++++++++++++++++- 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/activitypub.py b/activitypub.py index fac4200..1d5571b 100644 --- a/activitypub.py +++ b/activitypub.py @@ -31,6 +31,7 @@ SUPPORTED_TYPES = ( 'Like', 'Note', 'Undo', + 'Update', 'Video', ) @@ -80,6 +81,11 @@ def inbox(domain=None): # skip actor fetch below; we don't need it to undo a follow undo_follow(redirect_unwrap(activity)) return '' + elif type == 'Update': + if obj.get('type') == 'Person': + return '' # noop + else: + error(f'Sorry, {type} activities are not supported yet.', status=501) elif type == 'Delete': # we currently only actually delete followers for Deletes that are sent # to the shared inbox, not individual users' inboxes, to help scaling diff --git a/tests/test_activitypub.py b/tests/test_activitypub.py index 4f0bfe6..b58108d 100644 --- a/tests/test_activitypub.py +++ b/tests/test_activitypub.py @@ -148,6 +148,26 @@ DELETE = { 'object': 'https://mastodon.social/users/swentel', } +UPDATE_PERSON = { + '@context': 'https://www.w3.org/ns/activitystreams', + 'id': 'https://a/person#update', + 'type': 'Update', + 'actor': 'https://mastodon.social/users/swentel', + 'object': { + 'type': 'Person', + 'id': 'https://a/person', + }, +} +UPDATE_NOTE = { + '@context': 'https://www.w3.org/ns/activitystreams', + 'id': 'https://a/note#update', + 'type': 'Update', + 'actor': 'https://mastodon.social/users/swentel', + 'object': { + 'type': 'Note', + 'id': 'https://a/note', + }, +} @patch('requests.post') @patch('requests.get') @@ -652,6 +672,16 @@ class ActivityPubTest(testutil.TestCase): self.assertEqual('inactive', followee.key.get().status) self.assertEqual('active', other.key.get().status) + def test_update_person_noop(self, _, __, ___): + """Updates to Person objects do nothing.""" + got = self.client.post('/inbox', json=UPDATE_PERSON) + self.assertEqual(200, got.status_code) + + def test_update_note_not_implemented(self, _, __, ___): + """Updates to non-Person objects are not implemented.""" + got = self.client.post('/inbox', json=UPDATE_NOTE) + self.assertEqual(501, got.status_code) + def test_inbox_webmention_discovery_connection_fails(self, mock_head, mock_get, mock_post): mock_get.side_effect = [ @@ -817,7 +847,6 @@ class ActivityPubTest(testutil.TestCase): 'items': [ACTOR], }, resp.json) - def test_outbox_empty(self, _, mock_get, __): resp = self.client.get(f'/foo.com/outbox') self.assertEqual(200, resp.status_code)