https://t.me/RX1948
Server : Apache
System : Linux iad1-shared-b8-43 6.6.49-grsec-jammy+ #10 SMP Thu Sep 12 23:23:08 UTC 2024 x86_64
User : dh_edsupp ( 6597262)
PHP Version : 8.2.26
Disable Function : NONE
Directory :  /lib/python3/dist-packages/fail2ban/tests/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : //lib/python3/dist-packages/fail2ban/tests/__pycache__/observertestcase.cpython-310.pyc
o

;s*b�Y�@s�dZdZdZddlZddlZddlZddlZddlZddlm	Z	ddl
mZmZddl
mZdd	lmZmZdd
lmZddlmZdd
lmZddlmZmZGdd�de�ZGdd�de�ZGdd�de�ZdS)zSerg G. Brester (sebres)z"Copyright (c) 2014 Serg G. Brester�GPL�N�)�MyTime)�
FailTicket�	BanTicket)�FailManager)�	Observers�ObserverThread)�Utils�)�LogCaptureTestCase)�	DummyJail)�
getFail2BanDb�
Fail2BanDbcsJeZdZ�fdd�Z�fdd�Zdd�Zddd	�Zd
d�Zdd
�Z�Z	S)�BanTimeIncrcs,tt|���t�|_|j|j_t�|_dS��Call before every test case.N)�superr�setUpr
�_BanTimeIncr__jail�calcBanTimer	�Observer��self��	__class__��A/usr/lib/python3/dist-packages/fail2ban/tests/observertestcase.pyr.s
zBanTimeIncr.setUpcstt|���dS�N)rr�tearDownrrrrr5�zBanTimeIncr.tearDowncCs|j�|j||�Sr)rrr)r�banTime�banCountrrrr8r zBanTimeIncr.calcBanTimeNcsB|j���dd�|���d�d���dd�|���d�d���dd���dd���d	|�|��fd
d�tdd
�D�gd����dd�gd�}|durqt|�d��}|d
krq|d|d�||dgd
|}|��fdd�tdd
�D�|���dd���dd�|��fdd�tdd
�D�gd����dd�|��fdd�tdd
�D�gd����dd���dd�|��fdd�tdd
�D�gd����dd���dd�|�d �fd!d�td"�D�v���dd�|�d �fd#d�td"�D�v���d	d���dd���dd���dd�dS)$N�	increment�trueT�maxtime�1d�Q�rndtime�factor�multipliersc�g|]}��d|��qS��X�r��.0�i��arr�
<listcomp>G�z+BanTimeIncr.testDefault.<locals>.<listcomp>r��
��`	��%�K���,r'r'r'�30d)
r8r9r:r;r<r=r>iXi�i`	� rrcr+r,r.r/r2rrr4Sr5�2cr+r,r.r/r2rrr4Zr5)
r9r:r;r<r=r>r'r'r'r'z1.33c�g|]
}t��d|���qSr,��intrr/r2rrr4`�)
i<ixi�i�1i�ci��r'r'r'r'�12hcr+r,r.r/r2rrr4gr5�
r8r9r:r;r<r=�rHrHrH�24h�5mFc�&g|]}d�fdd�td�D�v�qS)r8c�g|]}��dd��qS�r-rr.r/r2rrr4nr5�6BanTimeIncr.testDefault.<locals>.<listcomp>.<listcomp>�
��range�r0�cr2rrr4n�&rOcrK)r8crLrMr.r/r2rrr4rr5rNrOrPrRr2rrr4rrT)	r�setBanTimeExtra�assertEqual�getBanTimeExtrarQ�len�split�
assertTrue�assertFalse)rr*�arr�multcntrr2r�testDefault;sh�&������zBanTimeIncr.testDefaultcCs,|�d�|�d�dd�td�D���dS)Nz1 2 4 8 16 32 64 128 256r@cSsg|]}td|>��qS)r)�strr/rrrr4~r5z/BanTimeIncr.testMultipliers.<locals>.<listcomp>�)r^�joinrQrrrr�testMultiplierszs
"zBanTimeIncr.testMultiplierscs�|j���dd���dd���dd���dd���dd�|��fd	d
�tdd�D�gd
����dd�|��fdd
�tdd�D�gd����dd���dd�|��fdd
�tdd�D�gd����dd���dd�|��fdd
�tdd�D�gd����dd���dd�|�d�fdd
�td�D�v���dd�|�d�fdd
�td�D�v���dd���dd���dd���dd���dd�dS)Nr%rIr(�formulazGban.Time * math.exp(float(ban.Count+1)*banFactor)/math.exp(1*banFactor)r)z2.0 / 2.885385r*crBr,rCr/r2rrr4�rEz+BanTimeIncr.testFormula.<locals>.<listcomp>rr6r7r?crBr,rCr/r2rrr4�rE)
r8r9r:r;r<r=r>iXi�i`	�1crBr,rCr/r2rrr4�rE)
i^iQi/i�r'r'r'r'r'r'rFcrBr,rCr/r2rrr4�rErGrJFcrK)r8c�g|]
}t��dd���qSrMrCr/r2rrr4�rE�6BanTimeIncr.testFormula.<locals>.<listcomp>.<listcomp>rOrPrRr2rrr4�rTrOcrK)r8crerMrCr/r2rrr4�rErfrOrPrRr2rrr4�rT)rrUrVrQrZr[rrr2r�testFormula�sR������zBanTimeIncr.testFormular)
�__name__�
__module__�__qualname__rrrr^rbrg�
__classcell__rrrrr,s
?rcsBeZdZ�fdd�Z�fdd�Zddd�Zdd	�Zd
d�Z�ZS)
�
BanTimeIncrDBcsztt|���tdurtjdkrt�d��tdurdSt�	dd�\}|_
t|j
�|_t
�|_|j|j_t�|_|jt_dS)rN)r�zEUnable to import fail2ban database module as sqlite is not available.z.db�	fail2ban_)rrlrr�sys�version_info�unittest�SkipTest�tempfile�mkstemp�
dbFilenamer�dbr
�jail�databaser	rr�Main)r�_rrrr�s�
zBanTimeIncrDB.setUpcs:tdurdS|j��dt_t�|j�tt	|��
�dS�zCall after every test case.N)rr�stoprry�os�removerurrlrrrrrr�s
zBanTimeIncrDB.tearDownNcCs<|j}|dur|�|j���}|�d�|j�|||�}|Sr)rw�
getBanTime�actions�
setBanTimer�incrBanTime)r�ticketr!rw�incrTimerrrr��s
zBanTimeIncrDB.incrBanTimec
	s�tdurdS�j}�j�|�|j�d�|�dd�|�dd�d}tt�	��}t
