webmention: when checking for fed.brid.gy backlink, don't require / path

fixes #278
pull/280/head
Ryan Barrett 2022-11-12 06:57:29 -08:00
rodzic 1b96e953d5
commit 938a4ac85c
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 6BE31FDF4776E9D4
3 zmienionych plików z 33 dodań i 3 usunięć

Wyświetl plik

@ -0,0 +1,17 @@
{% extends "base.html" %}
{% block title %}{{ domain }}'s followers - Bridgy Fed{% endblock %}
{% block content %}
<h2 class="row">
<a href="https://{{ domain }}/">🌐 {{ domain }}</a>
</h2>
<h3 class="row">
<a href="/user/{{ domain }}/followers">{{ followers }} follower{% if followers != '1' %}s{% endif %}</a>
<!-- | <a href="/user/{{ domain }}/following">{{ following }} following</a> -->
</h3>
{% include "responses.html" %}
{% endblock %}

Wyświetl plik

@ -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('<a href="http://localhost/"></a>',
'<a href="http://localhost"></a>'),
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)

Wyświetl plik

@ -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'])