|
9 | 9 | import io
|
10 | 10 | import tempfile
|
11 | 11 | from test import support
|
| 12 | +from test.support import import_helper |
12 | 13 | from test.support import os_helper
|
13 | 14 | from test.support import refleak_helper
|
14 | 15 | from test.support import socket_helper
|
@@ -1081,6 +1082,47 @@ def test_permissions_after_flush(self):
|
1081 | 1082 |
|
1082 | 1083 | self.assertEqual(os.stat(self._path).st_mode, mode)
|
1083 | 1084 |
|
| 1085 | + @unittest.skipUnless(hasattr(os, 'chown'), 'requires os.chown') |
| 1086 | + def test_ownership_after_flush(self): |
| 1087 | + # See issue gh-117467 |
| 1088 | + |
| 1089 | + pwd = import_helper.import_module('pwd') |
| 1090 | + grp = import_helper.import_module('grp') |
| 1091 | + st = os.stat(self._path) |
| 1092 | + |
| 1093 | + for e in pwd.getpwall(): |
| 1094 | + if e.pw_uid != st.st_uid: |
| 1095 | + other_uid = e.pw_uid |
| 1096 | + break |
| 1097 | + else: |
| 1098 | + self.skipTest("test needs more than one user") |
| 1099 | + |
| 1100 | + for e in grp.getgrall(): |
| 1101 | + if e.gr_gid != st.st_gid: |
| 1102 | + other_gid = e.gr_gid |
| 1103 | + break |
| 1104 | + else: |
| 1105 | + self.skipTest("test needs more than one group") |
| 1106 | + |
| 1107 | + try: |
| 1108 | + os.chown(self._path, other_uid, other_gid) |
| 1109 | + except OSError: |
| 1110 | + self.skipTest('test needs root privilege') |
| 1111 | + # Change permissions as in test_permissions_after_flush. |
| 1112 | + mode = st.st_mode | 0o666 |
| 1113 | + os.chmod(self._path, mode) |
| 1114 | + |
| 1115 | + self._box.add(self._template % 0) |
| 1116 | + i = self._box.add(self._template % 1) |
| 1117 | + # Need to remove one message to make flush() create a new file |
| 1118 | + self._box.remove(i) |
| 1119 | + self._box.flush() |
| 1120 | + |
| 1121 | + st = os.stat(self._path) |
| 1122 | + self.assertEqual(st.st_uid, other_uid) |
| 1123 | + self.assertEqual(st.st_gid, other_gid) |
| 1124 | + self.assertEqual(st.st_mode, mode) |
| 1125 | + |
1084 | 1126 |
|
1085 | 1127 | class _TestMboxMMDF(_TestSingleFile):
|
1086 | 1128 |
|
|
0 commit comments