kopia lustrzana https://github.com/snarfed/bridgy-fed
webfinger: handle users without handles
fixes https://console.cloud.google.com/errors/detail/CJ7P7OGD5oz_Dw;time=P30D?project=bridgy-federatedpull/741/head
rodzic
d538928fe6
commit
d0f7264db7
|
@ -306,6 +306,15 @@ class WebfingerTest(TestCase):
|
|||
base_url='https://web.brid.gy/')
|
||||
self.assertEqual(400, got.status_code, got.get_data(as_text=True))
|
||||
|
||||
def test_no_handle(self):
|
||||
class NoHandle(Fake):
|
||||
ABBREV = 'noh'
|
||||
handle = None
|
||||
|
||||
got = self.client.get(
|
||||
'/.well-known/webfinger?resource=acct:nohandle:user@noh.brid.gy')
|
||||
self.assertEqual(404, got.status_code)
|
||||
|
||||
@patch('requests.get')
|
||||
def test_create_user(self, mock_get):
|
||||
self.user.key.delete()
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
import logging
|
||||
from urllib.parse import urljoin, urlparse
|
||||
|
||||
from flask import g, redirect, render_template, request
|
||||
from flask import g, render_template, request
|
||||
from granary import as2
|
||||
from oauth_dropins.webutil import flask_util, util
|
||||
from oauth_dropins.webutil.flask_util import error, flash, Found
|
||||
|
@ -90,6 +90,10 @@ class Webfinger(flask_util.XrdOrJrd):
|
|||
if not user:
|
||||
error(f'No {cls.LABEL} user found for {id}', status=404)
|
||||
|
||||
ap_handle = user.handle_as('activitypub')
|
||||
if not ap_handle:
|
||||
error(f'{cls.LABEL} user {id} has no handle', status=404)
|
||||
|
||||
# backward compatibility for initial Web users whose AP actor ids are on
|
||||
# fed.brid.gy, not web.brid.gy
|
||||
subdomain = request.host.split('.')[0]
|
||||
|
@ -111,7 +115,7 @@ class Webfinger(flask_util.XrdOrJrd):
|
|||
# generate webfinger content
|
||||
actor_id = user.id_as(activitypub.ActivityPub)
|
||||
data = util.trim_nulls({
|
||||
'subject': 'acct:' + user.handle_as('activitypub').lstrip('@'),
|
||||
'subject': 'acct:' + ap_handle.lstrip('@'),
|
||||
'aliases': urls,
|
||||
'links':
|
||||
[{
|
||||
|
|
Ładowanie…
Reference in New Issue