CasperSecurity

Current Path : /lib/python3/dist-packages/twisted/runner/test/__pycache__/
Upload File :
Current File : //lib/python3/dist-packages/twisted/runner/test/__pycache__/test_procmon.cpython-310.pyc

o

�b�a�@s�dZddlZddlmZmZmZddlmZddlm	Z	ddl
mZddlm
Z
mZddlmZdd	lmZGd
d�d�ZGdd
�d
ee�ZGdd�dej�ZGdd�dej�ZdS)z&
Tests for L{twisted.runner.procmon}.
�N)�ProcessDone�ProcessExitedAlready�ProcessTerminated)�Clock)�globalLogPublisher)�Failure)�LoggingProtocol�ProcessMonitor)�
MemoryReactor)�unittestc@s>eZdZdZdZdZdZ				ddd�Zdd�Zd	d
�Z	dS)�DummyProcessa 
    An incomplete and fake L{IProcessTransport} implementation for testing how
    L{ProcessMonitor} behaves when its monitored processes exit.

    @ivar _terminationDelay: the delay in seconds after which the DummyProcess
        will appear to exit when it receives a TERM signal
    �NrcCs@||_||_||_||_||_||_||_||_|	|_|
|_	dS�N)
�proto�_reactor�_executable�_args�_environment�_path�_uid�_gid�_usePTY�	_childFDs)�self�reactor�
executable�args�environment�pathr�uid�gid�usePTY�childFDs�r#�B/usr/lib/python3/dist-packages/twisted/runner/test/test_procmon.py�__init__ s
zDummyProcess.__init__cCsP|jdfdd�}|jdurt��||vr&||\}}|j�||j|�|_dSdS)a�
        A partial implementation of signalProcess which can only handle TERM and
        KILL signals.
         - When a TERM signal is given, the dummy process will appear to exit
           after L{DummyProcess._terminationDelay} seconds with exit code 0
         - When a KILL signal is given, the dummy process will appear to exit
           immediately with exit code 1.

        @param signalID: The signal name or number to be issued to the process.
        @type signalID: C{str}
        r�rr
)�TERM�KILLN)�_terminationDelay�pidrr�	callLater�processEnded�_signalHandler)r�signalID�params�delay�statusr#r#r$�
signalProcess:s

��zDummyProcess.signalProcesscCs,d|_ttd�}|j�t|||���dS)zC
        Deliver the process ended event to C{self.proto}.
        Nr&)r*rrrr,r)rr1�	statusMapr#r#r$r,Qs
�zDummyProcess.processEnded)NNrN)
�__name__�
__module__�__qualname__�__doc__r*rr)r%r2r,r#r#r#r$rs

�rc@s0eZdZdZdd�Zdidddddfdd�ZdS)	�DummyProcessReactorz�
    @ivar spawnedProcesses: a list that keeps track of the fake process
        instances built by C{spawnProcess}.
    @type spawnedProcesses: C{list}
    cCst�|�t�|�g|_dSr)r
r%r�spawnedProcesses�rr#r#r$r%ds


zDummyProcessReactor.__init__r#Nrc
Cs4t||||||||||	�
}
|�|
�|j�|
�|
S)zz
        Fake L{reactor.spawnProcess}, that logs all the process
        arguments and returns a L{DummyProcess}.
        )r�makeConnectionr9�append)r�processProtocolrr�envrrr r!r"�procr#r#r$�spawnProcessjs�
z DummyProcessReactor.spawnProcess)r4r5r6r7r%r@r#r#r#r$r8]s
�r8c@seZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�Zd d!�Zd"d#�Zd$d%�Zd&d'�Zd(d)�Zd*d+�Zd,d-�Zd.d/�Zd0d1�Zd2d3�Zd4d5�Zd6d7�Zd8d9�Zd:d;�Z d<d=�Z!d>d?�Z"d@dA�Z#dBS)C�ProcmonTestsz&
    Tests for L{ProcessMonitor}.
    cCs2t�|_t|jd�|_d|j_d|j_d|j_dS)zL
        Create an L{ProcessMonitor} wrapped around a fake reactor.
        �r��
