tests: Properly escape arguments for cli interface

This commit is contained in:
Andrew Chow 2019-05-21 19:07:36 -04:00
parent c14896c6eb
commit 70e31cad0c
3 changed files with 18 additions and 6 deletions

View File

@ -3,6 +3,7 @@
import atexit import atexit
import json import json
import os import os
import shlex
import shutil import shutil
import subprocess import subprocess
import tempfile import tempfile
@ -79,12 +80,15 @@ class DeviceTestCase(unittest.TestCase):
return suite return suite
def do_command(self, args): def do_command(self, args):
cli_args = []
for arg in args:
cli_args.append(shlex.quote(arg))
if self.interface == 'cli': if self.interface == 'cli':
proc = subprocess.Popen(['hwi ' + ' '.join(args)], stdout=subprocess.PIPE, stderr=subprocess.DEVNULL, shell=True) proc = subprocess.Popen(['hwi ' + ' '.join(cli_args)], stdout=subprocess.PIPE, shell=True)
result = proc.communicate() result = proc.communicate()
return json.loads(result[0].decode()) return json.loads(result[0].decode())
elif self.interface == 'bindist': elif self.interface == 'bindist':
proc = subprocess.Popen(['../dist/hwi ' + ' '.join(args)], stdout=subprocess.PIPE, stderr=subprocess.DEVNULL, shell=True) proc = subprocess.Popen(['../dist/hwi ' + ' '.join(cli_args)], stdout=subprocess.PIPE, stderr=subprocess.DEVNULL, shell=True)
result = proc.communicate() result = proc.communicate()
return json.loads(result[0].decode()) return json.loads(result[0].decode())
elif self.interface == 'stdin': elif self.interface == 'stdin':

View File

@ -4,6 +4,7 @@ import argparse
import atexit import atexit
import json import json
import os import os
import shlex
import socket import socket
import subprocess import subprocess
import sys import sys
@ -82,12 +83,15 @@ class KeepkeyTestCase(unittest.TestCase):
return suite return suite
def do_command(self, args): def do_command(self, args):
cli_args = []
for arg in args:
cli_args.append(shlex.quote(arg))
if self.interface == 'cli': if self.interface == 'cli':
proc = subprocess.Popen(['hwi ' + ' '.join(args)], stdout=subprocess.PIPE, stderr=subprocess.DEVNULL, shell=True) proc = subprocess.Popen(['hwi ' + ' '.join(cli_args)], stdout=subprocess.PIPE, stderr=subprocess.DEVNULL, shell=True)
result = proc.communicate() result = proc.communicate()
return json.loads(result[0].decode()) return json.loads(result[0].decode())
elif self.interface == 'bindist': elif self.interface == 'bindist':
proc = subprocess.Popen(['../dist/hwi ' + ' '.join(args)], stdout=subprocess.PIPE, stderr=subprocess.DEVNULL, shell=True) proc = subprocess.Popen(['../dist/hwi ' + ' '.join(cli_args)], stdout=subprocess.PIPE, stderr=subprocess.DEVNULL, shell=True)
result = proc.communicate() result = proc.communicate()
return json.loads(result[0].decode()) return json.loads(result[0].decode())
elif self.interface == 'stdin': elif self.interface == 'stdin':

View File

@ -4,6 +4,7 @@ import argparse
import atexit import atexit
import json import json
import os import os
import shlex
import socket import socket
import subprocess import subprocess
import sys import sys
@ -82,12 +83,15 @@ class TrezorTestCase(unittest.TestCase):
return suite return suite
def do_command(self, args): def do_command(self, args):
cli_args = []
for arg in args:
cli_args.append(shlex.quote(arg))
if self.interface == 'cli': if self.interface == 'cli':
proc = subprocess.Popen(['hwi ' + ' '.join(args)], stdout=subprocess.PIPE, stderr=subprocess.DEVNULL, shell=True) proc = subprocess.Popen(['hwi ' + ' '.join(cli_args)], stdout=subprocess.PIPE, stderr=subprocess.DEVNULL, shell=True)
result = proc.communicate() result = proc.communicate()
return json.loads(result[0].decode()) return json.loads(result[0].decode())
elif self.interface == 'bindist': elif self.interface == 'bindist':
proc = subprocess.Popen(['../dist/hwi ' + ' '.join(args)], stdout=subprocess.PIPE, stderr=subprocess.DEVNULL, shell=True) proc = subprocess.Popen(['../dist/hwi ' + ' '.join(cli_args)], stdout=subprocess.PIPE, stderr=subprocess.DEVNULL, shell=True)
result = proc.communicate() result = proc.communicate()
return json.loads(result[0].decode()) return json.loads(result[0].decode())
elif self.interface == 'stdin': elif self.interface == 'stdin':