ids.translate_user_id: for Web, normalize home page URLs to domains

pull/714/head
Ryan Barrett 2023-11-03 11:00:34 -07:00
rodzic 1f6a227aee
commit 37d8b5d4fc
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 6BE31FDF4776E9D4
2 zmienionych plików z 9 dodań i 0 usunięć

6
ids.py
Wyświetl plik

@ -4,6 +4,7 @@ https://fed.brid.gy/docs#translate
"""
import logging
import re
from urllib.parse import urlparse
from common import subdomain_wrap, SUPERDOMAIN
import models
@ -25,6 +26,11 @@ def translate_user_id(*, id, from_proto, to_proto):
assert id and from_proto and to_proto
assert from_proto.owns_id(id) is not False
parsed = urlparse(id)
if from_proto.LABEL == 'web' and parsed.path.strip('/') == '':
# home page; replace with domain
id = parsed.netloc
if from_proto == to_proto:
return id

Wyświetl plik

@ -30,9 +30,12 @@ class IdsTest(TestCase):
(Fake, 'fake:user', Fake, 'fake:user'),
(Fake, 'fake:user', Web, 'fake:user'),
(Web, 'user.com', ActivityPub, 'https://fed.brid.gy/user.com'),
(Web, 'https://user.com/', ActivityPub, 'https://fed.brid.gy/user.com'),
(Web, 'user.com', ATProto, 'did:plc:123'),
(Web, 'https://user.com', ATProto, 'did:plc:123'),
(Web, 'user.com', Fake, 'fake:u:user.com'),
(Web, 'user.com', Web, 'user.com'),
(Web, 'https://user.com/', Web, 'user.com'),
]:
with self.subTest(from_=from_.LABEL, to=to.LABEL):
self.assertEqual(expected, translate_user_id(