webmention => AP/Salmon: handle no targets or followers, return 200

fixes https://console.cloud.google.com/errors/CIrig_2B6_i87AE
pull/59/head
Ryan Barrett 2018-11-27 07:44:27 -08:00
rodzic e964190162
commit 0af5c136bb
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 6BE31FDF4776E9D4
2 zmienionych plików z 21 dodań i 0 usunięć

Wyświetl plik

@ -294,6 +294,23 @@ class WebmentionTest(testutil.TestCase):
mock_get.assert_has_calls((self.req('http://a/post'),))
def test_no_targets(self, mock_get, mock_post):
mock_get.return_value = requests_response("""
<html>
<body class="h-entry">
<p class="e-content">no one to send to! <a href="http://localhost/"></a></p>
</body>
</html>""", content_type=CONTENT_TYPE_HTML)
got = app.get_response(
'/webmention', method='POST', body=urllib.urlencode({
'source': 'http://a/post',
'target': 'https://fed.brid.gy/',
}))
self.assertEquals(200, got.status_int)
mock_get.assert_has_calls((self.req('http://a/post'),))
def test_no_backlink(self, mock_get, mock_post):
mock_get.return_value = requests_response(
self.reply_html.replace('<a href="http://localhost/"></a>', ''),

Wyświetl plik

@ -209,6 +209,10 @@ class WebmentionHandler(webapp2.RequestHandler):
def try_salmon(self):
"""Returns True if we attempted OStatus delivery. Raises otherwise."""
target = self.target_resp.url if self.target_resp else self._single_target()
if not target:
logging.warning("No targets or followers. Ignoring.")
return False
resp = Response.get_or_create(
source=self.source_url, target=target, direction='out',
source_mf2=json.dumps(self.source_mf2))