kopia lustrzana https://gitlab.com/jaywink/federation
Don't crash diaspora retrieve_diaspora_webfinger on XRD parse error
rodzic
1bf4d8f41a
commit
ef46515ee7
|
@ -1,5 +1,10 @@
|
|||
# Changelog
|
||||
|
||||
## [unreleased]
|
||||
|
||||
### Fixes
|
||||
* Don't crash `federation.utils.diaspora.retrieve_diaspora_webfinger` if XRD parse raises an `xml.parsers.expat.ExpatError`.
|
||||
|
||||
## [0.9.1] - 2016-12-10
|
||||
|
||||
### Fixes
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
import xml
|
||||
from unittest.mock import patch, Mock
|
||||
from urllib.parse import quote
|
||||
|
||||
|
@ -69,6 +70,17 @@ class TestRetrieveDiasporaWebfinger(object):
|
|||
mock_fetch.assert_called_with("https://localhost/webfinger?q=%s" % quote("bob@localhost"))
|
||||
assert document == None
|
||||
|
||||
@patch("federation.utils.diaspora.fetch_document", return_value=("document", None, None))
|
||||
@patch("federation.utils.diaspora.retrieve_diaspora_host_meta", return_value=None)
|
||||
@patch("federation.utils.diaspora.XRD.parse_xrd", side_effect=xml.parsers.expat.ExpatError)
|
||||
def test_returns_none_on_xrd_parse_exception(self, mock_parse, mock_retrieve, mock_fetch):
|
||||
mock_retrieve.return_value = DiasporaHostMeta(
|
||||
webfinger_host="https://localhost"
|
||||
).xrd
|
||||
document = retrieve_diaspora_webfinger("bob@localhost")
|
||||
mock_parse.assert_called_once_with("document")
|
||||
assert document == None
|
||||
|
||||
|
||||
class TestRetrieveDiasporaHostMeta(object):
|
||||
@patch("federation.utils.diaspora.XRD.parse_xrd")
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
import logging
|
||||
import xml
|
||||
from urllib.parse import quote
|
||||
|
||||
from lxml import html
|
||||
|
@ -42,7 +43,10 @@ def retrieve_diaspora_webfinger(handle):
|
|||
document, code, exception = fetch_document(url)
|
||||
if exception:
|
||||
return None
|
||||
xrd = XRD.parse_xrd(document)
|
||||
try:
|
||||
xrd = XRD.parse_xrd(document)
|
||||
except xml.parsers.expat.ExpatError:
|
||||
return None
|
||||
return xrd
|
||||
|
||||
|
||||
|
|
Ładowanie…
Reference in New Issue