HEX
Server: Apache/2.4.58 (Ubuntu)
System: Linux ns3133907 6.8.0-86-generic #87-Ubuntu SMP PREEMPT_DYNAMIC Mon Sep 22 18:03:36 UTC 2025 x86_64
User: cssnetorguk (1024)
PHP: 8.2.28
Disabled: NONE
Upload Files
File: //lib/python3/dist-packages/fail2ban/tests/__pycache__/banmanagertestcase.cpython-312.pyc
�

�ogf�&���dZdZdZddlZddlmZmZddlmZdd	l	m
Z
dd
lmZGd�dej�ZGd
�dej�Zy)z
Cyril Jaquierz Copyright (c) 2004 Cyril Jaquier�GPL�N�)�setUpMyTime�tearDownMyTime�)�
BanManager)�DNSUtils)�	BanTicketc�^��eZdZ�fd�Z�fd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zd
�Zd�Z
�xZS)�
AddFailurec�~��tt|��t�t	dd�|_t
�|_y)�Call before every test case.�
193.168.0.128��;f�AN)�superr�setUprr
�_AddFailure__ticketr�_AddFailure__banManager��self�	__class__s ��C/usr/lib/python3/dist-packages/fail2ban/tests/banmanagertestcase.pyrzAddFailure.setUp$s-����
�D��!�
�-��O�\�:�$�-� �l�$��c�>��tt|��t�y�zCall after every test case.N)rr�tearDownrrs �rrzAddFailure.tearDown+s����
�D�"�$��rc��|j|jj|j��|j	|jj�d�|j	|jj
�d�|jjd�|j	|jj
�d�y)Nrr)�
assertTruer�addBanTicketr�assertEqual�size�getBanTotal�setBanTotal�rs r�testAddzAddFailure.testAdd0s����/�/�$�#�#�0�0����?�@����4�$�$�)�)�+�Q�/����4�$�$�0�0�2�A�6�������"����4�$�$�0�0�2�A�6rc�(�|j|jj|j��|j	|jj|j��|j|jj
�d�y)Nr)rrrr�assertFalser r!r$s r�testAddDuplicatezAddFailure.testAddDuplicate7se���/�/�$�#�#�0�0����?�@����4�$�$�1�1�$�-�-�@�A����4�$�$�)�)�+�Q�/rc�P�|jj�}d}dD�]�\}}tdd�}td|�}|�|j|�|j	|jj|��|j
|jj|��|j|jj�d�|jj|j��}|j|j|�|j|��|j	|j|�|kD�|j|�}|j|j�d�|dk(s��d|j|j|�d����y)Nr))rN)g�Tf�AN)ri�Q)r���rrrr*)
r�
getBanTimer
�
setBanTimerrr'r r!�
getTicketByID�getID�getEndOfBanTime�getTime)r�
defBanTime�prevEndOfBanTime�tnew�btnew�ticket1�ticket2�	bantickets        r�testAddDuplicateWithTimez#AddFailure.testAddDuplicateWithTime<sf��� � �+�+�-�*����;�k�d�E����
5�7�
���
-�7������u���?�?�4�$�$�1�1�'�:�;����D�%�%�2�2�7�;�<����D�%�%�*�*�,�a�0�� � �.�.�w�}�}��?�9����I�-�-�j�9�7�;R�;R�S]�;^�_��?�?�9�,�,�Z�8�;K�K�L��-�-�j�9�����I�%�%�'��6��r�k����Y�)�)�*�5�r�:�-;rc���|j|jj|j��t	dd�}|j|jj|��y)Nrr)rrrrr
�
_inBanList�r�tickets  r�testInListOKzAddFailure.testInListOK\sL���/�/�$�#�#�0�0����?�@��_�l�3�&��/�/�$�#�#�.�.�v�6�7rc���|j|jj|j��t	dd�}|j|jj
|��y)Nz
111.111.1.111r)rrrrr
r'r:r;s  r�
testInListNOKzAddFailure.testInListNOKasN���/�/�$�#�#�0�0����?�@��_�l�3�&����4�$�$�/�/��7�8rc
�D�t|jj�|jj��}d}dD]�}|jj|j�|dz
}|j
|�|j|jj|��|jt|jj|j���d|j��d|j��d|�d|�d�	���|jj|j�|dz
}|j
d	�|j|jj|��|j
d
�|j|jj|��|jt|jj|j���d|j��d|j��dd	�d|�d�	�y)Nr)��i�r*rzBanTicket: ip=z time=z	 bantime=z
 bancount=z #attempts=0 matches=[]r*rA)r
