From a5cb979814d962ee9a5d89a0a2528d97b49f771f Mon Sep 17 00:00:00 2001 From: Joshua Anderson Date: Fri, 5 Aug 2016 09:34:54 -0700 Subject: [PATCH] fix(run): return a 400 if command is empty --- rootfs/api/tests/test_app.py | 7 ++++++- rootfs/api/views.py | 2 ++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/rootfs/api/tests/test_app.py b/rootfs/api/tests/test_app.py index 433c01f72..13809ffb8 100644 --- a/rootfs/api/tests/test_app.py +++ b/rootfs/api/tests/test_app.py @@ -250,8 +250,13 @@ def test_run(self, mock_requests): response = self.client.post(url, body) self.assertEqual(response.status_code, 201, response.data) - # run command + # cannot run command without body url = '/v2/apps/{}/run'.format(app_id) + response = self.client.post(url, {}) + self.assertEqual(response.status_code, 400, response.data) + self.assertEqual(response.data, {'detail': 'command is a required field'}) + + # run command body = {'command': 'ls -al'} response = self.client.post(url, body) self.assertEqual(response.status_code, 200, response.data) diff --git a/rootfs/api/views.py b/rootfs/api/views.py index 40af758c8..0e0651f72 100644 --- a/rootfs/api/views.py +++ b/rootfs/api/views.py @@ -227,6 +227,8 @@ def logs(self, request, **kwargs): def run(self, request, **kwargs): app = self.get_object() + if not request.data.get('command'): + raise DeisException("command is a required field") rc, output = app.run(self.request.user, request.data['command']) return Response({'exit_code': rc, 'output': str(output)})