mirror of https://github.com/fail2ban/fail2ban
Real action info instead of calling map in test cases, covering of the new tag '<ip-host>';
dns lookup: pre-caching within test cases - prevent slow dns-resolving and failures if no-network, of if some IP addresses will be changed laterpull/1705/head
parent
a0bb51ef92
commit
59cf761129
|
@ -38,7 +38,9 @@ from ..server.server import Server
|
|||
from ..server.ipdns import IPAddr
|
||||
from ..server.jail import Jail
|
||||
from ..server.jailthread import JailThread
|
||||
from ..server.ticket import BanTicket
|
||||
from ..server.utils import Utils
|
||||
from .dummyjail import DummyJail
|
||||
from .utils import LogCaptureTestCase
|
||||
from ..helpers import getLogger, PREFER_ENC
|
||||
from .. import version
|
||||
|
@ -1677,7 +1679,7 @@ class ServerConfigReaderTests(LogCaptureTestCase):
|
|||
# complain --
|
||||
('j-complain-abuse',
|
||||
'complain['
|
||||
'name=%(__name__)s, grepopts="-m 1", grepmax=2, mailcmd="mail -s",' +
|
||||
'name=%(__name__)s, grepopts="-m 1", grepmax=2, mailcmd="mail -s Hostname: <ip-host> - ",' +
|
||||
# test reverse ip:
|
||||
'debug=1,' +
|
||||
# 2 logs to test grep from multiple logs:
|
||||
|
@ -1692,14 +1694,14 @@ class ServerConfigReaderTests(LogCaptureTestCase):
|
|||
'testcase01.log:Dec 31 11:59:59 [sshd] error: PAM: Authentication failure for kevin from 87.142.124.10',
|
||||
'testcase01a.log:Dec 31 11:55:01 [sshd] error: PAM: Authentication failure for test from 87.142.124.10',
|
||||
# both abuse mails should be separated with space:
|
||||
'mail -s Abuse from 87.142.124.10 abuse-1@abuse-test-server abuse-2@abuse-test-server',
|
||||
'mail -s Hostname: test-host - Abuse from 87.142.124.10 abuse-1@abuse-test-server abuse-2@abuse-test-server',
|
||||
),
|
||||
'ip6-ban': (
|
||||
# test reverse ip:
|
||||
'try to resolve 1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.8.b.d.0.1.0.0.2.abuse-contacts.abusix.org',
|
||||
'Lines containing failures of 2001:db8::1 (max 2)',
|
||||
# both abuse mails should be separated with space:
|
||||
'mail -s Abuse from 2001:db8::1 abuse-1@abuse-test-server abuse-2@abuse-test-server',
|
||||
'mail -s Hostname: test-host - Abuse from 2001:db8::1 abuse-1@abuse-test-server abuse-2@abuse-test-server',
|
||||
),
|
||||
}),
|
||||
)
|
||||
|
@ -1723,6 +1725,7 @@ class ServerConfigReaderTests(LogCaptureTestCase):
|
|||
|
||||
ipv4 = IPAddr('87.142.124.10')
|
||||
ipv6 = IPAddr('2001:db8::1');
|
||||
dmyjail = DummyJail()
|
||||
for jail, act, tests in testJailsActions:
|
||||
# print(jail, jails[jail])
|
||||
for a in jails[jail].actions:
|
||||
|
@ -1736,7 +1739,8 @@ class ServerConfigReaderTests(LogCaptureTestCase):
|
|||
for (test, ip) in (('ip4-ban', ipv4), ('ip6-ban', ipv6)):
|
||||
if not tests.get(test): continue
|
||||
self.pruneLog('# === %s ===' % test)
|
||||
ticket = _actions.CallingMap({
|
||||
'ip': ip, 'ip-rev': lambda self: self['ip'].getPTR(''), 'failures': 100,})
|
||||
ticket = BanTicket(ip)
|
||||
ticket.setAttempt(100)
|
||||
ticket = _actions.Actions.ActionInfo(ticket, dmyjail)
|
||||
action.ban(ticket)
|
||||
self.assertLogged(*tests[test], all=True)
|
||||
|
|
|
@ -273,6 +273,9 @@ def initTests(opts):
|
|||
c.set('192.0.2.%s' % i, None)
|
||||
c.set('198.51.100.%s' % i, None)
|
||||
c.set('203.0.113.%s' % i, None)
|
||||
c.set('2001:db8::%s' %i, 'test-host')
|
||||
# some legal ips used in our test cases (prevent slow dns-resolving and failures if will be changed later):
|
||||
c.set('87.142.124.10', 'test-host')
|
||||
if unittest.F2B.no_network: # pragma: no cover
|
||||
# precache all wrong dns to ip's used in test cases:
|
||||
c = DNSUtils.CACHE_nameToIp
|
||||
|
|
Loading…
Reference in New Issue