BF: RF test for "being a root" to check if actually can read the file

pull/2025/head
Yaroslav Halchenko 7 years ago committed by sebres
parent 49be8de902
commit a5b9128fcc

@ -675,7 +675,15 @@ class LogFileMonitor(LogCaptureTestCase):
os.chmod(self.name, 0) os.chmod(self.name, 0)
self.filter.getFailures(self.name) self.filter.getFailures(self.name)
failure_was_logged = self._is_logged('Unable to open %s' % self.name) failure_was_logged = self._is_logged('Unable to open %s' % self.name)
is_root = getpass.getuser() == 'root' # verify that we cannot access the file. Checking by name of user is not
# sufficient since could be a fakeroot or some other super-user
try:
with open(self.name) as f:
f.read()
is_root = True
except IOError:
is_root = False
# If ran as root, those restrictive permissions would not # If ran as root, those restrictive permissions would not
# forbid log to be read. # forbid log to be read.
self.assertTrue(failure_was_logged != is_root) self.assertTrue(failure_was_logged != is_root)

Loading…
Cancel
Save