mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-14 22:49:23 +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
|
||||
|
||||
|
||||
class HostmetaError(ProtocolError):
|
||||
pass
|
||||
|
||||
|
||||
class ActivityPubProtocolError(ActivityPubError):
|
||||
pass
|
||||
|
||||
@ -118,7 +114,7 @@ def convert_exceptions(to_class, msg="", from_none=False):
|
||||
|
||||
@sandbox
|
||||
def _get_webfinger_url(hostname):
|
||||
with convert_exceptions(HostmetaError):
|
||||
try:
|
||||
doc = ET.fromstring(
|
||||
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"):
|
||||
if link.attrib["rel"] == "lrdd":
|
||||
return link.attrib["template"]
|
||||
|
||||
return "https://%s/.well-known/webfinger?resource={uri}"
|
||||
except web.Error:
|
||||
# Fall back to the default Webfinger URL
|
||||
return "https://%s/.well-known/webfinger?resource={uri}" % hostname
|
||||
|
||||
|
||||
def has_webfinger_support(hostname):
|
||||
|
@ -255,6 +255,19 @@ class NetworklessFediverseTestCase(BaseFediverseTestCase):
|
||||
"\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):
|
||||
with self.mockWebfingerSupport("not called"), self.mockRequests([]):
|
||||
self.assertSnarfNoResponse("aaa @nonexistinguser@example.org bbb")
|
||||
|
Loading…
Reference in New Issue
Block a user