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__/clientbeautifiertestcase.cpython-312.pyc
�

G�kc/$��v�dZdZdZddlZddlmZddlmZddlmZdd	l	m
Z
mZGd
�dej�Z
y)zAlexander Koeppez>Copyright (c) 2016 Cyril Jaquier, 2011-2013 Yaroslav Halchenko�GPL�N�)�
Beautifier)�version)�IPAddr)�UnknownJailException�DuplicateJailExceptionc���eZdZ�fd�Z�fd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zd
�Zd�Z
d�Zd
�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Z�xZS)�BeautifierTestc�H��tt|��t�|_y)z Call before every test case N)�superr�setUpr�b��self�	__class__s ��I/usr/lib/python3/dist-packages/fail2ban/tests/clientbeautifiertestcase.pyrzBeautifierTest.setUp!s������#�%��<�$�&�c�*��tt|��y)z Call after every test case N)r
r�tearDownrs �rrzBeautifierTest.tearDown&s������&�(rc��dg}|jj|�|j|jj�|�y)N�test)r�setInputCmd�assertEqual�getInputCmd)r�cmds  r�testGetInputCmdzBeautifierTest.testGetInputCmd*s8��	��#��&�&���S�����4�6�6�%�%�'��-rc��|jjdg�|j|jjd�d�y)N�ping�pongzServer replied: pong�rrr�beautify�rs r�testPingzBeautifierTest.testPing/s4���&�&���f�X�����4�6�6�?�?�6�*�,B�Crc��|jjdg�|j|jjt�t�y)Nr)rrrr"rr#s r�testVersionzBeautifierTest.testVersion3s3���&�&���i�[�!����4�6�6�?�?�7�+�W�5rc��|jjdg�|j|jjd�d�y)N�add�sshzAdded jail sshr!r#s r�testAddJailzBeautifierTest.testAddJail7s4���&�&���e�W�����4�6�6�?�?�5�)�+;�<rc��|jjdg�|j|jjd�d�y)N�startzJail startedr!r#s r�
testStartJailzBeautifierTest.testStartJail;s3���&�&���g�Y�����4�6�6�?�?�4�(�.�9rc��|jjddg�|j|jjd�d�y)N�stopr)zJail stoppedr!r#s r�testStopJailzBeautifierTest.testStopJail?s5���&�&���f�e�_�%����4�6�6�?�?�4�(�.�9rc��|jjdg�|j|jjd�d�y)Nr/zShutdown successfulr!r#s r�testShutdownzBeautifierTest.testShutdownCs4���&�&���f�X�����4�6�6�?�?�4�(�*?�@rc
���|jjdg�ddddgff}d}|j|jj|�|�|jjddg�dgd�fd	d
ddt	d
�t	d�t	d�gfgff}d}|dz
}|dz
}|dz
}|dz
}|dz
}|dz
}|dz
}|dz
}|j|jj|�|�y)N�status)zNumber of jailsrz	Jail listr)�exim4z4Status
|- Number of jails:	0
`- Jail list:	ssh exim4�Filter))zCurrently failedr)zTotal failedr)z	File list�/var/log/auth.log�Actions)zCurrently banned�)zTotal bannedr9zBanned IP listz192.168.0.1z::ffff:10.2.2.1z2001:db8::1zStatus for the jail: ssh
z
|- Filter
z|  |- Currently failed:	0
z|  |- Total failed:	0
z#|  `- File list:	/var/log/auth.log
z`- Actions
z   |- Currently banned:	3
z   |- Total banned:	3
z6   `- Banned IP list:	192.168.0.1 10.2.2.1 2001:db8::1�rrrr"r�r�response�outputs   r�
testStatuszBeautifierTest.testStatusGs,���&�&���h�Z� �$�{�U�G�4D�&E�
F�(�E�&����4�6�6�?�?�8�,�f�5��&�&���h��&�'��������	�
�	�	�!�	"�	�
�	�
�	�	�
��(�&(�&��M��&��)�)�&��%�%�&��2�2�&��N��&��)�)�&��%�%�&��D�D�&����4�6�6�?�?�8�,�f�5rc��|jjdg�|j|jjd�d�y)N�	flushlogszrolled overzlogs: rolled overr!r#s r�
testFlushLogszBeautifierTest.testFlushLogsls4���&�&���k�]�#����4�6�6�?�?�=�1�3F�Grc��|jjddg�d}|j|jjd�|�y)N�get�syslogsocketz!Current syslog socket is:
`- auto�autor!�rr=s  r�testSyslogSocketzBeautifierTest.testSyslogSocketps;���&�&���e�^�,�-�/�&����4�6�6�?�?�6�*�F�3rc��|jjddg�d}|j|jjd�|�y)NrC�	logtargetz3Current logging target is:
`- /var/log/fail2ban.logz/var/log/fail2ban.logr!rFs  r�
testLogTargetzBeautifierTest.testLogTargetus<���&�&���e�[�)�*�A�&����4�6�6�?�?�#:�;�V�Drc��|jjddg�d}|j|jjd�|�y)NrC�loglevelzCurrent logging level is 'INFO'�INFOr!rFs  r�testLogLevelzBeautifierTest.testLogLevelzs;���&�&���e�Z�(�)�,�&����4�6�6�?�?�6�*�F�3rc��|jjddg�d}d|z}|j|jj|�|�|j|jjd�d�y)NrC�dbfilez"/var/lib/fail2ban/fail2ban.sqlite3zCurrent database file is:
`- �Database currently disabledr!r;s   r�
testDbFilezBeautifierTest.testDbFilesc���&�&���e�X�&�'�
1�(�+�h�6�&����4�6�6�?�?�8�,�f�5����4�6�6�?�?�4�(�*G�Hrc���|jjddg�d}|j|jjd�|�|j|jjd�d�y)NrC�
dbpurgeagez.Current database purge age is:
`- 86400secondsi�QrQr!rFs  r�testDbPurgeAgezBeautifierTest.testDbPurgeAge�sY���&�&���e�\�*�+�<�&����4�6�6�?�?�5�)�6�2����4�6�6�?�?�4�(�*G�Hrc�8�|jjgd��g}d}|j|jj|�|�dg}d}|j|jj|�|�|jjgd��ddg}d}|dz
}|j|jj|�|�|jjgd	��dg}|j|jj|�|�y)
N)rC�sshd�logpathzNo file is currently monitoredr7z3Current monitored log file(s):
`- /var/log/auth.log)�setrW�
addlogpath�/var/log/messagesr[zCurrent monitored log file(s):
z)|- /var/log/messages
`- /var/log/auth.log)rYrW�
dellogpathr[r!)rr<r=�	outputadds    r�testLogPathzBeautifierTest.testLogPath�s����&�&���/�0�
�(�+�&����4�6�6�?�?�8�,�f�5�!�
"�(�A�&����4�6�6�?�?�8�,�f�5��&�&���G�H�!�#6�
7�(�0�)��;�;�)����4�6�6�?�?�8�,�i�8��&�&���G�H�!�
"�(����4�6�6�?�?�8�,�f�5rc��|jjgd��d}|j|jjd�|�y)N)rCrW�logencodingz%Current log encoding is set to:
UTF-8zUTF-8r!rFs  r�testLogEncodingzBeautifierTest.testLogEncoding�s7���&�&���3�4�3�&����4�6�6�?�?�7�+�V�4rc��|jjgd��|j|jjg�d�|jjgd��ddgg}d}|dz
}|j|jj|�|�|j	dd	g�|d
z
}|j|jj|�|�|jjgd��|j|d�|j|jj|�|j
d
�d�y)N)rCrW�journalmatchzNo journal match filter set)rYrW�addjournalmatch�
_SYSTEMD_UNITzsshd.servicezCurrent match filter:
z_SYSTEMD_UNIT sshd.service�_COMMrWz
 + _COMM sshd)rYrW�deljournalmatch�z + r)rrrr"�append�remove�splitr;s   r�testJournalMatchzBeautifierTest.testJournalMatch�s���&�&���4�5����4�6�6�?�?�2�&�(E�F��&�&���7�8���/�
