Activity.target_for: fix infinite loop when author is object id

fixes #603 and https://console.cloud.google.com/errors/detail/CLPmoOqegtfm0AE;time=P30D?project=bridgy-federated
pull/602/head
Ryan Barrett 2023-07-27 15:04:15 -07:00
rodzic 2f308b43e2
commit 8850e27374
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 6BE31FDF4776E9D4
2 zmienionych plików z 11 dodań i 1 usunięć

Wyświetl plik

@ -133,7 +133,9 @@ class ActivityPub(User, Protocol):
for field in 'actor', 'author', 'attributedTo':
inner_obj = as1.get_object(obj.as1, field)
inner_id = inner_obj.get('id') or as1.get_url(inner_obj)
if not inner_id:
if (not inner_id
or inner_id == obj.as1.get('id')
or (obj.key and inner_id == obj.key.id())):
continue
# TODO: need a "soft" kwarg for load to suppress errors?

Wyświetl plik

@ -1932,6 +1932,14 @@ class ActivityPubUtilsTest(TestCase):
self.assertEqual('http://mas.to/inbox', ActivityPub.target_for(obj))
mock_get.assert_has_calls([self.as2_req('http://the/author')])
@patch('requests.get')
def test_target_for_author_is_object_id(self, mock_get):
obj = self.store_object(id='http://the/author', our_as1={
'author': 'http://the/author',
})
# test is that we short circuit out instead of infinite recursion
self.assertIsNone(ActivityPub.target_for(obj))
@patch('requests.post')
def test_send_blocklisted(self, mock_post):
self.assertFalse(ActivityPub.send(Object(as2=NOTE),