o ×¼_:&ã@sddZdZdZddlZddlmZmZddlmZdd l m Z Gd d „d ej ƒZ Gd d „d ej ƒZ dS)z Cyril Jaquierz Copyright (c) 2004 Cyril JaquierÚGPLéNé)Ú setUpMyTimeÚtearDownMyTimeé)Ú BanManager)Ú BanTicketcspeZdZ‡fdd„Z‡fdd„Zdd„Zdd„Zd d „Zd d „Zd d„Z dd„Z dd„Z dd„Z dd„Z ‡ZS)Ú AddFailurecs,tt|ƒ ¡tƒtddƒ|_tƒ|_dS)úCall before every test case.ú 193.168.0.128çÀ;fÑAN)Úsuperr ÚsetUprrÚ_AddFailure__ticketrÚ_AddFailure__banManager©Úself©Ú __class__©úC/usr/lib/python3/dist-packages/fail2ban/tests/banmanagertestcase.pyr#s  zAddFailure.setUpcótt|ƒ ¡tƒdS©zCall after every test case.N)r r ÚtearDownrrrrrr*ó zAddFailure.tearDowncCsZ| |j |j¡¡| |j ¡d¡| |j ¡d¡|j d¡| |j ¡d¡dS)Nrr)Ú assertTruerÚ addBanTicketrÚ assertEqualÚsizeÚ getBanTotalÚ setBanTotalrrrrÚtestAdd/s  zAddFailure.testAddcCs>| |j |j¡¡| |j |j¡¡| |j ¡d¡dS)Nr)rrrrÚ assertFalserrrrrrÚtestAddDuplicate6szAddFailure.testAddDuplicatecCsì|j ¡}d}dD]j\}}tddƒ}td|ƒ}|dur | |¡| |j |¡¡| |j |¡¡| |j ¡d¡|j  |  ¡¡}| |  |¡|  |¡¡| |  |¡|k¡|  |¡}| |  ¡d¡|dkrs| | |¡d¡q dS)Nr))r N)gÀTfÑAN)r i€Q)r éÿÿÿÿr r rr$) rÚ getBanTimerÚ setBanTimerrr"rrÚ getTicketByIDÚgetIDÚgetEndOfBanTimeÚgetTime)rÚ defBanTimeÚprevEndOfBanTimeÚtnewÚbtnewÚticket1Úticket2Ú banticketrrrÚtestAddDuplicateWithTime;s&      €êz#AddFailure.testAddDuplicateWithTimecCs4| |j |j¡¡tddƒ}| |j |¡¡dS)Nr r )rrrrrÚ _inBanList©rÚticketrrrÚ testInListOK[ó zAddFailure.testInListOKcCs4| |j |j¡¡tddƒ}| |j |¡¡dS)Nz 111.111.1.111r )rrrrrr"r3r4rrrÚ testInListNOK`r7zAddFailure.testInListNOKc Cst|j ¡|j ¡ƒ}d}dD]3}|j |j¡|d7}| |¡| |j |¡¡| t |j  | ¡¡ƒd| ¡| ¡||f¡q|j |j¡|d7}| d¡| |j |¡¡| d¡| |j |¡¡| t |j  | ¡¡ƒd| ¡| ¡d|f¡dS)Nr)éèiÐr$rzFBanTicket: ip=%s time=%s bantime=%s bancount=%s #attempts=0 matches=[]r$r9) rrÚgetIPr*rrr&r"rÚstrr')rr5ÚcÚirrrÚtestBanTimeIncres" ÿ  ÿzAddFailure.testBanTimeIncrcCs¤|j ¡}|j ¡}| |j |j¡¡| |j |j¡¡| |j |¡g¡| |j ||d¡|jg¡| |j  ¡d¡| |j |j¡¡t |j  ¡|dƒ}|  |j |¡¡| t |j ||d¡ƒd¡| t |j ||dd¡ƒd¡tdƒD]}t d||ƒ}| | |¡|d¡| |j |¡¡q„| t |j ||dd¡ƒd¡| t |j ||dd¡ƒd ¡| |j  ¡d¡dS) NrriXéz 193.168.0.%sé ré2é)rr%rr*rrr3rÚ unBanListrrr(r"ÚlenÚranger&)rÚbtimeÚstimer5r=rrrÚ testUnbanxs&    $ $$zAddFailure.testUnbanc Cs”|j ¡}|j d¡z7| |j |j¡¡| |j |j¡¡| |j |j  ¡|d¡g¡| |j  ¡d¡W|j |¡dS|j |¡w)Nr$r) rr%r&rrrr3rrCr*r)rrFrrrÚtestUnbanPermanent’s  "zAddFailure.testUnbanPermanentcCsXtddƒtddƒg}|d d¡|D]}|j |¡q| |jjddddd g¡dS) Nz 192.0.2.1r z 192.0.2.2rr$T)ÚorderedÚwithTimez:192.0.2.1 2006-12-31 23:59:59 + 600 = 2007-01-01 00:09:59z9192.0.2.2 2006-12-31 23:59:59 + -1 = 9999-12-31 23:59:59)rr&rrÚassertSortedEqualÚ getBanList)rÚticketsÚtrrrÚ testBanListsþþÿzAddFailure.testBanList)Ú__name__Ú __module__Ú __qualname__rrr!r#r2r6r8r>rHrIrPÚ __classcell__rrrrr "s    r cs\eZdZ‡fdd„Z‡fdd„ZdZdd„Zdd „Zd d „Zd d „Z dd„Z dd„Z ‡Z S)ÚStatusExtendedCymruInfocs`tt|ƒ ¡tj ¡tƒd|_d|_d|_ d|_ t |jdƒ}t ƒ|_ | |j  |¡¡dS)r z 93.184.216.34Ú15133ÚEUÚripenccr N)r rUrÚunittestÚF2BÚSkipIfNoNetworkrÚ _StatusExtendedCymruInfo__ban_ipÚ_StatusExtendedCymruInfo__asnÚ!_StatusExtendedCymruInfo__countryÚ_StatusExtendedCymruInfo__rirrrÚ$_StatusExtendedCymruInfo__banManagerrrr4rrrr®s  zStatusExtendedCymruInfo.setUpcrr)r rUrrrrrrr»rz StatusExtendedCymruInfo.tearDown)TNcCs^t}|jdr|jjtjjrdndd}n|jd}| d¡r-d|f|_t d|d¡‚|S) Nrré)ÚtimeoutrÚerrorFz.Skip test because service is not available: %s) rUÚ availabler`ÚgetBanListExtendedCymruInforYrZÚfastÚgetÚSkipTest)rÚtcÚ cymru_inforrrÚ_getBanListExtendedCymruInfoÂs ÿ   z4StatusExtendedCymruInfo._getBanListExtendedCymruInfocCs,| ¡}| ||jg|jg|jgdœ¡dS)N©ÚasnÚcountryÚrir)rkÚassertDictEqualr]r^r_)rrjrrrÚ testCymruInfoÏsþÿz%StatusExtendedCymruInfo.testCymruInfocCó | |j | ¡¡|jg¡dS©N)rr`ÚgeBanListExtendedASNrkr]rrrrÚtestCymruInfoASNÖóþz(StatusExtendedCymruInfo.testCymruInfoASNcCrrrs)rr`ÚgeBanListExtendedCountryrkr^rrrrÚtestCymruInfoCountryÛrvz,StatusExtendedCymruInfo.testCymruInfoCountrycCrrrs)rr`ÚgeBanListExtendedRIRrkr_rrrrÚtestCymruInfoRIRàrvz(StatusExtendedCymruInfo.testCymruInfoRIRcCs”tƒ|_tddƒ}| |j |¡¡| ¡}| |dgdgdgdœ¡tddƒ}| |j |¡¡| ¡}|j|ddgddgdd gdœd td dS) Nz0.0.0.0r Únxdomainrlz8.0.0.0g<fÑAÚ3356ÚUSÚarinr$)ÚlevelÚkey) rr`rrrrkrprLr;)rr5rjrrrÚtestCymruInfoNxdomainås( þÿ þ ýz-StatusExtendedCymruInfo.testCymruInfoNxdomain) rQrRrSrrrdrkrqrurxrzrrTrrrrrU­s   rU)Ú __author__Ú __copyright__Ú __license__rYÚutilsrrÚserver.banmanagerrÚ server.ticketrÚTestCaser rUrrrrÚs