N)r8rr	�pm�minRestartDelay�maxRestartDelay�	thresholdr:r#r#r$�setUp�s
zProcmonTests.setUpcCsL|jjdddgddid�t|j�}|�d|�|�d|�|�d|�d	S)
z+
        Repr includes all details
        �foo�arg1�arg2r
rC�rr r>�1�2N)rE�
addProcess�repr�assertIn�r�representationr#r#r$�test_reprLooksGood�s

zProcmonTests.test_reprLooksGoodcCs<|jjdddgid�t|j�}|�d|�|�d|�dS)z�
        Repr does not include unneeded details.

        Values of attributes that just mean "inherit from launching
        process" do not appear in the repr of a process.
        rJrKrL)r>�(�)N)rErPrQ�assertNotInrSr#r#r$�test_simpleReprLooksGood�s
z%ProcmonTests.test_simpleReprLooksGoodcCsD|jjdddgddid�|�|j��ddddgddifi�dS)	zW
        The list of monitored processes must be included in the pickle state.
        rJrKrLr
rCrM�	processesN)rErP�assertEqual�__getstate__r:r#r#r$�test_getStateIncludesProcesses�s�z+ProcmonTests.test_getStateIncludesProcessescCs|�d|j���dS)z~
        The private L{ProcessMonitor._reactor} instance variable should not be
        included in the pickle state.
        rN)rXrEr\r:r#r#r$�test_getStateExcludesReactor��z)ProcmonTests.test_getStateExcludesReactorcCs~|jjdddgddid�|�|jji�|�|jjdddgddifi�|j��|j�d�|�t|jj�	��dg�dS)	z�
        L{ProcessMonitor.addProcess} only starts the named program if
        L{ProcessMonitor.startService} has been called.
        rJrKrLr
rCrMrN)
rErPr[�	protocolsrZ�startServicer�advance�list�keysr:r#r#r$�test_addProcess�s 
zProcmonTests.test_addProcessc	Cs>|jjdddgddid�|jt|jjdddgddid�dS)z|
        L{ProcessMonitor.addProcess} raises a C{KeyError} if a process with the
        given name already exists.
        rJrKrLr
rCrMN)rErP�assertRaises�KeyErrorr:r#r#r$� test_addProcessDuplicateKeyError�s
�z-ProcmonTests.test_addProcessDuplicateKeyErrorcCsPddi}|j��|jjddgdd|d�|j�d�|�|jjdj|�dS)	z�
        L{ProcessMonitor.addProcess} takes an C{env} parameter that is passed to
        L{IReactorProcess.spawnProcess}.
        �KEY�valuerJr
rCrMrN)rErarPrrbr[r9r)r�fakeEnvr#r#r$�test_addProcessEnv�s

zProcmonTests.test_addProcessEnvcCsD|j��|jjddgdd�|j�d�|�|jjdjd�dS)z�
        L{ProcessMonitor.addProcess} takes an C{cwd} parameter that is passed
        to L{IReactorProcess.spawnProcess}.
        rJz	/mnt/lala)�cwdrN)rErarPrrbr[r9rr:r#r#r$�test_addProcessCwd�s
zProcmonTests.test_addProcessCwdcCsR|j��|j�ddg�|�t|jj�d�|j�d�|�t|jj�d�dS)zm
        L{ProcessMonitor.removeProcess} removes the process from the public
        processes list.
        rJr
rN)rErarPr[�lenrZ�
removeProcessr:r#r#r$�test_removeProcess�s

zProcmonTests.test_removeProcesscCs |j��|�t|jjd�dS)zz
        L{ProcessMonitor.removeProcess} raises a C{KeyError} if the given
        process name isn't recognised.
        rJN)rErarfrgrpr:r#r#r$�!test_removeProcessUnknownKeyError�s