||g������fdd�td	�D�gd
����
��j�|����dd��j�||dd�D�d
|dfg���|d������d�d��j�|����dd��j�||dd�D�d|ddfg���dd��j�|ddd�D�d|ddfg���dd��jj|||d�D�d|ddfg����jjd|dd�g��jj|dd�}��t|�d||df��jj|dd�}��t|�d||df��jj||dd�}��t|�d||df�d}td�D]#}��||d����d�}��||d��j�|��|}�q��||d����d�}��||d���||��j�|��|}t
|d|d g�}|�d!�|�
��j�||�t
|d"|d g�}|�d#�|�
��j�||��jj|dd�}��t|�d���t|d$�d%|||d|f���t|d
�d&|d"|d d#f��jj|d'dd�}��t|�d	���t|d�d&|d|d d!f���|d
�|����|d
�|����|d�|����|d�|d'��t
|d(|d#g������|d)������|d*����d*�����|d)������|d*����d)�����|d*����d*���
��j�|���jj|dd�}��t|�d	���t|d�d&|d(|d#d*f��j���jj|dd�}��t|�d	���d)���
��j�|���j���jj|dd�}��t|�d���|d$��|�d+�j_�j���jj|dd�}��t|�d
���|d$��|d"�d,�j_�j���jj|dd�}��|g�td-d.�}	d|	j_|	�dd��j|	_�j�|	�td/d-d0�}
d|
j_�j|
_�j�|
�t
||g�}|�d1�|�
��j�|	|�t
||d1g�}|�d2�|� d
�|�
��j�|
|��jj|	|dd�}��t|�d
���t|d$�d&||d1f��jj|
|dd�}��t|�d
���t|d$�d3||d1d2f��j�||	�D]}��|d
|d1f��j�||
�D]
}��|d|d1d2f��jj|dd4�D]}��|d	|d5f�|	j!dd6�|	�"�����j#���t��d&||d1f�|
j!dd6���|
�"�d�|	�d7d8�|	�!�|	�"�����j#���t��d&||d)f�|
�!���|
�"�d�dS)9NrOr#r$r*z&1 2 4 8 16 32 64 128 256 512 1024 2048�	192.0.2.1csg|]}���d��qS)rO)r�r/�rr�rrr4�r5z1BanTimeIncrDB.testBanTimeIncr.<locals>.<listcomp>�)rOrOrOcS�g|]
\}}}|||f�qSrr�r0r"�	timeOfBan�lastBanTimerrrr4�rEFr��cSr�rrr�rrrr4�rErcSr�rrr�rrrr4�rE�TcSr�rrr�rrrr4rE)�
forbantime�fromtimei����)r�r��correctBanTime)�ipr�zFFailTicket: ip=%s time=%s bantime=20 bancount=2 #attempts=0 matches=[])r�r�zH[FailTicket: ip=%s time=%s bantime=20 bancount=2 #attempts=0 matches=[]]�rwr�r��rAr'rHrdi@�rzGFailTicket: ip=%s time=%s bantime=%s bancount=13 #attempts=0 matches=[]zFFailTicket: ip=%s time=%s bantime=%s bancount=1 #attempts=0 matches=[]i ��3r-���i]������polling)�backendzDummyJail-2)�namer�ipi�.zFFailTicket: ip=%s time=%s bantime=%s bancount=2 #attempts=0 matches=[])�overalljailsiPF)r�r%�10m)$rrwrv�addJailr�r�rUrDr�timerrVrQ�incrBanCount�addBan�getBan�setTimer��getCurrentBansr_�assertNotEqualrXr[�
isTimedOutrZ�purge�getIP�	_purgeAger
�filter�
ignoreSelfrx�setBanCount�restoreCurrentBans�
getFailTicket�restored)
rrwr��stime�restored_ticketsr�r1r!�ticket2�jail1�jail2�ticket1�rowrr�r�testBanTimeIncr�sv�
��������


