Merge pull request #65 from jaywink/exceptions

Don't crash diaspora retrieve_diaspora_webfinger on XRD parse error
merge-requests/130/head
Jason Robinson 2017-01-12 22:02:24 +02:00 zatwierdzone przez GitHub
commit 3f0a412331
3 zmienionych plików z 22 dodań i 1 usunięć

Wyświetl plik

@ -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

Wyświetl plik

@ -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")

Wyświetl plik

@ -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