Implement JSON validation in append.

This commit is contained in:
Roberto Abdelkader Martínez Pérez
2019-08-21 08:52:13 +02:00
parent f6014ab403
commit 7a93c16dec
2 changed files with 10 additions and 2 deletions
+6 -1
View File
@@ -279,7 +279,12 @@ def append_route(app):
async def _append_route(request): async def _append_route(request):
"""Create a new Kapow! route.""" """Create a new Kapow! route."""
app.router._frozen = False app.router._frozen = False
content = await request.json()
try:
content = await request.json()
except Exception as exc:
return web.Response(status=400, reason="Malformed JSON")
name = "ROUTE_" + str(uuid4()).replace('-', '_') name = "ROUTE_" + str(uuid4()).replace('-', '_')
try: try:
app.router.add_route(content["method"], app.router.add_route(content["method"],
+4 -1
View File
@@ -170,4 +170,7 @@ def step_impl(context):
@when('I try to append with this malformed JSON document') @when('I try to append with this malformed JSON document')
@when('I try to append with this JSON document') @when('I try to append with this JSON document')
def step_impl(context): def step_impl(context):
raise NotImplementedError('STEP: When I try to append with this JSON document') context.response = requests.post(
f"{Env.KAPOW_CONTROLAPI_URL}/routes",
headers={"Content-Type": "application/json"},
data=context.text)