rename Protocol.for_domain => for_bridgy_subdomain

pull/646/head
Ryan Barrett 2023-09-22 11:55:19 -07:00
rodzic 0d2ec18edd
commit 6a6a1657a7
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 6BE31FDF4776E9D4
3 zmienionych plików z 12 dodań i 11 usunięć

Wyświetl plik

@ -81,10 +81,10 @@ class Protocol:
:class:`Protocol` subclass, or None if the provided domain or request
hostname domain is not a subdomain of brid.gy or isn't a known protocol
"""
return Protocol.for_domain(request.host, fed=fed)
return Protocol.for_bridgy_subdomain(request.host, fed=fed)
@staticmethod
def for_domain(domain_or_url, fed=None):
def for_bridgy_subdomain(domain_or_url, fed=None):
"""Returns the protocol for a brid.gy subdomain.
Args:
@ -183,10 +183,10 @@ class Protocol:
# step 1: check for our per-protocol subdomains
if util.is_web(id):
by_domain = Protocol.for_domain(id)
if by_domain:
logger.info(f' {by_domain.__name__} owns {id}')
return by_domain
by_subdomain = Protocol.for_bridgy_subdomain(id)
if by_subdomain:
logger.info(f' {by_subdomain.__name__} owns {id}')
return by_subdomain
# step 2: check if any Protocols say conclusively that they own it
# sort to be deterministic

Wyświetl plik

@ -44,7 +44,7 @@ class ProtocolTest(TestCase):
self.assertEqual(Web, PROTOCOLS['web'])
self.assertEqual(Web, PROTOCOLS['webmention'])
def test_for_domain_for_request(self):
def test_for_bridgy_subdomain_for_request(self):
for domain, expected in [
('fake.brid.gy', Fake),
('ap.brid.gy', ActivityPub),
@ -60,11 +60,11 @@ class ProtocolTest(TestCase):
('fake.com', None),
]:
with self.subTest(domain=domain, expected=expected):
self.assertEqual(expected, Protocol.for_domain(domain))
self.assertEqual(expected, Protocol.for_bridgy_subdomain(domain))
with app.test_request_context('/foo', base_url=f'https://{domain}/'):
self.assertEqual(expected, Protocol.for_request())
def test_for_domain_for_request_fed(self):
def test_for_bridgy_subdomain_for_request_fed(self):
for url, expected in [
('https://fed.brid.gy/', Fake),
('http://localhost/foo', Fake),
@ -72,7 +72,8 @@ class ProtocolTest(TestCase):
('https://baz/biff', None),
]:
with self.subTest(url=url, expected=expected):
self.assertEqual(expected, Protocol.for_domain(url, fed=Fake))
self.assertEqual(expected,
Protocol.for_bridgy_subdomain(url, fed=Fake))
with app.test_request_context('/foo', base_url=url):
self.assertEqual(expected, Protocol.for_request(fed=Fake))

Wyświetl plik

@ -50,7 +50,7 @@ class Webfinger(flask_util.XrdOrJrd):
cls = None
try:
user, id = util.parse_acct_uri(resource)
cls = Protocol.for_domain(id, fed=Web)
cls = Protocol.for_bridgy_subdomain(id, fed=Web)
if cls:
id = user
allow_indirect = True