summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_os.py49
-rw-r--r--Lib/test/test_posix.py15
2 files changed, 64 insertions, 0 deletions
diff --git a/Lib/test/test_os.py b/Lib/test/test_os.py
index 0857561..6b30e0b 100644
--- a/Lib/test/test_os.py
+++ b/Lib/test/test_os.py
@@ -2382,6 +2382,55 @@ class SpawnTests(unittest.TestCase):
self.assertRaises(ValueError, os.spawnve, os.P_NOWAIT, args[0], ('',), {})
self.assertRaises(ValueError, os.spawnve, os.P_NOWAIT, args[0], [''], {})
+ @requires_os_func('spawnve')
+ def test_spawnve_invalid_env(self):
+ # null character in the enviroment variable name
+ args = [sys.executable, '-c', 'pass']
+ newenv = os.environ.copy()
+ newenv["FRUIT\0VEGETABLE"] = "cabbage"
+ try:
+ exitcode = os.spawnve(os.P_WAIT, args[0], args, newenv)
+ except ValueError:
+ pass
+ else:
+ self.assertEqual(exitcode, 127)
+
+ # null character in the enviroment variable value
+ args = [sys.executable, '-c', 'pass']
+ newenv = os.environ.copy()
+ newenv["FRUIT"] = "orange\0VEGETABLE=cabbage"
+ try:
+ exitcode = os.spawnve(os.P_WAIT, args[0], args, newenv)
+ except ValueError:
+ pass
+ else:
+ self.assertEqual(exitcode, 127)
+
+ # equal character in the enviroment variable name
+ args = [sys.executable, '-c', 'pass']
+ newenv = os.environ.copy()
+ newenv["FRUIT=ORANGE"] = "lemon"
+ try:
+ exitcode = os.spawnve(os.P_WAIT, args[0], args, newenv)
+ except ValueError:
+ pass
+ else:
+ self.assertEqual(exitcode, 127)
+
+ # equal character in the enviroment variable value
+ filename = support.TESTFN
+ self.addCleanup(support.unlink, filename)
+ with open(filename, "w") as fp:
+ fp.write('import sys, os\n'
+ 'if os.getenv("FRUIT") != "orange=lemon":\n'
+ ' raise AssertionError')
+ args = [sys.executable, filename]
+ newenv = os.environ.copy()
+ newenv["FRUIT"] = "orange=lemon"
+ exitcode = os.spawnve(os.P_WAIT, args[0], args, newenv)
+ self.assertEqual(exitcode, 0)
+
+
# The introduction of this TestCase caused at least two different errors on
# *nix buildbots. Temporarily skip this to let the buildbots move along.
@unittest.skip("Skip due to platform/environment differences on *NIX buildbots")
diff --git a/Lib/test/test_posix.py b/Lib/test/test_posix.py
index 412b079..aa1b0e4 100644
--- a/Lib/test/test_posix.py
+++ b/Lib/test/test_posix.py
@@ -813,6 +813,21 @@ class PosixTester(unittest.TestCase):
self.assertEqual(type(k), item_type)
self.assertEqual(type(v), item_type)
+ @unittest.skipUnless(hasattr(os, "putenv"), "requires os.putenv()")
+ def test_putenv(self):
+ with self.assertRaises(ValueError):
+ os.putenv('FRUIT\0VEGETABLE', 'cabbage')
+ with self.assertRaises(ValueError):
+ os.putenv(b'FRUIT\0VEGETABLE', b'cabbage')
+ with self.assertRaises(ValueError):
+ os.putenv('FRUIT', 'orange\0VEGETABLE=cabbage')
+ with self.assertRaises(ValueError):
+ os.putenv(b'FRUIT', b'orange\0VEGETABLE=cabbage')
+ with self.assertRaises(ValueError):
+ os.putenv('FRUIT=ORANGE', 'lemon')
+ with self.assertRaises(ValueError):
+ os.putenv(b'FRUIT=ORANGE', b'lemon')
+
@unittest.skipUnless(hasattr(posix, 'getcwd'), 'test needs posix.getcwd()')
def test_getcwd_long_pathnames(self):
dirname = 'getcwd-test-directory-0123456789abcdef-01234567890abcdef'