From b158f83aa3795f387c8475ceb48df197a94a37e8 Mon Sep 17 00:00:00 2001 From: sebres Date: Mon, 13 Jan 2020 12:37:19 +0100 Subject: [PATCH 1/3] testIPAddr_CompareDNS: add missing network constraint (gh-2596) --- fail2ban/tests/filtertestcase.py | 1 + 1 file changed, 1 insertion(+) diff --git a/fail2ban/tests/filtertestcase.py b/fail2ban/tests/filtertestcase.py index d6ad8235..6ca8162b 100644 --- a/fail2ban/tests/filtertestcase.py +++ b/fail2ban/tests/filtertestcase.py @@ -2064,6 +2064,7 @@ class DNSUtilsNetworkTests(unittest.TestCase): ) def testIPAddr_CompareDNS(self): + unittest.F2B.SkipIfNoNetwork() ips = IPAddr('example.com') self.assertTrue(IPAddr("93.184.216.34").isInNet(ips)) self.assertTrue(IPAddr("2606:2800:220:1:248:1893:25c8:1946").isInNet(ips)) From 31a6c8cf5d8897b957fa47edb8c4dcdd5ef57836 Mon Sep 17 00:00:00 2001 From: sebres Date: Mon, 13 Jan 2020 20:12:16 +0100 Subject: [PATCH 2/3] closes gh-2599: fixes `splitwords` for unicode string --- fail2ban/helpers.py | 2 +- fail2ban/tests/misctestcase.py | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/fail2ban/helpers.py b/fail2ban/helpers.py index 213a405f..241543c1 100644 --- a/fail2ban/helpers.py +++ b/fail2ban/helpers.py @@ -291,7 +291,7 @@ def splitwords(s): """ if not s: return [] - return filter(bool, map(str.strip, re.split('[ ,\n]+', s))) + return filter(bool, map(lambda v: v.strip(), re.split('[ ,\n]+', s))) if sys.version_info >= (3,5): eval(compile(r'''if 1: diff --git a/fail2ban/tests/misctestcase.py b/fail2ban/tests/misctestcase.py index cd27ad92..9b986f53 100644 --- a/fail2ban/tests/misctestcase.py +++ b/fail2ban/tests/misctestcase.py @@ -66,6 +66,8 @@ class HelpersTest(unittest.TestCase): self.assertEqual(splitwords(' 1, 2 , '), ['1', '2']) self.assertEqual(splitwords(' 1\n 2'), ['1', '2']) self.assertEqual(splitwords(' 1\n 2, 3'), ['1', '2', '3']) + # string as unicode: + self.assertEqual(splitwords(u' 1\n 2, 3'), ['1', '2', '3']) if sys.version_info >= (2,7): From ec37b1942c4da76f7a0f71efe81bea6835466648 Mon Sep 17 00:00:00 2001 From: sebres Date: Tue, 14 Jan 2020 11:39:13 +0100 Subject: [PATCH 3/3] action.d/nginx-block-map.conf: fixed backslash substitution (different echo behavior in some shells, gh-2596) --- config/action.d/nginx-block-map.conf | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/config/action.d/nginx-block-map.conf b/config/action.d/nginx-block-map.conf index 0b6aa0ad..ee702907 100644 --- a/config/action.d/nginx-block-map.conf +++ b/config/action.d/nginx-block-map.conf @@ -103,6 +103,8 @@ actionstop = %(actionflush)s actioncheck = -actionban = echo "\\\\ 1;" >> '%(blck_lst_file)s'; %(blck_lst_reload)s +_echo_blck_row = printf '\%%s 1;\n' "" -actionunban = id=$(echo "" | sed -e 's/[]\/$*.^|[]/\\&/g'); sed -i "/^\\\\$id 1;$/d" %(blck_lst_file)s; %(blck_lst_reload)s +actionban = %(_echo_blck_row)s >> '%(blck_lst_file)s'; %(blck_lst_reload)s + +actionunban = id=$(%(_echo_blck_row)s | sed -e 's/[]\/$*.^|[]/\\&/g'); sed -i "/^$id$/d" %(blck_lst_file)s; %(blck_lst_reload)s