From e09b7002e00609e97c729828af8e165980c60a10 Mon Sep 17 00:00:00 2001 From: Daniel Black Date: Sat, 7 Dec 2013 12:11:04 +1100 Subject: [PATCH 1/3] TST: missed including testcases CustomDateFormatsTest --- fail2ban/tests/utils.py | 1 + 1 file changed, 1 insertion(+) diff --git a/fail2ban/tests/utils.py b/fail2ban/tests/utils.py index e719750a..290177a4 100644 --- a/fail2ban/tests/utils.py +++ b/fail2ban/tests/utils.py @@ -184,6 +184,7 @@ def gatherTests(regexps=None, no_network=False): tests.addTest(unittest.makeSuite(misctestcase.HelpersTest)) tests.addTest(unittest.makeSuite(misctestcase.SetupTest)) tests.addTest(unittest.makeSuite(misctestcase.TestsUtilsTest)) + tests.addTest(unittest.makeSuite(misctestcase.CustomDateFormatsTest)) # Filter if not no_network: From a37590b3eb29bf935f750e713ea23d576202921f Mon Sep 17 00:00:00 2001 From: Daniel Black Date: Sun, 8 Dec 2013 19:36:21 +1100 Subject: [PATCH 2/3] BF: Fix ISO8601 regex to handle [+-]XX timezone offsets --- fail2ban/server/iso8601.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fail2ban/server/iso8601.py b/fail2ban/server/iso8601.py index a53557fb..a28ce13b 100644 --- a/fail2ban/server/iso8601.py +++ b/fail2ban/server/iso8601.py @@ -41,7 +41,7 @@ __all__ = ["parse_date", "ParseError"] # Adapted from http://delete.me.uk/2005/03/iso8601.html ISO8601_REGEX_RAW = "(?P[0-9]{4})-(?P[0-9]{1,2})-(?P[0-9]{1,2})" \ "T(?P[0-9]{2}):(?P[0-9]{2})(:(?P[0-9]{2})(\.(?P[0-9]+))?)?" \ - "(?PZ|(([-+])([0-9]{2}):([0-9]{2})))?" + "(?PZ|[-+][0-9]{2}(:?[0-9]{2})?)?" ISO8601_REGEX = re.compile(ISO8601_REGEX_RAW) TIMEZONE_REGEX = re.compile("(?P[+-])(?P[0-9]{2}):?(?P[0-9]{2})?") From b64478c5126f493bfe6d7d4bfdaac9eca86813c8 Mon Sep 17 00:00:00 2001 From: Daniel Black Date: Sun, 8 Dec 2013 20:14:00 +1100 Subject: [PATCH 3/3] TST: iso8601 tests --- fail2ban/tests/misctestcase.py | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/fail2ban/tests/misctestcase.py b/fail2ban/tests/misctestcase.py index 5b33f78c..7c6e3283 100644 --- a/fail2ban/tests/misctestcase.py +++ b/fail2ban/tests/misctestcase.py @@ -172,6 +172,7 @@ class TestsUtilsTest(unittest.TestCase): from fail2ban.server import iso8601 import datetime +import time class CustomDateFormatsTest(unittest.TestCase): @@ -190,8 +191,25 @@ class CustomDateFormatsTest(unittest.TestCase): iso8601.parse_date, "2007-01-01T120:00:00Z") self.assertRaises(iso8601.ParseError, iso8601.parse_date, "2007-13-01T12:00:00Z") + date = iso8601.parse_date("2007-01-25T12:00:00+0400") + self.assertEqual( + date, + datetime.datetime(2007, 1, 25, 8, 0, tzinfo=iso8601.Utc())) + date = iso8601.parse_date("2007-01-25T12:00:00+04:00") + self.assertEqual( + date, + datetime.datetime(2007, 1, 25, 8, 0, tzinfo=iso8601.Utc())) + date = iso8601.parse_date("2007-01-25T12:00:00-0400") + self.assertEqual( + date, + datetime.datetime(2007, 1, 25, 16, 0, tzinfo=iso8601.Utc())) + date = iso8601.parse_date("2007-01-25T12:00:00-04") + self.assertEqual( + date, + datetime.datetime(2007, 1, 25, 16, 0, tzinfo=iso8601.Utc())) def testTimeZone(self): # Just verify consistent operation and improve coverage ;) - self.assertEqual(iso8601.parse_timezone(None), iso8601.UTC) - self.assertEqual(iso8601.parse_timezone('Z'), iso8601.UTC) + self.assertEqual((iso8601.parse_timezone(None).tzname(False), iso8601.parse_timezone(None).tzname(True)), time.tzname) + self.assertEqual(iso8601.parse_timezone('Z').tzname(True), "UTC") + self.assertEqual(iso8601.parse_timezone('Z').dst(True), datetime.timedelta(0))