Protocol.for_id: handle null Object.source_protocol

cd
Ryan Barrett 2023-06-13 21:36:56 -07:00
rodzic 65e1479d88
commit bfb462e414
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 6BE31FDF4776E9D4
2 zmienionych plików z 8 dodań i 3 usunięć

Wyświetl plik

@ -175,8 +175,9 @@ class Protocol:
logger.info(f'Trying {protocol.__name__}')
try:
obj = protocol.load(id)
logger.info(f"Looks like it's {obj.source_protocol}")
return PROTOCOLS[obj.source_protocol]
if obj.source_protocol:
logger.info(f"{obj.key} has source_protocol {obj.source_protocol}")
return PROTOCOLS[obj.source_protocol]
except werkzeug.exceptions.HTTPException:
# internal error we generated ourselves; try next protocol
pass
@ -185,7 +186,7 @@ class Protocol:
if code:
# we tried and failed fetching the id over the network
return None
logger.info(e)
raise
logger.info(f'No matching protocol found for {id} !')
return None

Wyświetl plik

@ -131,6 +131,10 @@ class ProtocolTest(TestCase):
Object(id='http://ui/obj', source_protocol='ui').put()
self.assertEqual(UIProtocol, Protocol.for_id('http://ui/obj'))
def test_for_id_object_missing_source_protocol(self):
Object(id='http://bad/obj').put()
self.assertIsNone(Protocol.for_id('http://bad/obj'))
@patch('requests.get')
def test_for_id_activitypub_fetch(self, mock_get):
mock_get.return_value = self.as2_resp(ACTOR)