fix SMTP notifications overwriting the ticket's ban duration

Use the ban duration supplied by ActionInfo instead of replacing it with the jail default. ActionInfo already falls back to the jail duration when the ticket has no explicit ban time.

Add regression coverage for increased and permanent ticket durations and the default-duration fallback.
This commit is contained in:
CrazyMax 2026-09-16 11:46:57 +02:00
parent 7212404e8f
commit b5714f7747
No known key found for this signature in database
GPG key ID: ADE44D8C9D44FBE4
3 changed files with 15 additions and 1 deletions

View file

@ -11,6 +11,7 @@ ver. 1.1.2-dev-1 (20??/??/??) - development nightly edition
-----------
### Fixes
* `action.d/smtp.py` - preserve the ticket's ban time in notification emails instead of replacing it with the jail's default
* `filter.d/nginx-botsearch.conf` - error-log regex extended with support of journal format (gh-3732)
* `filter.d/apache-noscript.conf` - match a request for the `cgi-bin` directory itself (no script name after it),
the `cgi-bin` alternative required a following path segment so `/cgi-bin/` and `/cgi-bin` were not matched (gh-4217)

View file

@ -126,7 +126,6 @@ class SMTPAction(ActionBase):
self.message_values = CallingMap(
jailname = self._jail.name,
hostname = socket.gethostname,
bantime = lambda: self._jail.actions.getBanTime(),
)
# bypass ban/unban for restored tickets

View file

@ -27,6 +27,8 @@ import importlib
from ..dummyjail import DummyJail
from ..utils import CONFIG_DIR, asyncserver, Utils, uni_decode
from ...server.actions import Actions
from ...server.ticket import BanTicket
class _SMTPActionTestCase():
@ -63,6 +65,7 @@ class _SMTPActionTestCase():
aInfo = {
'ip': "127.0.0.2",
'failures': 3,
'bantime': self.jail.actions.getBanTime(),
'matches': "Test fail 1\n",
'ipjailmatches': "Test fail 1\nTest Fail2\n",
'ipmatches': "Test fail 1\nTest Fail2\nTest Fail3\n",
@ -97,6 +100,17 @@ class _SMTPActionTestCase():
def testBan(self):
self._testBan()
def testBanTime(self):
self.jail.actions.setBanTime(600)
for bantime, expected in ((None, 600), (3600, 3600), (-1, -1)):
with self.subTest(bantime=bantime):
ticket = BanTicket('127.0.0.2')
ticket.setBanTime(bantime)
aInfo = Actions.ActionInfo(ticket, self.jail)
self._exec_and_wait(lambda: self.action.ban(aInfo))
self.assertIn('banned for %i seconds' % expected, self.smtpd.data)
self.assertEqual(aInfo['bantime'], expected)
def testNOPByRestored(self):
self._testBan(restored=True)