From 70aef2c3c68d690232fe6c96ba2b6d84ca8af019 Mon Sep 17 00:00:00 2001 From: sebres Date: Mon, 11 Dec 2023 21:26:55 +0100 Subject: [PATCH] py3.12: silence warnings "invalid escape sequence" --- fail2ban/tests/fail2banregextestcase.py | 16 ++++++++-------- fail2ban/tests/servertestcase.py | 24 ++++++++++++------------ 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/fail2ban/tests/fail2banregextestcase.py b/fail2ban/tests/fail2banregextestcase.py index 685aa3b0..9a9c7d50 100644 --- a/fail2ban/tests/fail2banregextestcase.py +++ b/fail2ban/tests/fail2banregextestcase.py @@ -221,7 +221,7 @@ class Fail2banRegexTest(LogCaptureTestCase): self.pruneLog() self.assertTrue(_test_exec( "-d", "^Epoch", - "1490349000 test failed.dns.ch", "^\s*test \S+" + "1490349000 test failed.dns.ch", r"^\s*test \S+" )) self.assertLogged('Lines: 1 lines, 0 ignored, 1 matched, 0 missed', all=True) self.assertNotLogged('Unable to find a corresponding IP address') @@ -229,7 +229,7 @@ class Fail2banRegexTest(LogCaptureTestCase): self.pruneLog() self.assertTrue(_test_exec( "-d", "^Epoch", "-o", "id", - "1490349000 test this/is/some/path/32", "^\s*test \S+" + "1490349000 test this/is/some/path/32", r"^\s*test \S+" )) self.assertLogged('this/is/some/path/32', all=True) @@ -439,23 +439,23 @@ class Fail2banRegexTest(LogCaptureTestCase): # with different ID/IP from failregex (ID/User from first, IP from second message): self.assertTrue(_test('-o', 'ID:"" | IP: | U:', log, flt+'[failregex="' - '^'+prefix+'User \S+ not allowed\n' - '^'+prefix+'Received disconnect from ' + '^'+prefix+r'User \S+ not allowed'+'\n' + '^'+prefix+r'Received disconnect from ' '"]')) self.assertLogged('ID:"User root" | IP:192.0.2.76 | U:root') self.pruneLog() # with different ID/IP from failregex (User from first, ID and IP from second message): self.assertTrue(_test('-o', 'ID:"" | IP: | U:', log, flt+'[failregex="' - '^'+prefix+'User \S+ not allowed\n' - '^'+prefix+'Received disconnect from port \d+' + '^'+prefix+r'User \S+ not allowed'+'\n' + '^'+prefix+r'Received disconnect from port \d+' '"]')) self.assertLogged('ID:"192.0.2.76 port 58846" | IP:192.0.2.76 | U:root') self.pruneLog() # first with sshd and prefregex: _test_variants() # the same without prefregex and MLFID directly in failregex (no merge with prefregex groups): - _test_variants('common', prefix="\s*\S+ sshd\[\d+\]:\s+") + _test_variants('common', prefix=r"\s*\S+ sshd\[\d+\]:\s+") def testNoDateTime(self): # datepattern doesn't match: @@ -541,7 +541,7 @@ class Fail2banRegexTest(LogCaptureTestCase): 'svc[2] connect started 192.0.2.4\n' 'svc[2] connect authorized 192.0.2.4\n' 'svc[2] connect finished 192.0.2.4\n', - 'common[prefregex="^svc\[\d+\] connect .+$"' + r'common[prefregex="^svc\[\d+\] connect .+$"' ', failregex="' '^started\n' '^finished \n' diff --git a/fail2ban/tests/servertestcase.py b/fail2ban/tests/servertestcase.py index 311341ae..a9e9ed43 100644 --- a/fail2ban/tests/servertestcase.py +++ b/fail2ban/tests/servertestcase.py @@ -1372,12 +1372,12 @@ class ServerConfigReaderTests(LogCaptureTestCase): "`{ nft flush set inet f2b-table addr6-set-j-w-nft-mp 2> /dev/null; } || ", ), 'stop': ( - "`{ nft -a list chain inet f2b-table f2b-chain | grep -oP '@addr-set-j-w-nft-mp\s+.*\s+\Khandle\s+(\d+)$'; } | while read -r hdl; do`", - "`nft delete rule inet f2b-table f2b-chain $hdl; done`", - "`nft delete set inet f2b-table addr-set-j-w-nft-mp`", - "`{ nft -a list chain inet f2b-table f2b-chain | grep -oP '@addr6-set-j-w-nft-mp\s+.*\s+\Khandle\s+(\d+)$'; } | while read -r hdl; do`", - "`nft delete rule inet f2b-table f2b-chain $hdl; done`", - "`nft delete set inet f2b-table addr6-set-j-w-nft-mp`", + r"`{ nft -a list chain inet f2b-table f2b-chain | grep -oP '@addr-set-j-w-nft-mp\s+.*\s+\Khandle\s+(\d+)$'; } | while read -r hdl; do`", + r"`nft delete rule inet f2b-table f2b-chain $hdl; done`", + r"`nft delete set inet f2b-table addr-set-j-w-nft-mp`", + r"`{ nft -a list chain inet f2b-table f2b-chain | grep -oP '@addr6-set-j-w-nft-mp\s+.*\s+\Khandle\s+(\d+)$'; } | while read -r hdl; do`", + r"`nft delete rule inet f2b-table f2b-chain $hdl; done`", + r"`nft delete set inet f2b-table addr6-set-j-w-nft-mp`", ), 'ip4-check': ( r"`nft list chain inet f2b-table f2b-chain | grep -q '@addr-set-j-w-nft-mp[ \t]'`", @@ -1418,12 +1418,12 @@ class ServerConfigReaderTests(LogCaptureTestCase): "`{ nft flush set inet f2b-table addr6-set-j-w-nft-ap 2> /dev/null; } || ", ), 'stop': ( - "`{ nft -a list chain inet f2b-table f2b-chain | grep -oP '@addr-set-j-w-nft-ap\s+.*\s+\Khandle\s+(\d+)$'; } | while read -r hdl; do`", - "`nft delete rule inet f2b-table f2b-chain $hdl; done`", - "`nft delete set inet f2b-table addr-set-j-w-nft-ap`", - "`{ nft -a list chain inet f2b-table f2b-chain | grep -oP '@addr6-set-j-w-nft-ap\s+.*\s+\Khandle\s+(\d+)$'; } | while read -r hdl; do`", - "`nft delete rule inet f2b-table f2b-chain $hdl; done`", - "`nft delete set inet f2b-table addr6-set-j-w-nft-ap`", + r"`{ nft -a list chain inet f2b-table f2b-chain | grep -oP '@addr-set-j-w-nft-ap\s+.*\s+\Khandle\s+(\d+)$'; } | while read -r hdl; do`", + r"`nft delete rule inet f2b-table f2b-chain $hdl; done`", + r"`nft delete set inet f2b-table addr-set-j-w-nft-ap`", + r"`{ nft -a list chain inet f2b-table f2b-chain | grep -oP '@addr6-set-j-w-nft-ap\s+.*\s+\Khandle\s+(\d+)$'; } | while read -r hdl; do`", + r"`nft delete rule inet f2b-table f2b-chain $hdl; done`", + r"`nft delete set inet f2b-table addr6-set-j-w-nft-ap`", ), 'ip4-check': ( r"""`nft list chain inet f2b-table f2b-chain | grep -q '@addr-set-j-w-nft-ap[ \t]'`""",