Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(3945)

Side by Side Diff: Lib/test/test_os.py

Issue 13703: Hash collision security issue
Patch Set: Created 1 year, 3 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « Lib/test/test_hash.py ('k') | Lib/test/test_sys.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # As a test suite for the os module, this is woefully inadequate, but this 1 # As a test suite for the os module, this is woefully inadequate, but this
2 # does add tests for a few functions which have been determined to be more 2 # does add tests for a few functions which have been determined to be more
3 # portable than they had been thought to be. 3 # portable than they had been thought to be.
4 4
5 import os 5 import os
6 import errno 6 import errno
7 import unittest 7 import unittest
8 import warnings 8 import warnings
9 import sys 9 import sys
10 import shutil 10 import shutil
11 from test import support 11 from test import support
12 from test.script_helper import assert_python_ok
12 13
13 # Detect whether we're on a Linux system that uses the (now outdated 14 # Detect whether we're on a Linux system that uses the (now outdated
14 # and unmaintained) linuxthreads threading library. There's an issue 15 # and unmaintained) linuxthreads threading library. There's an issue
15 # when combining linuxthreads with a failed execv call: see 16 # when combining linuxthreads with a failed execv call: see
16 # http://bugs.python.org/issue4970. 17 # http://bugs.python.org/issue4970.
17 if (hasattr(os, "confstr_names") and 18 if (hasattr(os, "confstr_names") and
18 "CS_GNU_LIBPTHREAD_VERSION" in os.confstr_names): 19 "CS_GNU_LIBPTHREAD_VERSION" in os.confstr_names):
19 libpthread = os.confstr("CS_GNU_LIBPTHREAD_VERSION") 20 libpthread = os.confstr("CS_GNU_LIBPTHREAD_VERSION")
20 USING_LINUXTHREADS= libpthread.startswith("linuxthreads") 21 USING_LINUXTHREADS= libpthread.startswith("linuxthreads")
21 else: 22 else:
(...skipping 545 matching lines...) Expand 10 before | Expand all | Expand 10 after
567 class DevNullTests(unittest.TestCase): 568 class DevNullTests(unittest.TestCase):
568 def test_devnull(self): 569 def test_devnull(self):
569 f = open(os.devnull, 'w') 570 f = open(os.devnull, 'w')
570 f.write('hello') 571 f.write('hello')
571 f.close() 572 f.close()
572 f = open(os.devnull, 'r') 573 f = open(os.devnull, 'r')
573 self.assertEqual(f.read(), '') 574 self.assertEqual(f.read(), '')
574 f.close() 575 f.close()
575 576
576 class URandomTests(unittest.TestCase): 577 class URandomTests(unittest.TestCase):
577 def test_urandom(self): 578 def test_urandom_length(self):
578 try: 579 self.assertEqual(len(os.urandom(0)), 0)
579 self.assertEqual(len(os.urandom(1)), 1) 580 self.assertEqual(len(os.urandom(1)), 1)
580 self.assertEqual(len(os.urandom(10)), 10) 581 self.assertEqual(len(os.urandom(10)), 10)
581 self.assertEqual(len(os.urandom(100)), 100) 582 self.assertEqual(len(os.urandom(100)), 100)
582 self.assertEqual(len(os.urandom(1000)), 1000) 583 self.assertEqual(len(os.urandom(1000)), 1000)
583 except NotImplementedError: 584
584 pass 585 def test_urandom_value(self):
586 data1 = os.urandom(16)
587 data2 = os.urandom(16)
588 self.assertNotEqual(data1, data2)
589
590 def get_urandom_subprocess(self, count):
591 code = '\n'.join((
592 'import os, sys',
593 'data = os.urandom(%s)' % count,
594 'sys.stdout.buffer.write(data)',
595 'sys.stdout.buffer.flush()'))
596 out = assert_python_ok('-c', code)
597 stdout = out[1]
598 self.assertEqual(len(stdout), 16)
599 return stdout
600
601 def test_urandom_subprocess(self):
602 data1 = self.get_urandom_subprocess(16)
603 data2 = self.get_urandom_subprocess(16)
604 self.assertNotEqual(data1, data2)
585 605
586 class ExecTests(unittest.TestCase): 606 class ExecTests(unittest.TestCase):
587 @unittest.skipIf(USING_LINUXTHREADS, 607 @unittest.skipIf(USING_LINUXTHREADS,
588 "avoid triggering a linuxthreads bug: see issue #4970") 608 "avoid triggering a linuxthreads bug: see issue #4970")
589 def test_execvpe_with_bad_program(self): 609 def test_execvpe_with_bad_program(self):
590 self.assertRaises(OSError, os.execvpe, 'no such app-', 610 self.assertRaises(OSError, os.execvpe, 'no such app-',
591 ['no such app-'], None) 611 ['no such app-'], None)
592 612
593 def test_execvpe_with_bad_arglist(self): 613 def test_execvpe_with_bad_arglist(self):
594 self.assertRaises(ValueError, os.execvpe, 'notepad', [], None) 614 self.assertRaises(ValueError, os.execvpe, 'notepad', [], None)
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after
813 URandomTests, 833 URandomTests,
814 ExecTests, 834 ExecTests,
815 Win32ErrorTests, 835 Win32ErrorTests,
816 TestInvalidFD, 836 TestInvalidFD,
817 PosixUidGidTests, 837 PosixUidGidTests,
818 Pep383Tests 838 Pep383Tests
819 ) 839 )
820 840
821 if __name__ == "__main__": 841 if __name__ == "__main__":
822 test_main() 842 test_main()
OLDNEW
« no previous file with comments | « Lib/test/test_hash.py ('k') | Lib/test/test_sys.py » ('j') | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld cbc36f91f3f7