HEX
Server: Apache
System: Linux srv1.prosuiteplus.com 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64
User: prosuiteplus (1001)
PHP: 8.3.20
Disabled: NONE
Upload Files
File: //lib/python3/dist-packages/fail2ban/tests/__pycache__/samplestestcase.cpython-38.pyc
U

]^W/�	@s�dZdZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlmZddl
mZddlmZdd	lmZmZmZmZej�e���Zej�ej�e�d
�Zej�ej�e�d�Ze�d�Z e�!d
e�"e �d�Z#Gdd�de
j$�Z%dd�Z&edd�fedd�ffD]`\Z'Z(e)e(e�*ej�e'd���D]:Z(e(�+d�dZ,e,�-d��s>e.e%de,�/�e&e,e'���q>�qdS)z"Copyright (c) 2013 Steven HiscocksZGPL�N�)�Regex)�Filter)�FilterReader�)�setUpMyTime�tearDownMyTime�TEST_NOW�
CONFIG_DIRZconfig�files�<HOST>z\.[+\*](?!\?)[^\$\^]*z.*(?:\.[+\*].*|[^\$])$csNeZdZ�fdd�Z�fdd�Zdd�Zdd�Zdd
d�Zedd
��Z	�Z
S)�FilterSamplesRegexcs&tt|���t�|_d|_t�dS)zCall before every test case.N)�superr
�setUp�dict�_filters�_filterTestsr��self��	__class__��@/usr/lib/python3/dist-packages/fail2ban/tests/samplestestcase.pyr4szFilterSamplesRegex.setUpcstt|���t�dS)zCall after every test case.N)rr
�tearDownrrrrrr;szFilterSamplesRegex.tearDowncCs(|�tdd�t�|�D��dkd�dS)z Check to ensure some tests existcSsg|]}|d�d�r|�qS)rZtestSampleRegexs��
startswith)�.0Ztestrrr�
<listcomp>Cs�z9FilterSamplesRegex.testFiltersPresent.<locals>.<listcomp>�
z&Expected more FilterSampleRegexs testsN)�
assertTrue�len�inspectZ
getmembersrrrr�testFiltersPresent@s��z%FilterSamplesRegex.testFiltersPresentcCs||�t�dtd��|�t�dtd��|�t�dtd��|�t�dtd��|�t�dtd��d	S)
z9Tests regexp RE_WRONG_GREED is intact (positive/negative)zgreedy .* testz test not hard-anchoredzgreedy .+ testz test vary .* anchored$z" test no catch-all, hard-anchored$znon-greedy .*? testznon-greedy .+? testz! test vary catch-all .* anchored$N)r�RE_WRONG_GREED�search�RE_HOST�assertFalserrrr�testReWrongGreedyCatchAllHs�����z,FilterSamplesRegex.testReWrongGreedyCatchAllNcCs�|j�|�}|r|Std�}d|_d|_d|_d|_|dkrBt�}|��}t	|d||t
jjd�}|�
|��|�|�
|��d�|��|�i�|��D]�}|ddkr�|d}n(|ddkr�|dg}n|�d	|f�|D]|}|d
dkr�||_q�|d
dk�r|�|�q�|d
d
k�r,|�|�q�|d
dk�rF|�|�q�|d
dkr�|�|�q�q�|��}	|	D].}
t�|
��rltd|t|
��td�f���ql|t �g}||j|<|S)NTFZjail)�basedir�share_configrz	multi-set��setz$Unexpected config-token %r in streamrZ	prefregexZaddfailregexZaddignoreregexZmaxlinesZdatepatternz�Following regexp of "%s" contains greedy catch-all before <HOST>, that is not hard-anchored at end or has not precise sub expression after <HOST>:
%sr)!r�getrZ
returnRawHostZ
checkAllRegexZ
checkFindTimeZactiver�copyr�unittestZF2Br)�assertEqualZgetFileZgetJailName�readZ
getOptionsZconvert�failZ	prefRegexZaddFailRegexZaddIgnoreRegexZsetMaxLinesZsetDatePattern�getFailRegexr#r$�AssertionError�str�replacer%r+)r�fltName�namer(�opts�fltZ
filterConfZoptZoptval�	regexList�frrrr�_readFilterVsZ�

�


zFilterSamplesRegex._readFiltercCstdd�t|���D��S)Ncss$|]\}}|�d�s||fVqdS)ztest.Nr)r�k�vrrr�	<genexpr>�s
z4FilterSamplesRegex._filterOptions.<locals>.<genexpr>)r�list�items�r8rrr�_filterOptions�sz!FilterSamplesRegex._filterOptions)N)�__name__�
__module__�__qualname__rrr"r'r<�staticmethodrC�
__classcell__rrrrr
2s
5r
cs��fdd�}|S)Nc!s�|�tj�tj�td���d���g}t�}i}i}d}|t|�k�r�||}|d7}t�	tj�td|��}d}|D�]}	t
�d|	�}
|
�r�z&t�
|
�d��}|
�d�dkr�|}Wqx|
�d�d	k�r�g|_d}t|t�r�|n|gD]�}|�r|��}|�|�n|}|�t|t��|�d
��r6t|�d
��}|s�|�|�}|�d�}
|
�sf|�rbt|�nd}
�|
}
|j|
��|d
�}|j�|
||f�q�Wqx|
�d�dk�r�|�|�WqxWn>tk
�r�}ztd||��|��f��W5d}~XYnXt|�}	n |sx|	�d�sx|	� ��sqxni}|�r*qx|j�sV�}
|j|
��dd
�}|
|ifg|_|jD�] \}
}}|\}}|�!�}d}�zxi}d}|�d�dk�r�|�"|	�}n6d}|�d��r�|�d�|	}	|�"dt#|	�$d�ft%�}|�s|�d��r�|�d�k�rW�q\|�&|�dd�d�W�q\|d\}}}}|�dd��sn|dk�sP|�d��rn|�'|�|�'||�W�q\|�|�dd�d�|�(t|�dddd�|D��t|�)��D]�\}}|dk�r�|�|d�}|dk�r�|d k�r�|}|d!k�r�t|�d"i��}t|tttf��r |�*||��q�|�(||��q�|�d#d�}|�sL|dk	�r�zt+j+�,|d$�}Wn$tk
�r�t+j+�,|d%�}YnXt-�.|�/��}||j0d&7}|�(||d'|t-�1d$t-�2|��|t-�1d$t-�2|��||f�|�'|�|�'||�Wn�t3k
�rz}zdddl4}t3d(|
||��|��|	||dk�r<||ndd)�|�5|��6��d)�|�5|��6��f	��W5d}~XYnX�q\qxq<t|j7�)��D]R\}
}|\}}|�!�}t8|�D].\}} |�||k�p�| |kd*|
|| f��q��q�dS)+NZlogsz,No sample log file available for '%s' filterrrFz4^#+ ?(failJSON|(?:file|filter)Options|addFILE):(.+)$rZfileOptionsZ
filterOptionsztest.conditionztest.filter-name�rBZaddFILEz	%s: %s:%i�#���TZlogtypeZjournalztest.prefix-linez
�filter�matchz!Line not matched when should haveZnofailz Line matched when shouldn't havezMultiple regexs matched %rcSsg|]}|d�qS)rr)r�xrrrr�sz?testSampleRegexsFactory.<locals>.testFilter.<locals>.<listcomp>)�timerMZdescrLZhostZattemptsZmatchesrOz%Y-%m-%dT%H:%M:%Sz%Y-%m-%dT%H:%M:%S.%fg��.Az:UTC Time  mismatch %s (%s) != %s (%s)  (diff %.3f seconds)z@%s: %s on: %s:%i, line:
 %sregex (%s):
 %s
faildata: %s
fail: %s�
z %s: Regex has no samples: %i: %r)9r�os�path�isfile�join�TEST_FILES_DIRr+r �	fileinputZ	FileInput�rerM�json�loads�groupr�
isinstancer@r-�updaterr,�evalrCr4r<�append�
ValueError�filenameZ
filelineno�nextr�stripr2ZprocessLine�TEST_NOW_STR�rstripr	r&�addr/rAZassertSortedEqual�datetime�strptimerO�mktimeZ	timetupleZmicrosecond�strftime�gmtimer3�pprintZpformat�
splitlinesr�	enumerate)!r�	filenamesZregexsUsedReZ
commonOptsZfaildata�ir`ZlogFileZignoreBlock�lineZjsonREMatchr8ZfltOptsr6r9�eZ
regexsUsedIdxr:Z	failregexr1Z	checktimeZretZfidZfail2banTimer=r>Zfv�tZ
jsonTimeLocalZjsonTimerkZfailRegexIndexZ	failRegex�r(r7rr�
testFilter�s&��



�
�$
��



���
�� ��z+testSampleRegexsFactory.<locals>.testFilterr)r7r(rtrrsr�testSampleRegexsFactory�s%rucCs|�d�o|�d�S)Nzcommon.conf�.conf)�endswith�rNrrr�<lambda>7�rycCs|�d�o|�d�S)Nzzzz-rv)rrwrxrrrry8rzzfilter.d�.ztestSampleRegexs%s)0Z
__copyright__Z__license__rfrVr!rXrQrW�sysrOr.Zserver.failregexrZ
server.filterrZclient.filterreaderrZutilsrrr	r
ZutcfromtimestampZ	isoformatrcrRrT�dirname�__file__ZTEST_CONFIG_DIRrUZ_resolveHostTagr%�compile�escaper#ZTestCaser
ruZbasedir_Zfilter_rL�listdir�
rpartitionZ
filterNamer�setattr�upperrrrr�<module>sF
])

��
