mirror of https://github.com/fail2ban/fail2ban
TST: more client/jailreader tests
parent
d74dd31d23
commit
1407b955e6
4
MANIFEST
4
MANIFEST
|
@ -242,3 +242,7 @@ files/fail2ban-tmpfiles.conf
|
||||||
files/fail2ban.service
|
files/fail2ban.service
|
||||||
files/ipmasq-ZZZzzz_fail2ban.rul
|
files/ipmasq-ZZZzzz_fail2ban.rul
|
||||||
files/gen_badbots
|
files/gen_badbots
|
||||||
|
testcases/config/jail.conf
|
||||||
|
testcases/config/fail2ban.conf
|
||||||
|
testcases/config/filter.d/simple.conf
|
||||||
|
testcases/config/action.d/brokenaction.conf
|
||||||
|
|
|
@ -109,6 +109,22 @@ option = %s
|
||||||
|
|
||||||
class JailReaderTest(LogCaptureTestCase):
|
class JailReaderTest(LogCaptureTestCase):
|
||||||
|
|
||||||
|
def testJailActionEmpty(self):
|
||||||
|
jail = JailReader('emptyaction', basedir=os.path.join('testcases','config'))
|
||||||
|
self.assertTrue(jail.read())
|
||||||
|
self.assertTrue(jail.getOptions())
|
||||||
|
self.assertTrue(jail.isEnabled())
|
||||||
|
self.assertTrue(self._is_logged('No filter set for jail emptyaction'))
|
||||||
|
self.assertTrue(self._is_logged('No actions were defined for emptyaction'))
|
||||||
|
|
||||||
|
def testJailActionBrokenDef(self):
|
||||||
|
jail = JailReader('brokenactiondef', basedir=os.path.join('testcases','config'))
|
||||||
|
self.assertTrue(jail.read())
|
||||||
|
self.assertFalse(jail.getOptions())
|
||||||
|
self.assertTrue(jail.isEnabled())
|
||||||
|
self.assertTrue(self._is_logged('Error in action definition joho[foo'))
|
||||||
|
self.assertTrue(self._is_logged('Caught exception: While reading action joho[foo we should have got 1 or 2 groups. Got: 0'))
|
||||||
|
|
||||||
def testStockSSHJail(self):
|
def testStockSSHJail(self):
|
||||||
jail = JailReader('ssh-iptables', basedir='config') # we are running tests from root project dir atm
|
jail = JailReader('ssh-iptables', basedir='config') # we are running tests from root project dir atm
|
||||||
self.assertTrue(jail.read())
|
self.assertTrue(jail.read())
|
||||||
|
@ -157,7 +173,7 @@ class JailReaderTest(LogCaptureTestCase):
|
||||||
os.remove(f2)
|
os.remove(f2)
|
||||||
os.rmdir(d)
|
os.rmdir(d)
|
||||||
|
|
||||||
class JailsReaderTest(unittest.TestCase):
|
class JailsReaderTest(LogCaptureTestCase):
|
||||||
|
|
||||||
def testProvidingBadBasedir(self):
|
def testProvidingBadBasedir(self):
|
||||||
if not os.path.exists('/XXX'):
|
if not os.path.exists('/XXX'):
|
||||||
|
@ -176,6 +192,7 @@ class JailsReaderTest(unittest.TestCase):
|
||||||
# We should not "read" some bogus jail
|
# We should not "read" some bogus jail
|
||||||
old_comm_commands = comm_commands[:] # make a copy
|
old_comm_commands = comm_commands[:] # make a copy
|
||||||
self.assertFalse(jails.getOptions("BOGUS"))
|
self.assertFalse(jails.getOptions("BOGUS"))
|
||||||
|
self.assertTrue(self._is_logged("No section: 'BOGUS'"))
|
||||||
# and there should be no side-effects
|
# and there should be no side-effects
|
||||||
self.assertEqual(jails.convert(), old_comm_commands)
|
self.assertEqual(jails.convert(), old_comm_commands)
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,4 @@
|
||||||
|
|
||||||
|
[Definition]
|
||||||
|
|
||||||
|
actioban = hit with big stick <ip>
|
|
@ -0,0 +1,5 @@
|
||||||
|
[Definition]
|
||||||
|
|
||||||
|
# 3 = INFO
|
||||||
|
loglevel = 3
|
||||||
|
|
|
@ -0,0 +1,4 @@
|
||||||
|
|
||||||
|
[Definition]
|
||||||
|
|
||||||
|
failregex = <IP>
|
|
@ -0,0 +1,20 @@
|
||||||
|
|
||||||
|
[DEFAULT]
|
||||||
|
filter = simple
|
||||||
|
|
||||||
|
[emptyaction]
|
||||||
|
enabled = true
|
||||||
|
filter =
|
||||||
|
action =
|
||||||
|
|
||||||
|
[brokenactiondef]
|
||||||
|
enabled = true
|
||||||
|
action = joho[foo
|
||||||
|
|
||||||
|
[brokenaction]
|
||||||
|
enabled = true
|
||||||
|
action = brokenaction
|
||||||
|
|
||||||
|
[missingaction]
|
||||||
|
enabled = true
|
||||||
|
action = thefunkychickendance
|
Loading…
Reference in New Issue