bug fix for application/ld+json content type

fixes #522
pull/525/head
Ryan Barrett 2023-05-28 08:06:36 -07:00
rodzic b7bebb4075
commit 72024f90b1
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 6BE31FDF4776E9D4
3 zmienionych plików z 16 dodań i 2 usunięć

Wyświetl plik

@ -108,7 +108,7 @@ class ActivityPub(User, Protocol):
resp = signed_get(url, headers=headers, gateway=True)
if not resp.content:
_error('empty response')
elif common.content_type(resp) == as2.CONTENT_TYPE:
elif common.content_type(resp) in as2.CONTENT_TYPES:
try:
return resp.json()
except requests.JSONDecodeError:

Wyświetl plik

@ -153,7 +153,8 @@ class FollowCallback(indieauth.Callback):
as2_url = None
for link in webfinger.get('links', []):
if link.get('rel') == 'self' and link.get('type') == as2.CONTENT_TYPE:
type = link.get('type', '').split(';')[0]
if link.get('rel') == 'self' and type in as2.CONTENT_TYPES:
as2_url = link.get('href')
if not as2_url:

Wyświetl plik

@ -1369,6 +1369,19 @@ class ActivityPubUtilsTest(TestCase):
self.as2_req('http://orig'),
))
@patch('requests.get')
def test_fetch_direct_ld_content_type(self, mock_get):
mock_get.return_value = requests_response(AS2_OBJ, headers={
'Content-Type': 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"',
})
obj = Object(id='http://orig')
ActivityPub.fetch(obj)
self.assertEqual(AS2_OBJ, obj.as2)
mock_get.assert_has_calls((
self.as2_req('http://orig'),
))
@patch('requests.get')
def test_fetch_via_html(self, mock_get):
mock_get.side_effect = [HTML_WITH_AS2, AS2]