From 938a4ac85cc33e297327e8d2f00c3982e87d2ce3 Mon Sep 17 00:00:00 2001 From: Ryan Barrett Date: Sat, 12 Nov 2022 06:57:29 -0800 Subject: [PATCH] webmention: when checking for fed.brid.gy backlink, don't require / path fixes #278 --- templates/followers.html | 17 +++++++++++++++++ tests/test_webmention.py | 12 ++++++++++++ webmention.py | 7 ++++--- 3 files changed, 33 insertions(+), 3 deletions(-) create mode 100644 templates/followers.html diff --git a/templates/followers.html b/templates/followers.html new file mode 100644 index 0000000..53a029e --- /dev/null +++ b/templates/followers.html @@ -0,0 +1,17 @@ +{% extends "base.html" %} + +{% block title %}{{ domain }}'s followers - Bridgy Fed{% endblock %} + +{% block content %} + +

+ 🌐 {{ domain }} +

+

+ {{ followers }} follower{% if followers != '1' %}s{% endif %} + +

+ +{% include "responses.html" %} + +{% endblock %} diff --git a/tests/test_webmention.py b/tests/test_webmention.py index 3680786..c97727f 100644 --- a/tests/test_webmention.py +++ b/tests/test_webmention.py @@ -366,6 +366,18 @@ class WebmentionTest(testutil.TestCase): mock_get.assert_has_calls((self.req('http://a/post'),)) + def test_backlink_without_trailing_slash(self, mock_get, mock_post): + mock_get.return_value = requests_response( + self.reply_html.replace('', + ''), + content_type=CONTENT_TYPE_HTML) + + got = self.client.post('/webmention', data={ + 'source': 'http://a/post', + 'target': 'https://fed.brid.gy/', + }) + self.assertEqual(200, got.status_code) + def test_activitypub_create_reply(self, mock_get, mock_post): mock_get.side_effect = self.activitypub_gets mock_post.return_value = requests_response('abc xyz', status=203) diff --git a/webmention.py b/webmention.py index 3cc84af..db761be 100644 --- a/webmention.py +++ b/webmention.py @@ -54,9 +54,10 @@ class Webmention(View): # check for backlink to bridgy fed (for webmention spec and to confirm # source's intent to federate to mastodon) - if (request.host_url not in source_resp.text and - urllib.parse.quote(request.host_url, safe='') not in source_resp.text): - error("Couldn't find link to {request.host_url}") + host_url = request.host_url.rstrip('/') # don't require / path + if (host_url not in source_resp.text and + urllib.parse.quote(host_url, safe='') not in source_resp.text): + error(f"Couldn't find link to {host_url}") # convert source page to ActivityStreams entry = mf2util.find_first_entry(self.source_mf2, ['h-entry'])