%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /usr/lib/python2.7/site-packages/fail2ban/tests/
Upload File :
Create Path :
Current File : //usr/lib/python2.7/site-packages/fail2ban/tests/actionstestcase.pyo

�
��&dc@s�dZdZdZddlZddlZddlZddlmZddlm	Z	dd	l
mZdd
lm
Z
mZmZmZejjejje�d�Zde
fd
��YZdS(sDaniel BlacksCopyright (c) 2013 Daniel BlacktGPLi����Ni(t
FailTicket(tUtilsi(t	DummyJail(tLogCaptureTestCaset
with_alt_timetwith_tmpdirtMyTimetfilestExecuteActionscBs�eZd�Zd�Zid�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zed
��Z
d�Zd�Zeed
���ZRS(cCs2tt|�j�t�|_|jj|_dS(N(tsuperR	tsetUpRt_ExecuteActions__jailtactionst_ExecuteActions__actions(tself((sB/usr/lib/python2.7/site-packages/fail2ban/tests/actionstestcase.pyR)scCstt|�j�dS(N(R
R	ttearDown(R((sB/usr/lib/python2.7/site-packages/fail2ban/tests/actionstestcase.pyR/scCs�|jjd�|jd}d|jdd�|_d|jdd�|_d|jdd�|_d	|jd
d�|_d|jdd�|_d
|jdd�|_|S(Ntips
echo ip starttstarttsecho ip ban <ip>tbansecho ip unban <ip>tunbans
echo ip checktchecks
echo ip flushtflushsecho ip stoptstop(	Rtaddtgettactionstartt	actionbantactionunbantactionchecktactionflusht
actionstop(Rtotact((sB/usr/lib/python2.7/site-packages/fail2ban/tests/actionstestcase.pyt
defaultAction2s
cCs-|jjd�|jt|jjd�dS(Nttest(RRtassertRaisest
ValueError(R((sB/usr/lib/python2.7/site-packages/fail2ban/tests/actionstestcase.pyttestActionsAddDuplicateName=scCs�|jjd�|j|jd�|jd|j�|jd|j�|jjd�|jd=|jd=|jd|j�|jt|j�d�|jjd�|j|jj�d�|j	t
|jjd�dS(NR$snonexistant actionttest1iis	127.0.0.1(RRt
assertTruetassertIntassertNotIntassertEqualtlent
setBanTimet
getBanTimeR%R&tremoveBannedIP(R((sB/usr/lib/python2.7/site-packages/fail2ban/tests/actionstestcase.pyttestActionsManipulationAs

cCs�|j|jjd�d�|jd�|j�|j|jjdddg�d�|jd�|jd�|jd�|jd	�dS(
Ns	192.0.2.1is
Ban 192.0.2.1s	192.0.2.2s	192.0.2.3is192.0.2.1 already banneds
Ban 192.0.2.2s
Ban 192.0.2.3(R,RtaddBannedIPtassertLoggedtpruneLogtassertNotLogged(R((sB/usr/lib/python2.7/site-packages/fail2ban/tests/actionstestcase.pyttestAddBannedIPPs

%


cCs�|j�|jj�|jddt�|jj�|jj�|jdd
�|j|jj�ddd	gfg�|j|jjd
�ddg�dS(Ns
stdout: %rsip starttwaitsip flushsip stopsCurrently bannedisTotal bannedsBanned IP listtshortsstdout: 'ip start'sstdout: 'ip flush'sstdout: 'ip stop'(sCurrently bannedi(sTotal bannedi(sCurrently bannedi(sTotal bannedi(	R#RRR3tTrueRtjoinR,tstatus(R((sB/usr/lib/python2.7/site-packages/fail2ban/tests/actionstestcase.pyttestActionsOutputZs



csV�jjdtjjtd�idd6��jd��jj��jt	j
�fd�d���jj��jj��jd��jt
�jjd	d
i��jjdtjjtd�idd6dd
6��jt�jjdtjjtd�idd6dd
6dd6��jt�jjdtjjtd�i�dS(NtActionsaction.d/action.pytvaluetopt1sTestAction initialisedcs
�jd�S(NsTestAction action start(t
_is_logged((R(sB/usr/lib/python2.7/site-packages/fail2ban/tests/actionstestcase.pyt<lambda>nsisTestAction action stoptAction3s/does/not/exist.pytAction4tvalue2topt2tAction5tvalue3topt3(RRtostpathR:tTEST_FILES_DIRR3RR)Rtwait_forRR%tIOErrort	TypeError(R((RsB/usr/lib/python2.7/site-packages/fail2ban/tests/actionstestcase.pyttestAddActionPythonfs*	

"


		cs��jt�jjdtjjtd�i��jt�jjdtjjtd�i��jjdtjjtd�i��jj��j	t
j�fd�d���jj��jj��j
d�dS(NR=saction.d/action_noAction.pysaction.d/action_nomethod.pysaction.d/action_errors.pycs
�jd�S(NsFailed to start(R@((R(sB/usr/lib/python2.7/site-packages/fail2ban/tests/actionstestcase.pyRA�sisFailed to stop(R%tRuntimeErrorRRRIRJR:RKRR)RRLRR3(R((RsB/usr/lib/python2.7/site-packages/fail2ban/tests/actionstestcase.pyttestAddPythonActionNOK�s"	
"

cCs�|jjdtjjtd�i�|jjdtjjtd�i�|jjtd��|jj	�|j
d�|jd�|jd�|jj�|j
d�|jd	�|jd
�dS(Ntaction1saction.d/action_modifyainfo.pytaction2s1.2.3.4sFailed to execute bansaction1 ban deleted aInfo IPsaction2 ban deleted aInfo IPsFailed to execute unbansaction1 unban deleted aInfo IPsaction2 unban deleted aInfo IP(
RRRIRJR:RKRt
putFailTicketRt_Actions__checkBanR5R3t_Actions__flushBan(R((sB/usr/lib/python2.7/site-packages/fail2ban/tests/actionstestcase.pyttestBanActionsAInfo�s"		






cCs3d|j_d|j_|jjd�|jj�tjd�d}x=|dkr�d|}|jjt	|d��|d7}qKW|j
dd	t�tjd
�x=|dkr�d|}|jjt	|d
��|d7}q�W|j
dd	t�|jj�|jj
�|j
d
�|jd�dS(Niiidiis
192.0.2.%dis / 20,R7i�i2s / 50,sUnbanned 30, 0 ticket(s)sUnbanned 50, 0 ticket(s)(Rt
banPrecedencet
unbanMaxCountR.RRtsetTimeRRTRR3R9RR:R5(RtiR((sB/usr/lib/python2.7/site-packages/fail2ban/tests/actionstestcase.pyttestUnbanOnBusyBanBombing�s*







cCs�|jidd6dd6�}|jd|d<t|_|jj�|jd$�|j|jjd�d	�|j|jjd
�d	�|j	ddd%dd
dddtdt�|j
d�|jd|d<|jjd
�|j	ddt�|j
d�|jj
�|j	dddddddd&ddtdt�|j
d�|j|d<|j|jjd
�d	�|j	dd'dddtdt�|jdddt�|j
d�|jj
�|j	dddddddtdt�|jddd(d)ddt�|j
d �|j|d<|jj�|jj�|j	ddd*d!dtdt�|jd"ddd#dt�dS(+Ns	 <family>RRs; exit 1sactionflush?family=inet6s
stdout: %rsip starts	192.0.2.1is2001:db8::1s
Ban 192.0.2.1sBan 2001:db8::1sip ban 192.0.2.1sip ban 2001:db8::1tallR7s>[test-phase 1a] simulate inconsistent irreparable env by unbansactioncheck?family=inet6s,Invariant check failed. Unban is impossible.s>[test-phase 1b] simulate inconsistent irreparable env by flushsip flush inet4sip flush inet6sFailed to flush banss'No flush occurred, do consistency checks<Invariant check failed. Trying to restore a sane environmentsip stops[test-phase 2] consistent envsip check inet4s-[test-phase 3] failed flush in consistent envsip check inet6sUnable to restore environments![test-phase end] flush successfulsaction ip terminatedtERRORsUnban tickets each individualysstdout: 'ip start'sstdout: 'ip start'sstdout: 'ip stop'sstdout: 'ip start'sstdout: 'ip stop'sstdout: 'ip start'sstdout: 'ip stop'(R#RR9tactionstart_on_demandRRR5R,R2R3R4RR0RVRR:(RR"((sB/usr/lib/python2.7/site-packages/fail2ban/tests/actionstestcase.pyttestActionsConsistencyCheck�s~	









	



	






	cCs�|jidd6dd6dd6dd6�}|jd|d<t|_t|_|jj�|jd,�|j|jj	d
�d�|j|jj	d�d�|j
d
ddddddddddtdt�|jd|d<|jd�|jj
d�|j
ddddtdt�|jdddddddt�|jd�|j|jj	d�d�|j
ddddddddddtdt�|jdddddt�|j|d<|j|jj	d�d�|jd|d<|jd�|jj�|j
dd dd!d"d#dddd$dtdt�|jdddt�|jd%�|j|d<|j|jj	d�d�|j
ddddddtdt�|jdd&dddt�|jd'�|j|d<|jj�|j
d"d#dd!dddtdt�|jdd dddddddddt�|jd(�|j|d<|jj�|jj�|j
dd!ddddd)dtdt�|jd*dd d+dt�dS(-Ns	 <family>RRRRs; exit 1sactionflush?family=inet6s
stdout: %rsip starts	192.0.2.1is2001:db8::1s
Ban 192.0.2.1sBan 2001:db8::1sip start inet4sip ban 192.0.2.1sip start inet6sip ban 2001:db8::1R]R7sactioncheck?family=inet6s>[test-phase 1a] simulate inconsistent irreparable env by unbans<Invariant check failed. Trying to restore a sane environments
ip stop inet6s
ip stop inet4s<[test-phase 1b] simulate inconsistent irreparable env by bansip check inet6sUnable to restore environmentsFailed to execute bans2001:db8::2s>[test-phase 1c] simulate inconsistent irreparable env by flushsip flush inet4sip flush inet6sFailed to flush banss'No flush occurred, do consistency checksFailed to flush bans in jails[test-phase 2] consistent envsip check inet4s-[test-phase 3] failed flush in consistent envs![test-phase end] flush successfulsaction ip terminatedR^sUnban tickets each individualysstdout: 'ip start'(R#RR9R_tactionrepair_on_unbanRRR5R,R2R3RR4R0RVRR:(RR"((sB/usr/lib/python2.7/site-packages/fail2ban/tests/actionstestcase.pyt"testActionsConsistencyCheckDiffFam"s�+		




	



	








	





	







	cCs�|jidd6dd6dd6dd6d	d
6�}|d|d<t|_d
|_d|_|jd�|j|jjddg�d�|j	dddddddddddt�|jd�|j
|d�|j	d�|jd�|j�|j
|d�|j	d�|jd�tj
tj�d �|jd!�|j|jjddd"g�d#�|j	d$d%d&dd'dd(dt�|j
|d�|j
|d�|jd)d*dddd+dddd,d-d.dt�tj
tj�d �tj|d�tj|d�|jd/�|j|jjddg�d�|j	d0dd1dd2d3d4dd+dd,dt�|jd5�|j|jjd"�d#�|j	d6dd7dt�|jd0dd1dd2d3d4dd+dd,dt�|jd8�|j
|d�|j	d9�|jd:�|j�|j
|d�|j	d:d;dt�|jd9�d<|_d=|_|j|jjtdd>��d>�|j	d?d@dt�dS(ANs <family>; touch "<FN>"Rs <family>; test -f "<FN>"Rs <family>; echo -n "" > "<FN>"Rs <family>; rm -f "<FN>"Rs) <family>; echo "<ip> <family>" >> "<FN>"Rs	/<family>tFNs%echo ip repair <family>; touch "<FN>"sGecho ip reban <ip> <family>; echo "<ip> <family> -- rebanned" >> "<FN>"s[test-phase 0] initial bans	192.0.2.1s2001:db8::1is
Ban 192.0.2.1sBan 2001:db8::1s
stdout: %rsip start inet4sip ban 192.0.2.1 inet4sip start inet6sip ban 2001:db8::1 inet6R]s[test-phase 1] check bans/inet4s192.0.2.1 inet4s2001:db8::1 inet6s/inet6is#[test-phase 2] check already banneds2001:db8::2is192.0.2.1 already banneds2001:db8::1 already bannedsBan 2001:db8::2sip check inet4sip check inet6sReban 192.0.2.1sReban 2001:db8::1sip reban 192.0.2.1 inet4sip reban 2001:db8::1 inet6s192.0.2.1 inet4 -- repaireds2001:db8::1 inet6 -- repaireds3[test-phase 3a] check reban after sane env repaireds<Invariant check failed. Trying to restore a sane environmentsip repair inet4sip repair inet6sReban 192.0.2.1, action 'ip'sReban 2001:db8::1, action 'ip's>[test-phase 3a] check reban by epoch mismatch (without repair)sReban 2001:db8::2, action 'ip'sip reban 2001:db8::2 inet6s[test-phase 4] check rebans192.0.2.1 inet4 -- rebanneds2001:db8::1 inet6 -- rebanneds2001:db8::2 inet6 -- rebannedRsexit 1isFailed to execute rebansError banning 192.0.2.1(R#R9R_tactionrepairtactionrebanR4R,RR2R3tdumpFileR5RRZttimeRItremoveRt_Actions__reBanR(RttmpR"((sB/usr/lib/python2.7/site-packages/fail2ban/tests/actionstestcase.pyt!testActionsRebanBrokenAfterRepair�s�	
			
"







%	

"









		%(t__name__t
__module__RRR#R'R1R6R<RORQRWRR\R`RbRRk(((sB/usr/lib/python2.7/site-packages/fail2ban/tests/actionstestcase.pyR	's					
				&	K	o(t
__author__t
__copyright__t__license__RgRIttempfilet
server.ticketRtserver.utilsRt	dummyjailRtutilsRRRRRJR:tdirnamet__file__RKR	(((sB/usr/lib/python2.7/site-packages/fail2ban/tests/actionstestcase.pyt<module>s"!

Zerion Mini Shell 1.0