HEX
Server: LiteSpeed
System: Linux 112.webhostingindonesia.co.id 5.14.0-570.62.1.el9_6.x86_64 #1 SMP PREEMPT_DYNAMIC Tue Nov 11 10:10:59 EST 2025 x86_64
User: iyfwylsv (10313)
PHP: 8.2.30
Disabled: NONE
Upload Files
File: //usr/lib/python3.9/site-packages/fail2ban/tests/__pycache__/banmanagertestcase.cpython-39.pyc
a

�M^��;��@spdZdZdZddlZddlmZmZddlmZdd	l	m
Z
dd
lmZGdd�dej
�ZGd
d�dej
�ZdS)z
Cyril Jaquierz Copyright (c) 2004 Cyril Jaquier�GPL�N�)�setUpMyTime�tearDownMyTime�)�
BanManager)�DNSUtils)�	BanTicketcspeZdZ�fdd�Z�fdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�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__��E/usr/lib/python3.9/site-packages/fail2ban/tests/banmanagertestcase.pyr$szAddFailure.setUpcstt|���t�dS�zCall after every test case.N)rr
�tearDownrrrrrr+szAddFailure.tearDowncCsZ|�|j�|j��|�|j��d�|�|j��d�|j�d�|�|j��d�dS)Nrr)�
assertTruer�addBanTicketr�assertEqual�sizeZgetBanTotalZsetBanTotalrrrr�testAdd0s
zAddFailure.testAddcCs>|�|j�|j��|�|j�|j��|�|j��d�dS)Nr)rrrr�assertFalserrrrrr�testAddDuplicate7szAddFailure.testAddDuplicatecCs�|j��}d}dD]�\}}tdd�}td|�}|dur@|�|�|�|j�|��|�|j�|��|�|j��d�|j�	|�
��}|�|�|�|�|��|�|�|�|k�|�|�}|�|��d�|dkr|�|�|�d�qdS)Nr))r
N)g�Tf�AN)r
i�Q)r
���rr
rr!)
r�
getBanTimer	�
setBanTimerrrrr�
getTicketByID�getIDZgetEndOfBanTime�getTime)rZ
defBanTimeZprevEndOfBanTimeZtnewZbtnewZticket1Zticket2Z	banticketrrr�testAddDuplicateWithTime<s"




z#AddFailure.testAddDuplicateWithTimecCs4|�|j�|j��tdd�}|�|j�|��dS)Nrr
)rrrrr	�
_inBanList�r�ticketrrr�testInListOK\s
zAddFailure.testInListOKcCs4|�|j�|j��tdd�}|�|j�|��dS)Nz
111.111.1.111r
)rrrrr	rr(r)rrr�
testInListNOKas
zAddFailure.testInListNOKc	Cst|j��|j���}d}dD]f}|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!r-)r	rr%r&rrr#rr�strr$)rr*�c�irrr�testBanTimeIncrfs"
�

�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&rrr(r�	unBanListrr	r%r�len�ranger#)r�btimeZstimer*r0rrr�	testUnbanys&

  $$$zAddFailure.testUnbanc	Cs�|j��}|j�d�zl|�|j�|j��|�|j�|j��|�|j�|j�	�|d�g�|�|j�
�d�W|j�|�n|j�|�0dS)Nr!r)rr"r#rrrr(rr6r&r)rr9rrr�testUnbanPermanent�s
"zAddFailure.testUnbanPermanentcCsXtdd�tdd�g}|d�d�|D]}|j�|�q&|�|jjddd�dd	g�dS)
Nz	192.0.2.1r
z	192.0.2.2rr!T)ZorderedZwithTimez: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)r	r#rr�assertSortedEqualZ
getBanList)rZtickets�trrr�testBanList�s���zAddFailure.testBanList)�__name__�
__module__�__qualname__rrrr r'r+r,r1r:r;r>�
__classcell__rrrrr
#s r
cs\eZdZ�fdd�Z�fdd�ZdZdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Z�ZS)�StatusExtendedCymruInfocsntt|���tj��t�ttt	�
d���|_d|_d|_
d|_t|jd�}t�|_|�|j�|��dS)rzresolver1.opendns.comZ36692�US�arinr
N)rrCr�unittest�F2BZSkipIfNoNetworkr�next�iterrZdnsToIpZ _StatusExtendedCymruInfo__ban_ip�_StatusExtendedCymruInfo__asn�!_StatusExtendedCymruInfo__country�_StatusExtendedCymruInfo__rirr	r�$_StatusExtendedCymruInfo__banManagerrrr)rrrr�s
zStatusExtendedCymruInfo.setUpcstt|���t�dSr)rrCrrrrrrr�sz StatusExtendedCymruInfo.tearDown)TNcCs^t}|jdr*|jjtjjr dndd�}n
|jd}|�d�rZd|f|_t�d|d��|S)	Nrr�)�timeoutr�errorFz.Skip test because service is not available: %s)	rC�	availablerMZgetBanListExtendedCymruInforFrG�fast�getZSkipTest)rZtc�
cymru_inforrr�_getBanListExtendedCymruInfo�s
�


z4StatusExtendedCymruInfo._getBanListExtendedCymruInfocCs,|��}|�||jg|jg|jgd��dS)N�ZasnZcountryZrir)rU�assertDictEqualrJrKrL)rrTrrr�
testCymruInfo�s��z%StatusExtendedCymruInfo.testCymruInfocCs |�|j�|���|jg�dS�N)rrMZgeBanListExtendedASNrUrJrrrr�testCymruInfoASN�s�z(StatusExtendedCymruInfo.testCymruInfoASNcCs |�|j�|���|jg�dSrY)rrMZgeBanListExtendedCountryrUrKrrrr�testCymruInfoCountry�s�z,StatusExtendedCymruInfo.testCymruInfoCountrycCs |�|j�|���|jg�dSrY)rrMZgeBanListExtendedRIRrUrLrrrr�testCymruInfoRIR�s�z(StatusExtendedCymruInfo.testCymruInfoRIRcCs�t�|_tdd�}|�|j�|��|��}|�|dgdgdgd��tdd�}|�|j�|��|��}|j|ddgddgdd	gd�d
td�dS)Nz0.0.0.0r
ZnxdomainrVz8.0.0.0g<f�AZ3356rDrEr!)�level�key)	rrMr	rrrUrWr<r.)rr*rTrrr�testCymruInfoNxdomain�s(
��
��z-StatusExtendedCymruInfo.testCymruInfoNxdomain)
r?r@rArrrQrUrXrZr[r\r_rBrrrrrC�s

rC)�
__author__�
__copyright__�__license__rF�utilsrrZserver.banmanagerrZserver.ipdnsrZ
server.ticketr	ZTestCaser
rCrrrr�<module>s