Web.fetch: ignore uid if set; we use URL as id

props and thanks to @fluffy-critter for being my unintentional edge case QA department 😆🙏

fixes https://console.cloud.google.com/errors/detail/CKLuk-v4x8X0NQ;time=P30D?project=bridgy-federated
pull/736/head
Ryan Barrett 2023-11-26 16:22:24 -08:00
rodzic 3c460c88ad
commit dc3b23f80b
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 6BE31FDF4776E9D4
3 zmienionych plików z 21 dodań i 3 usunięć

Wyświetl plik

@ -20,7 +20,7 @@ from web import Web
COMMENT_AS2 = { COMMENT_AS2 = {
**as2.from_as1(COMMENT), **as2.from_as1(COMMENT),
'type': 'Note', 'type': 'Note',
'id': 'https://web.brid.gy/r/tag:fake.com:123456', 'id': 'https://fed.brid.gy/r/https://fake.com/123456',
'url': 'https://web.brid.gy/r/https://fake.com/123456', 'url': 'https://web.brid.gy/r/https://fake.com/123456',
'name': 'A ☕ reply', 'name': 'A ☕ reply',
'contentMap': {'en': COMMENT['content']}, 'contentMap': {'en': COMMENT['content']},
@ -33,7 +33,6 @@ HTML = """\
<meta http-equiv="refresh" content="0;url=https://fake.com/123456"></head> <meta http-equiv="refresh" content="0;url=https://fake.com/123456"></head>
<body class=""> <body class="">
<article class="h-entry"> <article class="h-entry">
<span class="p-uid">tag:fake.com:123456</span>
<time class="dt-published" datetime="2012-12-05T00:58:26+00:00">2012-12-05T00:58:26+00:00</time> <time class="dt-published" datetime="2012-12-05T00:58:26+00:00">2012-12-05T00:58:26+00:00</time>
<a class="u-url" href="https://fake.com/123456">fake.com/123456</a> <a class="u-url" href="https://fake.com/123456">fake.com/123456</a>
<div class="e-content p-name"> <div class="e-content p-name">

Wyświetl plik

@ -2126,6 +2126,20 @@ class WebUtilTest(TestCase):
'url': 'https://user.com/post', 'url': 'https://user.com/post',
}, obj.mf2) }, obj.mf2)
def test_load_id_is_url_not_uid(self, mock_get, __):
mock_get.return_value = requests_response(NOTE_HTML.replace(
'<a href="http://localhost/"></a>', """\
<data class="p-uid" value="abc123"></data>
<a href="http://localhost/"></a>
"""))
obj = Web.load('https://user.com/post')
self.assertEqual('https://user.com/post', obj.key.id())
self.assertEqual('https://user.com/post', obj.as1['id'])
self.assertEqual(NOTE_MF2, obj.mf2)
self.assertNotIn('uid', obj.mf2['properties'])
def test_fetch_user_homepage(self, mock_get, __): def test_fetch_user_homepage(self, mock_get, __):
mock_get.return_value = ACTOR_HTML_RESP mock_get.return_value = ACTOR_HTML_RESP

7
web.py
Wyświetl plik

@ -401,12 +401,17 @@ class Web(User, Protocol):
if not entry: if not entry:
error(f'No microformats2 h-entry found in {url}') error(f'No microformats2 h-entry found in {url}')
# discard uid if set; we use URL as id
props = entry.setdefault('properties', {})
if 'uid' in props:
logger.info(f'Discarding uid property: {props["uid"]}')
props.pop('uid')
# store final URL in mf2 object, and also default url property to it, # store final URL in mf2 object, and also default url property to it,
# since that's the fallback for AS1/AS2 id # since that's the fallback for AS1/AS2 id
if is_homepage: if is_homepage:
entry.setdefault('rel-urls', {}).update(parsed.get('rel-urls', {})) entry.setdefault('rel-urls', {}).update(parsed.get('rel-urls', {}))
entry.setdefault('type', ['h-card']) entry.setdefault('type', ['h-card'])
props = entry.setdefault('properties', {})
if parsed['url']: if parsed['url']:
entry['url'] = parsed['url'] entry['url'] = parsed['url']
props.setdefault('url', [parsed['url']]) props.setdefault('url', [parsed['url']])