return 400 on more bad inputs, eg webmention source URLs

pull/59/head
Ryan Barrett 2019-08-13 07:29:25 -07:00
rodzic 65044b081c
commit 879f6d1752
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 6BE31FDF4776E9D4
2 zmienionych plików z 23 dodań i 0 usunięć

Wyświetl plik

@ -82,6 +82,10 @@ def _requests_fn(fn, url, parse_json=False, **kwargs):
try:
resp = fn(url, **kwargs)
except ValueError as e:
msg = 'Bad URL %s: %s' % (url, e)
logging.warning(msg)
raise exc.HTTPBadRequest(msg)
except (requests.ConnectionError, requests.Timeout) as e:
logging.warning(url, exc_info=True)
raise exc.HTTPBadGateway(unicode(e))

Wyświetl plik

@ -282,6 +282,15 @@ class WebmentionTest(testutil.TestCase):
return data
def test_bad_source_url(self, mock_get, mock_post):
got = app.get_response('/webmention', method='POST', body=b'')
self.assertEquals(400, got.status_int)
mock_get.side_effect = ValueError('foo bar')
got = app.get_response('/webmention', method='POST',
body=urllib.urlencode({'source': 'bad'}))
self.assertEquals(400, got.status_int)
def test_no_source_entry(self, mock_get, mock_post):
mock_get.return_value = requests_response("""
<html>
@ -316,6 +325,16 @@ class WebmentionTest(testutil.TestCase):
mock_get.assert_has_calls((self.req('http://a/post'),))
def test_bad_target_url(self, mock_get, mock_post):
mock_get.side_effect = (
requests_response(self.reply_html.replace('http://orig/post', 'bad'),
content_type=CONTENT_TYPE_HTML),
ValueError('foo bar'))
got = app.get_response('/webmention', method='POST',
body=urllib.urlencode({'source': 'http://a/post'}))
self.assertEquals(400, got.status_int)
def test_no_backlink(self, mock_get, mock_post):
mock_get.return_value = requests_response(
self.reply_html.replace('<a href="http://localhost/"></a>', ''),