mirror of
https://github.com/Mikaela/Limnoria.git
synced 2025-02-25 18:10:44 +01:00
Fediverse: Add support for missing host-meta document
This commit is contained in:
parent
21a2ace7a1
commit
501770e544
@ -61,10 +61,6 @@ class ProtocolError(ActivityPubError):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class HostmetaError(ProtocolError):
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
class ActivityPubProtocolError(ActivityPubError):
|
class ActivityPubProtocolError(ActivityPubError):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@ -118,7 +114,7 @@ def convert_exceptions(to_class, msg="", from_none=False):
|
|||||||
|
|
||||||
@sandbox
|
@sandbox
|
||||||
def _get_webfinger_url(hostname):
|
def _get_webfinger_url(hostname):
|
||||||
with convert_exceptions(HostmetaError):
|
try:
|
||||||
doc = ET.fromstring(
|
doc = ET.fromstring(
|
||||||
web.getUrlContent("https://%s/.well-known/host-meta" % hostname)
|
web.getUrlContent("https://%s/.well-known/host-meta" % hostname)
|
||||||
)
|
)
|
||||||
@ -126,8 +122,9 @@ def _get_webfinger_url(hostname):
|
|||||||
for link in doc.iter(XRD_URI + "Link"):
|
for link in doc.iter(XRD_URI + "Link"):
|
||||||
if link.attrib["rel"] == "lrdd":
|
if link.attrib["rel"] == "lrdd":
|
||||||
return link.attrib["template"]
|
return link.attrib["template"]
|
||||||
|
except web.Error:
|
||||||
return "https://%s/.well-known/webfinger?resource={uri}"
|
# Fall back to the default Webfinger URL
|
||||||
|
return "https://%s/.well-known/webfinger?resource={uri}" % hostname
|
||||||
|
|
||||||
|
|
||||||
def has_webfinger_support(hostname):
|
def has_webfinger_support(hostname):
|
||||||
|
@ -255,6 +255,19 @@ class NetworklessFediverseTestCase(BaseFediverseTestCase):
|
|||||||
"\x02someuser\x02 (@someuser@example.org): My Biography",
|
"\x02someuser\x02 (@someuser@example.org): My Biography",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def testProfileNoHostmeta(self):
|
||||||
|
expected_requests = [
|
||||||
|
(HOSTMETA_URL, utils.web.Error("blah")),
|
||||||
|
(WEBFINGER_URL, WEBFINGER_DATA),
|
||||||
|
(ACTOR_URL, ACTOR_DATA),
|
||||||
|
]
|
||||||
|
|
||||||
|
with self.mockRequests(expected_requests):
|
||||||
|
self.assertResponse(
|
||||||
|
"profile @someuser@example.org",
|
||||||
|
"\x02someuser\x02 (@someuser@example.org): My Biography",
|
||||||
|
)
|
||||||
|
|
||||||
def testProfileSnarfer(self):
|
def testProfileSnarfer(self):
|
||||||
with self.mockWebfingerSupport("not called"), self.mockRequests([]):
|
with self.mockWebfingerSupport("not called"), self.mockRequests([]):
|
||||||
self.assertSnarfNoResponse("aaa @nonexistinguser@example.org bbb")
|
self.assertSnarfNoResponse("aaa @nonexistinguser@example.org bbb")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user