CasperSecurity

Current Path : /usr/lib/python3/dist-packages/fail2ban/tests/__pycache__/
Upload File :
Current File : //usr/lib/python3/dist-packages/fail2ban/tests/__pycache__/sockettestcase.cpython-310.pyc

o

;s*b��@s�dZdZdZddlZddlZddlZddlZddlZddlZddl	m
Z
ddlmZdd	l
mZmZmZmZmZdd
lmZddlmZddl	m
Z
dd
�ZGdd�de�ZGdd�de
�ZGdd�de
�ZdS)zSteven Hiscocksz"Copyright (c) 2013 Steven Hiscocks�GPL�N�)�LogCaptureTestCase�)�protocol)�asyncore�RequestHandler�loop�AsyncServer�AsyncServerException)�Utils)�CSocketcGstd��)N�test unpickle error��	Exception��args�r�?/usr/lib/python3/dist-packages/fail2ban/tests/sockettestcase.py�TestMsgError,src@s$eZdZedffdd�Zdd�ZdS)�TestMsgrcCs
||_dS�N��unpickle)�selfrrrr�__init__/s
zTestMsg.__init__cCs|jSrr�rrrr�
__reduce__1szTestMsg.__reduce__N)�__name__�
__module__�__qualname__rrrrrrrr.srcszeZdZ�fdd�Zdd�Zedd��Zddd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Z�ZS)�SocketcsVt�|�tt|���t|�|_t�dd�\}}t�	|�t�
|�||_d|_dS)zCall before every test case.z
fail2ban.sockz
f2b-socketN)
r�setUp�superr!r
�server�tempfile�mkstemp�os�close�remove�	sock_name�serverThread)r�sock_fdr*��	__class__rrr"7s




zSocket.setUpcCs&|jr|j��|��t�|�dS)zCall after every test case.N)r+r$�stop�_stopServerThreadr�tearDownrrrrr1Bs
zSocket.tearDowncCs|S)z<Test transmitter proceed method which just returns first argr)�messagerrr�proceedIszSocket.proceedFcCsNtj|jj|j|fd�|_}d|_|��|�t�	|jj
tj�
d���|S)N)�targetrT�
)�	threading�Threadr$�startr*r+�daemon�
assertTruer�wait_for�isActive�unittest�F2B�maxWaitTime)r�forcer+rrr�_createServerThreadNs�zSocket._createServerThreadcs,|j�t��fdd�tj�d��d|_dS)Ncs���p
��tj�Sr)�is_alive�joinr�DEFAULT_SLEEP_TIMEr�r+rr�<lambda>Zs
z*Socket._stopServerThread.<locals>.<lambda>r5)r+rr;r=r>r?rrrErr0Ws

�
zSocket._stopServerThreadcCsZ|��}|j��|��|�|���|j��|�|j���|�tj	�
|j��dSr)rAr$r(r0�assertFalserBr/r<r'�path�existsr*�rr+rrr�testStopPerCloseUnexpected^s

z!Socket.testStopPerCloseUnexpectedc
Cs4zt|j�WSty}zWYd}~dSd}~wwr)r
r*r)r�errr�
_serverSocketks��zSocket._serverSocketcCs�|��}t�|jd�}gd�}|�|�|�|�|�|�t�gg�d�|jdddd�|�|�|�|�|��|��|j	�
�t�|jd�}|�|�|�dg�|j	��|��|�
|���|�
|j	���|�
tj�|j��dS)	Nr��A�testr2�ERROR: test unpickle errorz!PROTO-error: load message failed:rT��all�SHUTDOWN)rArr;rM�assertEqual�sendr�assertLoggedr(r$�stop_communicationr/r0rGrBr<r'rHrIr*)rr+�client�testMessagerrr�
testSocketqs"

zSocket.testSocketcsf|��}t�|jd��dddtjjgg�tj}zdd�t_|�	t
d��fdd��W|t_dS|t_w)	NrrOrPr2cSs|��Sr)r(rrrrrF�sz0Socket.testSocketConnectBroken.<locals>.<lambda>zreset by peer|Broken pipecs�j�tj�d�d�S)Nr5)�timeout)rVr=r>r?r�rYrZrrrF�s)rArr;rMr�CSPROTO�ENDr�found_terminator�assertRaisesRegexr)rr+�org_handlerrr]r�testSocketConnectBroken�s
�zSocket.testSocketConnectBrokencCs�|��}t�|jd�}gd�}|�|�|�|�tj}zdd�t_|�|�|�d�W|t_n|t_w|jdddd	�|j	�
�|��|�|�
��dS)
NrrNcSst�Sr)rrrrrrF�sz.Socket.testStopByCommunicate.<locals>.<lambda>rQzUnexpected communication errorrTrR)rArr;rMrUrVrr`rWr$r/r0rGrB)rr+rYrZrbrrr�testStopByCommunicate�s

zSocket.testStopByCommunicatecsttj�ddi���fdd�}z|t_|��}|�t��fdd�tj�d���W�t_n�t_w|j	dd	d
d�dS)N�cntrrcs,�dd7<�ddkrtd���|�S)Nrer�2ztest errors in poll)�RuntimeErrorr��err�org_pollrr�_produce_error�sz-Socket.testLoopErrors.<locals>._produce_errorcs�ddkS)Nrerfrr)rirrrF�sz'Socket.testLoopErrors.<locals>.<lambda>r5z1Server connection was closed: test errors in poll�0Too many errors - stop logging connection errorsTrR)
r�pollrAr:rr;r=r>r?rW)rrkr+rrhr�testLoopErrors�s$
�zSocket.testLoopErrorscCsxt|jd���|�t|jj|jd�|�d�}|j��|�	�|�
|���|�
|j���|�
t
j�|j��dS)N�wFT)�openr*r(�assertRaisesrr$r8rAr/r0rGrBr<r'rHrIrJrrr�testSocketForce�s�

zSocket.testSocketForce)F)rrr r"r1�staticmethodr3rAr0rKrMr[rcrdrnrr�
__classcell__rrr-rr!5s

	
!r!c@seZdZdd�Zdd�ZdS)�
ClientMisccs^ddi��fdd�}�fdd�}t||d�|jdd	d
dd�|�d
�|jddddd�dS)Nrercs�ddkS)Nre�(rr��phaserr�_active�sz,ClientMisc.testErrorsInLoop.<locals>._activecs �dd7<td�d��)Nrerz	test *%d*rrrwrr�_poll�sz*ClientMisc.testErrorsInLoop.<locals>._poll)�use_pollztest *1*z	test *10*z	test *20*TrRrlz	test *21*z	test *22*z	test *23*)r	rW�assertNotLogged)rryrzrrwr�testErrorsInLoop�s
zClientMisc.testErrorsInLoopcCs:tj}ttjd�t_zt��t��W|t_dS|t_w)Nro)�sys�stdoutrpr'�devnullr�printFormatted�	printWiki)r�saved_stdoutrrr�testPrintFormattedAndWiki�s
z$ClientMisc.testPrintFormattedAndWikiN)rrr r}r�rrrrru�s
ru)�
__author__�
__copyright__�__license__r'r~r%r6�timer=�utilsr�r�server.asyncserverrrr	r
r�server.utilsr�client.csocketr
r�objectrr!rurrrr�<module>s(,
Hacker Blog, Shell İndir, Sql İnjection, XSS Attacks, LFI Attacks, Social Hacking, Exploit Bot, Proxy Tools, Web Shell, PHP Shell, Alfa Shell İndir, Hacking Training Set, DDoS Script, Denial Of Service, Botnet, RFI Attacks, Encryption
Telegram @BIBIL_0DAY