HEX
Server: Apache
System: Linux scp1.abinfocom.com 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64
User: confeduphaar (1010)
PHP: 8.1.33
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //usr/lib/python3/dist-packages/twisted/conch/test/__pycache__/test_channel.cpython-38.pyc
U


W[C/�@s�dZddlmZmZddlmZz\ddlmZddlm	Z	ddl
mZddlm
Z
ddlmZdd	lmZdd
lmZdZWnek
r�dZeZ
YnXdd
lmZddlmZGdd�de
�Zddd�ZGdd�dej�ZdS)z
Test ssh/channel.py.
�)�division�absolute_import)�verifyObject)�channel)�SSHTransportAddress)�SSHServerTransport)�
SSHService)�
interfaces)�IPv4Address)�StringTransportNzConch SSH not supported.)�unittest)�
intToBytesc@s8eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�ZdS)
�MockConnectiona�
    A mock for twisted.conch.ssh.connection.SSHConnection.  Record the data
    that channels send, and when they try to close the connection.

    @ivar data: a L{dict} mapping channel id #s to lists of data sent by that
        channel.
    @ivar extData: a L{dict} mapping channel id #s to lists of 2-tuples
        (extended data type, data) sent by that channel.
    @ivar closes: a L{dict} mapping channel id #s to True if that channel sent
        a close message.
    cCsi|_i|_i|_dS)N)�data�extData�closes��self�r�A/usr/lib/python3/dist-packages/twisted/conch/test/test_channel.py�__init__)szMockConnection.__init__cCsdS)z,
        Return our logging prefix.
        rrrrrr�	logPrefix/szMockConnection.logPrefixcCs|j�|g��|�dS)z'
        Record the sent data.
        N)r�
setdefault�append)rrrrrr�sendData6szMockConnection.sendDatacCs|j�|g��||f�dS)z0
        Record the sent extended data.
        N)rrr)rr�typerrrr�sendExtendedData=szMockConnection.sendExtendedDatacCsd|j|<dS)z?
        Record that the channel sent a close message.
        TN)r)rrrrr�	sendCloseDszMockConnection.sendCloseN)	�__name__�
__module__�__qualname__�__doc__rrrrrrrrrrsrcCs&t�}|�t||d��|�|�dS)a�
    Connect a SSHTransport which is already connected to a remote peer to
    the channel under test.

    @param service: Service used over the connected transport.
    @type service: L{SSHService}

    @param hostAddress: Local address of the connected transport.
    @type hostAddress: L{interfaces.IAddress}

    @param peerAddress: Remote address of the connected transport.
    @type peerAddress: L{interfaces.IAddress}
    )�hostAddress�peerAddressN)rZmakeConnectionrZ
setService)�servicer"r#Z	transportrrr�connectSSHTransportLs�r%c@s�eZdZdZeZdd�Zdd�Zdd�Zdd	�Z	d
d�Z
dd
�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zd S)!�ChannelTestsz"
    Tests for L{SSHChannel}.
    cCs&t�|_tj|jdd�|_d|j_dS)z�
        Initialize the channel.  remoteMaxPacket is 10 so that data is able
        to be sent (the default of 0 means no data is sent because no packets
        are made).
        �
)�conn�remoteMaxPacketschannelN)rr(r�
SSHChannel�namerrrr�setUphs
�zChannelTests.setUpcCs|�ttj|j��dS)zK
        L{SSHChannel} instances provide L{interfaces.ITransport}.
        N)�
assertTruerr	Z
ITransportrrrrr�test_interfacetszChannelTests.test_interfacec	Cstj|jd�}|�|jd�|�|jd�|�|jd�|�|jd�|�|jd�|�|j|j�|�	|j
�|�	|j�t�ddddd	d
d�}|�|jd�|�|jd�|�|jd�|�|jd�|�|jd�|�|jd	�|�|j
d
�|�|jd�dS)
a�
        Test that SSHChannel initializes correctly.  localWindowSize defaults
        to 131072 (2**17) and localMaxPacket to 32768 (2**15) as reasonable
        defaults (what OpenSSH uses for those variables).

        The values in the second set of assertions are meaningless; they serve
        only to verify that the instance variables are assigned in the correct
        order.
        )r(ii�r�������N)rr*r(�assertEqualZlocalWindowSizeZlocalWindowLeftZlocalMaxPacket�remoteWindowLeftr)�assertIsNonerZavatar)r�cZc2rrr�	test_init{s$
zChannelTests.test_initcCs.|�t|j�d�|�ttjdd��d�dS)z{
        Test that str(SSHChannel) works gives the channel name and local and
        remote windows at a glance..
        z%<SSHChannel channel (lw 131072 rw 0)>r/�ZlocalWindowz<SSHChannel None (lw 1 rw 0)>N)r6�strrr*rrrr�test_str�s��zChannelTests.test_strcCs.|�|j��d�|�tjdd���d�dS)z
        Test that bytes(SSHChannel) works, gives the channel name and
        local and remote windows at a glance..

        s%<SSHChannel channel (lw 131072 rw 0)>r/r;s<SSHChannel None (lw 1 rw 0)>N)r6r�	__bytes__r*rrrr�
test_bytes�s��zChannelTests.test_bytescCs|�|j��d�dS)z�
        Test that SSHChannel.logPrefix gives the name of the channel, the
        local channel ID and the underlying connection.
        z.SSHChannel channel (unknown) on MockConnectionN)r6rrrrrr�test_logPrefix�szChannelTests.test_logPrefixcsdg��fdd�}||j_|j�d�|j�dd�|j�d�|�|jjd�|�|jj�|��d�|�|jj	d	�|�|j
