ENH: added new test cases for `fail2ban-client get <JAIL> banip` command (gh-1916)

pull/2315/head
SP 2019-01-04 17:06:47 +03:00
parent 3d477d229d
commit 7f5f7017db
2 changed files with 37 additions and 0 deletions

View File

@ -261,3 +261,10 @@ class BeautifierTest(unittest.TestCase):
output = "Sorry but the command is invalid"
self.assertEqual(self.b.beautifyError(IndexError()), output)
def testJailBanList(self):
self.b.setInputCmd(["get", "ssh", "banip"])
response = ["192.168.0.1", "192.168.1.10"]
output = "192.168.0.1 192.168.1.10"
self.assertEqual(self.b.beautify(response), output)
self.assertEqual(self.b.beautify([]), "")

View File

@ -1227,6 +1227,36 @@ class Fail2banServerTest(Fail2banClientServerBase):
"Jail 'test-jail1' stopped",
"Jail 'test-jail1' started", all=True, wait=MID_WAITTIME)
# test the list of banned IP addresses, step 0: prepare
self.pruneLog("[test-phase 9a]")
self.execCmd(SUCCESS, startparams, "reload", "--unban", "test-jail1")
self.assertLogged(
"Jail 'test-jail1' reloaded", wait=MID_WAITTIME)
# test the list of banned IP addresses, step 1: ban IP addresses
self.pruneLog("[test-phase 9b]")
self.execCmd(SUCCESS, startparams,
"set", "test-jail1", "banip", "192.168.0.1")
self.assertLogged("[test-jail1] Ban 192.168.0.1", wait=MID_WAITTIME)
self.execCmd(SUCCESS, startparams,
"set", "test-jail1", "banip", "192.168.1.10")
self.assertLogged("[test-jail1] Ban 192.168.1.10", wait=MID_WAITTIME)
self.execCmd(SUCCESS, startparams, "get", "test-jail1", "banip")
self.assertLogged(
"192.168.1.10 192.168.0.1",
"192.168.0.1 192.168.1.10", wait=MID_WAITTIME)
# test the list of banned IP addresses, step 2: unban IP addresses
self.pruneLog("[test-phase 9c]")
self.execCmd(SUCCESS, startparams,
"set", "test-jail1", "unbanip", "192.168.0.1")
self.assertLogged("[test-jail1] Unban 192.168.0.1", wait=MID_WAITTIME)
self.execCmd(SUCCESS, startparams,
"set", "test-jail1", "unbanip", "192.168.1.10")
self.assertLogged("[test-jail1] Unban 192.168.1.10", wait=MID_WAITTIME)
self.execCmd(SUCCESS, startparams, "get", "test-jail1", "banip")
self.assertNotLogged(
"192.168.1.10 192.168.0.1",
"192.168.0.1 192.168.1.10", wait=MID_WAITTIME)
# test action.d/nginx-block-map.conf --
@unittest.F2B.skip_if_cfg_missing(action="nginx-block-map")
@with_foreground_server_thread(startextra={