o ×¼_/$ã@s^dZdZdZddlZddlmZddlmZddlmZdd l m Z m Z Gd d „d ej ƒZ dS) zAlexander Koeppez>Copyright (c) 2016 Cyril Jaquier, 2011-2013 Yaroslav HalchenkoÚGPLéNé)Ú Beautifier)Úversion)ÚIPAddr)ÚUnknownJailExceptionÚDuplicateJailExceptioncsèeZdZ‡fdd„Z‡fdd„Zdd„Zdd„Zd d „Zd d „Zd d„Z dd„Z dd„Z dd„Z dd„Z dd„Zdd„Zdd„Zdd„Zdd „Zd!d"„Zd#d$„Zd%d&„Zd'd(„Zd)d*„Zd+d,„Zd-d.„Zd/d0„Zd1d2„Zd3d4„Z‡ZS)5ÚBeautifierTestcstt|ƒ ¡tƒ|_dS)z Call before every test case N)Úsuperr ÚsetUprÚb©Úself©Ú __class__©úI/usr/lib/python3/dist-packages/fail2ban/tests/clientbeautifiertestcase.pyr !s zBeautifierTest.setUpcstt|ƒ ¡dS)z Call after every test case N)r r ÚtearDownr rrrr&szBeautifierTest.tearDowncCs(dg}|j |¡| |j ¡|¡dS)NÚtest)r Ú setInputCmdÚ assertEqualÚ getInputCmd)rÚcmdrrrÚtestGetInputCmd*s zBeautifierTest.testGetInputCmdcCó&|j dg¡| |j d¡d¡dS)NÚpingÚpongzServer replied: pong©r rrÚbeautifyr rrrÚtestPing/ózBeautifierTest.testPingcCs&|j dg¡| |j t¡t¡dS)Nr)r rrrrr rrrÚ testVersion3r zBeautifierTest.testVersioncCr)NÚaddÚsshzAdded jail sshrr rrrÚ testAddJail7r zBeautifierTest.testAddJailcCó&|j dg¡| |j d¡d¡dS)NÚstartz Jail startedrr rrrÚ testStartJail;r zBeautifierTest.testStartJailcCs(|j ddg¡| |j d¡d¡dS)NÚstopr#z Jail stoppedrr rrrÚ testStopJail?szBeautifierTest.testStopJailcCr%)Nr(zShutdown successfulrr rrrÚ testShutdownCr zBeautifierTest.testShutdownc CsÒ|j dg¡ddddgff}d}| |j |¡|¡|j ddg¡dgd¢fd d d d td ƒtdƒtdƒgfgff}d}|d7}|d7}|d7}|d7}|d7}|d7}|d7}|d7}| |j |¡|¡dS)NÚstatus)zNumber of jailsrz Jail listr#Úexim4z4Status |- Number of jails: 0 `- Jail list: ssh exim4ÚFilter))zCurrently failedr)z Total failedr)z File listú/var/log/auth.logÚActions)zCurrently bannedé)z Total bannedr0zBanned IP listz 192.168.0.1z::ffff:10.2.2.1z 2001:db8::1zStatus for the jail: ssh z |- Filter z| |- Currently failed: 0 z| |- Total failed: 0 z#| `- File list: /var/log/auth.log z `- Actions z |- Currently banned: 3 z |- Total banned: 3 z6 `- Banned IP list: 192.168.0.1 10.2.2.1 2001:db8::1©r rrrr©rÚresponseÚoutputrrrÚ testStatusGs4 ýýùzBeautifierTest.testStatuscCr)NÚ flushlogsz rolled overzlogs: rolled overrr rrrÚ testFlushLogslr zBeautifierTest.testFlushLogscCó,|j ddg¡d}| |j d¡|¡dS)NÚgetÚ syslogsocketz!Current syslog socket is: `- autoÚautor©rr4rrrÚtestSyslogSocketpózBeautifierTest.testSyslogSocketcCr8)Nr9Ú logtargetz3Current logging target is: `- /var/log/fail2ban.logz/var/log/fail2ban.logrr<rrrÚ testLogTargetur>zBeautifierTest.testLogTargetcCr8)Nr9ÚloglevelzCurrent logging level is 'INFO'ÚINFOrr<rrrÚ testLogLevelzr>zBeautifierTest.testLogLevelcCsH|j ddg¡d}d|}| |j |¡|¡| |j d¡d¡dS)Nr9Údbfilez"/var/lib/fail2ban/fail2ban.sqlite3zCurrent database file is: `- úDatabase currently disabledrr2rrrÚ testDbFiles zBeautifierTest.testDbFilecCs@|j ddg¡d}| |j d¡|¡| |j d¡d¡dS)Nr9Ú dbpurgeagez.Current database purge age is: `- 86400secondsi€QrErr<rrrÚtestDbPurgeAge†szBeautifierTest.testDbPurgeAgecCs°|j gd¢¡g}d}| |j |¡|¡dg}d}| |j |¡|¡|j gd¢¡ddg}d}|d7}| |j |¡|¡|j gd ¢¡dg}| |j |¡|¡dS) N)r9ÚsshdÚlogpathzNo file is currently monitoredr.z3Current monitored log file(s): `- /var/log/auth.log)ÚsetrIÚ addlogpathú/var/log/messagesrMzCurrent monitored log file(s): z)|- /var/log/messages `- /var/log/auth.log)rKrIÚ dellogpathrMr)rr3r4Ú outputaddrrrÚ testLogPathŒszBeautifierTest.testLogPathcCs,|j gd¢¡d}| |j d¡|¡dS)N)r9rIÚ logencodingz%Current log encoding is set to: UTF-8zUTF-8rr<rrrÚtestLogEncodingŸr>zBeautifierTest.testLogEncodingcCsÈ|j gd¢¡| |j g¡d¡|j gd¢¡ddgg}d}|d7}| |j |¡|¡| dd g¡|d 7}| |j |¡|¡|j gd ¢¡| |d ¡| |j |¡| d ¡d¡dS)N)r9rIÚ journalmatchzNo journal match filter set)rKrIÚaddjournalmatchÚ _SYSTEMD_UNITz sshd.servicezCurrent match filter: z_SYSTEMD_UNIT sshd.serviceÚ_COMMrIz + _COMM sshd)rKrIÚdeljournalmatchéz + r)r rrrÚappendÚremoveÚsplitr2rrrÚtestJournalMatch¤s "zBeautifierTest.testJournalMatchcCsd|j gd¢¡d}d}| |j d¡|d¡| |j |¡|d¡| |j d¡|d¡dS)N)r9rIÚ datepatternzCurrent date pattern set to: )NúDefault DetectorszNot set/requiredr^)rrz test (test)r©rr4r3rrrÚtestDatePattern¶sÿÿÿzBeautifierTest.testDatePatterncCs”|j gd¢¡d}| |j g¡|¡|j gd¢¡tddƒtdƒtddƒtd ƒg}d }|d 7}|d 7}|d 7}|d7}| |j |¡|¡dS)N)r9rIÚignoreipz No IP address/network is ignored)rKrIÚ addignoreipz 127.0.0.0éz::1z 2001:db8::é z::ffff:10.0.2.1z)These IP addresses/networks are ignored: z|- 127.0.0.0/8 z|- ::1 z|- 2001:db8::/32 z `- 10.0.2.1r1r_rrrÚ testIgnoreIPÁsüzBeautifierTest.testIgnoreIPcCóP|j gd¢¡d}| |j g¡|¡d}|d7}| |j ddg¡|¡dS)N)r9rIÚ failregexz No regular expression is definedz.The following regular expression are defined: z|- [0]: ^$ `- [1]: .*z^$z.*rr<rrrÚ testFailRegexÔó zBeautifierTest.testFailRegexcCsN|j gd¢¡d}| |j g¡|¡d}|d7}| |j dg¡|¡dS)N)r9rIÚactionszNo actions for jail sshdz)The jail sshd has the following actions: ziptables-multiportrr<rrrÚ testActionsÝs zBeautifierTest.testActionscCsP|j gd¢¡d}| |j g¡|¡d}|d7}d}| |j |¡|¡dS)N)r9rIÚactionpropertiesÚiptablesz+No properties for jail sshd action iptablesz;The jail sshd action iptables has the following properties:z actionban, actionunban)Ú actionbanÚ actionunbanrr_rrrÚtestActionPropertiesæsz#BeautifierTest.testActionPropertiescCrf)N)r9rIÚ actionmethodsrmz(No methods for jail sshd action iptablesz9The jail sshd action iptables has the following methods: z ban, unbanÚbanÚunbanrr<rrrÚtestActionMethodsðriz BeautifierTest.testActionMethodscCs^tdƒ}d}| |j |¡|¡tdƒ}d}| |j |¡|¡d}| |j tƒ¡|¡dS)NrIz(Sorry but the jail 'sshd' does not existzThe jail 'sshd' already existsz Sorry but the command is invalid)rrr Ú beautifyErrorrÚ IndexErrorr2rrrÚtestBeautifyErrorýsz BeautifierTest.testBeautifyError)Ú__name__Ú __module__Ú __qualname__r rrrr!r$r'r)r*r5r7r=r@rCrFrHrPrRr\r`rerhrkrprtrwÚ __classcell__rrrrr s6  %     r )Ú __author__Ú __copyright__Ú __license__ÚunittestÚclient.beautifierrrÚ server.ipdnsrÚ exceptionsrrÚTestCaser rrrrÚs