def test_quote_with_shell(self): "Test shell quoting with a real shell" if os.name != 'posix': return from subprocess import PIPE, Popen workdir = tempfile.mkdtemp() try: s = "'\\\"; touch %s/foo #'" % workdir cmd = 'echo %s' % gnupg.shell_quote(s) p = Popen(cmd, shell=True, stdout=PIPE, stderr=PIPE) p.communicate() self.assertEqual(p.returncode, 0) files = os.listdir(workdir) self.assertEqual(files, []) fn = "'ab?'" cmd = 'touch %s/%s' % (workdir, gnupg.shell_quote(fn)) p = Popen(cmd, shell=True, stdout=PIPE, stderr=PIPE) p.communicate() self.assertEqual(p.returncode, 0) files = os.listdir(workdir) self.assertEqual(files, ["'ab?'"]) finally: shutil.rmtree(workdir, ignore_errors=True)
def test_quote_with_shell(self): "Test shell quoting with a real shell" if os.name != 'posix': return from subprocess import PIPE, Popen workdir = tempfile.mkdtemp() try: s = "'\\\"; touch %s/foo #'" % workdir cmd = 'echo %s' % gnupg.shell_quote(s) p = Popen(cmd, shell=True, stdout=PIPE, stderr=PIPE) p.communicate() self.assertEqual(p.returncode, 0) files = os.listdir(workdir) self.assertEqual(files, []) fn = "'ab?'" cmd = 'touch %s/%s' % (workdir, gnupg.shell_quote(fn)) p = Popen(cmd, shell=True, stdout=PIPE, stderr=PIPE) p.communicate() self.assertEqual(p.returncode, 0) files = os.listdir(workdir) self.assertEqual(files, ["'ab?'"]) finally: shutil.rmtree(workdir)