https://t.me/RX1948
Server : Apache
System : Linux iad1-shared-b8-43 6.6.49-grsec-jammy+ #10 SMP Thu Sep 12 23:23:08 UTC 2024 x86_64
User : dh_edsupp ( 6597262)
PHP Version : 8.2.26
Disable Function : NONE
Directory :  /lib/python3/dist-packages/fail2ban/tests/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : //lib/python3/dist-packages/fail2ban/tests/__pycache__/samplestestcase.cpython-310.pyc
o

;s*b�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�s�e/e&de-�0�e'e-e(��q�q�dS)z"Copyright (c) 2013 Steven Hiscocks�GPL�N�)�Regex)�Filter�
FileContainer)�FilterReader�)�setUpMyTime�tearDownMyTime�TEST_NOW�
CONFIG_DIR�config�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.pyr4s
zFilterSamplesRegex.setUpcstt|���t�dS)zCall after every test case.N)rr�tearDownr
rrrrr;s
zFilterSamplesRegex.tearDowncCs(|�tdd�t�|�D��dkd�dS)z Check to ensure some tests existcSsg|]}|d�d�r|�qS)r�testSampleRegexs��
startswith)�.0�testrrr�
<listcomp>Cs
�z9FilterSamplesRegex.testFiltersPresent.<locals>.<listcomp>�
z&Expected more FilterSampleRegexs testsN)�
assertTrue�len�inspect�
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|_|dur!t�}|��}t	|d||t
jjd�}|�
|��|�|�
|��d�|��|�i�|��D]_}|ddkrZ|d}n|ddkrf|dg}n|�d	|f�|D];}|d
dkr|||_qp|d
dkr�|�|�qp|d
d
kr�|�|�qp|d
dkr�|�|�qp|d
dkr�|�|�qpqM|��}	|	D]}
t�|
�r�td|t|
��td�f��q�|t �g}||j|<|S)NTF�jail)�basedir�share_configrz	multi-set��setz$Unexpected config-token %r in streamr�	prefregex�addfailregex�addignoreregex�maxlines�datepatternz�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�getr�
returnRawHost�
checkAllRegex�
checkFindTime�activer�copyr�unittest�F2Br0�assertEqual�getFile�getJailName�read�
getOptions�convert�fail�	prefRegex�addFailRegex�addIgnoreRegex�setMaxLines�setDatePattern�getFailRegexr)r*�AssertionError�str�replacer+r2)r�fltName�namer/�opts�flt�
filterConf�opt�optval�	regexList�frrrr�_readFilterVs\�


��
��

zFilterSamplesRegex._readFiltercCstdd�|��D��S)Ncss&�|]\}}|�d�s||fVqdS)ztest.Nr)r �k�vrrr�	<genexpr>�s�$z4FilterSamplesRegex._filterOptions.<locals>.<genexpr>)r�items�rRrrr�_filterOptions�sz!FilterSamplesRegex._filterOptions)N)�__name__�
__module__�__qualname__rrr(r-rY�staticmethodr_�
__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�]�}	t
�|��d|	�}	t
�d	|	�}
|
�rz�t�|
�d
��}|
�d�dkrg|}Wq>|
�d�dkr�g|_d}t|t�rz|n|gD]Q}|r�|��}|�|�n|}|�t|t��|�d
�r�t|�d
��}|s�|�|�}|�d�}
|
s�|r�t|�nd}
�|
}
|j|
��|d�}|j�|
||f�q}Wq>|
�d�dkr�|�|�Wq>Wnty�}z
td||��|��f��d}~wwt |�}	t
�|��d|	�}	n|�s|	�!d��s|	�"��sq>i}|�rq>|j�s3�}
|j|
��dd�}|
|ifg|_|	�#d�}	|jD�]�\}
}}|�d��rPt|d��sP�q;|\}}|�$�}d}�z3i}|�d�dk�rl|�%|	�}n|�d��ry|�d�|	}	|�%dt&|	ft'�}|�r�g}|D]'}|\}}}}|du�s�|�d��r�|�(|�|�(||��q�|�|��q�|}|�s�|�)|�dd�d�W�q;|�|�dd�d�|�*t|�dddd �|D��|D]�}|\}}}}|�+�D]@\}}|d!v�r*|�|d�}|du�r|d"k�r|}|d#k�rt|�d$i��}t|tttf��r$|�,||��q�|�*||��q�|�d%d�}|du�r~z	t-j-�.|d&�}Wnt�yQt-j-�.|d'�}Ynwt/�0|�1��}||j2d(7}|�*||d)|t/�3d&t/�4|��|t/�3d&t/�4|��||f�|�(|�|�(||��q�W�q;t5�y�}z0ddl6}t5d*|
||��|��|	||dk�r�||ndd+�|�7|��8��d+�|�7|��8��f	��d}~wwq>|t|�ks%|j9�+�D])\}
}|\}}|�$�}t:|�D]\}} |�||v�p�| |vd,|
|| f��q�q�dS)-N�logsz,No sample log file available for '%s' filterrr�rb)�modeFzUTF-8z4^#+ ?(failJSON|(?:file|filter)Options|addFILE):(.+)$r�fileOptions�
filterOptionsztest.conditionztest.filter-name�r^�addFILEz	%s: %s:%i�#z
�
constraint����logtype�journalztest.prefix-line�nofail�matchz!Line not matched when should havez Line matched when shouldn't havezMultiple regexs matched %rcSsg|]}|d�qS)rr)r �xrrrr"�z?testSampleRegexsFactory.<locals>.testFilter.<locals>.<listcomp>)�timerr�descrm�host�attempts�matchesruz%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_DIRr2r%�	fileinput�	FileInputr�decode_line�filename�rerr�json�loads�groupr�
isinstance�listr=�updaterr8�evalr_rNrY�append�
ValueError�
filelineno�nextr�strip�rstriprL�processLine�TEST_NOW_STRr�addr,r@r]�assertSortedEqual�datetime�strptimeru�mktime�	timetuple�microsecond�strftime�gmtimerM�pprint�pformat�
splitlinesr�	enumerate)!r�	filenames�regexsUsedRe�
commonOpts�faildata�ir��logFile�ignoreBlock�line�jsonREMatchrR�fltOptsrPrS�e�
regexsUsedIdxrW�	failregexrF�ret�found�fid�fail2banTimerZr[�fv�t�
jsonTimeLocal�jsonTimer��failRegexIndex�	failRegex�r/rQrr�
testFilter�sD���



�
����

���



�
����
�#����������z+testSampleRegexsFactory.<locals>.testFilterr)rQr/r�rr�r�testSampleRegexsFactory�s-r�cCs|�d�o
|�d�S)Nzcommon.conf�.conf)�endswith�rsrrr�<lambda>?sr�cCs|�d�o	|�d�S)Nzzzz-r�)rr�r�rrrr�@rtzfilter.d�.ztestSampleRegexs%s)1�
__copyright__�__license__r�r�r&r�r{r��sysrur>�server.failregexr�
server.filterrr�client.filterreaderr�utilsr	r
rr�utcfromtimestamp�	isoformatr�r|r~�dirname�__file__�TEST_CONFIG_DIRr�_resolveHostTagr+�compile�escaper)�TestCaserr��basedir_�filter_�filter�listdir�
rpartition�
filterNamer�setattr�upperrrrr�<module>sN
]
1
��

����

https://t.me/RX1948 - 2025