rr.r0rrr,r'r �strr-)rr<�c�is    r�testBanTimeIncrzAddFailure.testBanTimeIncrfs����T�]�]�(�(�*�D�M�M�,A�,A�,C�D�&��!��y�a����!�!�$�-�-�0�!�q�&�!�	���Q�����D�%�%�2�2�6�:�;����C��)�)�7�7�����G�H�PV�P\�P\�P^�`f�`n�`n�`p�rs�uv�w�y�	y���� � ����/��a������B�����4�$�$�1�1�&�9�:����D�����4�$�$�1�1�&�9�:����3�t�(�(�6�6�v�|�|�~�F�G�OU�|�|�~�_e�_m�_m�_o�qs�uv�w�yrc�|�|jj�}|jj�}|j	|jj|j��|j	|jj
|j��|j|jj|�g�|j|jj||zdz�|jg�|j|jj�d�|j	|jj|j��t|jj�|dz�}|j|jj|��|jt|jj||zdz��d�|jt|jj||zdzdz��d�td�D]a}td|z|�}|j|j|�|dzz�|j	|jj|���c|jt|jj||zdzdz��d�|jt|jj||zdzdz��d	�|j|jj�d�y)
NrriX�z193.168.0.%s�
r�2�)rr+rr0rrr:r �	unBanListr!r
r.r'�len�ranger,)r�btime�stimer<rDs     r�	testUnbanzAddFailure.testUnbanys���
�
�
�
&�
&�
(�%�
�-�-�
�
�
!�%��/�/�$�#�#�0�0����?�@��/�/�$�#�#�.�.�t�}�}�=�>����4�$�$�.�.�u�5�r�:����4�$�$�.�.�u�u�}�q�/@�A�D�M�M�?�S����4�$�$�)�)�+�Q�/��/�/�$�#�#�0�0����?�@��T�]�]�(�(�*�E�C�K�8�&����4�$�$�1�1�&�9�:����3�t�(�(�2�2�5�5�=�1�3D�E�F��J����3�t�(�(�2�2�5�5�=�3�3F��3J�K�L�a�P���8�;�a��n�q�(�%�0�6�	���V�&�&�u�-��"��4�5��?�?�4�$�$�1�1�&�9�:�;����3�t�(�(�2�2�5�5�=�4�3G�!�3K�L�M�q�Q����3�t�(�(�2�2�5�5�=�4�3G�!�3K�L�M�q�Q����4�$�$�)�)�+�Q�/rc��|jj�}|jjd�	|j|jj	|j
��|j|jj
|j
��|j|jj|j
j�|zdz�g�|j|jj�d�|jj|�y#|jj|�wxYw)Nr*r)rr+r,rrrr:r rKr0r!)rrNs  r�testUnbanPermanentzAddFailure.testUnbanPermanent�s���
�
�
�
&�
&�
(�%������r�"�'��?�?�4�$�$�1�1�$�-�-�@�A��?�?�4�$�$�/�/��
�
�>�?����D�%�%�/�/��
�
�0E�0E�0G�%�0O�RS�0S�T�VX�Y����D�%�%�*�*�,�a�0�������&��4������&�s�CD.�.Ec��tdd�tdd�g}|djd�|D]}|jj|��|j	|jjdd��dd	g�y)
Nz	192.0.2.1rz	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)r
r,rr�assertSortedEqual�
getBanList)r�tickets�ts   r�testBanListzAddFailure.testBanList�s����[�,�'��[�,�'�
�'�
�!�*������%�a����!�!�!�$�%�����*�*�5�5�d�T�5�R�B�A��r)�__name__�
__module__�__qualname__rrr%r(r8r=r?rErPrRrZ�
__classcell__�rs@rrr#s<���#��
7�0�
;�@8�
9�
y�&0�4	'�
rrc�P��eZdZ�fd�Z�fd�ZdZd�Zd�Zd�Zd�Z	d�Z
d	�Z�xZS)
�StatusExtendedCymruInfoc���tt|��tjj�t
�tttjd���|_d|_d|_
d|_t|jd�}t!�|_|j%|j"j'|��y)rzresolver1.opendns.com�36692�US�arinrN)rrar�unittest�F2B�SkipIfNoNetworkr�next�iterr	�dnsToIp� _StatusExtendedCymruInfo__ban_ip�_StatusExtendedCymruInfo__asn�!_StatusExtendedCymruInfo__country�_StatusExtendedCymruInfo__rirr
r�$_StatusExtendedCymruInfo__banManagerrr)rr<rs  �rrzStatusExtendedCymruInfo.setUp�s�������,�.�
�,�,��� �
�-��t�H�,�,�-D�E�F�G�$�-��$�*��$�.��$�*��T�]�]�L�1�&� �l�$���/�/�$�#�#�0�0��8�9rc�>��tt|��t�yr)rrarrrs �rrz StatusExtendedCymruInfo.tearDown�s������/�1��r)TNc�*�t}|jdr9|jjtj
jrdnd��}n|jd}|jd�r$d|f|_t	jd|dz��|S)	Nrr�)�timeoutr�errorFz.Skip test because service is not available: %s)	ra�	availablerp�getBanListExtendedCymruInforfrg�fast�get�SkipTest)r�tc�
cymru_infos   r�_getBanListExtendedCymruInfoz4StatusExtendedCymruInfo._getBanListExtendedCymruInfo�s����"��\�\�!�_��!�!�=�=��,�,�#�#�Q��>�.�:����Q��:��^�^�G����#�2�<�	�	�	�K�j�Y`�Na�a�	b�b�	�rc��|j�}|j||jg|jg|jgd��y)N��asn�country�rir)r}�assertDictEqualrmrnro)rr|s  r�
testCymruInfoz%StatusExtendedCymruInfo.testCymruInfo�sA���0�0�2�*����z������^�^�$�����	�rc��|j|jj|j��|jg�y�N)r rp�geBanListExtendedASNr}rmr$s r�testCymruInfoASNz(StatusExtendedCymruInfo.testCymruInfoASN��6��������)�)�$�*K�*K�*M�N��J�J�<�rc��|j|jj|j��|jg�yr�)r rp�geBanListExtendedCountryr}rnr$s r�testCymruInfoCountryz,StatusExtendedCymruInfo.testCymruInfoCountry�s7��������-�-�d�.O�.O�.Q�R��N�N��rc��|j|jj|j��|jg�yr�)r rp�geBanListExtendedRIRr}ror$s r�testCymruInfoRIRz(StatusExtendedCymruInfo.testCymruInfoRIR�r�rc��t�|_tdd�}|j|jj	|��|j�}|j
|dgdgdgd��tdd�}|j|jj	|��|j�}|j|ddgddgdd	gd�d
t��y)Nz0.0.0.0r�nxdomainrz8.0.0.0g<f�A�3356rdrer*)�level�key)	rrpr
rrr}r�rVrB)rr<r|s   r�testCymruInfoNxdomainz-StatusExtendedCymruInfo.testCymruInfoNxdomain�s��� �l�$���Y��-�&��/�/�$�#�#�0�0��8�9��0�0�2�*����z����L���	���Y��-�&��/�/�$�#�#�0�0��8�9��0�0�2�*������V�%���&��V�$�	&�-/�S��:r)
r[r\r]rrrvr}r�r�r�r�r�r^r_s@rrara�s2���:��
��
���
�
�
:rra)�
__author__�
__copyright__�__license__rf�utilsrr�server.banmanagerr�server.ipdnsr	�
server.ticketr
�TestCaserra�rr�<module>r�sN��.�
�2�
����.�*�#�%�H��"�"�H�VL:�h�/�/�L:r