kopia lustrzana https://github.com/snarfed/bridgy-fed
/convert: handle missing protocols
fixes https://console.cloud.google.com/errors/detail/CLHg5u_DuYGWaw;time=P30D?project=bridgy-federatedpull/781/head
rodzic
4572f7b111
commit
178b5ccde3
10
convert.py
10
convert.py
|
@ -35,8 +35,10 @@ def convert(dest, _, src=None):
|
|||
:func:`convert_source_path_redirect`
|
||||
"""
|
||||
if src:
|
||||
src_cls = PROTOCOLS.get(src)
|
||||
if not src_cls:
|
||||
error(f'No protocol found for {src}', status=404)
|
||||
logger.info(f'Overriding any domain protocol with {src}')
|
||||
src_cls = PROTOCOLS[src]
|
||||
else:
|
||||
src_cls = Protocol.for_request(fed=Protocol)
|
||||
if not src_cls:
|
||||
|
@ -108,4 +110,8 @@ def convert_source_path_redirect(src, dest, _):
|
|||
request.url = request.url.replace(f'/{src}/', '/')
|
||||
return convert(dest, None, src)
|
||||
|
||||
return redirect(subdomain_wrap(PROTOCOLS[src], new_path), code=301)
|
||||
proto = PROTOCOLS.get(src)
|
||||
if not proto:
|
||||
error(f'No protocol found for {src}', status=404)
|
||||
|
||||
return redirect(subdomain_wrap(proto, new_path), code=301)
|
||||
|
|
|
@ -330,3 +330,10 @@ A ☕ reply
|
|||
self.assert_multiline_equals(HTML, resp.get_data(as_text=True),
|
||||
ignore_blanks=True)
|
||||
|
||||
def test_missing_protocols(self):
|
||||
resp = self.client.get('/convert/https:/user.com/post')
|
||||
self.assertEqual(404, resp.status_code)
|
||||
|
||||
resp = self.client.get('/convert/https:/user.com/post',
|
||||
base_url='https://fed.brid.gy/')
|
||||
self.assertEqual(404, resp.status_code)
|
||||
|
|
Ładowanie…
Reference in New Issue