z.ProcmonTests.test_removeProcessUnknownKeyErrorcCsH|j�ddg�|j�d�|�|jjdt�|�d|jj���dS)a
        When a process has been started, an instance of L{LoggingProtocol} will
        be added to the L{ProcessMonitor.protocols} dict and the start time of
        the process will be recorded in the L{ProcessMonitor.timeStarted}
        dictionary.
        rJN)	rErP�startProcess�assertIsInstancer`rrR�timeStartedrdr:r#r#r$�test_startProcess�szProcmonTests.test_startProcesscCs2|j�ddg�|j�d�|�|j�d��dS)zr
        L{ProcessMonitor.startProcess} silently returns if the named process is
        already started.
        rJN)rErPrs�assertIsNoner:r#r#r$�test_startProcessAlreadyStartedsz,ProcmonTests.test_startProcessAlreadyStartedcC�|�t|jjd�dS)zy
        L{ProcessMonitor.startProcess} raises a C{KeyError} if the given
        process name isn't recognised.
        rJN)rfrgrErsr:r#r#r$� test_startProcessUnknownKeyErrorr_z-ProcmonTests.test_startProcessUnknownKeyErrorcCs�|j��|j�ddg�|�d|jj�d}|jjdj_|j�|jj	�|j�
d�|j�|�|�|j��|jj
d�dS)zm
        L{ProcessMonitor.stopProcess} immediately sends a TERM signal to the
        named process.
        rJr
N)rErarPrRr`�	transportr)rrbrH�stopProcessr[�secondsru)r�	timeToDier#r#r$�"test_stopProcessNaturalTerminations
z/ProcmonTests.test_stopProcessNaturalTerminationcCs�|j��|j�ddg�|�d|jj�|j�|jj�|jjdj}|jj	d|_
|j�d�|j�|jj	d�|�d|jj
d�|j�d�|�|j��|jj
d�dS)z�
        L{ProcessMonitor.stopProcess} kills a process which fails to terminate
        naturally within L{ProcessMonitor.killTime} seconds.
        rJr
gN)rErarPrRr`rrbrHr{�killTimer)r|r[rur})rr?r#r#r$�test_stopProcessForcedKill4s
z'ProcmonTests.test_stopProcessForcedKillcCry)zx
        L{ProcessMonitor.stopProcess} raises a C{KeyError} if the given process
        name isn't recognised.
        rJN)rfrgrEr|r:r#r#r$�test_stopProcessUnknownKeyErrorJr_z,ProcmonTests.test_stopProcessUnknownKeyErrorcCs&|j�ddg�|�|j�d��dS)z�
        L{ProcessMonitor.stopProcess} silently returns if the named process
        is already stopped. eg Process has crashed and a restart has been
        rescheduled, but in the meantime, the service is stopped.
        rJN)rErPrwr|r:r#r#r$�test_stopProcessAlreadyStoppedQsz+ProcmonTests.test_stopProcessAlreadyStoppedcC��g}|�tj|j�t�|j�|j�ddg�|j��|j�	d�|�
d|jj�|j�	|jj�|jjd�
d�|�t|�d�|dd}|dd}|dd}|dd}|�|d	�|�|d
�|�|d�|�|d�dS)
zS
        Getting a complete output line on stdout generates a log message.
        rJr�
hello world!
r
�
log_namespace�stream�tag�line�%twisted.runner.procmon.ProcessMonitor�stdout�hello world!N)�
addCleanupr�removeObserverr<�addObserverrErPrarrbrRr`rH�outReceived�assertEqualsro�r�events�	namespacer�r�r�r#r#r$�test_outputReceivedCompleteLineZ�$
z,ProcmonTests.test_outputReceivedCompleteLinecCr�)
zS
        Getting a complete output line on stderr generates a log message.
        rJrr�r