0�(�$�&��(�(�&����4�6�6�?�?�8�,�f�5�
�/�/�7�F�#�$��O��&����4�6�6�?�?�8�,�f�5��&�&���7�8�
�/�/�(�1�+�����4�6�6�?�?�8�,�f�l�l�5�.A�!�.D�Erc�Z�|jjgd��d}d}|j|jjd�|dz�|j|jj|�|dz�|j|jjd�|dz�y)N)rCrW�datepatternzCurrent date pattern set to: )N�Default DetectorszNot set/requiredro)rrztest (test)r!�rr=r<s   r�testDatePatternzBeautifierTest.testDatePattern�s����&�&���3�4�*�&�
(�(����4�6�6�?�?�4�(�
�
��!����4�6�6�?�?�8�,�
�
 � �"����4�6�6�?�?�#3�4�
�]��rc��|jjgd��d}|j|jjg�|�|jjgd��t	dd�t	d�t	dd�t	d	�g}d
}|dz
}|dz
}|d
z
}|dz
}|j|jj|�|�y)N)rCrW�ignoreipz No IP address/network is ignored)rYrW�addignoreipz	127.0.0.0�z::1z
2001:db8::� z::ffff:10.0.2.1z)These IP addresses/networks are ignored:
z|- 127.0.0.0/8
z|- ::1
z|- 2001:db8::/32
z`- 10.0.2.1r:rps   r�testIgnoreIPzBeautifierTest.testIgnoreIP�s����&�&���0�1�-�&����4�6�6�?�?�2�&��/��&�&���3�4�	�+�q��	�%�=�	�,���	�
��	�(�8�&����&��J��&�� � �&��M��&����4�6�6�?�?�8�,�f�5rc��|jjgd��d}|j|jjg�|�d}|dz
}|j|jjddg�|�y)N)rCrW�	failregexz No regular expression is definedz.The following regular expression are defined:
z|- [0]: ^$
`- [1]: .*z^$z.*r!rFs  r�
testFailRegexzBeautifierTest.testFailRegex�sh���&�&���1�2�-�&����4�6�6�?�?�2�&��/�<�&��$�$�&����4�6�6�?�?�D�$�<�0�&�9rc��|jjgd��d}|j|jjg�|�d}|dz
}|j|jjdg�|�y)N)rCrW�actionszNo actions for jail sshdz)The jail sshd has the following actions:
ziptables-multiportr!rFs  r�testActionszBeautifierTest.testActions�sh���&�&���/�0�%�&����4�6�6�?�?�2�&��/�7�&�� � �&����4�6�6�?�?�$8�#9�:�F�Crc��|jjgd��d}|j|jjg�|�d}|dz
}d}|j|jj|�|�y)N)rCrW�actionproperties�iptablesz+No properties for jail sshd action iptablesz;The jail sshd action iptables has the following properties:z
actionban, actionunban)�	actionban�actionunbanr!rps   r�testActionPropertiesz#BeautifierTest.testActionProperties�si���&�&���D�E�8�&����4�6�6�?�?�2�&��/�H�&��&�&�&�
)�(����4�6�6�?�?�8�,�f�5rc��|jjgd��d}|j|jjg�|�d}|dz
}|j|jjddg�|�y)N)rCrW�
actionmethodsr�z(No methods for jail sshd action iptablesz9The jail sshd action iptables has the following methods:
z
ban, unban�ban�unbanr!rFs  r�testActionMethodsz BeautifierTest.testActionMethods�sh���&�&���A�B�5�&����4�6�6�?�?�2�&��/�G�&��L��&����4�6�6�?�?�E�7�#3�4�f�=rc�N�td�}d}|j|jj|�|�t	d�}d}|j|jj|�|�d}|j|jjt��|�y)NrWz(Sorry but the jail 'sshd' does not existzThe jail 'sshd' already existsz Sorry but the command is invalid)rrr�
beautifyErrorr	�
IndexErrorr;s   r�testBeautifyErrorz BeautifierTest.testBeautifyError�s���
!�&�
)�(�5�&����4�6�6�'�'��1�6�:�
#�F�
+�(�+�&����4�6�6�'�'��1�6�:�-�&����4�6�6�'�'�
��5�v�>r)�__name__�
__module__�__qualname__rrrr$r&r*r-r0r2r>rArGrJrNrRrUr^rarlrqrwrzr}r�r�r��
__classcell__)rs@rrrs�����
)�.�
D�6�=�:�:�A�#6�JH�4�
E�
4�
I�I�6�&5�
F�$	�6�&:�D�6�>�
?rr)�
__author__�
__copyright__�__license__�unittest�client.beautifierrr�server.ipdnsr�
exceptionsrr	�TestCaser�rr�<module>r�s9��( �
�P�
����*��!�E�h?�X�&�&�h?r