j|jdg�|�|jjg�|�|j
j
|jd
g�d�d<|j�d�|��d�|j�d�|j��|j�d�|��d�d
S)zq
        Test that addWindowBytes adds bytes to the window and resumes writing
        if it was paused.
        Fcsd�d<dS�NTrrr��cbrr�stubStartWriting�sz:ChannelTests.test_addWindowBytes.<locals>.stubStartWriting�testr/�2�*r�)r/rE�sPaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaN)rZstartWriting�write�
writeExtended�addWindowBytesr6r7r-�
areWriting�bufr(r�extBufr�assertFalse�loseConnection)rrDrrBr�test_addWindowBytes�s(
z ChannelTests.test_addWindowBytescCsLdd�|j_|�|j�dd��|�|j�dd��|�|j�dd��dS)zn
        Test that requestReceived handles requests by dispatching them to
        request_* methods.
        cSs|dkS)NrHr)rrrr�<lambda>�rHz3ChannelTests.test_requestReceived.<locals>.<lambda>stest-methodrH�as
bad-methodN)rZrequest_test_methodr-ZrequestReceivedrPrrrr�test_requestReceived�sz!ChannelTests.test_requestReceivedcCs*|�|jj�|j��|�|jj�dS)zM
        Test that the default closeReceieved closes the connection.
        N)rPr�closingZ
closeReceivedr-rrrr�test_closeReceieved�s
z ChannelTests.test_closeReceievedcs.dg��fdd�}||j_|j�d�|j�d�|�|jj�|��d�|j�d�|j�d�|jj|j}|�	|d	dg�|�	|jj
d
�|j�d�|�	|d	ddd
g�|�	|jj
d�d�d<|j�d�|�|jj�|��d�|�	|d	ddd
dg�|�	|jjd�|�	|jj
d�dS)z�
        Test that write handles data correctly.  Send data up to the size
        of the remote window, splitting the data into packets of length
        remoteMaxPacket.
        Fcsd�d<dSrArrrBrr�stubStopWriting�sz0ChannelTests.test_write.<locals>.stubStopWriting�drTrrIsta�da��12345678901�
1234567890�1r3�123456�12345�6N)r�stopWritingrJrPrMr-rLr(rr6r7rN�rrXrrrBr�
test_write�s,zChannelTests.test_writec	sRdg��fdd�}||j_|j�dd�|j�dd�|j�dd�|�|jj�|��d	�|j�d
�|j�dd�|jj|j}|�	|ddd
g�|�	|jj
d�|j�dd�|�	|ddd
ddg�|�	|jj
d�d�d	<|j�dd�|�|jj�|��d	�|�	|ddd
dddg�|�	|jjddgg�|�	|jj
d	�dS)z�
        Test that writeExtended handles data correctly.  Send extended data
        up to the size of the window, splitting the extended data into packets
        of length remoteMaxPacket.
        Fcsd�d<dSrArrrBrrrXsz8ChannelTests.test_writeExtended.<locals>.stubStopWritingr/rYrTr0�trrI)r/rZ)r0re)r0rTr[r1r\)r1r])r1r^r3r2r_)r2r`raN)rrbrKrPrMr-rLr(rr6r7rOrcrrBr�test_writeExtendeds<��zChannelTests.test_writeExtendedcCs>|j�d�|j�tttd���|�|jj|jdg�dS)zS
        Test that writeSequence is equivalent to write(''.join(sequece)).
        rIr's
0123456789N)	rrLZ
writeSequence�mapr
�ranger6r(rrrrr�test_writeSequence8szChannelTests.test_writeSequencecCs�|j�d�|j�dd�|j��|�|jj�|j��|j�d�|�|jj�|j��|j�d�|�	|jj�|j��dS)zk
        Tesyt that loseConnection() doesn't close the channel until all
        the data is sent.
        sdatar/sdatadatar2�N)
rrJrKrQr8r(r�getrLr-rrrr�test_loseConnectionAs
z ChannelTests.test_loseConnectioncCs6tddd�}t|jj|d�|�t|�|j���dS)z�
        L{SSHChannel.getPeer} returns the same object as the underlying
        transport's C{getPeer} method returns.
        �TCPz192.168.0.1i1�)r$r#N)r
r%rr(r6rZgetPeer)rZpeerrrr�test_getPeerPszChannelTests.test_getPeercCs6tddd�}t|jj|d�|�t|�|j���dS)z�
        L{SSHChannel.getHost} returns the same object as the underlying
        transport's C{getHost} method returns.
        rmz	127.0.0.1i90)r$r"N)r
r%rr(r6rZgetHost)rZhostrrr�test_getHost[szChannelTests.test_getHostN)rrr r!�skipTest�skipr,r.r:r=r?r@rRrUrWrdrfrirlrnrorrrrr&as"		#&	r&)NN)r!Z
__future__rrZzope.interface.verifyrZtwisted.conch.sshrZtwisted.conch.ssh.addressrZtwisted.conch.ssh.transportrZtwisted.conch.ssh.servicerZtwisted.internetr	Ztwisted.internet.addressr
Ztwisted.test.proto_helpersrrp�ImportError�objectZ
twisted.trialrZtwisted.python.compatr
rr%ZTestCaser&rrrr�<module>s&
0