r�r�r�r�r��stderrr�N)r�rr�r<r�rErPrarrbrRr`rH�errReceivedr�ror�r#r#r$�!test_ouputReceivedCompleteErrLineur�z.ProcmonTests.test_ouputReceivedCompleteErrLinecCs�g}|�tj|j�t�|j�|j�ddg�|j��|j�	d�|�
d|jj�|j�	|jj�|jjd�
d�|�t|�d�|d}|d}|d}|d}|d}|�|d	�|�|d
�|�|d�|�|td��dS)
zN
        Getting invalid UTF-8 results in the repr of the raw message
        rJrs�hello world!
r
r�r�r�r�r�r�s
�hello world!N)r�rr�r<r�rErPrarrbrRr`rHr�r�rorQ)rr��messager�r�r��outputr#r#r$�*test_outputReceivedCompleteLineInvalidUTF8�s&
z7ProcmonTests.test_outputReceivedCompleteLineInvalidUTF8cCsg}|�tj|j�t�|j�|j�ddg�|j��|j�	d�|�
d|jj�|j�	|jj�|jjd�
d�|�t|�d�|jjd�ttd���|�t|�d�|dd}|dd}|dd}|dd}|�|d	�|�|d
�|�|d�|�|d�dS)
zM
        Getting partial line results in no events until process end
        rJrshello world!r
r�r�r�r�r�r�r�N)r�rr�r<r�rErPrarrbrRr`rHr�r�ror,rrr�r#r#r$�test_outputReceivedPartialLine�s(
z+ProcmonTests.test_outputReceivedPartialLinecCs�|j�ddg�|j��|j�d�|�d|jj�|j�|jj�|jjd�t	t
d���|�d|jj�|j�d�|�d|jj�dS)z�
        L{ProcessMonitor.connectionLost} should immediately restart a process
        if it has been running longer than L{ProcessMonitor.threshold} seconds.
        rJrN)rErPrarrbrRr`rHr,rrrXr:r#r#r$�#test_connectionLostLongLivedProcess�s
z0ProcmonTests.test_connectionLostLongLivedProcesscCs�|j�ddg�|j��|j�d�|j�d�|�d|jj�|jjd}|�|�	��|j�|jj
djj�|�
|�	��|�d|jj�dS)z�
        L{ProcessMonitor.connectionLost} cancels a scheduled process killer and
        deletes the DelayedCall from the L{ProcessMonitor.murder} list.
        rJr
N)rErPrarrbr|rR�murder�
assertTrue�activer`r{r)�assertFalserX)r�delayedCallr#r#r$�test_connectionLostMurderCancel�s
z,ProcmonTests.test_connectionLostMurderCancelcCsj|j��|j�ddg�|�d|jj�|jjdj�d�|j�|jjdjj	�|�
d|jj�dS)z�
        L{ProcessMonitor.connectionLost} removes the corresponding
        ProcessProtocol instance from the L{ProcessMonitor.protocols} list.
        rJr(N)rErarPrRr`r{r2rrbr)rXr:r#r#r$�#test_connectionLostProtocolDeletion�s
z0ProcmonTests.test_connectionLostProtocolDeletioncCs�d|j_d|j_|j��|j�ddg�|�|jjd|jj�|j�|jj	d�|jj
d�tt
d���|�|jjd|jj�dS)z}
        L{ProcessMonitor.connectionLost} will wait at least minRestartDelay s
        and at most maxRestartDelay s
        rC�rJr
rN)rErFrGrarPr[r0rrbrHr`r,rrr:r#r#r$�%test_connectionLostMinMaxRestartDelay�s
z2ProcmonTests.test_connectionLostMinMaxRestartDelaycCs�|j��|j�ddg�|j�|jjd�|�d|jj�|�|jj	d|jj
�|jjd�tt
d���|�|jj	d|jj
d�dS)z|
        L{ProcessMonitor.connectionLost} doubles the restart delay each time
        the process dies too quickly.
        rJr
rrCN)rErarPrrbrHrRr`r[r0rFr,rrr:r#r#r$�&test_connectionLostBackoffDelayDoubless
 z3ProcmonTests.test_connectionLostBackoffDelayDoublescCs:|j�ddg�|j��|j�d�|�d|jj�dS)zP
        L{ProcessMonitor.startService} starts all monitored processes.
        rJrN)rErPrarrbrRr`r:r#r#r$�test_startServices
zProcmonTests.test_startServicecCs�|j�ddg�|j�ddg�|j��|j�|jj�|�d|jj�|�d|jj�|j�d�|j��|j�|jj	d�|�
i|jj�dS)zT
        L{ProcessMonitor.stopService} should stop all monitored processes.
        rJ�barr
N)rErPrarrbrHrRr`�stopServicer�r[r:r#r#r$�test_stopService's

zProcmonTests.test_stopServicecCsl|j�ddg�|j��|j�d�|j��|j�d�t|jj�}|��}|�	|g�|�
|j�dS)zR
        L{ProcessMonitor.restartAll} succeeds when there is one process.
        rJr