�
�
�



�









�
�
�
�zBanTimeIncrDB.testBanTimeIncrcCstdurdS|j}|j�|�|j�d�|�dd�tj}|�	�|�
|j�|�d�|�d�d|j_
|�ddd	�|jd
dd�|�d
�|�d�|�d�tt���}|j��}|�|g�d}t||dg�}t�}|�d�td�D]}|�|�|�d|||�qz|�d�|�|��d�|�|���|�d�|j�|j|�|jj ||ddd�}	|�t!|	�d�t||g�}t�}|�d�|�|�|�d||j|�|�d�t"�#|jd�}
|�|
�|�|
�$�|�%��|
}t&�'|�}
|�|
|�|�d|
|d�|�d�|�|
�(�d�|�|
��d�|jj ||dd�}	|�t!|	�d�|�|	d�(�d�|�|	d��d�t||ddg�}|�)|�|�*|j�+��t|t��dg�}|�)|�|�|j�+��|�d�|jj ||dd�}	|�t!|	�d�|�|	d�(�d�|�|	d��d�t|dt��dg�}|�d �|�)|�|�|j�+��|�d�t|dt��dg�}|�d!�|�)|�|�*|j�+��|�d�|jj ||dd�}	|�t!|	�d"�|�|	d�(�d �|�|	d��d�|�,�dS)#NrOr#r$�nopr�r��DB_PURGEg����MbP?�db_purgezPurge database event occurredT)�waitg�������?r��xr��failureFoundr�Fr�r�banFound��<ztest-expired-ban-timeztest-actionsi@�rdztest-permanentr�r-r)-rrwrvr�r�r�rUrry�start�db_set�add�
wait_emptyr��add_named_timer�assertLogged�	wait_idlerDrr��getBansrVrr�setMaxRetryrQ�
addFailure�getBanCountrZr�r�r�r�rXr
�wait_for�getRetry�getMaxRetryr�wrapr�
putFailTicketr[�checkBanr|)rrw�obsr��ticketsr�r��failManagerr1r�r��failticket2rrr�testObserver�s�
























zBanTimeIncrDB.testObserverr)	rhrirjrrr�r�r�rkrrrrrl�s


jrlcsHeZdZ�fdd�Z�fdd�Zdd�ZGdd�de�Zd	d
�Z�Z	S)�ObserverTestc�tt|���dSr)rr�rrrrrr6�zObserverTest.setUpcr�r{)rr�rrrrrr:r�zObserverTest.tearDowncCst�}|��|�d�tdg�}|�d|j�|�d|jd�|�d�|�|j�|�	|tdg��d|_
|�d|j�|�d|jd�|�dtj�|�
|j�|�	|tdg��d|_
|�d�|�	|tdg��|�
|���|�
|���|��d}dS)	Nr�test�call�test2T�test3rOF)r	r�r��setr��clearr�r[�is_fullrV�pausedr
�DEFAULT_SLEEP_TIMErZ�isActive�isAliver|)rr��orrr�testObserverBanTimeIncr>s,



z$ObserverTest.testObserverBanTimeIncrc@seZdZdd�ZdS)zObserverTest._BadObservercCstd��)N�run bad thread exception)�RuntimeErrorrrrr�run^szObserverTest._BadObserver.runN)rhrirjr�rrrr�_BadObserver]sr�cs�t��}dd�|_tj}g��fdd�t_z|��|��|����t	�
��fdd�d��W|t_n|t_w��d���t
��d����ddt���t�dd�d	�dS)
NcSsdS)Nrr)�vrrr�<lambda>dsz1ObserverTest.testObserverBadRun.<locals>.<lambda>cs
��|�Sr)�append)�args)�xrrr�hs
cst��o��d�S)N�Unhandled exception)rX�
_is_loggedr�rr�rrr�msr�r�rrr�)r�r�r�ro�__excepthook__r�r|rarZr
r�r�rVrXr�r_)rr��prev_exchookrr�r�testObserverBadRunas

zObserverTest.testObserverBadRun)
rhrirjrrr�r	r�r�rkrrrrr�4sr�)�
__author__�
__copyright__�__license__r}rorqrsr��
server.mytimer�
server.ticketrr�server.failmanagerr�server.observerrr	�server.utilsr
�utilsr�	dummyjailr
�databasetestcaserrrrlr�rrrr�<module>s.

https://t.me/RX1948 - 2025