You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
fail2ban/fail2ban-tests.patch

42 lines
1.4 KiB

commit b2a1032f5738575f1c368360ba93fc7da5991225
Author: Yaroslav Halchenko <debian@onerussian.com>
Date: Tue Aug 12 11:31:42 2014 -0400
ENH/BF(TST): making permissions restrictive is not sufficient -- really remove file to test
diff --git a/fail2ban/tests/filtertestcase.py b/fail2ban/tests/filtertestcase.py
index c02e861..1fa3116 100644
--- a/fail2ban/tests/filtertestcase.py
+++ b/fail2ban/tests/filtertestcase.py
@@ -24,6 +24,7 @@ __license__ = "GPL"
from __builtin__ import open as fopen
import unittest
+import getpass
import os
import sys
import time
@@ -349,10 +350,20 @@ class LogFileMonitor(LogCaptureTestCase):
# shorter wait time for not modified status
return not self.isModified(0.4)
- def testNoLogFile(self):
+ def testUnaccessibleLogFile(self):
os.chmod(self.name, 0)
self.filter.getFailures(self.name)
- self.assertTrue(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'
+ # If ran as root, those restrictive permissions would not
+ # forbid log to be read.
+ self.assertTrue(failure_was_logged != is_root)
+
+ def testNoLogFile(self):
+ _killfile(self.file, self.name)
+ self.filter.getFailures(self.name)
+ failure_was_logged = self._is_logged('Unable to open %s' % self.name)
+ self.assertTrue(failure_was_logged)
def testRemovingFailRegex(self):
self.filter.delFailRegex(0)