From e3b36756c07502cf7ff628bb2ecfecdde5760412 Mon Sep 17 00:00:00 2001 From: "Sergey G. Brester" Date: Tue, 12 Dec 2023 14:13:39 +0100 Subject: [PATCH 1/3] main.yml: test python 3.13 --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 1758aaee..780b0ab6 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -22,7 +22,7 @@ jobs: runs-on: ubuntu-20.04 strategy: matrix: - python-version: [3.6, 3.7, 3.8, 3.9, '3.10', '3.11', '3.12', pypy3.10] + python-version: [3.7, 3.8, 3.9, '3.10', '3.11', '3.12', '3.13.0-alpha.2', pypy3.10] fail-fast: false # Steps represent a sequence of tasks that will be executed as part of the job steps: From 337a519cb2ad12a23d51cb74c37de5961bc044e5 Mon Sep 17 00:00:00 2001 From: sebres Date: Tue, 12 Dec 2023 14:21:11 +0100 Subject: [PATCH 2/3] python3.13 support - unittest.makeSuite is removed in 3.13 --- fail2ban/tests/utils.py | 96 +++++++++++++++++++++-------------------- 1 file changed, 49 insertions(+), 47 deletions(-) diff --git a/fail2ban/tests/utils.py b/fail2ban/tests/utils.py index 1d01d845..1e05c911 100644 --- a/fail2ban/tests/utils.py +++ b/fail2ban/tests/utils.py @@ -397,75 +397,77 @@ def gatherTests(regexps=None, opts=None): tests = FilteredTestSuite() + loadTests = unittest.defaultTestLoader.loadTestsFromTestCase; + # Server - tests.addTest(unittest.makeSuite(servertestcase.Transmitter)) - tests.addTest(unittest.makeSuite(servertestcase.JailTests)) - tests.addTest(unittest.makeSuite(servertestcase.RegexTests)) - tests.addTest(unittest.makeSuite(servertestcase.LoggingTests)) - tests.addTest(unittest.makeSuite(servertestcase.ServerConfigReaderTests)) - tests.addTest(unittest.makeSuite(actiontestcase.CommandActionTest)) - tests.addTest(unittest.makeSuite(actionstestcase.ExecuteActions)) + tests.addTest(loadTests(servertestcase.Transmitter)) + tests.addTest(loadTests(servertestcase.JailTests)) + tests.addTest(loadTests(servertestcase.RegexTests)) + tests.addTest(loadTests(servertestcase.LoggingTests)) + tests.addTest(loadTests(servertestcase.ServerConfigReaderTests)) + tests.addTest(loadTests(actiontestcase.CommandActionTest)) + tests.addTest(loadTests(actionstestcase.ExecuteActions)) # Ticket, BanTicket, FailTicket - tests.addTest(unittest.makeSuite(tickettestcase.TicketTests)) + tests.addTest(loadTests(tickettestcase.TicketTests)) # FailManager - tests.addTest(unittest.makeSuite(failmanagertestcase.AddFailure)) - tests.addTest(unittest.makeSuite(failmanagertestcase.FailmanagerComplex)) + tests.addTest(loadTests(failmanagertestcase.AddFailure)) + tests.addTest(loadTests(failmanagertestcase.FailmanagerComplex)) # BanManager - tests.addTest(unittest.makeSuite(banmanagertestcase.AddFailure)) + tests.addTest(loadTests(banmanagertestcase.AddFailure)) try: import dns - tests.addTest(unittest.makeSuite(banmanagertestcase.StatusExtendedCymruInfo)) + tests.addTest(loadTests(banmanagertestcase.StatusExtendedCymruInfo)) except ImportError: # pragma: no cover pass # ClientBeautifier - tests.addTest(unittest.makeSuite(clientbeautifiertestcase.BeautifierTest)) + tests.addTest(loadTests(clientbeautifiertestcase.BeautifierTest)) # ClientReaders - tests.addTest(unittest.makeSuite(clientreadertestcase.ConfigReaderTest)) - tests.addTest(unittest.makeSuite(clientreadertestcase.JailReaderTest)) - tests.addTest(unittest.makeSuite(clientreadertestcase.FilterReaderTest)) - tests.addTest(unittest.makeSuite(clientreadertestcase.JailsReaderTest)) - tests.addTest(unittest.makeSuite(clientreadertestcase.JailsReaderTestCache)) + tests.addTest(loadTests(clientreadertestcase.ConfigReaderTest)) + tests.addTest(loadTests(clientreadertestcase.JailReaderTest)) + tests.addTest(loadTests(clientreadertestcase.FilterReaderTest)) + tests.addTest(loadTests(clientreadertestcase.JailsReaderTest)) + tests.addTest(loadTests(clientreadertestcase.JailsReaderTestCache)) # CSocket and AsyncServer - tests.addTest(unittest.makeSuite(sockettestcase.Socket)) - tests.addTest(unittest.makeSuite(sockettestcase.ClientMisc)) + tests.addTest(loadTests(sockettestcase.Socket)) + tests.addTest(loadTests(sockettestcase.ClientMisc)) # Misc helpers - tests.addTest(unittest.makeSuite(misctestcase.HelpersTest)) - tests.addTest(unittest.makeSuite(misctestcase.SetupTest)) - tests.addTest(unittest.makeSuite(misctestcase.TestsUtilsTest)) - tests.addTest(unittest.makeSuite(misctestcase.MyTimeTest)) + tests.addTest(loadTests(misctestcase.HelpersTest)) + tests.addTest(loadTests(misctestcase.SetupTest)) + tests.addTest(loadTests(misctestcase.TestsUtilsTest)) + tests.addTest(loadTests(misctestcase.MyTimeTest)) # Database - tests.addTest(unittest.makeSuite(databasetestcase.DatabaseTest)) + tests.addTest(loadTests(databasetestcase.DatabaseTest)) # Observer - tests.addTest(unittest.makeSuite(observertestcase.ObserverTest)) - tests.addTest(unittest.makeSuite(observertestcase.BanTimeIncr)) - tests.addTest(unittest.makeSuite(observertestcase.BanTimeIncrDB)) + tests.addTest(loadTests(observertestcase.ObserverTest)) + tests.addTest(loadTests(observertestcase.BanTimeIncr)) + tests.addTest(loadTests(observertestcase.BanTimeIncrDB)) # Filter - tests.addTest(unittest.makeSuite(filtertestcase.IgnoreIP)) - tests.addTest(unittest.makeSuite(filtertestcase.BasicFilter)) - tests.addTest(unittest.makeSuite(filtertestcase.LogFile)) - tests.addTest(unittest.makeSuite(filtertestcase.LogFileMonitor)) - tests.addTest(unittest.makeSuite(filtertestcase.LogFileFilterPoll)) + tests.addTest(loadTests(filtertestcase.IgnoreIP)) + tests.addTest(loadTests(filtertestcase.BasicFilter)) + tests.addTest(loadTests(filtertestcase.LogFile)) + tests.addTest(loadTests(filtertestcase.LogFileMonitor)) + tests.addTest(loadTests(filtertestcase.LogFileFilterPoll)) # each test case class self will check no network, and skip it (we see it in log) - tests.addTest(unittest.makeSuite(filtertestcase.IgnoreIPDNS)) - tests.addTest(unittest.makeSuite(filtertestcase.GetFailures)) - tests.addTest(unittest.makeSuite(filtertestcase.DNSUtilsTests)) - tests.addTest(unittest.makeSuite(filtertestcase.DNSUtilsNetworkTests)) - tests.addTest(unittest.makeSuite(filtertestcase.JailTests)) + tests.addTest(loadTests(filtertestcase.IgnoreIPDNS)) + tests.addTest(loadTests(filtertestcase.GetFailures)) + tests.addTest(loadTests(filtertestcase.DNSUtilsTests)) + tests.addTest(loadTests(filtertestcase.DNSUtilsNetworkTests)) + tests.addTest(loadTests(filtertestcase.JailTests)) # DateDetector - tests.addTest(unittest.makeSuite(datedetectortestcase.DateDetectorTest)) - tests.addTest(unittest.makeSuite(datedetectortestcase.CustomDateFormatsTest)) + tests.addTest(loadTests(datedetectortestcase.DateDetectorTest)) + tests.addTest(loadTests(datedetectortestcase.CustomDateFormatsTest)) # Filter Regex tests with sample logs - tests.addTest(unittest.makeSuite(samplestestcase.FilterSamplesRegex)) + tests.addTest(loadTests(samplestestcase.FilterSamplesRegex)) # bin/fail2ban-client, bin/fail2ban-server - tests.addTest(unittest.makeSuite(fail2banclienttestcase.Fail2banClientTest)) - tests.addTest(unittest.makeSuite(fail2banclienttestcase.Fail2banServerTest)) + tests.addTest(loadTests(fail2banclienttestcase.Fail2banClientTest)) + tests.addTest(loadTests(fail2banclienttestcase.Fail2banServerTest)) # bin/fail2ban-regex - tests.addTest(unittest.makeSuite(fail2banregextestcase.Fail2banRegexTest)) + tests.addTest(loadTests(fail2banregextestcase.Fail2banRegexTest)) # # Python action testcases @@ -495,17 +497,17 @@ def gatherTests(regexps=None, opts=None): logSys.warning("I: Skipping pyinotify backend testing. Got exception '%s'" % e) for Filter_ in filters: - tests.addTest(unittest.makeSuite( + tests.addTest(loadTests( filtertestcase.get_monitor_failures_testcase(Filter_))) try: # pragma: systemd no cover from ..server.filtersystemd import FilterSystemd - tests.addTest(unittest.makeSuite(filtertestcase.get_monitor_failures_journal_testcase(FilterSystemd))) + tests.addTest(loadTests(filtertestcase.get_monitor_failures_journal_testcase(FilterSystemd))) except ImportError as e: # pragma: no cover logSys.warning("I: Skipping systemd backend testing. Got exception '%s'" % e) # Server test for logging elements which break logging used to support # testcases analysis - tests.addTest(unittest.makeSuite(servertestcase.TransmitterLogging)) + tests.addTest(loadTests(servertestcase.TransmitterLogging)) return tests From 7e88c9be8db703ca85c9b7b91eb432c808eb13bd Mon Sep 17 00:00:00 2001 From: sebres Date: Tue, 12 Dec 2023 14:27:24 +0100 Subject: [PATCH 3/3] more compat issues (Logger.warn -> Logger.warning) --- fail2ban/tests/utils.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fail2ban/tests/utils.py b/fail2ban/tests/utils.py index 1e05c911..bd4c7e02 100644 --- a/fail2ban/tests/utils.py +++ b/fail2ban/tests/utils.py @@ -296,7 +296,7 @@ def initTests(opts): # precache all invalid ip's (TEST-NET-1, ..., TEST-NET-3 according to RFC 5737): c = DNSUtils.CACHE_ipToName - c.clear = lambda: logSys.warn('clear CACHE_ipToName is disabled in test suite') + c.clear = lambda: logSys.warning('clear CACHE_ipToName is disabled in test suite') # increase max count and max time (too many entries, long time testing): c.setOptions(maxCount=10000, maxTime=5*60) for i in range(256): @@ -314,7 +314,7 @@ def initTests(opts): c.set('8.8.4.4', 'dns.google') # precache all dns to ip's used in test cases: c = DNSUtils.CACHE_nameToIp - c.clear = lambda: logSys.warn('clear CACHE_nameToIp is disabled in test suite') + c.clear = lambda: logSys.warning('clear CACHE_nameToIp is disabled in test suite') for i in ( ('999.999.999.999', set()), ('abcdef.abcdef', set()),