Skip to content

Commit 7da5212

Browse files
fix(run): return a 400 if command is empty (#952)
1 parent 4909684 commit 7da5212

2 files changed

Lines changed: 8 additions & 1 deletion

File tree

rootfs/api/tests/test_app.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,8 +250,13 @@ def test_run(self, mock_requests):
250250
response = self.client.post(url, body)
251251
self.assertEqual(response.status_code, 201, response.data)
252252

253-
# run command
253+
# cannot run command without body
254254
url = '/v2/apps/{}/run'.format(app_id)
255+
response = self.client.post(url, {})
256+
self.assertEqual(response.status_code, 400, response.data)
257+
self.assertEqual(response.data, {'detail': 'command is a required field'})
258+
259+
# run command
255260
body = {'command': 'ls -al'}
256261
response = self.client.post(url, body)
257262
self.assertEqual(response.status_code, 200, response.data)

rootfs/api/views.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,8 @@ def logs(self, request, **kwargs):
227227

228228
def run(self, request, **kwargs):
229229
app = self.get_object()
230+
if not request.data.get('command'):
231+
raise DeisException("command is a required field")
230232
rc, output = app.run(self.request.user, request.data['command'])
231233
return Response({'exit_code': rc, 'output': str(output)})
232234

0 commit comments

Comments
 (0)