From dc3b23f80b4fb71cfb5545d79db4cf32d690b21f Mon Sep 17 00:00:00 2001 From: Ryan Barrett Date: Sun, 26 Nov 2023 16:22:24 -0800 Subject: [PATCH] Web.fetch: ignore uid if set; we use URL as id MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- tests/test_convert.py | 3 +-- tests/test_web.py | 14 ++++++++++++++ web.py | 7 ++++++- 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/tests/test_convert.py b/tests/test_convert.py index b5676db..c0643b7 100644 --- a/tests/test_convert.py +++ b/tests/test_convert.py @@ -20,7 +20,7 @@ from web import Web COMMENT_AS2 = { **as2.from_as1(COMMENT), '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', 'name': 'A ☕ reply', 'contentMap': {'en': COMMENT['content']}, @@ -33,7 +33,6 @@ HTML = """\
- tag:fake.com:123456 fake.com/123456
diff --git a/tests/test_web.py b/tests/test_web.py index 3374a5a..d7dfff0 100644 --- a/tests/test_web.py +++ b/tests/test_web.py @@ -2126,6 +2126,20 @@ class WebUtilTest(TestCase): 'url': 'https://user.com/post', }, obj.mf2) + def test_load_id_is_url_not_uid(self, mock_get, __): + mock_get.return_value = requests_response(NOTE_HTML.replace( + '', """\ + + +""")) + + 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, __): mock_get.return_value = ACTOR_HTML_RESP diff --git a/web.py b/web.py index 9350b12..e2eba10 100644 --- a/web.py +++ b/web.py @@ -401,12 +401,17 @@ class Web(User, Protocol): if not entry: 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, # since that's the fallback for AS1/AS2 id if is_homepage: entry.setdefault('rel-urls', {}).update(parsed.get('rel-urls', {})) entry.setdefault('type', ['h-card']) - props = entry.setdefault('properties', {}) if parsed['url']: entry['url'] = parsed['url'] props.setdefault('url', [parsed['url']])