Fix /shell/run commands splitting

This patch splits shell commands either with ';' or '\n'.
more_events
Roberto Hueso Gómez 2020-01-20 12:47:35 +01:00 committed by Alvaro Neira Ayuso
parent 96c2ddea2d
commit 9890d60300
3 changed files with 3 additions and 3 deletions

View File

@ -49,7 +49,7 @@ def reboot():
def execCMD(request, ogRest):
cmd = request.getrun()
cmds = cmd.split(" ")
cmds = cmd.split(";|\n")
try:
ogRest.proc = subprocess.Popen(cmds, stdout=subprocess.PIPE, shell=True)
(output, error) = ogRest.proc.communicate()

View File

@ -62,7 +62,7 @@ class restResponse():
class ogThread():
def execcmd(client, request, ogRest):
if request.getrun() == None:
if not request.getrun():
response = restResponse(ogResponses.BAD_REQUEST)
client.send(response.get())
return

View File

@ -14,7 +14,7 @@ class TestShellRunMethods(unittest.TestCase):
def test_post_with_echo(self):
req_json = '{"run":"echo \\"croqueta\\"", "echo":true}'
response_json = '{"out": "\\"croqueta\\"\\n"}'
response_json = '{"out": \"croqueta\\n\"}'
req = 'POST /shell/run HTTP/1.0\r\nContent-Length:'+ \
str(len(req_json)) + \
'\r\nContent-Type:application/json\r\n\r\n' + req_json