diff --git a/plugins/Fediverse/activitypub.py b/plugins/Fediverse/activitypub.py index 0d062068a..511551c3b 100644 --- a/plugins/Fediverse/activitypub.py +++ b/plugins/Fediverse/activitypub.py @@ -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): diff --git a/plugins/Fediverse/test.py b/plugins/Fediverse/test.py index d06c0ead7..a6046d346 100644 --- a/plugins/Fediverse/test.py +++ b/plugins/Fediverse/test.py @@ -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")