Download:
child 222:e02db9d564fb
parent 220:5379500bba11
221:e9237bf3d48e
Anton Shestakov <av6@dwimlabs.net>, Wed, 24 Aug 2016 19:29:28 +0800
queue: handle invalid JSON payload by raising HTTPError(400)

1 файлов изменено, 9 вставок(+), 3 удалений(-) [+]
hooks-queue.py file | annotate | diff | comparison | revisions
--- a/hooks-queue.py Wed Aug 24 12:13:29 2016 +0800
+++ b/hooks-queue.py Wed Aug 24 19:29:28 2016 +0800
@@ -7,7 +7,7 @@
import yaml
from tornado.ioloop import IOLoop
from tornado.options import define, options
-from tornado.web import Application, RequestHandler, URLSpec
+from tornado.web import Application, HTTPError, RequestHandler, URLSpec
from candolint.utils import lookup_option, timestamp
@@ -23,6 +23,12 @@
def rconn(self):
return self.application.rconn
+ def parse_json_payload(self):
+ try:
+ return json.loads(self.request.body)
+ except ValueError:
+ raise HTTPError(400, 'malformed JSON')
+
def push(self, base, changes):
for change in changes:
item = base.copy()
@@ -37,7 +43,7 @@
class BitbucketHookHandler(BaseHookHandler):
def post(self):
- payload = json.loads(self.request.body)
+ payload = self.parse_json_payload()
base = {
'url': payload['repository']['links']['html']['href'],
'scm': payload['repository']['scm'],
@@ -69,7 +75,7 @@
self.finish({'result': 'pong'})
def handle_push(self):
- payload = json.loads(self.request.body)
+ payload = self.parse_json_payload()
base = {
'url': payload['repository']['html_url'],
'scm': 'git',