kopia lustrzana https://gitlab.com/jaywink/federation
Do NodeInfo fetch if Mastodon API version indicates Pleroma server
rodzic
04f3bd44d7
commit
1687fdb59a
|
@ -52,6 +52,13 @@ def int_or_none(value):
|
|||
|
||||
|
||||
def parse_mastodon_document(doc, host):
|
||||
# Check first this is not actually Pleroma. It supports NodeInfo but also has the
|
||||
# Mastodon API route
|
||||
if doc.get('version', '').find('Pleroma') > -1:
|
||||
# Use NodeInfo instead, otherwise this is logged as Mastodon
|
||||
from federation.hostmeta.fetchers import fetch_nodeinfo_document
|
||||
return fetch_nodeinfo_document(host)
|
||||
|
||||
result = deepcopy(defaults)
|
||||
result['host'] = host
|
||||
result['name'] = doc.get('title', host)
|
||||
|
|
|
@ -113,5 +113,9 @@ NODEINFO2_10_DOC = """
|
|||
}
|
||||
"""
|
||||
|
||||
PLEROMA_MASTODON_API_DOC = """
|
||||
{"description":"A Pleroma instance, an alternative fediverse server","email":"foobar@pleroma.local","max_toot_chars":5000,"stats":{"domain_count":5,"status_count":127,"user_count":11},"thumbnail":"https://kemo.one/instance/thumbnail.jpeg","title":"Pleromaa","uri":"https://pleroma.local","urls":{"streaming_api":"wss://pleroma.local"},"version":"2.3.3 (compatible; Pleroma 0.9.0 ffa552f1a41c530a7eff25d27cf0a82e710067b6)"}
|
||||
"""
|
||||
|
||||
STATISTICS_JSON_DOC = '{"name":"diaspora*","network":"Diaspora","version":"0.5.7.0-p56ebcc76","registrations_open"' \
|
||||
':true,"services":[],"twitter":false,"tumblr":false,"facebook":false,"wordpress":false}'
|
||||
|
|
|
@ -6,7 +6,7 @@ from federation.hostmeta.parsers import (
|
|||
parse_mastodon_document, parse_matrix_document)
|
||||
from federation.tests.fixtures.hostmeta import (
|
||||
NODEINFO2_10_DOC, NODEINFO_10_DOC, NODEINFO_20_DOC, STATISTICS_JSON_DOC, MASTODON_DOC, MASTODON_ACTIVITY_DOC,
|
||||
MASTODON_RC_DOC, MASTODON_DOC_NULL_CONTACT, MATRIX_SYNAPSE_DOC)
|
||||
MASTODON_RC_DOC, MASTODON_DOC_NULL_CONTACT, MATRIX_SYNAPSE_DOC, PLEROMA_MASTODON_API_DOC)
|
||||
|
||||
|
||||
class TestIntOrNone:
|
||||
|
@ -15,6 +15,11 @@ class TestIntOrNone:
|
|||
|
||||
|
||||
class TestParseMastodonDocument:
|
||||
@patch('federation.hostmeta.fetchers.fetch_nodeinfo_document', autospec=True)
|
||||
def test_calls_nodeinfo_fetcher_if_pleroma(self, mock_fetch):
|
||||
parse_mastodon_document(json.loads(PLEROMA_MASTODON_API_DOC), 'example.com')
|
||||
mock_fetch.assert_called_once_with('example.com')
|
||||
|
||||
@patch('federation.hostmeta.parsers.fetch_document')
|
||||
def test_parse_mastodon_document(self, mock_fetch):
|
||||
mock_fetch.return_value = MASTODON_ACTIVITY_DOC, 200, None
|
||||
|
|
Ładowanie…
Reference in New Issue