Gracefully handle unknown status types

Fixes #432
This commit is contained in:
Mouse Reeve 2020-12-30 12:01:15 -08:00
parent 673d70aca9
commit e0adb3307b
2 changed files with 12 additions and 2 deletions

View file

@ -185,11 +185,15 @@ def handle_create(activity):
''' someone did something, good on them '''
# deduplicate incoming activities
activity = activity['object']
status_id = activity['id']
status_id = activity.get('id')
if models.Status.objects.filter(remote_id=status_id).count():
return
serializer = activitypub.activity_objects[activity['type']]
try:
serializer = activitypub.activity_objects[activity['type']]
except KeyError:
return
activity = serializer(**activity)
try:
model = models.activity_models[activity.type]

View file

@ -272,6 +272,12 @@ class Incoming(TestCase):
incoming.handle_create(activity)
self.assertEqual(models.Status.objects.count(), 2)
def test_handle_create_unknown_type(self):
''' folks send you all kinds of things '''
activity = {'object': {'id': 'hi'}, 'type': 'Fish'}
result = incoming.handle_create(activity)
self.assertIsNone(result)
def test_handle_create_remote_note_with_mention(self):
''' should only create it under the right circumstances '''
self.assertEqual(models.Status.objects.count(), 1)