N)rErPrarrb�
restartAllrcr9�popr�rwr*)rrZ�	myProcessr#r#r$�!test_restartAllRestartsOneProcess=s

z.ProcmonTests.test_restartAllRestartsOneProcesscCs�|j�ddg�|j��|j�|jj�|�d|jj�|j�d�|jjd�t	t
d���|�|jjd�
��|j��|�|jjd�
��dS)ze
        L{ProcessMonitor.stopService} should cancel any scheduled process
        restarts.
        rJr
rN)rErPrarrbrHrRr`r,rrr��restartr�r�r�r:r#r#r$�test_stopServiceCancelRestartsMs

z+ProcmonTests.test_stopServiceCancelRestartscCsxd|j_d|j_|j��|j�ddg�|j�d�|j�d�|j�d�|j��|j�d�|�	|jj
i�dS)ze
        L{ProcessMonitor.stopService} should cancel all scheduled process
        restarts.
        �rJr
�N)rErHrFrarPrrbr|r�r[r`r:r#r#r$�(test_stopServiceCleanupScheduledRestartsas

z5ProcmonTests.test_stopServiceCleanupScheduledRestartsN)$r4r5r6r7rIrUrYr]r^rerhrlrnrqrrrvrxrzrr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r#r#r#r$rA�sD

	

		rAc@s0eZdZdZdd�Zdd�Zdd�Zdd	�Zd
S)�DeprecationTestszQ
    Tests that check functionality that should be deprecated is deprecated.
    cCst�|_t|jd�|_dS)z5
        Create reactor and process monitor.
        rBN)r8rr	rEr:r#r#r$rIszDeprecationTests.setUpcCsx|j�ddg�|jj}|�t|�d�|��}d}|D]}|�|dt�d|dvr.d}q|�|dt	|����d	S)
a
        _Process.toTuple is deprecated.

        When getting the deprecated processes property, the actual
        data (kept in the class _Process) is converted to a tuple --
        which produces a DeprecationWarning per process so converted.
        rJr
F�category�toTupler�Tzno tuple deprecation found:N)
rErPrZr�ro�
flushWarnings�assertIs�DeprecationWarningr�rQ)r�myprocesses�warnings�foundToTuple�warningr#r#r$�test_toTuple�s�zDeprecationTests.test_toTuplecCsF|jj}|�|i�|��}|�d�}|�|dt�|�|g�dS)a
        Accessing L{ProcessMonitor.processes} results in deprecation warning

        Even when there are no processes, and thus no process is converted
        to a tuple, accessing the L{ProcessMonitor.processes} property
        should generate its own DeprecationWarning.
        rr�N)rErZr�r�r�r�r�)r�myProcessesr��firstr#r#r$�test_processes�s
zDeprecationTests.test_processescCs2t�|j�|��}|D]
}|�|dt�qdS)zO
        Pickling an L{ProcessMonitor} results in deprecation warnings
        r�N)�pickle�dumpsrEr�r�r�)rr�r�r#r#r$�
test_getstate�s
�zDeprecationTests.test_getstateN)r4r5r6r7rIr�r�r�r#r#r#r$r�ysr�)r7r��twisted.internet.errorrrr�twisted.internet.taskr�twisted.loggerr�twisted.python.failurer�twisted.runner.procmonrr	�twisted.test.proto_helpersr
�
twisted.trialrrr8�TestCaserA�SynchronousTestCaser�r#r#r#r$�<module>s K/p
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