mirror of
https://github.com/python/cpython.git
synced 2025-08-01 15:43:13 +00:00
Bug 3228: Explicitly supply the file mode to avoid creating executable files,
and add corresponding tests. Possible 2.5 backport candidate
This commit is contained in:
parent
0879250284
commit
70a6dbd46e
2 changed files with 30 additions and 3 deletions
|
@ -716,6 +716,16 @@ class TestMaildir(TestMailbox):
|
|||
for msg in self._box:
|
||||
pass
|
||||
|
||||
def test_file_perms(self):
|
||||
# From bug #3228, we want to verify that the file created inside a Maildir
|
||||
# subfolder isn't marked as executable.
|
||||
subfolder = self._box.add_folder('subfolder')
|
||||
path = os.path.join(subfolder._path, 'maildirfolder')
|
||||
st = os.stat(path)
|
||||
perms = st.st_mode
|
||||
self.assertFalse((perms & 0111)) # Execute bits should all be off.
|
||||
|
||||
|
||||
class _TestMboxMMDF(TestMailbox):
|
||||
|
||||
def tearDown(self):
|
||||
|
@ -805,11 +815,27 @@ class _TestMboxMMDF(TestMailbox):
|
|||
self._box.close()
|
||||
|
||||
|
||||
|
||||
class TestMbox(_TestMboxMMDF):
|
||||
|
||||
_factory = lambda self, path, factory=None: mailbox.mbox(path, factory)
|
||||
|
||||
def test_file_perms(self):
|
||||
# From bug #3228, we want to verify that the mailbox file isn't executable,
|
||||
# even if the umask is set to something that would leave executable bits set.
|
||||
# We only run this test on platforms that support umask.
|
||||
if hasattr(os, 'umask'):
|
||||
try:
|
||||
old_umask = os.umask(0077)
|
||||
self._box.close()
|
||||
os.unlink(self._path)
|
||||
self._box = mailbox.mbox(self._path, create=True)
|
||||
self._box.add('')
|
||||
self._box.close()
|
||||
st = os.stat(self._path)
|
||||
perms = st.st_mode
|
||||
self.assertFalse((perms & 0111)) # Execute bits should all be off.
|
||||
finally:
|
||||
os.umask(old_umask)
|
||||
|
||||
class TestMMDF(_TestMboxMMDF):
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue