HEX
Server: Apache/2.4.65 (Debian)
System: Linux kubikelcreative 5.10.0-35-amd64 #1 SMP Debian 5.10.237-1 (2025-05-19) x86_64
User: www-data (33)
PHP: 8.4.13
Disabled: NONE
Upload Files
File: //usr/lib/python3/dist-packages/fail2ban/tests/__pycache__/samplestestcase.cpython-39.pyc
a

���`�0�	@s�dZdZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlmZddl
mZmZddlmZdd	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��sBe/e&de-�0�e'e-e(���qB�q dS)z"Copyright (c) 2013 Steven HiscocksZGPL�N�)�Regex)�Filter�
FileContainer)�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�tearDownr	rrrrr;szFilterSamplesRegex.tearDowncCs(|�tdd�t�|�D��dkd�dS)z Check to ensure some tests existcSsg|]}|d�d�r|�qS)rZtestSampleRegexs��
startswith)�.0�testrrr�
<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|_|durBt�}|��}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�_readFilterVsV�

�


zFilterSamplesRegex._readFiltercCstdd�|��D��S)Ncss$|]\}}|�d�s||fVqdS)ztest.Nr)r�k�vrrr�	<genexpr>��z4FilterSamplesRegex._filterOptions.<locals>.<genexpr>)r�items�r:rrr�_filterOptions�sz!FilterSamplesRegex._filterOptions)N)�__name__�
__module__�__qualname__rrr$r)r>�staticmethodrE�
__classcell__rrrrr2s
5rcs��fdd�}|S)Nc!s(|�tj�tj�td���d���g}t�}i}i}d}|t|�k�r�||}|d7}tj	tj�td|�dd�}d}|D�]D}	t
�|��d|	�}	t
�d	|	�}
|
�r,�z&t�|
�d
��}|
�d�dkr�|}Wq||
�d�dk�r�g|_d}t|t�r�|n|gD]�}|�r|��}|�|�n|}|�t|t��|�d
��rLt|�d
��}|s�|�|�}|�d�}
|
�s||�rxt|�nd}
�|
}
|j|
��|d�}|j�|
||f�q�Wq||
�d�dk�r�|�|�Wq|Wn@t�y}z&td||��|��f��WYd}~n
d}~00t |�}	t
�|��d|	�}	n |s||	�!d�s||	�"��sHq|ni}|�rTq||j�s��}
|j|
��dd�}|
|ifg|_|	�#d�}	|jD�].\}
}}|�d��r�t|d��s��q�|\}}|�$�}d}�zfi}|�d�dk�r�|�%|	�}n,|�d��r|�d�|	}	|�%dt&|	ft'�}|�r�g}|D]N}|\}}}}|du�sR|�d��rn|�(|�|�(||��q,|�|��q,|}|�s�|�)|�dd�d�W�q�|�|�dd�d�|�*t|�dddd �|D��|D�]X}|\}}}}|�+�D]�\}}|d!v�r�|�|d�}|du�rB|d"k�r(|}|d#k�rBt|�d$i��}t|tttf��rd|�,||��q�|�*||��q�|�d%d�}|du�rzt-j-�.|d&�}Wn"t�y�t-j-�.|d'�}Yn0t/�0|�1��}||j2d(7}|�*||d)|t/�3d&t/�4|��|t/�3d&t/�4|��||f�|�(|�|�(||��q�Wn�t5�y�}zlddl6}t5d*|
||��|��|	||dk�rz||ndd+�|�7|��8��d+�|�7|��8��f	��WYd}~n
d}~00�q�q|q<|j9�+�D]R\}
}|\}}|�$�}t:|�D].\}} |�||v�p| |vd,|
|| f��q�q�dS)-NZlogsz,No sample log file available for '%s' filterrr�rb)�modeFzUTF-8z4^#+ ?(failJSON|(?:file|filter)Options|addFILE):(.+)$rZfileOptionsZ
filterOptionsztest.conditionztest.filter-name�rDZaddFILEz	%s: %s:%i�#z
�
constraint���ZlogtypeZjournalztest.prefix-lineZnofail�matchz!Line not matched when should havez Line matched when shouldn't havezMultiple regexs matched %rcSsg|]}|d�qS)rr)r�xrrrrrBz?testSampleRegexsFactory.<locals>.testFilter.<locals>.<listcomp>)�timerQZdescrOZhostZattemptsZmatchesrSz%Y-%m-%dT%H:%M:%Sz%Y-%m-%dT%H:%M:%S.%fg��.Az:UTC Time  mismatch %s (%s) != %s (%s)  (diff %.3f seconds)zC%s: %s on: %s:%i, line:
  %s
regex (%s):
  %s
faildata: %s
fail: %s�
z %s: Regex has no samples: %i: %r);r!�os�path�isfile�join�TEST_FILES_DIRr-r"�	fileinputZ	FileInputrZdecode_line�filename�rerQ�json�loads�groupr�
isinstance�listr/�updaterr.�evalrEr6r>�append�
ValueErrorZ
filelineno�nextr�strip�rstripr4ZprocessLine�TEST_NOW_STRr
�addr(r1rCZassertSortedEqual�datetime�strptimerS�mktimeZ	timetupleZmicrosecond�strftime�gmtimer5�pprintZpformat�
splitlinesr�	enumerate)!r�	filenamesZregexsUsedReZ
commonOptsZfaildata�ir[ZlogFileZignoreBlock�lineZjsonREMatchr:ZfltOptsr8r;�eZ
regexsUsedIdxr<Z	failregexr3Zret�foundZfidZfail2banTimer?r@Zfv�tZ
jsonTimeLocalZjsonTimerpZfailRegexIndexZ	failRegex�r*r9rr�
testFilter�s(���



�

���





���
��$��z+testSampleRegexsFactory.<locals>.testFilterr)r9r*rzrryr�testSampleRegexsFactory�s-r{cCs|�d�o|�d�S)Nzcommon.conf�.conf)�endswith�rRrrr�<lambda>?rBrcCs|�d�o|�d�S)Nzzzz-r|)rr}r~rrrr@rBzfilter.d�.ztestSampleRegexs%s)1Z
__copyright__Z__license__rkrZr#r]rUr\�sysrSr0Zserver.failregexrZ
server.filterrrZclient.filterreaderrZutilsrr	r
rZutcfromtimestampZ	isoformatrirVrX�dirname�__file__ZTEST_CONFIG_DIRrYZ_resolveHostTagr'�compile�escaper%ZTestCaserr{Zbasedir_Zfilter_�filter�listdir�
rpartitionZ
filterNamer�setattr�upperrrrr�<module>sF
]1

��
