From 970291867bf3499f772d88d23c1fa628e6c6363e Mon Sep 17 00:00:00 2001 From: Steven Hiscocks Date: Fri, 10 May 2013 17:14:13 +0100 Subject: [PATCH] TST: Improve tests for JailReader extract options --- fail2ban/tests/clientreadertestcase.py | 30 +++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/fail2ban/tests/clientreadertestcase.py b/fail2ban/tests/clientreadertestcase.py index 61101aa5..79bd4664 100644 --- a/fail2ban/tests/clientreadertestcase.py +++ b/fail2ban/tests/clientreadertestcase.py @@ -145,11 +145,35 @@ class JailReaderTest(unittest.TestCase): self.assertEqual(jail.getName(), 'sshd') def testSplitOption(self): - action = "mail-whois[name=SSH]" + # Simple example + option = "mail-whois[name=SSH]" expected = ['mail-whois', {'name': 'SSH'}] - result = JailReader.extractOptions(action) - self.assertEquals(expected, result) + result = JailReader.extractOptions(option) + self.assertEqual(expected, result) + # Empty option + option = "abc[]" + expected = ['abc', {}] + result = JailReader.extractOptions(option) + self.assertEqual(expected, result) + + # More complex examples + option = 'option[opt01=abc,opt02="123",opt03="with=okay?",opt04="andwith,okay...",opt05="how about spaces",opt06="single\'in\'double",opt07=\'double"in"single\', opt08= leave some space, opt09=one for luck, opt10=, opt11=]' + expected = ['option', { + 'opt01': "abc", + 'opt02': "123", + 'opt03': "with=okay?", + 'opt04': "andwith,okay...", + 'opt05': "how about spaces", + 'opt06': "single'in'double", + 'opt07': "double\"in\"single", + 'opt08': "leave some space", + 'opt09': "one for luck", + 'opt10': "", + 'opt11': "", + }] + result = JailReader.extractOptions(option) + self.assertEqual(expected, result) class FilterReaderTest(unittest.TestCase):