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__/samplestestcase.cpython-39.opt-2.pyc
a

TPUG��8�	@s~dZdZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
mZddlm
Z
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�
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__��B/usr/lib/python3.9/site-packages/fail2ban/tests/samplestestcase.pyr3szFilterSamplesRegex.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>Bs�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�testReWrongGreedyCatchAllGs�����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
getOptions�convert�failZ	prefRegexZaddFailRegexZaddIgnoreRegexZsetMaxLinesZsetDatePattern�getFailRegexr%r&�AssertionError�str�replacer'r-)r�fltName�namer*�opts�fltZ
filterConf�optZoptval�	regexList�frrrr�_readFilterUsV�

�


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@�staticmethodrG�
__classcell__rrrrr1s
5rcs��fdd�}|S)Nc"s|�tj�tj�td���d���g}t�}i}i}d}|t|�k�r�||}|d7}ttj�td|�ddd�}d|_	d}d}	|D�] }
|	d7}	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|�}
n |s�|
�d�s�|
���s2q�ni}|�r>q�|j�sj�}|j|��dd�}||ifg|_|
� d�}
|jD�]*\}}}|�d��r�t|d��s��qz|\}}|�!�}d}�zfi}|�d�dk�r�|�"|
�}n,|�d��r�|�d�|
}
|�"dt#|
ft$�}|�rjg}|D]N}|\}}}}|du�s<|�d��rX|�%|�|�%||��q|�|��q|}|�s�|�&|�dd�d�W�qz|�|�dd�d�|�'t|�dddd �|D��|D�]X}|\}}}}|�(�D]�\}}|d!v�r�|�|d�}|du�r,|d"k�r|}|d#k�r,t|�d$i��}t|tttf��rN|�)||��q�|�'||��q�|�d%d�}|du�rzt*j*�+|d&�}Wn"t�y�t*j*�+|d'�}Yn0t,�-|�.��}||j/d(7}|�'||d)|t,�0d&t,�1|��|t,�0d&t,�1|��||f�|�%|�|�%||��q�Wn�t2�y�}zhddl3}t2d*|||��|	|
||dk�r`||ndd+�|�4|��5��d+�|�4|��5��f	��WYd}~n
d}~00�qzq�q<|j6�(�D]R\}}|\}}|�!�}t7|�D].\} }!|�| |v�p�|!|vd,|| |!f��q֐q�dS)-NZlogsz,No sample log file available for '%s' filterrrzUTF-8T)ZdoOpenFz4^#+ ?(failJSON|(?:file|filter)Options|addFILE):(.+)$rZfileOptionsZ
filterOptionsztest.conditionztest.filter-name�rFZaddFILEz	%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�xrrrrrDz?testSampleRegexsFactory.<locals>.testFilter.<locals>.<listcomp>)�timerQZdescrO�hostZattemptsZmatchesrSz%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)8r!�os�path�isfile�join�TEST_FILES_DIRr-r"rZwaitForLineEnd�rerQ�json�loads�groupr�
isinstance�listr/�updaterr.�evalrGr7r@�append�
ValueErrorZgetFileName�nextr�strip�rstripr5ZprocessLine�TEST_NOW_STRr
�addr(r1rEZassertSortedEqual�datetime�strptimerS�mktimeZ	timetupleZmicrosecond�strftime�gmtimer6�pprintZpformat�
splitlinesr�	enumerate)"r�	filenamesZregexsUsedReZ
commonOptsZfaildata�i�filenameZlogFileZignoreBlockZlnnum�lineZjsonREMatchr;ZfltOptsr9r<�eZ
regexsUsedIdxr>Z	failregexr4Zret�foundZfidZfail2banTimerArBZfv�tZ
jsonTimeLocalZjsonTimeroZfailRegexIndexZ	failRegex�r*r:rr�
testFilter�s*���



�


���





���
��$��z+testSampleRegexsFactory.<locals>.testFilterr)r:r*rzrryr�testSampleRegexsFactory�s/r{cCs|�d�o|�d�S)Nzcommon.conf�.conf)�endswith�rRrrr�<lambda>@rDrcCs|�d�o|�d�S)Nzzzz-r|)rr}r~rrrrArDzfilter.d�.ztestSampleRegexs%s)0Z
__copyright__Z__license__rjr#r\rVr[�sysrSr0Zserver.failregexrZ
server.filterrrZclient.filterreaderrZutilsrr	r
rZutcfromtimestampZ	isoformatrhrWrY�dirname�__file__ZTEST_CONFIG_DIRrZZ_resolveHostTagr'�compile�escaper%ZTestCaserr{Zbasedir_Zfilter_�filter�listdir�
rpartitionZ
filterNamer�setattr�upperrrrr�<module>sD
]3

��
