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__/misctestcase.cpython-39.pyc
a

�L��s��@s�dZdZdZddlZddlZddlZddlZddlZddlZddl	Z	ddl
m
Z
ddlmZddl
mZmZd	d
lmZmZmZmZmZmZmZmZmZd	dlmZGdd
�d
ej�Zdd�Zdd�Z Gdd�dej�Z!Gdd�de�Z"Gdd�dej�Z#dS)zYaroslav Halchenkoz%Copyright (c) 2013 Yaroslav Halchenko�GPL�N)�glob)�StringIO�)�LogCaptureTestCase�logSys�)	�formatExceptionInfo�	mbasename�	TraceBack�FormatterWithTraceBack�	getLogger�getVerbosityFormat�
splitwords�
uni_decode�
uni_string)�MyTimec@s$eZdZdd�Zdd�Zdd�ZdS)�HelpersTestcCs@ztd��Wn.t�\}}|�|d�|�|d�Yn0dS)NzVery bad exception�
ValueError�rr	�assertEqual��self�name�args�r�?/usr/lib/python3.9/site-packages/fail2ban/tests/misctestcase.py�testFormatExceptionInfoBasic+s
z(HelpersTest.testFormatExceptionInfoBasiccCsBztdd��Wn.t�\}}|�|d�|�|d�Yn0dS)NzVery badrz('Very bad', None)rrrrr�testFormatExceptionConvertArgs3s
z*HelpersTest.testFormatExceptionConvertArgscCs�|�td�g�|�td�g�|�td�g�|�td�dg�|�td�ddg�|�td�ddg�|�td�ddg�|�td�gd	��|�td
�gd	��dS)N�z  �1z 1 2 �2z 1, 2 , z 1
  2z	 1
  2, 3)r r!�3z	1	  2,
 3
)rr�rrrr�testsplitwords<szHelpersTest.testsplitwordsN)�__name__�
__module__�__qualname__rrr$rrrrr)s	rcCs"ddl}|j|dd�}t|���S)NrT)�shell)�
subprocess�check_outputr�rstrip)�cmdr)�retrrr�_sh_callHsr.cCstd�S)Nz?fail2ban-python -c 'import sys; print(tuple(sys.version_info))')r.rrrr�_getSysPythonVersionMsr/cs,eZdZ�fdd�Zdd�Zdd�Z�ZS)�	SetupTestcs�tt|���tj��tj�tj�	t
�ddd�}tj�|�rB|pDd|_|jsXt�
d��t�}|tttj��kr�t�
dtttj��|f��dS)Nz..zsetup.pyzLSeems to be running not out of source distribution -- cannot locate setup.pyziSeems to be running with python distribution %s -- install can be tested only with system distribution %s)�superr0�setUp�unittest�F2BZ
SkipIfFast�os�path�join�dirname�__file__�exists�setupZSkipTestr/�str�tuple�sys�version_info)rr;ZsysVer��	__class__rrr2Ss
���zSetupTest.setUpc	Cst|js
dSt��}tjjtjkr$dnd}z:t�	dt
j|j||f�|�t�
|��Wt�|�nt�|�0dS)Nz >/dev/null 2>&1rz#%s %s --dry-run install --root=%s%s)r;�tempfile�mkdtempr3r4�	log_level�logging�DEBUGr5�systemr>�
executable�
assertTrue�listdir�shutil�rmtree)r�tmp�	supdbgoutrrr�testSetupInstallDryRuncs�z SetupTest.testSetupInstallDryRunc
s&|js
dSt���tj�d�}tjjt	j
kr2dnd}�z�|�t�dt
j|j�|f�d��fdd�}|ttd����}gd	�}t|��|�r�d
d�}i}t|��|�D]4}tj��|�}	tj�|	�r�|||	d��p�d||<q�|j||d
||�|fd�dD]*}
|jtj�tj��|
��d|
d��qtd�d��d�}|�t|�dk�|D]$}|�tj�|�tj�t
j���qZWt���t�dt
j|j|�r�|dndf�|�r"tj�d��r"t�d�nPt���t�dt
j|j|�r�|dndf�|�r tj�d��r t�d�0dS)N�buildz >/dev/nullrz%s %s install --root=%s%srcs�fdd�|D�S)Ncs g|]}|t��dd��qS)rN)�len)�.0�x�rMrr�
<listcomp>�zESetupTest.testSetupInstallRoot.<locals>.strippath.<locals>.<listcomp>r)�lrTrr�	strippath~sz1SetupTest.testSetupInstallRoot.<locals>.strippathz%s/*)�etcZusr�varcsFg}t�|�D]2\�}}t�|||�}|��fdd�|D��q|S)Nc3s|]}tj��|�VqdS�N)r5r6r7)rR�f��baserr�	<genexpr>�rVzISetupTest.testSetupInstallRoot.<locals>.recursive_glob.<locals>.<genexpr>)r5�walk�fnmatch�filter�extend)Ztreeroot�pattern�results�dirs�filesZ	goodfilesrr]r�recursive_glob�s
z6SetupTest.testSetupInstallRoot.<locals>.recursive_glob�*z6Got: %s Needed: %s under %s. Files under new paths: %s��msg)zetc/fail2ban/fail2ban.confzetc/fail2ban/jail.confz
Can't find %szfind z -name fail2ban-python�
z%s %s clean --all%sz 2>&1)r;rBrCr5r6r:r3r4rDrErFrrGr>rH�sortedr�set�
differencer7rIr.�splitrQ�realpathrKrL)rZremove_buildrNrXZgotZneedrhrg�missingZmissing_fullr\Z
installedPathrrTr�testSetupInstallRootssh
����
���
�

��
�zSetupTest.testSetupInstallRoot)r%r&r'r2rOrs�
__classcell__rrr@rr0Qsr0c@s\eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�ZdS)�TestsUtilsTestcCsT|�td�d�|�td�d�|�td�d�|�td�d�|�td�d�dS)	Nz	sample.py�samplez/long/path/sample.pyz/long/path/__init__.pyz
path.__init__z/long/path/base.pyz	path.basez/long/path/base)rr
r#rrr�
testmbasename�s
zTestsUtilsTest.testmbasenamecCs,|�ttdd�td�td�td�dS)Nstestzf2b-test::non-existing-encodingstest�utestÏ)�assertRaises�	Exceptionrrr#rrr�testUniConverters�s�z TestsUtilsTest.testUniConverterscCs(t}Gdd�d�}|�}|�tjd|�|�dd�|��|�d|�|�dd�|�dt���|d�}|�tjd	||�|jd
ddd
�|�d||�|jdddd
�|�d�Gdd�dtj	�}|j
}z@t|j
�|_
|j
|�g7_
|�tjd�|�d�W||_
n||_
0|�d�dS)Nc@seZdZddd�Zdd�ZdS)z,TestsUtilsTest.testSafeLogging.<locals>.TestrcSs
||_dSr[)�err)rr{rrr�__init__�sz5TestsUtilsTest.testSafeLogging.<locals>.Test.__init__cSs|jrtd��ndSdS)N�no representation for test!u.conv-error (òðåòèé), unterminated utf Ï)r{ryr#rrr�__repr__�s
z5TestsUtilsTest.testSafeLogging.<locals>.Test.__repr__N)r)r%r&r'r|r~rrrr�Test�s
rztest 1a: %r�	Tracebackr}ztest 1b: %rz.[phase 2] test error conversion by encoding %srztest 2a: %r, %sztest 2azError by logging handlerF��allztest 2b: %r, %sztest 2bz*[phase 3] test unexpected error in handlerc@seZdZdd�ZdS)z5TestsUtilsTest.testSafeLogging.<locals>._ErrorHandlercSstd��dS)Nzerror in handler test!)ry)r�recordrrr�handle�sz<TestsUtilsTest.testSafeLogging.<locals>._ErrorHandler.handleN)r%r&r'r�rrrr�
_ErrorHandler�sr�ztest 3aztest 3bZOK)�	DefLogSys�logrE�NOTICE�assertLogged�pruneLog�noticer>�getdefaultencoding�Handler�handlers�list)rrr�testr�Z_org_handlerrrr�testSafeLogging�s0
zTestsUtilsTest.testSafeLoggingc	s�dD]�}t|d�}dd����fdd��zt�d��WntyP|�}Yn0d|vrh|�d	|�nd
|vr||�d	|�|�d|�qdS)N)TF)�compresscSs
t��dSr[)rrrrr�
func_raise�sz0TestsUtilsTest.testTraceBack.<locals>.func_raisecs|r�|d�n��dS)Nrr)�i��
deep_functionr�rrr��sz3TestsUtilsTest.testTraceBack.<locals>.deep_function�zfail2ban-testcases�>Zcoverage�:)r�printr�assertIn�assertNotIn)rr��tb�srr�r�
testTraceBack�s
zTestsUtilsTest.testTraceBackcOs |jt||g|�Ri|��dSr[)ZassertRaisesRegex�AssertionError)rZregexpZfunr�kwargsrrr�_testAssertionErrorREsz$TestsUtilsTest._testAssertionErrorREcsrdd�}��t�jd|d���t�jd�jd���d�fdd����t�jd	td
���d�fdd��dS)
NcSst|��dSr[)�KeyErrorrjrrr�_key_errsz;TestsUtilsTest.testExtendedAssertRaisesRE.<locals>._key_err�^failed$�failed�
__failed__z$failed.* does not match .*__failed__cs��d�jd�S)Nr�r�)r��failrr#rr�<lambda>s�z;TestsUtilsTest.testExtendedAssertRaisesRE.<locals>.<lambda>rrzJ0 AssertionError not raised X.* does not match .*AssertionError not raisedcs��d�fdd��S)Nz^0 AssertionError not raised X$cs��dtd�S)Nrr)r��intrr#rrr�&rVzMTestsUtilsTest.testExtendedAssertRaisesRE.<locals>.<lambda>.<locals>.<lambda>)r�rr#rrr�%s
�)rxr�r�r�r�r�)rr�rr#r�testExtendedAssertRaisesREs$��
�
�
�z)TestsUtilsTest.testExtendedAssertRaisesREcs2��dgd����dd���dd���ddd�dD����dgd����dd���dd���ddd�dD����d	�jdd���d
�jdtd����d
�jddd�dD����d�jdd���d�jdtd����d�jddd�dD��t}���|�d���d��jdddd��jdddd��jdddd��jdddd����|�d���d��jdddd��jddddd�t	j
jd}t	j
_��t
t	j
�d�t����t	j
�dd���d ���t	j
�d!�d!���t	j
�d"�d"�dt	j
_zN��t	j
�d#d���d ���t	j
�d!�d$���t	j
�d"�d"�W|t	j
_n
|t	j
_0��t	j
�d�����|�d���d%�jd���d&�jdd��jd'�jdddd��jd(�jdddd��jd)�jdddd*d+��jd,�jdddd��jd-�jdddd*d+��jd&�jdddd���ddd.giddd.gi���t�jddd.gidd.dgi���dd/gd/dg��jdd/ggd/dggd.d0��jdd/ggd/dggdd1���t�fd2d���jddd/gidd/dgidd1���t�fd3d���jd4d/d5gd6d7gd8�gd7d6gd5d/gd9�d4gdd1��jd4d/d5gd6d7gd8�gd7d6gd5d/gd9�d4gd:d0���t�fd;d����d<d=gd>d=gggfd<d=gd=d>gggf���td?�td@����t�jd?gd@g���t�jd?ggd@gg���dA�jdgd5d/g���dB�jdd/gd5d/g�dS)CN�a)r��b�c�dZcbacss|]}|dkr|VqdS�r�Nr�rRr�rrrr_.rVz;TestsUtilsTest.testExtendedAssertMethods.<locals>.<genexpr>)r�r�r�Zcbdcss|]}|dkr|��VqdSr���upperr�rrrr_2rVz'a' unexpectedly found in 'cba'z#1 unexpectedly found in \[0, 1, 2\]rr�z&'A' unexpectedly found in \['C', 'A'\]�Acss|]}|dkr|��VqdSr�r�r�rrrr_9rVz'a' was not found in 'xyz'Zxyzz5 was not found in \[0, 1, 2\]�z!'A' was not found in \['C', 'B'\]css|]}|dkr|��VqdS)r�Nr�r�rrrr_?rVz
test "xyz"r�Tr�ZzyxFZtest_zyxz
xxxx "xxx"cSsdS�N�2rrrrrr�QrVz:TestsUtilsTest.testExtendedAssertMethods.<locals>.<lambda>r��g9@cSsdSr�rrrrrr�VrVg@z.* was found in the logz+All of the .* were found present in the logzwas found in the logzwas not found in the logz&was not found in the log, waited 1e-06g���ư>)r��waitz"None among .* was found in the logz0None among .* was found in the log, waited 1e-06r�B)�level��
nestedOnlycs�jddggddggddd�S�Nr�r�rT)r�r���assertSortedEqualrr#rrr�ws�cs"�jdddgidddgiddd�Sr�r�rr#rrr�zs��Z�C�E�F�r�r��r�r����cs4�jdddgddgd�gddgddgd�dgdd	�S)
Nr�r�r�r�r�r�r�Tr�r�rr#rrr��s(�rZA1ZA2�ABCZCBAz\['A'\] != \['C', 'B'\]z\['A', 'B'\] != \['B', 'C'\])r�r�r��ranger�r��debugr�ZassertNotLoggedr3r4�fastZassertFalse�
isinstanceZmaxWaitTime�boolrZassertDictEqualrxr�r�r�)rrZorgfastrr#r�testExtendedAssertMethods)s�������




��
�
��
��
�
� ,�,����z(TestsUtilsTest.testExtendedAssertMethodscCs>|�td�d�|�tddd�d�|�tdddd�d�dS)NrzA%(asctime)s %(name)-24s[%(process)d]: %(levelname)-7s %(message)sF)�paddingz<%(asctime)s %(name)s[%(process)d]: %(levelname)s %(message)s)Zaddtimer�z0%(name)s[%(process)d]: %(levelname)s %(message)s)rrr#rrr�testVerbosityFormat�s
���z"TestsUtilsTest.testVerbosityFormatcCs�t�}t}d}td�}t�|�}|�||��|�|�|�d�|��}|�	|�
��d��|�d�}|�	|dk�|�
|d|�||d|dd��dS)	Nz %(tb)s | %(tbc)s : %(message)sZfail2ban_testsZXXXz: XXX�|�
rr)rrr
rE�
StreamHandler�setFormatter�
addHandler�error�getvaluerIr+�endswith�indexr)rZstrout�	Formatter�fmtr�outr�Zpindexrrr�testFormatterWithTraceBack�s



z)TestsUtilsTest.testFormatterWithTraceBackcCs2t}|�dtjj�|�dddd�|�d�dS)Nzlazy logging: %rr�rrr�znot all arguments converted)r�r�r3r4Zlog_lazyr�r�)rrrrr�testLazyLogging�szTestsUtilsTest.testLazyLoggingN)
r%r&r'rwrzr�r�r�r�r�r�r�r�rrrrru�s* fruc@seZdZdd�Zdd�ZdS)�
MyTimeTestcCs�tj}|�|d�d�|�|d�d�|�|d�d�|�|d�d�|�|d�d	�|�|d
�d	�|�|d�d�|�t|d
��dddd�|�t|d��dddd�dS)NZ1y6mo30w15d12h35m25si]��z2yy 3mo 4ww 10dd 5hh 30mm 20ssi$�mz>2 years 3 months 4 weeks 10 days 5 hours 30 minutes 20 secondsz!1 year + 1 month - 1 week + 1 dayi��zI2 * 0.5 yea + 1*1 mon - 3*1/3 wee + 2/2 day - (2*12 hou 3*20 min 80 sec) g@��Az(2*.5y+1*1mo-3*1/3w+2/2d-(2*12h3*20m80s) z!1ye -2mo -3we -4da -5ho -6mi -7seiQ	pz1 month�<�gp>@z1 yearg�v@)rZstr2secondsr�float)rZstr2secrrr�testStr2Seconds�s zMyTimeTest.testStr2SecondscCs�dd�}|�|d�d�|�|d�d�|�|d�d�|�|d	�d
�|�|d�d�|�|d
�d�|�|d�d�|�|d�d�|�|d�d�|�|d�d�|�|d�d�|�|d�d�|�|d�d�dS)NcSstt�|��Sr[)r<rZseconds2str)r�rrrr��rVz(MyTimeTest.testSec2Str.<locals>.<lambda>i)z1y 3w 4di(�z1y 3dg�~AZ1yi��z2w 1di�tZ2wi�z	2d 7h 15mi�z2d 1hg��@z3h 31miZ2hiZ1hiz59m 50s�;Z59sr�0)r)rZsec2strrrr�testSec2Str�szMyTimeTest.testSec2StrN)r%r&r'r�r�rrrrr��sr�)$�
__author__�
__copyright__�__license__rEr5r>r3rBrKrar�ior�utilsrrr�Zhelpersr	r
rrr
rrrrZ
server.mytimerZTestCaserr.r/r0rur�rrrr�<module>s,,d