mirror of https://github.com/fail2ban/fail2ban
Merge python-3.12--asyncore: python 3.12 support, see gh-3487
commit
4e326cb5cb
|
@ -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', pypy3.10]
|
||||
python-version: [3.6, 3.7, 3.8, 3.9, '3.10', '3.11', '3.12', pypy3.10]
|
||||
fail-fast: false
|
||||
# Steps represent a sequence of tasks that will be executed as part of the job
|
||||
steps:
|
||||
|
@ -59,6 +59,13 @@ jobs:
|
|||
python -m pip install systemd-python || echo 'systemd not available'
|
||||
#readline if available as module:
|
||||
python -c 'import readline' 2> /dev/null || python -m pip install readline || echo 'readline not available'
|
||||
# asyncore/asynchat:
|
||||
if dpkg --compare-versions "$F2B_PYV" ge 3.12; then
|
||||
#sudo apt-get -y install python${F2B_PY/2/}-setuptools || echo 'setuptools not unavailable'
|
||||
python -m pip install setuptools || echo "can't install setuptools"
|
||||
python -m pip install pyasynchat || echo "can't install pyasynchat";
|
||||
python -m pip install pyasyncore || echo "can't install pyasyncore";
|
||||
fi
|
||||
|
||||
- name: Before scripts
|
||||
run: |
|
||||
|
|
|
@ -284,7 +284,7 @@ def splitwords(s):
|
|||
"""
|
||||
if not s:
|
||||
return []
|
||||
return list(filter(bool, [v.strip() for v in re.split('[\s,]+', s)]))
|
||||
return list(filter(bool, [v.strip() for v in re.split(r'[\s,]+', s)]))
|
||||
|
||||
def _merge_dicts(x, y):
|
||||
"""Helper to merge dicts.
|
||||
|
|
|
@ -18,7 +18,6 @@
|
|||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
import os
|
||||
import smtpd
|
||||
import threading
|
||||
import unittest
|
||||
import re
|
||||
|
@ -29,9 +28,11 @@ else:
|
|||
import imp
|
||||
|
||||
from ..dummyjail import DummyJail
|
||||
|
||||
from ..utils import CONFIG_DIR, asyncserver, Utils, uni_decode
|
||||
|
||||
try:
|
||||
import smtpd
|
||||
|
||||
class TestSMTPServer(smtpd.SMTPServer):
|
||||
|
||||
def __init__(self, *args):
|
||||
|
@ -160,3 +161,6 @@ class SMTPActionTest(unittest.TestCase):
|
|||
self.assertTrue("From: %s <%s>" %
|
||||
(self.action.fromname, self.action.fromaddr) in self.smtpd.data)
|
||||
self.assertEqual(set(self.smtpd.rcpttos), set(["test@example.com", "test2@example.com"]))
|
||||
|
||||
except ImportError as e:
|
||||
print("I: Skipping smtp tests: %s" % e)
|
||||
|
|
|
@ -221,7 +221,7 @@ class Fail2banRegexTest(LogCaptureTestCase):
|
|||
self.pruneLog()
|
||||
self.assertTrue(_test_exec(
|
||||
"-d", "^Epoch",
|
||||
"1490349000 test failed.dns.ch", "^\s*test <F-ID>\S+</F-ID>"
|
||||
"1490349000 test failed.dns.ch", r"^\s*test <F-ID>\S+</F-ID>"
|
||||
))
|
||||
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 <F-ID>\S+</F-ID>"
|
||||
"1490349000 test this/is/some/path/32", r"^\s*test <F-ID>\S+</F-ID>"
|
||||
))
|
||||
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:"<fid>" | IP:<ip> | U:<F-USER>', log,
|
||||
flt+'[failregex="'
|
||||
'^'+prefix+'<F-ID>User <F-USER>\S+</F-USER></F-ID> not allowed\n'
|
||||
'^'+prefix+'Received disconnect from <ADDR>'
|
||||
'^'+prefix+r'<F-ID>User <F-USER>\S+</F-USER></F-ID> not allowed'+'\n'
|
||||
'^'+prefix+r'Received disconnect from <ADDR>'
|
||||
'"]'))
|
||||
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:"<fid>" | IP:<ip> | U:<F-USER>', log,
|
||||
flt+'[failregex="'
|
||||
'^'+prefix+'User <F-USER>\S+</F-USER> not allowed\n'
|
||||
'^'+prefix+'Received disconnect from <F-ID><ADDR> port \d+</F-ID>'
|
||||
'^'+prefix+r'User <F-USER>\S+</F-USER> not allowed'+'\n'
|
||||
'^'+prefix+r'Received disconnect from <F-ID><ADDR> port \d+</F-ID>'
|
||||
'"]'))
|
||||
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\[<F-MLFID>\d+</F-MLFID>\]:\s+")
|
||||
_test_variants('common', prefix=r"\s*\S+ sshd\[<F-MLFID>\d+</F-MLFID>\]:\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\[<F-MLFID>\d+</F-MLFID>\] connect <F-CONTENT>.+</F-CONTENT>$"'
|
||||
r'common[prefregex="^svc\[<F-MLFID>\d+</F-MLFID>\] connect <F-CONTENT>.+</F-CONTENT>$"'
|
||||
', failregex="'
|
||||
'^started\n'
|
||||
'^<F-NOFAIL><F-MLFFORGET>finished</F-MLFFORGET></F-NOFAIL> <ADDR>\n'
|
||||
|
|
|
@ -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]'`""",
|
||||
|
|
Loading…
Reference in New Issue