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: //lib/python3.9/site-packages/fail2ban/tests/__pycache__/banmanagertestcase.cpython-39.opt-2.pyc
a

�M^��;��@spdZdZdZddlZddlmZmZddlmZdd	l	m
Z
dd
lmZGdd�dej
�ZGd
d�dej
�ZdS)z
Cyril Jaquierz Copyright (c) 2004 Cyril JaquierZGPL�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)r
r	�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���rrrr )
r�
getBanTimer�
setBanTimerrrrr�
getTicketByID�getIDZgetEndOfBanTime�getTime)rZ
defBanTimeZprevEndOfBanTimeZtnewZbtnewZticket1Zticket2Z	banticketrrr�testAddDuplicateWithTime<s"




z#AddFailure.testAddDuplicateWithTimecCs4|�|j�|j��tdd�}|�|j�|��dS)Nrr)rrrrr�
_inBanList�r�ticketrrr�testInListOK\s
zAddFailure.testInListOKcCs4|�|j�|j��tdd�}|�|j�|��dS)Nz
111.111.1.111r)rrrrrrr'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,)rrr$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�	unBanListrrr$r�len�ranger")r�btimeZstimer)r/rrr�	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'rr5r%r)rr8rrr�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)rr"rr�assertSortedEqualZ
getBanList)rZtickets�trrr�testBanList�s���zAddFailure.testBanList)�__name__�
__module__�__qualname__rrrrr&r*r+r0r9r: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)r
zresolver1.opendns.comZ36692�US�arinrN)r
rBr�unittest�F2BZSkipIfNoNetworkr�next�iterrZdnsToIpZ _StatusExtendedCymruInfo__ban_ip�_StatusExtendedCymruInfo__asn�!_StatusExtendedCymruInfo__country�_StatusExtendedCymruInfo__rirrr�$_StatusExtendedCymruInfo__banManagerrrr(rrrr�s
zStatusExtendedCymruInfo.setUpcstt|���t�dSr)r
rBrrrrrrr�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)	rB�	availablerLZgetBanListExtendedCymruInforErFZfast�getZSkipTest)rZtc�
cymru_inforrr�_getBanListExtendedCymruInfo�s
�


z4StatusExtendedCymruInfo._getBanListExtendedCymruInfocCs,|��}|�||jg|jg|jgd��dS)N�ZasnZcountryZrir)rS�assertDictEqualrIrJrK)rrRrrr�
testCymruInfo�s��z%StatusExtendedCymruInfo.testCymruInfocCs |�|j�|���|jg�dS�N)rrLZgeBanListExtendedASNrSrIrrrr�testCymruInfoASN�s�z(StatusExtendedCymruInfo.testCymruInfoASNcCs |�|j�|���|jg�dSrW)rrLZgeBanListExtendedCountryrSrJrrrr�testCymruInfoCountry�s�z,StatusExtendedCymruInfo.testCymruInfoCountrycCs |�|j�|���|jg�dSrW)rrLZgeBanListExtendedRIRrSrKrrrr�testCymruInfoRIR�s�z(StatusExtendedCymruInfo.testCymruInfoRIRcCs�t�|_tdd�}|�|j�|��|��}|�|dgdgdgd��tdd�}|�|j�|��|��}|j|ddgddgdd	gd�d
td�dS)Nz0.0.0.0rZnxdomainrTz8.0.0.0g<f�AZ3356rCrDr )�level�key)	rrLrrrrSrUr;r-)rr)rRrrr�testCymruInfoNxdomain�s(
��
��z-StatusExtendedCymruInfo.testCymruInfoNxdomain)
r>r?r@rrrPrSrVrXrYrZr]rArrrrrB�s

rB)�
__author__Z
__copyright__Z__license__rEZutilsrrZserver.banmanagerrZserver.ipdnsrZ
server.ticketrZTestCaser	rBrrrr�<module>s