From a208b11796e07fe86aba4397028a0de36e2638ca Mon Sep 17 00:00:00 2001 From: sebres Date: Wed, 25 Apr 2018 19:06:03 +0200 Subject: [PATCH] added log message if ignored by `ignoreself` rule (similar to both other rules `ignoreip` and `ignorecommand`), and test covered now; --- fail2ban/server/filter.py | 1 + fail2ban/tests/filtertestcase.py | 10 +++++++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/fail2ban/server/filter.py b/fail2ban/server/filter.py index f86d9613..bac1ba53 100644 --- a/fail2ban/server/filter.py +++ b/fail2ban/server/filter.py @@ -496,6 +496,7 @@ class Filter(JailThread): # check own IPs should be ignored and 'ip' is self IP: if self.__ignoreSelf and ip in DNSUtils.getSelfIPs(): + self.logIgnoreIp(ip, log_ignore, ignore_source="ignoreself rule") return True for net in self.__ignoreIpList: diff --git a/fail2ban/tests/filtertestcase.py b/fail2ban/tests/filtertestcase.py index 253ae111..bf1bf84d 100644 --- a/fail2ban/tests/filtertestcase.py +++ b/fail2ban/tests/filtertestcase.py @@ -336,17 +336,21 @@ class IgnoreIP(LogCaptureTestCase): ipList = ("127.0.0.1",) # test ignoreSelf is false: for ip in ipList: - self.assertFalse(self.filter.inIgnoreIPList(ip)) + self.assertFalse(self.filter.inIgnoreIPList(ip, log_ignore=True)) + self.assertNotLogged("[%s] Ignore %s by %s" % (self.jail.name, ip, "ignoreself rule")) # test ignoreSelf with true: self.filter.ignoreSelf = True + self.pruneLog() for ip in ipList: - self.assertTrue(self.filter.inIgnoreIPList(ip)) + self.assertTrue(self.filter.inIgnoreIPList(ip, log_ignore=True)) + self.assertLogged("[%s] Ignore %s by %s" % (self.jail.name, ip, "ignoreself rule")) def testIgnoreIPOK(self): ipList = "127.0.0.1", "192.168.0.1", "255.255.255.255", "99.99.99.99" for ip in ipList: self.filter.addIgnoreIP(ip) - self.assertTrue(self.filter.inIgnoreIPList(ip)) + self.assertTrue(self.filter.inIgnoreIPList(ip, log_ignore=True)) + self.assertLogged("[%s] Ignore %s by %s" % (self.jail.name, ip, "ip")) def testIgnoreIPNOK(self): ipList = "", "999.999.999.999", "abcdef.abcdef", "192.168.0."