kopia lustrzana https://github.com/snarfed/bridgy-fed
salmon: return 400 on bad XML
also handle URL path with just domain, e.g. /snarfed.org/salmonpull/27/head
rodzic
ad01716fda
commit
02f1e67cf9
|
@ -4,6 +4,7 @@ https://github.com/salmon-protocol/salmon-protocol/blob/master/draft-panzer-salm
|
|||
https://github.com/salmon-protocol/salmon-protocol/blob/master/draft-panzer-magicsig-01.html
|
||||
"""
|
||||
import logging
|
||||
from xml.etree.ElementTree import ParseError
|
||||
|
||||
import appengine_config
|
||||
|
||||
|
@ -26,7 +27,10 @@ class SlapHandler(webapp2.RequestHandler):
|
|||
def post(self, username, domain):
|
||||
logging.info('Got: %s', self.request.body)
|
||||
|
||||
parsed = utils.parse_magic_envelope(self.request.body)
|
||||
try:
|
||||
parsed = utils.parse_magic_envelope(self.request.body)
|
||||
except ParseError as e:
|
||||
common.error(self, 'Could not parse POST body as XML: %s' % e)
|
||||
data = utils.decode(parsed['data'])
|
||||
logging.info('Decoded: %s', data)
|
||||
|
||||
|
@ -57,4 +61,5 @@ class SlapHandler(webapp2.RequestHandler):
|
|||
|
||||
app = webapp2.WSGIApplication([
|
||||
(r'/%s/salmon' % common.ACCT_RE, SlapHandler),
|
||||
(r'/()%s/salmon' % common.DOMAIN_RE, SlapHandler),
|
||||
], debug=appengine_config.DEBUG)
|
||||
|
|
|
@ -130,3 +130,8 @@ class SalmonTest(testutil.TestCase):
|
|||
self.assertEqual('ostatus', resp.protocol)
|
||||
self.assertEqual('complete', resp.status)
|
||||
self.assertEqual(atom_like, resp.source_atom)
|
||||
|
||||
def test_bad_xml(self, mock_urlopen, mock_get, mock_post):
|
||||
got = app.get_response('/foo.com/salmon', method='POST',
|
||||
body='not xml'.encode('utf-8'))
|
||||
self.assertEquals(400, got.status_int)
|
||||
|
|
Ładowanie…
Reference in New Issue