Bug 3228: take a test from Niels Gustaebel's patch, and based on his patch, check for having os.stat available

This commit is contained in:
Andrew M. Kuchling 2008-08-05 01:00:57 +00:00
parent 7e30b67bf4
commit 10288e19bf
1 changed files with 29 additions and 6 deletions

View File

@ -716,10 +716,32 @@ class TestMaildir(TestMailbox):
for msg in self._box:
pass
def test_file_perms(self):
def test_file_permissions(self):
# Verify that message files are created without execute permissions
if not hasattr(os, "stat") or not hasattr(os, "umask"):
return
msg = mailbox.MaildirMessage(self._template % 0)
orig_umask = os.umask(0)
try:
key = self._box.add(msg)
finally:
os.umask(orig_umask)
path = os.path.join(self._path, self._box._lookup(key))
mode = os.stat(path).st_mode
self.assert_(mode & 0111 == 0)
def test_folder_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')
if not hasattr(os, "stat") or not hasattr(os, "umask"):
return
orig_umask = os.umask(0)
try:
subfolder = self._box.add_folder('subfolder')
finally:
os.umask(orig_umask)
path = os.path.join(subfolder._path, 'maildirfolder')
st = os.stat(path)
perms = st.st_mode
@ -823,7 +845,7 @@ class TestMbox(_TestMboxMMDF):
# 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'):
if hasattr(os, 'umask') and hasattr(os, 'stat'):
try:
old_umask = os.umask(0077)
self._box.close()
@ -831,12 +853,13 @@ class TestMbox(_TestMboxMMDF):
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)
st = os.stat(self._path)
perms = st.st_mode
self.assertFalse((perms & 0111)) # Execute bits should all be off.
class TestMMDF(_TestMboxMMDF):
_factory = lambda self, path, factory=None: mailbox.MMDF(path, factory)