kopia lustrzana https://github.com/snarfed/bridgy-fed
consolidate ap_address in ATProto, Fake, Web (partially) into User
rodzic
e9e8827ef9
commit
9b8b02e99f
|
@ -66,7 +66,7 @@ class ActivityPub(User, Protocol):
|
|||
"""Validate id, require URL, don't allow Bridgy Fed domains.
|
||||
|
||||
TODO: normalize scheme and domain to lower case. Add that to
|
||||
webutil.util.UrlCanonicalizer?
|
||||
:class:`util.UrlCanonicalizer`?
|
||||
"""
|
||||
super()._pre_put_hook()
|
||||
id = self.key.id()
|
||||
|
|
|
@ -78,10 +78,6 @@ class ATProto(User, Protocol):
|
|||
def web_url(self):
|
||||
return bluesky.Bluesky.user_url(self.handle_or_id())
|
||||
|
||||
def ap_address(self):
|
||||
"""Returns this user's AP address, eg '@handle.com@bsky.brid.gy'."""
|
||||
return f'@{self.handle_or_id()}@{self.ABBREV}{common.SUPERDOMAIN}'
|
||||
|
||||
@classmethod
|
||||
def owns_id(cls, id):
|
||||
return (id.startswith('at://')
|
||||
|
|
|
@ -396,12 +396,11 @@ class User(StringIdModel, metaclass=ProtocolUserMeta):
|
|||
def ap_address(self):
|
||||
"""Returns this user's ActivityPub address, eg '@me@foo.com'.
|
||||
|
||||
To be implemented by subclasses.
|
||||
|
||||
Returns:
|
||||
str
|
||||
"""
|
||||
raise NotImplementedError()
|
||||
# TODO: use self.handle_as? need it to fall back to id?
|
||||
return f'@{self.handle_or_id()}@{self.ABBREV}{common.SUPERDOMAIN}'
|
||||
|
||||
def ap_actor(self, rest=None):
|
||||
"""Returns this user's ActivityPub/AS2 actor id.
|
||||
|
|
|
@ -1786,7 +1786,7 @@ http://this/404s
|
|||
self.assertEqual('@baz@user.com', g.user.ap_address())
|
||||
|
||||
g.user.direct = False
|
||||
self.assertEqual('@user.com@localhost', g.user.ap_address())
|
||||
self.assertEqual('@user.com@web.brid.gy', g.user.ap_address())
|
||||
|
||||
def test_ap_actor(self, *_):
|
||||
self.assertEqual('http://localhost/user.com', g.user.ap_actor())
|
||||
|
|
|
@ -81,7 +81,7 @@ WEBFINGER_NO_HCARD = {
|
|||
}],
|
||||
}
|
||||
WEBFINGER_FAKE = {
|
||||
'subject': 'acct:fake:user@fake',
|
||||
'subject': 'acct:fake:handle:user@fa.brid.gy',
|
||||
'aliases': ['fake:user'],
|
||||
'links': [{
|
||||
'rel': 'canonical_uri',
|
||||
|
@ -162,7 +162,7 @@ class WebfingerTest(TestCase):
|
|||
|
||||
def test_user_infer_protocol_from_resource_subdomain(self):
|
||||
got = self.client.get(
|
||||
'/.well-known/webfinger?resource=acct:fake:user@fake.brid.gy',
|
||||
'/.well-known/webfinger?resource=acct:fake:handle:user@fake.brid.gy',
|
||||
headers={'Accept': 'application/json'})
|
||||
self.assertEqual(200, got.status_code)
|
||||
self.assertEqual('application/jrd+json', got.headers['Content-Type'])
|
||||
|
@ -180,7 +180,7 @@ class WebfingerTest(TestCase):
|
|||
|
||||
def test_user_infer_protocol_resource_overrides_request(self):
|
||||
got = self.client.get(
|
||||
'/.well-known/webfinger?resource=acct:fake:user@fake.brid.gy',
|
||||
'/.well-known/webfinger?resource=acct:fake:handle:user@fake.brid.gy',
|
||||
base_url='https://ap.brid.gy/',
|
||||
headers={'Accept': 'application/json'})
|
||||
self.assertEqual(200, got.status_code)
|
||||
|
@ -276,7 +276,7 @@ class WebfingerTest(TestCase):
|
|||
mock_get.return_value = requests_response(test_web.ACTOR_HTML)
|
||||
|
||||
expected = copy.deepcopy(WEBFINGER_NO_HCARD)
|
||||
expected['subject'] = 'acct:user.com@localhost'
|
||||
expected['subject'] = 'acct:user.com@web.brid.gy'
|
||||
|
||||
got = self.client.get('/.well-known/webfinger?resource=acct:user.com@fed.brid.gy',
|
||||
headers={'Accept': 'application/json'})
|
||||
|
|
|
@ -76,9 +76,6 @@ class Fake(User, protocol.Protocol):
|
|||
def web_url(self):
|
||||
return self.key.id()
|
||||
|
||||
def ap_address(self):
|
||||
return f'@{self.key.id()}@fake'
|
||||
|
||||
@classmethod
|
||||
def owns_id(cls, id):
|
||||
if id.startswith('nope') or id == 'fake:nope':
|
||||
|
|
4
web.py
4
web.py
|
@ -114,8 +114,8 @@ class Web(User, Protocol):
|
|||
"""
|
||||
if self.direct:
|
||||
return f'@{self.username()}@{self.key.id()}'
|
||||
else:
|
||||
return f'@{self.key.id()}@{request.host}'
|
||||
|
||||
return super().ap_address()
|
||||
|
||||
def ap_actor(self, rest=None):
|
||||
"""Returns this user's ActivityPub/AS2 actor id.
|
||||
|
|
Ładowanie…
Reference in New Issue