kopia lustrzana https://github.com/snarfed/bridgy-fed
rodzic
371a92a5db
commit
4a55739b91
|
@ -93,7 +93,8 @@ DOMAINS = (PRIMARY_DOMAIN,) + OTHER_DOMAINS
|
|||
|
||||
|
||||
def not_5xx(resp):
|
||||
return isinstance(resp, tuple) and resp[1] // 100 != 5
|
||||
return (isinstance(resp, tuple) and len(resp) > 1 and util.is_int(resp[1]) and
|
||||
resp[1] // 100 != 5)
|
||||
|
||||
|
||||
def requests_get(url, **kwargs):
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
# coding=utf-8
|
||||
"""Unit tests for models.py."""
|
||||
from app import app
|
||||
from models import MagicKey, Response
|
||||
from . import testutil
|
||||
|
||||
|
@ -52,9 +53,10 @@ class ResponseTest(testutil.TestCase):
|
|||
self.assertEqual('abc__1 xyz__Z', resp.key.id())
|
||||
|
||||
def test_proxy_url(self):
|
||||
resp = Response.get_or_create('abc', 'xyz')
|
||||
self.assertIsNone(resp.proxy_url(self.handler))
|
||||
with app.test_request_context('/'):
|
||||
resp = Response.get_or_create('abc', 'xyz')
|
||||
self.assertIsNone(resp.proxy_url())
|
||||
|
||||
resp.source_as2 = 'as2'
|
||||
self.assertEqual('http://localhost/render?source=abc&target=xyz',
|
||||
resp.proxy_url(self.handler))
|
||||
resp.source_as2 = 'as2'
|
||||
self.assertEqual('http://localhost/render?source=abc&target=xyz',
|
||||
resp.proxy_url())
|
||||
|
|
|
@ -94,8 +94,7 @@ class WebfingerTest(testutil.TestCase):
|
|||
def test_host_meta_handler_xrds(self):
|
||||
got = client.get('/.well-known/host-meta.xrds')
|
||||
self.assertEqual(200, got.status_code)
|
||||
self.assertEqual('application/xrds+xml; charset=utf-8',
|
||||
got.headers['Content-Type'])
|
||||
self.assertEqual('application/xrds+xml', got.headers['Content-Type'])
|
||||
body = got.get_data(as_text=True)
|
||||
self.assertTrue(body.startswith('<XRDS'), body)
|
||||
|
||||
|
|
24
webfinger.py
24
webfinger.py
|
@ -174,5 +174,29 @@ class Webfinger(User):
|
|||
return super().template_vars(domain=domain, url=url)
|
||||
|
||||
|
||||
class HostMeta(common.XrdOrJrd):
|
||||
"""Renders and serves the /.well-known/host-meta file.
|
||||
|
||||
Supports both JRD and XRD; defaults to XRD.
|
||||
https://tools.ietf.org/html/rfc6415#section-3
|
||||
"""
|
||||
DEFAULT_TYPE = common.XrdOrJrd.XRD
|
||||
|
||||
def template_prefix(self):
|
||||
return 'host-meta'
|
||||
|
||||
def template_vars(self):
|
||||
return {'host_uri': request.host_url}
|
||||
|
||||
|
||||
@app.get('/.well-known/host-meta.xrds')
|
||||
def host_meta_xrds():
|
||||
"""Renders and serves the /.well-known/host-meta.xrds XRDS-Simple file."""
|
||||
return (render_template('host-meta.xrds', host_uri=request.host_url),
|
||||
{'Content-Type': 'application/xrds+xml'})
|
||||
|
||||
|
||||
app.add_url_rule('/acct:<domain>', view_func=User.as_view('user'))
|
||||
app.add_url_rule('/.well-known/webfinger', view_func=Webfinger.as_view('webfinger'))
|
||||
app.add_url_rule('/.well-known/host-meta', view_func=HostMeta.as_view('hostmeta'))
|
||||
app.add_url_rule('/.well-known/host-meta.json', view_func=HostMeta.as_view('hostmeta-json'))
|
||||
|
|
Ładowanie…
Reference in New Issue