From 34390b3fe1e4e69df3ea3cc7f45f8a7a3a471ddd Mon Sep 17 00:00:00 2001 From: sebres Date: Thu, 22 Jun 2023 19:35:09 +0200 Subject: [PATCH] extended tests covering unban tuple IDs --- fail2ban/tests/fail2banclienttestcase.py | 8 ++++++-- fail2ban/tests/servertestcase.py | 7 ++++++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/fail2ban/tests/fail2banclienttestcase.py b/fail2ban/tests/fail2banclienttestcase.py index 9d3f382f..1ab6ac9e 100644 --- a/fail2ban/tests/fail2banclienttestcase.py +++ b/fail2ban/tests/fail2banclienttestcase.py @@ -1408,8 +1408,12 @@ class Fail2banServerTest(Fail2banClientServerBase): all=True, wait=MID_WAITTIME ) - # unban 1, 2 and 5: - self.execCmd(SUCCESS, startparams, 'unban', '125-000-001', '125-000-002', '125-000-005') + # unban 1, 2 and 5 (as expr): + self.execCmd(SUCCESS, startparams, 'unban', '125-000-001', '125-000-002') + self.execCmd(SUCCESS, startparams, 'unban', '--expr', '"125-000-005"') + # check tuple IDs don't consider as a list of IDs to unban: + self.execCmd(SUCCESS, startparams, 'unban', '--expr', '("125-000-003","125-000-004")') + self.assertLogged('%r is not banned' % (('125-000-003', '125-000-004'),)) _out_file(mpfn) # check really unbanned but other sessions are still present (blacklisted in map-file): mp = _read_file(mpfn) diff --git a/fail2ban/tests/servertestcase.py b/fail2ban/tests/servertestcase.py index 7cba9add..628b7253 100644 --- a/fail2ban/tests/servertestcase.py +++ b/fail2ban/tests/servertestcase.py @@ -372,8 +372,13 @@ class Transmitter(TransmitterBase): # ... (no error, IPs logged only): self.assertEqual( self.transm.proceed( - ["set", self.jailName, "unbanip", "192.0.2.255", "192.0.2.254"]),(0, 0)) + ["set", self.jailName, "unbanip", "--", "192.0.2.255", "192.0.2.254"]),(0, 0)) self.assertLogged("192.0.2.255 is not banned", "192.0.2.254 is not banned", all=True, wait=True) + # tuple ID: + self.assertEqual( + self.transm.proceed( + ["set", self.jailName, "unbanip", "--expr", "(1,2,3)"]),(0, 0)) + self.assertLogged("%r is not banned" % ((1,2,3),), wait=True) def testJailAttemptIP(self): self.server.startJail(self.jailName) # Jail must be started