%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /usr/lib/python3/dist-packages/twisted/conch/test/__pycache__/
Upload File :
Create Path :
Current File : //usr/lib/python3/dist-packages/twisted/conch/test/__pycache__/test_cftp.cpython-312.pyc

�

Ϫ�f?����dZddlZddlZddlZddlZddlZddlZddlZddlm	Z	m
Z
ddlmZddl
mZddlmZddlmZddlmZmZdd	lmZdd
lmZmZmZmZmZddlmZddl m!Z!dd
l"m#Z#m$Z$ddl%m&Z&ddl'm(Z(ddl)m*Z*ddl+m,Z,ddl-m.Z.ddl/m0Z0e.d�Z1e.d�Z2e1r-	ddl3m4Z4ddl5m6Z6ddl7m8Z8ddl9m:Z:ddl;m<Z<m=Z=ddl>m?Z?ddlm@Z@dZBde2e1ej�ed�fvrdZBeeBd�Gd �d!e0��ZDGd"�d#e0�ZEGd$�d%e!�ZFGd&�d'�ZGGd(�d)�ZHee�Gd*�d+e	��ZIeeBd�Gd,�d-e0��ZJGd.�d/�ZKGd0�d1ej��ZMGd2�d3e�ZNeeBd�Gd4�d5eN��ZOeeBd�Gd6�d7eN��ZPeeBd�ee,d8�d9�ee,d:�d;�Gd<�d=eN����ZQy#eA$rY��(wxYw)>z*
Tests for L{twisted.conch.scripts.cftp}.
�N)�BytesIO�
TextIOWrapper)�skipIf)�implementer)�ls)�	ISFTPFile)�FileTransferTestAvatar�SFTPTestBase)�portal)�defer�error�
interfaces�protocol�reactor)�Clock)�StringTransport)�getProcessOutputAndValue�getProcessValue)�log)�UserDatabase)�FilePath)�which)�
requireModule)�TestCase�cryptographyztwisted.conch.unix)�cftp)�
SSHSession)�filetransfer)�EXTENDED_DATA_STDERR)�
test_conch�test_ssh)�	FakeStdio)�FileTransferForTestAvatarFTz*don't run w/o spawnProcess or cryptographyc�(�eZdZdZdd�Zdd�Zdd�Zy)�SSHSessionTestsz=
    Tests for L{twisted.conch.scripts.cftp.SSHSession}.
    Nc��t�|_t�|_|j|j_t	�|_t
|j
�|_|j|j_y�N)r"�stdior�channelr�stderrBufferr�stderr��selfs �>/usr/lib/python3/dist-packages/twisted/conch/test/test_cftp.py�setUpzSSHSessionTests.setUp>sP���[��
�!�|���!�Z�Z�����#�I���#�D�$5�$5�6���"�k�k�����c��|jj�|j|jj�y)z|
        L{twisted.conch.scripts.cftp.SSHSession.eofReceived} loses the write
        half of its stdio connection.
        N)r)�eofReceived�
assertTruer(�
writeConnLostr,s r.�test_eofReceivedz SSHSessionTests.test_eofReceivedFs*��
	
��� � �"�����
�
�0�0�1r0c���d}|jd�}|jjt|dz�|j	|j
j
�|dz�y)z�
        L{twisted.conch.scripts.cftp.SSHSession.extReceived} decodes
        stderr data using UTF-8 with the "backslashescape" error handling and
        writes the result to its own stderr.
        u☃�utf-8��s\xffN)�encoder)�extReceivedr�assertEqualr*�getvalue)r-�	errorText�
errorBytess   r.�test_extReceivedStderrz&SSHSessionTests.test_extReceivedStderrNs`��"�	��%�%�g�.�
���� � � ��� �	
�	
������&�&�(���!�	
r0)�returnN)�__name__�
__module__�__qualname__�__doc__r/r5r?�r0r.r%r%8s���*�2�
r0r%c�z�eZdZdZeedd��dZd�Zd�Zd�Z	d�Z
d	�Zej�Z		ejej d
�dZejej e�eed
�d��Zd�Zy#ej$$rdZY�CwxYw#ejej e�wxYw)�ListingTestsz�
    Tests for L{lsLine}, the function which generates an entry for a file or
    directory in an SFTP I{ls} command's output.
    �tzsetNz8Cannot test timestamp formatting code without time.tzsetc�Z��d�_�fd�}�jtd|�dtjvra�jtjtjdtjd��jtj�yd�}�j|�y)zo
        Patch the L{ls} module's time function so the results of L{lsLine} are
        deterministic.
        i�[c����jSr')�nowr,s�r.�fakeTimez$ListingTests.setUp.<locals>.fakeTimeps����8�8�Or0�time�TZc�n�	tjd=tj�y#t$rY� wxYw)NrN)�os�environ�KeyErrorrMrHrEr0r.�cleanupz#ListingTests.setUp.<locals>.cleanup|s2����
�
�4�(��
�
��� ����s�(�	4�4N)
rK�patchrrPrQ�
addCleanup�operator�setitemrMrH)r-rLrSs`  r.r/zListingTests.setUpisy���
���	�	
�
�
�2�v�x�(��2�:�:���O�O�H�,�,�b�j�j�$��
�
�4�@P�Q��O�O�D�J�J�'�
�
�O�O�G�$r0c�|�|tjd<tj�t	j
d|�S)zl
        Call L{ls.lsLine} after setting the timezone to C{timezone} and return
        the result.
        rN�foo)rPrQrMrHr�lsLine)r-�timezone�stats   r.�
_lsInTimezonezListingTests._lsInTimezone�s,��$��
�
�4���
�
���y�y���%�%r0c���|jdz
}tjdddddddd|df
�}|j|j	d|�d�|j|j	d|�d�y)z�
        A file with an mtime six months (approximately) or more in the past has
        a listing including a low-resolution timestamp.
        �r�America/New_Yorkz;!---------    0 0        0               0 Apr 26  1973 foo�Pacific/Aucklandz;!---------    0 0        0               0 Apr 27  1973 fooN�rKrP�stat_resultr;r]�r-�thenr\s   r.�test_oldFilezListingTests.test_oldFile��|���x�x�0�1���~�~�q�!�Q��1�a��A�t�Q�?�@��������1�4�8�I�	
�	
������1�4�8�I�	
r0c���|jdz
dz}tjdddddddd|df
�}|j|j	d|�d�|j|j	d|�d�y)	��
        A file with a high-resolution timestamp which falls on a day of the
        month which can be represented by one decimal digit is formatted with
        one padding 0 to preserve the columns which come after it.
        r_i��rr`z;!---------    0 0        0               0 May 01  1973 fooraz;!---------    0 0        0               0 May 02  1973 fooNrbrds   r.�test_oldSingleDigitDayOfMonthz*ListingTests.test_oldSingleDigitDayOfMonth�����x�x�0�1�5E�F���~�~�q�!�Q��1�a��A�t�Q�?�@��������1�4�8�I�	
�	
������1�4�8�I�	
r0c���|jdz
}tjdddddddd|df
�}|j|j	d|�d�|j|j	d|�d�y)z�
        A file with an mtime fewer than six months (approximately) in the past
        has a listing including a high-resolution timestamp excluding the year.
        逛zrr`�;!---------    0 0        0               0 Aug 28 17:33 foora�;!---------    0 0        0               0 Aug 29 09:33 fooNrbrds   r.�test_newFilezListingTests.test_newFile�rgr0�
es_AR.UTF8FTz'The es_AR.UTF8 locale is not installed.c��|jdz
}tjdddddddd|df
�}tj�}tj
tjd�|jtj
tj|�|j|jd|�d�|j|jd|�d�y)	zC
        The month name in the date is locale independent.
        rmrrqr`rnraroN)
rKrPrc�locale�	getlocale�	setlocale�LC_ALLrUr;r])r-rer\�
currentLocales    r.�test_localeIndependentz#ListingTests.test_localeIndependent�s����x�x�0�1���~�~�q�!�Q��1�a��A�t�Q�?�@���(�(�*�
��������5�����(�(�&�-�-��G�������1�4�8�I�	
�	
������1�4�8�I�	
r0c���|jdz
dz}tjdddddddd|df
�}|j|j	d|�d�|j|j	d|�d�y)	rirmiFrr`z;!---------    0 0        0               0 Sep 01 17:33 fooraz;!---------    0 0        0               0 Sep 02 09:33 fooNrbrds   r.�test_newSingleDigitDayOfMonthz*ListingTests.test_newSingleDigitDayOfMonth�rkr0)rArBrCrD�getattrrM�skipr/r]rfrjrprsrtrwrurv�
localeSkip�ErrorrrxrzrEr0r.rGrG`s����
�t�W�d�#�+�I��%�:	&�
�$
�(
�(%�F�$�$�&�M�7�	��F���V�]�]�L�9��J��������
�6��J�A�B�
�C�
�,
��=�|�|�	��J�	��
	�������
�6�s)�B�B�B�B�B�B�B:rGc�"��eZdZdZ�fd�Z�xZS)�InMemorySSHChannelzp
    Minimal implementation of a L{SSHChannel} like class which only reads and
    writes data from memory.
    c�>��||_d|_t�|�
�y)zt
        @param conn: The SSH connection associated with this channel.
        @type conn: L{SSHConnection}
        rN)�conn�localClosed�super�__init__)r-r��	__class__s  �r.r�zInMemorySSHChannel.__init__s���
��	����
���r0)rArBrCrDr��
__classcell__)r�s@r.r�r�s����
�r0r�c�"�eZdZdZd�Zd�Zd�Zy)�FilesystemAccessExpectationszC
    A test helper used to support expected filesystem access.
    c��i|_yr'��_cacher,s r.r�z%FilesystemAccessExpectations.__init__s	����r0c�&�||j||f<y)z�

        @param path: Path at which the stream is requested.
        @type path: L{str}

        @param path: Flags with which the stream is requested.
        @type path: L{str}

        @param stream: A stream.
        @type stream: C{File}
        Nr�)r-�path�flags�streams    r.�putz FilesystemAccessExpectations.puts��&,����T�5�M�"r0c�<�|jj||f�S)a
        Remove a stream from the memory.

        @param path: Path at which the stream is requested.
        @type path: L{str}

        @param path: Flags with which the stream is requested.
        @type path: L{str}

        @return: A stream.
        @rtype: C{File}
        )r��pop)r-r�r�s   r.r�z FilesystemAccessExpectations.pop(s���{�{����e�}�-�-r0N)rArBrCrDr�r�r�rEr0r.r�r�s����,�
.r0r�c��eZdZdZd�Zd�Zy)�InMemorySFTPClienta'
    A L{filetransfer.FileTransferClient} which does filesystem operations in
    memory, without touching the local disc or the network interface.

    @ivar _availableFiles: File like objects which are available to the SFTP
        client.
    @type _availableFiles: L{FilesystemRegister}
    c�F�t|�|_ddd�|_||_y)N��
)�requests�
buffersize)r��	transport�options�_availableFiles)r-�availableFiless  r.r�zInMemorySFTPClient.__init__Bs'��+�D�1�����
��� .��r0c�:�|jj||�S)z}
        @see: L{filetransfer.FileTransferClient.openFile}.

        Retrieve and remove cached file based on flags.
        )r�r�)r-�filenamer��attrss    r.�openFilezInMemorySFTPClient.openFileJs���#�#�'�'��%�8�8r0N)rArBrCrDr�r�rEr0r.r�r�8s���.�9r0r�c�:�eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
y	)
�InMemoryRemoteFilez;
    An L{ISFTPFile} which handles all data in memory.
    c�<�||_tj|�y)zL
        @param name: Name of this file.
        @type name: L{str}
        N)�namerr�)r-r�s  r.r�zInMemoryRemoteFile.__init__Ys��
��	�����r0c�p�|j|�|j|�tj|�S)z/
        @see: L{ISFTPFile.writeChunk}
        )�seek�writer�succeed)r-�start�datas   r.�
writeChunkzInMemoryRemoteFile.writeChunkas+��	
�	�	�%���
�
�4���}�}�T�"�"r0c��d|_y)zo
        @see: L{ISFTPFile.writeChunk}

        Keeps data after file was closed to help with testing.
        TN)�_closedr,s r.�closezInMemoryRemoteFile.closeis����r0c��yr'rEr,s r.�getAttrszInMemoryRemoteFile.getAttrsq���r0c��yr'rE)r-�offset�lengths   r.�	readChunkzInMemoryRemoteFile.readChunkur�r0c��yr'rE)r-r�s  r.�setAttrszInMemoryRemoteFile.setAttrsyr�r0c�,�tj|�S)zb
        Get current data of file.

        Allow reading data event when file is closed.
        )rr<r,s r.r<zInMemoryRemoteFile.getvalue}s������%�%r0N)rArBrCrDr�r�r�r�r�r�r<rEr0r.r�r�Ss*����#��
�
�
�&r0r�c��eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zd
�Zd�Z
d�Zd
�Zdd�Zdd�Zd�Zd�Zd�Zd�Zy)�StdioClientTestsz(
    Tests for L{cftp.StdioClient}.
    c�d�t�|_t|j�}tj|�|_d|j
_t�x|_|j
_	|jdd�|j
j
j|j
_y)zm
        Create a L{cftp.StdioClient} hooked up to dummy transport and a fake
        user database.
        �/i��N)r��fakeFilesystemr�r�StdioClient�client�currentDirectoryr�database�_pwd�setKnownConsoleSizer�)r-�
sftpClients  r.r/zStdioClientTests.setUp�s���
;�<���'��(;�(;�<�
��&�&�z�2���'*����$�+7�>�9��
����(�
	
� � ��b�)�!%��� 2� 2� <� <����r0c	��|jjtj�dt	j
�dddtj�|jjd�}|j|jd�|S)zs
        The I{exec} command runs its arguments locally in a child process
        using the user's shell.
        �secret��rY�barzexec print(1 + 2)s3
)r��addUser�getpass�getuserrP�getuid�sys�
executabler��_dispatchCommand�addCallbackr;�r-�ds  r.�	test_execzStdioClientTests.test_exec�sf��
	
�
�
����O�O��x�����d�E�5�#�.�.�	
�
�K�K�(�(�)<�=��	�
�
�d�&�&��/��r0c	��|jjtj�dt	j
�dddd�|jjd�}|j|jd�|S)zr
        If the local user has no shell, the I{exec} command runs its arguments
        using I{/bin/sh}.
        r�r�rYr��zexec echo hello�hello
�
r�r�r�r�rPr�r�r�r�r;r�s  r.�test_execWithoutShellz&StdioClientTests.test_execWithoutShell�sb��
	
�
�
����O�O��x�����d�E�5�"�	
�
�K�K�(�(�):�;��	�
�
�d�&�&�
�3��r0c	��|jjtj�dt	j
�dddd�|jjd�}|j|jd�|S)zO
        The I{exec} command is run for lines which start with C{"!"}.
        r�r�rYr�z/bin/shz!echo hellor�r�r�s  r.�	test_bangzStdioClientTests.test_bang�sa��	
�
�
����O�O��x�����d�E�5�)�	
�
�K�K�(�(��7��	�
�
�d�&�&�
�3��r0c�f����ddl�G���fd�d�}|jtd|��y)a
        For the duration of this test, patch C{cftp}'s C{fcntl} module to return
        a fixed width and height.

        @param width: the width in characters
        @type width: L{int}
        @param height: the height in characters
        @type height: L{int}
        rNc���eZdZ���fd�Zy)�7StdioClientTests.setKnownConsoleSize.<locals>.FakeFcntlc�v��|�jk7r|jd�tjd��dd�S)Nz#Only window-size queries supported.�4Hr)�
TIOCGWINSZ�fail�struct�pack)r-�fd�opt�mutate�height�tty�widths    ���r.�ioctlz=StdioClientTests.setKnownConsoleSize.<locals>.FakeFcntl.ioctl�s3����#�.�.�(��I�I�C�D��{�{�4����1�=�=r0N)rArBrCr�)r�r�r�s���r.�	FakeFcntlr��s���
>r0r��fcntl)r�rTr)r-r�r�r�r�s `` @r.r�z$StdioClientTests.setKnownConsoleSize�s&���	�	>�	>�	
�
�
�4��)�+�.r0c���|jdd�t�x}|j_t	d�}d|_t
j|�}d|_|j�}|jd�|xjdz
c_|jj||�d}|j|jjj�|�y	)
a(
        L{StdioClient._printProgressBar} prints a progress description,
        including percent done, amount transferred, transfer rate, and time
        remaining, all based the given start time, the given L{FileWrapper}'s
        progress information and the reactor's current time.
        r��"�x�samplei(g@is#
b'sample' 40% 4.0kB 2.0kBps 00:03 N)r�rr�rrr�r�FileWrapper�size�seconds�advance�total�_printProgressBarr;r��value�r-�clock�wrapped�wrapper�	startTime�results      r.�test_printProgressBarReportingz/StdioClientTests.test_printProgressBarReporting�s���	
� � ��R�(�&+�g�-�����#��$�-�� ����"�"�7�+�� ����M�M�O�	�
�
�
�c���
�
���
����%�%�g�y�9�8��������.�.�4�4�6��?r0c�p�|jdd�t�x}|j_t	d�}d|_t
j|�}|j�}|jj||�d}|j|jjj�|�y)z�
        L{StdioClient._printProgressBar} prints a progress description that
        indicates 0 bytes transferred if no bytes have been transferred and no
        time has passed.
        r�r�r�r�s!
b'sample'  0% 0.0B 0.0Bps 00:00 N)
r�rr�rrr�rr�r�r�r;r�r�r�s      r.�test_printProgressBarNoProgressz0StdioClientTests.test_printProgressBarNoProgress�s���	
� � ��R�(�&+�g�-�����#��$�-�� ����"�"�7�+���M�M�O�	����%�%�g�y�9�6��������.�.�4�4�6��?r0c��|jdd�t�}d|_tj|�}|j
j
|d�d}|j||j
jj��y)z5
        Print the progress for empty files.
        r�r�s
empty-filers%
b'empty-file'100% 0.0B 0.0Bps 00:00 N)
r�rr�rr�r�r�r;r�r�)r-r�r�rs    r.�test_printProgressBarEmptyFilez/StdioClientTests.test_printProgressBarEmptyFilesn��	
� � ��R�(��)��$����"�"�7�+�����%�%�g�q�1�:���������!6�!6�!<�!<�!>�?r0c�^�|jjd�}|jd|�y)zK
        Returns empty value for both filename and remaining data.
        z  )r�r�N�r��_getFilenamer;�r-rs  r.�test_getFilenameEmptyz&StdioClientTests.test_getFilenameEmptys(�����)�)�$�/������6�*r0c�^�|jjd�}|jd|�y)zd
        Returns empty value for remaining data when line contains
        only a filename.
        �
only-local)rr�Nrr	s  r.�test_getFilenameOnlyLocalz*StdioClientTests.test_getFilenameOnlyLocals)��
���)�)�,�7�����+�V�4r0c�^�|jjd�}|jd|�y)ze
        Returns filename and remaining data striped of leading and trailing
        spaces.
        z local  remote file  )�localzremote fileNrr	s  r.�test_getFilenameNotQuotedz*StdioClientTests.test_getFilenameNotQuoted#s*��
���)�)�*A�B�����1�6�:r0c�^�|jjd�}|jd|�y)z�
        Returns filename and remaining data not striped of leading and trailing
        spaces when quoted paths are requested.
        z" " local file "  " remote  file " )z local file z" remote  file "Nrr	s  r.�test_getFilenameQuotedz'StdioClientTests.test_getFilenameQuoted,s*��
���)�)�*N�O�����=�v�Fr0Nc��|�|j�}t|d�5}|j|�ddd�|S#1swY|SxYw)ab
        Create a local file and return its path.

        When `path` is L{None}, it will create a new temporary file.

        @param path: Optional path for the new file.
        @type path: L{str}

        @param content: Content to be written in the new file.
        @type content: L{bytes}

        @return: Path to the newly create file.
        N�wb)�mktemp�openr�)r-r��content�files    r.�makeFilezStdioClientTests.makeFile5sF���<��;�;�=�D�
�$��
�	 ���J�J�w��	 ���	 ���s	�;�Ac��|jjj�}|jd�}|j	d�}g}g}|D�]T\}}}g}	|D]}
|	j|�d|
����|	jd|�d|���|j|	�|j
d�jd�j	d�}|dd	}|d	jd
�j	d
�}
|j|
�g}|dd	D]o}
|
j�jdd�d}
|
j�j	dd�}
|j|
d�d|
dj�����q|j|d	�|j|���W|r%|jt|�t|��n|j||�|jdt|�d
�y)a
        Check output of cftp client for a put request.


        @param transfers: List with tuple of (local, remote, progress).
        @param randomOrder: When set to C{True}, it will ignore the order
            in which put reposes are received

        r7z

� zTransferred z to r�
N����
�r�z5There are still put responses which were not checked.)
r�r�r��decode�split�appendr��strip�extend�rsplitr;�sorted�len)r-�	transfers�randomOrder�output�expectedOutput�actualOutputr�remote�expected�expectedTransfer�line�
progressParts�actual�last�actualTransfers               r.�checkPutMessagez StdioClientTests.checkPutMessageIs������&�&�,�,�.�����w�'�����f�%������'0�	0�#�E�6�8� "�� �
;�� �'�'�5�'��4�&�(9�:�
;��#�#�l�5�'��f�X�$F�G��!�!�"2�3�"�J�J�q�M�/�/��5�;�;�D�A�M�"�3�B�'�F� ��$�*�*�4�0�6�6�t�<�D��M�M�$���N��s���
F���z�z�|�*�*�3��2�1�5���z�z�|�)�)�#�q�1���%�%��a��	��4��7�=�=�?�2C�&D�E�
F�
�!�!�&��*�-�����/�?	0�B����V�N�3�V�L�5I�J����^�\�:����
���K�C�	
r0c���d}|j|��}tjtjztjz}t
jjdt
jj|��}t|�}|jj||tj|��d|jjjd<|jj!|�}|j#|�|j%||j'��|j)|j*�|j-||gd�fg�y)z�
        A name based on local path is used when remote path is not
        provided.

        The progress is updated while chunks are transferred.
        s
Test
Content)rr�r�r�)z	76% 10.0B�
100% 13.0Br7N)rr�	FXF_WRITE�	FXF_CREAT�	FXF_TRUNCrPr��join�basenamer�r�r�rr�r�r��cmd_PUT�successResultOfr;r<r3r�r5)r-r�	localPathr��
remoteName�
remoteFile�deferreds       r.�test_cmd_PUTSingleNoRemotePathz/StdioClientTests.test_cmd_PUTSingleNoRemotePath�s��%���M�M�'�M�2�	��&�&��)?�)?�?�,�BX�BX�X���W�W�\�\�#�r�w�w�'7�'7�	�'B�C�
�'�
�3�
������
�E�5�=�=��3L�M�35������"�"�<�0��;�;�&�&�y�1�����X�&�����*�"5�"5�"7�8����
�*�*�+������%N�
O�P�	
r0c��|j�}tjtjztjz}d}t|�}|jj||tj|��|jj|�d|�d��}|j|�|j||dgfg�|j|j�|j!d|j#��y)z�
        Remote path is extracted from first filename after local file.

        Any other data in the line is ignored.
        z/remote-pathrz ignored�	100% 0.0Br0N)rrr8r9r:r�r�r�rr�r�r=r>r5r3r�r;r<)r-r?r�r@rArBs      r.�test_cmd_PUTSingleRemotePathz-StdioClientTests.test_cmd_PUTSingleRemotePath�s����M�M�O�	��&�&��)?�)?�?�,�BX�BX�X��#�
�'�
�3�
������
�E�5�=�=��3L�M��;�;�&�&�)��A�j�\��'J�K�����X�&����y�*�{�m�D�E�F����
�*�*�+�����j�1�1�3�4r0c�"�|j�}tjj|�}d}tjj	|�}|jtjj||���}tjtjztjz}d|��}d|��}t|�}	t|�}
|jj||tj|	��|jj||tj|
��|jj!tjj|d��}|j#|�|j%|	j&�|j)d|	j+��|j%|
j&�|j)d|
j+��|j-||dgf||dgfgd��y	)
z�
        When a gobbing expression is used local files are transferred with
        remote file names based on local names.
        �second-name�r�r��*r0rET�r)N)rrPr�r<�dirnamer;rr8r9r:r�r�r�rr�r�r=r>r3r�r;r<r5)r-�first�	firstName�
secondName�parent�secondr��firstRemotePath�secondRemotePath�firstRemoteFile�secondRemoteFilerBs            r.� test_cmd_PUTMultipleNoRemotePathz1StdioClientTests.test_cmd_PUTMultipleNoRemotePath�s���
�
�
����G�G�$�$�U�+�	�"�
�������'�����B�G�G�L�L���$D��E���&�&��)?�)?�?�,�BX�BX�X���i�[�/���z�l�+��,�_�=��-�.>�?����������
�
�o�8V�W�������e�U�]�]�3C�%D�	
��;�;�&�&�r�w�w�|�|�F�C�'@�A�����X�&�����/�/�0�����o�6�6�8�9����(�0�0�1�����.�7�7�9�:������+��7��)�K�=�9�
��	�	
r0c�@�|j�}tjj|�}d}tjj	|�}|jtjj||���}tjtjztjz}t|�}t|�}d|��}	d|��}
|jj|	|tj|��|jj|
|tj|��|jj!dj#tjj|d���}|j%|�|j'|j(�|j+d|j-��|j'|j(�|j+d|j-��|j/||dgf||dgfgd�	�y
)z�
        When a gobbing expression is used local files are transferred with
        remote file names based on local names.
        when a remote folder is requested remote paths are composed from
        remote path and local filename.
        rHrIz/remote/z	{} remoterJr0rETrKN)rrPr�r<rLr;rr8r9r:r�r�r�rr�r�r=�formatr>r3r�r;r<r5)r-rMrNrOrPrQr�rTrUrRrSrBs            r.�"test_cmd_PUTMultipleWithRemotePathz3StdioClientTests.test_cmd_PUTMultipleWithRemotePath�s����
�
����G�G�$�$�U�+�	�"�
�������'�����B�G�G�L�L���$D��E���&�&��)?�)?�?�,�BX�BX�X��,�Y�7��-�j�9��$�Y�K�0��%�j�\�2����������
�
�o�8V�W�������e�U�]�]�3C�%D�	
��;�;�&�&�{�'9�'9�"�'�'�,�,�v�s�:S�'T�U�����X�&�����/�/�0�����o�6�6�8�9����(�0�0�1�����.�7�7�9�:�����	�K�=�1���k�]�3�
��	�	
r0)Nr0)F)rArBrCrDr/r�r�r�r�rrrr
r
rrrr5rCrFrVrYrEr0r.r�r��sg���=�&��
�/�*@�0@�$@�+�5�;�G��(;
�z
�05�&!
�F#
r0r�c��eZdZd�Zd�Zy)�FileTransferTestRealmc��||_yr')�testDir)r-r]s  r.r�zFileTransferTestRealm.__init__�s	����r0c�>�t|j�}|d|d�fS)Nrc��yr'rErEr0r.�<lambda>z5FileTransferTestRealm.requestAvatar.<locals>.<lambda>s�r0)r	r])r-�avatarID�mindr�as     r.�
requestAvatarz#FileTransferTestRealm.requestAvatar�s!��"�4�<�<�0���!�}�a��-�-r0N)rArBrCr�rdrEr0r.r[r[�s���.r0r[c�L�eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zd
�Zd�Z
y)
�SFTPTestProcessz�
    Protocol for testing cftp. Provides an interface between Python (where all
    the tests are) and the cftp client process (which does the work that is
    being tested).
    c�\�|j�||_d|_d|_d|_y)zr
        @param onOutReceived: A L{Deferred} to be fired as soon as data is
        received from stdout.
        NF)�clearBuffer�
onOutReceived�onProcessEnd�_expectingCommand�
_processEnded)r-ris  r.r�zSFTPTestProcess.__init__
s0��
	
����*��� ���!%���"��r0c�.�d|_g|_d|_y)zR
        Clear any buffered data received from stdout. Should be private.
        r0N)�buffer�_linesReceived�_lineBufferr,s r.rhzSFTPTestProcess.clearBuffers����� �����r0c�~�tjd|z�|j|zjd�}|j	d�|_|j
j
|�|j�%|jdc}|_|j|�|xj|z
c_	|j�y)zO
        Called by Twisted when the cftp client prints data to stdout.
        zgot %r�
rN)r�msgrpr!r�ror$ri�callbackrn�_checkForCommand)r-r��linesr�s    r.�outReceivedzSFTPTestProcess.outReceiveds���	����4�� ��!�!�D�(�/�/��6�� �9�9�R�=������"�"�5�)����)�$(�$6�$6��!�A�t�!�
�J�J�t�����t������r0c� �d}|jr�|j|k(rpdj|j�}|j	|�r|t|�d}|j
�|jdc}|_|j|�yyy)Nscftp> rr)rkrpr;ro�
startswithr'rhrt)r-�prompt�bufr�s    r.ruz SFTPTestProcess._checkForCommand.s������!�!�d�&6�&6�&�&@��*�*�T�0�0�1�C��~�~�f�%��#�f�+�-�(������(,�(>�(>��%�A�t�%�
�J�J�s�O�
'A�!r0c�4�tjd|z�y)zO
        Called by Twisted when the cftp client prints data to stderr.
        zerr: %sN)rrs)r-r�s  r.�errReceivedzSFTPTestProcess.errReceived8s��	���	�D� �!r0c��|jS)zQ
        Return the contents of the buffer of data received from stdout.
        )rnr,s r.�	getBufferzSFTPTestProcess.getBuffer>s���{�{�r0c���tj�|_|j�t	|t
�r|j
d�}|jj|dz�|jS)a�
        Issue the given command via the cftp client. Return a C{Deferred} that
        fires when the server returns a result. Note that the C{Deferred} will
        callback even if the server returns some kind of error.

        @param command: A string containing an sftp command.

        @return: A C{Deferred} that fires when the sftp server returns a
        result. The payload is the server's response string.
        r7rr)	r�Deferredrkrh�
isinstance�strr9r�r��r-�commands  r.�
runCommandzSFTPTestProcess.runCommandDsY��"'���!1��������g�s�#��n�n�W�-�G������W�u�_�-��%�%�%r0c��tjd�}|D�cgc]}|j|j|��� }}tj|�Scc}w)ax
        Run each command in sequence and return a Deferred that fires when all
        commands are completed.

        @param commands: A list of strings containing sftp commands.

        @return: A C{Deferred} that fires when all commands are completed. The
        payload is a list of response strings from the server, in the same
        order as the commands.
        r�)r�DeferredSemaphore�runr��
gatherResults)r-�commands�semr��dls     r.�	runScriptzSFTPTestProcess.runScriptVsM���%�%�a�(��?G�
H�G�c�g�g�d�o�o�w�/�
H��
H��"�"�2�&�&��Is�#Ac���|jrtjd�Stj�|_|j
j
d�|jS)z�
        Kill the process if it is still running.

        If the process is still running, sends a KILL signal to the transport
        and returns a C{Deferred} which fires when L{processEnded} is called.

        @return: a C{Deferred}.
        N�KILL)rlrr�r�rjr��
signalProcessr,s r.�killProcesszSFTPTestProcess.killProcessesI������=�=��&�&�!�N�N�,������$�$�V�,�� � � r0c�v�d|_|jr&|jdc}|_|jd�yy)zF
        Called by Twisted when the cftp client process ends.
        TN)rlrjrt)r-�reasonr�s   r.�processEndedzSFTPTestProcess.processEndedts;��"������#'�#4�#4�d� �A�t� �
�J�J�t��r0N)rArBrCrDr�rhrwrur}rr�r�r�r�rEr0r.rfrfs9���	#�� �"�"��&�$
'�
!�r0rfc�*�eZdZd�Zd�Zd�Zd�Zd�Zy)�CFTPClientTestBasec���tdd�5}|jtj�ddd�tdd�5}|jtj�ddd�tjdd�tdd�5}|jdtjz�ddd�tj|�S#1swY��xYw#1swY�wxYw#1swY�6xYw)N�dsa_test.pubr�dsa_testi���kh_tests
127.0.0.1 )
rr�r!�publicDSA_openssh�privateDSA_opensshrP�chmod�publicRSA_opensshr
r/�r-�fs  r.r/zCFTPClientTestBase.setUps���
�.�$�
'�	0�1�
�G�G�H�.�.�/�	0�
�*�d�
#�	1�q�
�G�G�H�/�/�0�	1�
����U�#�
�)�T�
"�	@�a�
�G�G�M�H�$>�$>�>�?�	@��!�!�$�'�'�	0�	0��	1�	1��	@�	@�s#� C� C�#C#�C�C �#C,c��t|j�}tj|�}|j	tj��tj�}||_tjd|d��|_
y)Nrz	127.0.0.1)�	interface)r[r]r�Portal�registerCheckerr!�conchTestPublicKeyChecker�ConchTestServerFactoryr�	listenTCP�server)r-�realm�p�facs    r.�startServerzCFTPClientTestBase.startServer�s`��%�d�l�l�3���M�M�%� ��	���(�<�<�>�?��-�-�/����
��'�'��3�+�F��r0c�v�t|jjd�s|jd�Sd|jjj_t
j|jjjjj�}|j|j�|S)N�protor�)�hasattrr��factory�
_cbStopServerr��expectedLoseConnectionr�
maybeDeferredr��loseConnectionr�r�s  r.�
stopServerzCFTPClientTestBase.stopServer�s����t�{�{�*�*�G�4��%�%�d�+�+�;<������!�!�8������� 3� 3� 9� 9� C� C� R� R�S��	�
�
�d�(�(�)��r0c�T�tj|jj�Sr')rr�r��
stopListening�r-�ignoreds  r.r�z CFTPClientTestBase._cbStopServer�s���"�"�4�;�;�#<�#<�=�=r0c��dD]}	tj|��tj|�S#t$rY�;wxYw)N)r�r�r�)rP�remove�
BaseExceptionr
�tearDownr�s  r.r�zCFTPClientTestBase.tearDown�sH��8�	�A�
��	�	�!��	�
�$�$�T�*�*��!�
��
�s�3�	?�?N)rArBrCr/r�r�r�r�rEr0r.r�r�~s��(�G��>�+r0r�c��eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zd
�Zdd�Z
d
�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zy)�OurServerCmdLineClientTestsz�
    Functional tests which launch a SFTP server over TCP on localhost and check
    cftp command line interface using a spawned process.

    Due to the spawned process you can not add a debugger breakpoint for the
    client code.
    c�"��tj���j�d}�jj	�j
}t
j||zj�d��}tjdtj�d|���tj�}t|��_|j#�fd��t$j&j)�}t$j*j-tj.�|d<g}i}|D]4}t1|t2�r|j5d�}|j7|��6|D]N}||}	t1|t2�r|j5d�}t1|	t2�r|	j5d�}	|	||<�Ptj|�tj|�t9j:�j tj||�	�|S)
Nz�-p %i -l testuser --known-hosts kh_test --user-authentications publickey --host-key-algorithms ssh-rsa -i dsa_test -a -v 127.0.0.1r��mod�running rc�8���jj�Sr')�processProtocolrh��_r-s �r.r`z3OurServerCmdLineClientTests.setUp.<locals>.<lambda>������ 4� 4� @� @� B�r0�
PYTHONPATHr7��env)r�r/r�r��getHost�portr �	_makeArgsr!rrsr�r�rr�rfr�r�rPrQ�copy�pathsepr;r�r�r�r9r"r�spawnProcess)
r-�cmdsr�r�r��encodedCmds�
encodedEnv�cmd�var�vals
`         r.r/z!OurServerCmdLineClientTests.setUp�s����� � ��&�����
�	
��{�{�"�"�$�)�)���#�#�T�D�[�$7�$7�$9�v�F�����(�3�>�>�*�!�D�6�2�3��N�N���.�q�1���	�
�
�B�C��j�j�o�o����J�J�O�O�C�H�H�5��L�����
��	$�C��#�s�#��j�j��)�����s�#�	$��	"�C��c�(�C��#�s�#��j�j��)���#�s�#��j�j��)��!�J�s�O�
	"�	��������
������ � �#�.�.�+�:�	
��r0c�P���j�}|j�fd��|S)Nc�8���jj�Sr')r�r�r�s �r.r`z6OurServerCmdLineClientTests.tearDown.<locals>.<lambda>�r�r0)r�r�r�s` r.r�z$OurServerCmdLineClientTests.tearDown�s!����O�O���	�
�
�B�C��r0c��	|jjjd�y#tj$rYywxYw)Nr�)r�r�r�r
�ProcessExitedAlreadyr�s  r.�_killProcessz(OurServerCmdLineClientTests._killProcess�s9��	�� � �*�*�8�8��@���)�)�	��	�s�%(�>�>c�8�|jj|�S)z�
        Run the given command with the cftp client. Return a C{Deferred} that
        fires when the command is complete. Payload is the server's output for
        that command.
        )r�r�r�s  r.r�z&OurServerCmdLineClientTests.runCommand�s���#�#�.�.�w�7�7r0c�8�|jj|�S)z�
        Run the given commands with the cftp client. Returns a C{Deferred}
        that fires when the commands are all complete. The C{Deferred}'s
        payload is a list of output for each command.
        )r�r�)r-r�s  r.r�z%OurServerCmdLineClientTests.runScript�s���#�#�-�-�h�7�7r0c��|j}|jddddd�}d�}|j|�|j|j|jtj�d|jg�|S)z�
        Test that 'pwd' reports the current remote directory, that 'lpwd'
        reports the current local directory, and that changing to a
        subdirectory then changing to its parent leaves you in the original
        remote directory.
        �pwd�lpwdzcd testDirectory�cd ..c��g}|D]4}t|t�r|jd�}|j|��6|dd|ddzS)zH
            Callback function for handling command output.
            r7N��)r��bytesr r")r*r�r�s   r.�	cmdOutputz8OurServerCmdLineClientTests.testCdPwd.<locals>.cmdOutput�sU���D��
!���c�5�)��*�*�W�-�C����C� �
!����8�d�1�2�h�&�&r0r�)r]r�r�r;r�rP�getcwd)r-�homeDirr�r�s    r.�	testCdPwdz%OurServerCmdLineClientTests.testCdPwd�sg���,�,���N�N�5�&�*<�g�u�M��		'�	
�
�
�i� �	�
�
�d�&�&����r�y�y�{�B����(U�V��r0c�X���fd�}�jdddd�}|j|�S)z�
        Check that 'ls -l' output includes the access permissions and that
        this output changes appropriately with 'chmod'.
        c����j��j|djd���j|dd��j|djd�|d��j|dd�y)Nrs
-rw-r--r--r�r0rs
----------r�)�flushLoggedErrorsr3ryr;��resultsr-s �r.�_checkz7OurServerCmdLineClientTests.testChAttrs.<locals>._checkss����"�"�$��O�O�G�A�J�1�1�-�@�A����W�Q�Z��-��O�O�G�A�J�1�1�-�@�'�!�*�M����W�Q�Z��-r0zls -l testfile1zchmod 0 testfile1zchmod 644 testfile1�r�r��r-r�r�s`  r.�testChAttrsz'OurServerCmdLineClientTests.testChAttrss5���	.�
�N�N����!�	
���}�}�V�$�$r0c����fd�}�jdd�jj�zddd�}|jd��|j|�S)z�
        Check 'ls' works as expected. Checks for wildcards, hidden files,
        listing directories and listing empty directories.
        c�����j|dgd���j|dgd���j|dddg��j|dgd���j|d	d
g�y)Nr�s
testDirectory�testRemoveFile�testRenameFiles	testfile1r�rr�r�r�)s.testHiddenFiler�r�r�r0�r;r�s �r.r�z4OurServerCmdLineClientTests.testList.<locals>._check*s���������
�V�
�
�����
�V�
�
���W�Q�Z�*;�=N�)O�P������
�V�
�
���W�Q�Z�#��/r0rzls ../zls *Filezls -a *Filezls -l testDirectoryc�J�|D�cgc]}|jd���c}Scc}w)Nrr)r!)�xs�xs  r.r`z6OurServerCmdLineClientTests.testList.<locals>.<lambda>@s��"�!=�Q�!�'�'�%�.�!=���!=s� )r�r]r<r�r�s`  r.�testListz$OurServerCmdLineClientTests.testList$sW���
	0�
�N�N���t�|�|�,�,�.�.���!�
��	
�
�
�=�>��}�}�V�$�$r0c��|jd�}tjd�jd�j	�}t|t�r|jd�}|j|j|�|S)zB
        Check that running the '?' command returns help.
        �?Nr�r7)
r�rr��cmd_HELPr#r�r�r9r�r;)r-r��helpTexts   r.�testHelpz$OurServerCmdLineClientTests.testHelpCsg��
�O�O�C� ���#�#�D�)�2�2�2�6�<�<�>���h��$����w�/�H�	�
�
�d�&�&��1��r0Nc�b�|j|j�|j�|�y)zg
        Assert that the files at C{name1} and C{name2} contain exactly the
        same data.
        N)r;�
getContent)r-�name1�name2rss    r.�assertFilesEqualz,OurServerCmdLineClientTests.assertFilesEqualOs(��
	
����)�)�+�U�-=�-=�-?��Er0c�h���dj�jj�jj��t�t�r�jd����fd�}�j
d�jj�d��}|j|�|j�fd��|S)z�
        Test that 'get' saves the remote file to the correct local location,
        that the output of 'get' is correct and that 'rm' actually removes
        the file.
        z)Transferred {}/testfile1 to {}/test file2r7c�����j|j����j�jj	d��jj	d�d��jd�S)N�	testfile1�
test file2z
get failedzrm "test file2")r3�endswithrr]�childr��rr+r-s ��r.�	_checkGetz6OurServerCmdLineClientTests.testGet.<locals>._checkGetds_����O�O�F�O�O�N�;�<��!�!����"�"�;�/����"�"�<�0��
�
�?�?�#4�5�5r0zget testfile1 "z/test file2"c�t���j�jjd�j��S)Nr��assertFalser]r�existsr�s �r.r`z5OurServerCmdLineClientTests.testGet.<locals>.<lambda>p�*���d�&�&�t�|�|�'9�'9�,�'G�'N�'N�'P�Q�r0)rXr]r�r�r�r9r�r�)r-rr�r+s`  @r.�testGetz#OurServerCmdLineClientTests.testGetVs����E�K�K��L�L����L�L���
���n�c�*�+�2�2�7�;�N�	6�
�O�O�o�d�l�l�.?�.?�-@��M�N��	�
�
�i� �	�
�
�Q�	
��r0c�R���fd�}�jd�}|j|�S)zQ
        Test that 'get' works correctly when given wildcard parameters.
        c�����j�jjd�td�d��j�jjd�td�d�y)N�testRemoveFile�testRemoveFile get failed�testRenameFile�testRenameFile get failed)rr]rr)r�r-s �r.r�z;OurServerCmdLineClientTests.testWildcardGet.<locals>._checkys_����!�!����"�"�#3�4��)�*�+�
�

�!�!����"�"�#3�4��)�*�+�
r0z
get testR*)r�r�r�s`  r.�testWildcardGetz+OurServerCmdLineClientTests.testWildcardGetts'���

	�
�O�O�L�)���}�}�V�$�$r0c�V���d�jj�jzdz�jj�jzdz���fd�}�jd�jj�d��}|j	|�|j	�fd��|S)z�
        Check that 'put' uploads files correctly and that they can be
        successfully removed. Also check the output of the put command.
        sTransferred s/testfile1 to s/test"file2c�����j�jjd��jjd���j|j	����jd�S)Nr�
test"file2zrm "test\"file2")rr]rr3r
r�rs ��r.�	_checkPutz6OurServerCmdLineClientTests.testPut.<locals>._checkPut�s[����!�!����"�"�;�/����1C�1C�L�1Q�
�
�O�O�F�O�O�N�;�<��?�?�#6�7�7r0�put z/testfile1 "test\"file2"c�t���j�jjd�j��S)Nr rr�s �r.r`z5OurServerCmdLineClientTests.testPut.<locals>.<lambda>�rr0)r]�asBytesModer�r�r�)r-r!r�r+s`  @r.�testPutz#OurServerCmdLineClientTests.testPut�s����
��l�l�&�&�(�-�-�
.��
 ��l�l�&�&�(�-�-�
.��	
�	�	8�
�O�O�d�4�<�<�#4�#4�"5�5N�O�P��	�
�
�i� �	�
�
�Q�	
��r0c�����jjd�jd��5}|jd�ddd��jjd�jd��5}|jd�ddd��fd�}�j	d	�jj
�d
��}|j
|�|S#1swY��xYw#1swY�VxYw)zb
        Check that 'put' uploads files correctly when overwriting a longer
        file.
        �shorterFile�w��mode�aN�
longerFile�bbc����j�jjd��jjd��y)Nr'r,)rr]r)rr-s �r.r!zEOurServerCmdLineClientTests.test_putOverLongerFile.<locals>._checkPut�s4����!�!����"�"�=�1�4�<�<�3E�3E�l�3S�
r0r"z/shorterFile longerFile)r]rrr�r�r�r�)r-r�r!r�s`   r.�test_putOverLongerFilez2OurServerCmdLineClientTests.test_putOverLongerFile�s�����\�\�
�
�
�
.�
3�
3��
3�
=�	��
�G�G�D�M�	�
�\�\�
�
��
-�
2�
2��
2�
<�	��
�G�G�E�N�	�	�

�O�O�d�4�<�<�#4�#4�"5�5L�M�N��	�
�
�i� ���	�	��	�	�s�C
�2C�
C�C"c�����jjd���j��jd�jd��5}|j	d�ddd��jjd�jd��5}|j	d�ddd���fd�}�jd	�jj�d
��}|j|�|S#1swY��xYw#1swY�WxYw)z�
        Check that 'put' uploads files correctly when overwriting a longer
        file and you use a wildcard to specify the files to upload.
        �dirrr(r)r+Nr-c�z���j�jd��jjd��y)Nr)rrr])rr-�someDirs ��r.r!zMOurServerCmdLineClientTests.test_putMultipleOverLongerFile.<locals>._checkPut�s+����!�!�'�-�-��"7����9K�9K�F�9S�Tr0r"z/dir/*)r]r�createDirectoryrr�r�r�r�)r-r�r!r�r3s`   @r.�test_putMultipleOverLongerFilez:OurServerCmdLineClientTests.test_putMultipleOverLongerFile�s�����,�,�$�$�U�+�����!�
�]�]�6�
"�
'�
'�S�
'�
1�	�Q�
�G�G�D�M�	�
�\�\�
�
��
'�
,�
,�#�
,�
6�	�!�
�G�G�E�N�	�	U�
�O�O�d�4�<�<�#4�#4�"5�V�<�=��	�
�
�i� ���	�	��	�	�s�C0�C<�0C9�<Dc����fd�}�jdd�jj�d�d�jj�z�}|j	|�|S)z�
        What happens if you issue a 'put' command and include a wildcard (i.e.
        '*') in parameter? Check that all files matching the wildcard are
        uploaded to the correct directory.
        c����j|dd��j|dd��j�jjd��jj	�jd�d��j�jjd��jj	�jd�d�y)Nrr0rrrrr)r;rr]rrPr�s �r.�checkz:OurServerCmdLineClientTests.testWildcardPut.<locals>.check�s�������W�Q�Z��-����W�Q�Z��-��!�!����"�"�#3�4����#�#�%�+�+�,<�=�+�
�

�!�!����"�"�#3�4����#�#�%�+�+�,<�=�+�
r0r�r"z/testR*zcd %s)r�r]r�r<r�)r-r8r�s`  r.�testWildcardPutz+OurServerCmdLineClientTests.testWildcardPut�sZ���
	�
�N�N���4�<�<�$�$�%�W�-��d�l�l�+�+�-�-�
��
	
�
�
�e���r0c����fd�}�jdd�}|j|�|j�jd�|S)z�
        Test that 'ln' creates a file which appears as a link in the output of
        'ls'. Check that removing the new file succeeds without output.
        c����j��j|dd��j|djd�d��j	d�S)Nrr0r��lzlink failedzrm testLink)r�r;r3ryr�r�s �r.r�z4OurServerCmdLineClientTests.testLink.<locals>._check�sO����"�"�$����W�Q�Z��-��O�O�G�A�J�1�1�$�7��G��?�?�=�1�1r0zln testLink testfile1zls -l testLinkr0�r�r�r;r�s`  r.�testLinkz$OurServerCmdLineClientTests.testLink�sA���	2�
�N�N�2�4D�E��	�
�
�f��	�
�
�d�&�&��,��r0c����fd�}�jdd�}|j|�|j�jd�|S)zV
        Test that we can create and remove directories with the cftp client.
        c����j|dd��j|djd���jd�S)Nrr0r��dzrmdir testMakeDirectory)r;r3ryr�r�s �r.r�z?OurServerCmdLineClientTests.testRemoteDirectory.<locals>._checksB������W�Q�Z��-��O�O�G�A�J�1�1�$�7�8��?�?�#<�=�=r0�mkdir testMakeDirectoryzls -l testMakeDirector?r0r=r�s`  r.�testRemoteDirectoryz/OurServerCmdLineClientTests.testRemoteDirectory�sA���
	>�

�N�N�4�6O�P��	�
�
�f��	�
�
�d�&�&��,��r0c�X���fd�}�jdd�}|j|�|S)z�
        Test that a C{mkdir} on an existing directory fails with the
        appropriate error, and doesn't log an useless error server side.
        c�Z���j|dd��j|dd�y)Nrr0r�sremote error 11: mkdir failedr�r�s �r.r�zHOurServerCmdLineClientTests.test_existingRemoteDirectory.<locals>._checks,������W�Q�Z��-����W�Q�Z�)I�Jr0rBr�r�s`  r.�test_existingRemoteDirectoryz8OurServerCmdLineClientTests.test_existingRemoteDirectory
s.���	K�
�N�N�4�6O�P��	�
�
�f���r0c�����jd�jj�d��}|j�jd�|j�fd��|j�jd�|S)z�
        Test that we can create a directory locally and remove it with the
        cftp client. This test works because the 'remote' server is running
        out of a local directory.
        zlmkdir z/testLocalDirectoryr0c�&���jd�S)Nzrmdir testLocalDirectory)r�r�s �r.r`z@OurServerCmdLineClientTests.testLocalDirectory.<locals>.<lambda> s������0J� K�r0)r�r]r�r�r;r�s` r.�testLocalDirectoryz.OurServerCmdLineClientTests.testLocalDirectorysb���
�O�O�g�d�l�l�&7�&7�%8�8K�L�M��	�
�
�d�&�&��,�	�
�
�K�L�	�
�
�d�&�&��,��r0c����fd�}�jdd�}|j|�|j�jd�|S)z1
        Test that we can rename a file.
        c�z���j|dd��j|dd��jd�S)Nrr0r�s	testfile2zrename testfile2 testfile1)r;r�r�s �r.r�z6OurServerCmdLineClientTests.testRename.<locals>._check)s;������W�Q�Z��-����W�Q�Z��6��?�?�#?�@�@r0zrename testfile1 testfile2zls testfile?r0r=r�s`  r.�
testRenamez&OurServerCmdLineClientTests.testRename$sA���
	A�

�N�N�7��H��	�
�
�f��	�
�
�d�&�&��,��r0r')rArBrCrDr/r�r�r�r�r�r�r�rrrrr%r/r5r9r>rCrFrIrLrEr0r.r�r��sr���(�T�
�8�8��4%�,%�>
�F��<%�(�8�(�(�<�"
��
�
r0r�c�4�eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z	y)	�OurServerBatchFileTestszm
    Functional tests which launch a SFTP server over localhost and checks csftp
    in batch interface.
    c�N�tj|�|j�yr'�r�r/r�r,s r.r/zOurServerBatchFileTests.setUp;s��� � ��&����r0c�L�tj|�|j�Sr')r�r�r�r,s r.r�z OurServerBatchFileTests.tearDown?s���#�#�D�)���� � r0c����|j��t�d�5}|j|�ddd�|jj	�j
}d|�fz}t
j|j�d��dd}tjdtj�d|���tjj�}tj j#tj$�|d<d|jj&_t+tj||�	�}�fd
�}|j-d��|j/|�|S#1swY��5xYw)Nr(z�-p %i -l testuser --known-hosts kh_test --user-authentications publickey --host-key-algorithms ssh-rsa -i dsa_test -a -v -b %s 127.0.0.1rr�r�r�rr�r�c�2��tj��|Sr')rPr�)�res�fns �r.�_cleanupz9OurServerBatchFileTests._getBatchOutput.<locals>._cleanupZs����I�I�b�M��Jr0c��|dS)NrrE)rTs r.r`z9OurServerBatchFileTests._getBatchOutput.<locals>.<lambda>^s
��#�a�&�r0)rrr�r�r�r�r r�r!rrsr�r�rPrQr�r�r;r�r�r�rr��addBoth)	r-r��fpr�r�r�r�rVrUs	        @r.�_getBatchOutputz'OurServerBatchFileTests._getBatchOutputCs���
�[�[�]��
�"�c�]�	�b��H�H�Q�K�	��{�{�"�"�$�)�)��
!��2�J����#�#�D�J�J�L�f�=�a�b�A�����(�3�>�>�*�!�D�6�2�3��j�j�o�o����J�J�O�O�C�H�H�5��L��56������2�$�S�^�^�T�s�C��	�	
�
�
�(�)�	�	�	�(����9	�	�s�E#�#E-c�Z��d}�fd�}�j|�}|j|�|S)z�
        Test whether batch file function of cftp ('cftp -b batchfile').
        This works by treating the file as a list of commands to be run.
        zpwd
ls
exit
c���|jd�}tjdt|�z��j	�j
j
�j|d��j|ddgd��y)NrrzRES %sr�r����r�)	r!rrs�repr�assertInr]r$r�r;�rTr-s �r.�_cbCheckResultz=OurServerBatchFileTests.testBatchFile.<locals>._cbCheckResultmse����)�)�E�"�C��G�G�H�t�C�y�(�)��M�M�$�,�,�2�2�4�9�9�3�q�6�B�����A�b�	�V�
r0�rZr��r-r�rar�s`   r.�
testBatchFilez%OurServerBatchFileTests.testBatchFilecs2���
��
	�
� � ��&��	�
�
�n�%��r0c�Z��d}�fd�}�j|�}|j|�|S)zO
        Test that an error in the batch file stops running the batch.
        zchown 0 missingFile
pwd
exit
c�n���j�jj�j|�yr')�assertNotInr]r$r�r`s �r.raz9OurServerBatchFileTests.testError.<locals>._cbCheckResult�s&������T�\�\�5�5�7�<�<�c�Br0rbrcs`   r.�	testErrorz!OurServerBatchFileTests.testErrorzs3�����
	C�
� � ��&��	�
�
�n�%��r0c�Z��d}�fd�}�j|�}|j|�|S)z_
        Test that a minus sign '-' at the front of a line ignores
        any errors.
        z-chown 0 missingFile
pwd
exit
c�n���j�jj�j|�yr')r_r]r$r�r`s �r.raz@OurServerBatchFileTests.testIgnoredError.<locals>._cbCheckResult�s$����M�M�$�,�,�2�2�4�9�9�3�?r0rbrcs`   r.�testIgnoredErrorz(OurServerBatchFileTests.testIgnoredError�s3���
��
	@�
� � ��&��	�
�
�n�%��r0N)
rArBrCrDr/r�rZrdrhrkrEr0r.rNrN4s&���
�!��@�.� r0rN�sshz$no ssh command-line client available�sftpz%no sftp command-line client availablec�"�eZdZdZd�Zd�Zd�Zy)�OurServerSftpClientTestsz@
    Test the sftp server against sftp command line client.
    c�L�tj|�|j�Sr'rPr,s r.r/zOurServerSftpClientTests.setUp�s��� � ��&����!�!r0c�"�|j�Sr')r�r,s r.r�z!OurServerSftpClientTests.tearDown�s����� � r0c�4�����	�ttj���j��t	�d�5}|jd�ddd��jj�j�	tj��fd�}�jtd|�d�jj_
tdd��}��	fd	�}�fd
�}|j|�|j�fd��|j|�S#1swY��xYw)a
        Test the return of extended attributes by the server: the sftp client
        should ignore them, but still be able to parse the response correctly.

        This test is mainly here to check that
        L{filetransfer.FILEXFER_ATTR_EXTENDED} has the correct value.
        r(z	ls .
exitNc�$���||�}d|d<|S)Nr��ext_foorE)r-�sr��
oldGetAttrs   �r.�	_getAttrszCOurServerSftpClientTests.test_extendedAttributes.<locals>._getAttrs�s����t�Q�'�E�$�E�)���Lr0rwTrl)�-o�PubkeyAcceptedKeyTypes=ssh-dssz-Vc�H��|dk(rd}nd}|dddddddd	dd
�fzd�df
z
}|S)
Nr)rxryrEz-Fz	/dev/nullrxzIdentityFile=dsa_testzUserKnownHostsFile=kh_testzHostKeyAlgorithms=ssh-rsazPort=%iz-bztestuser@127.0.0.1rE)�status�argsrUr�s  ��r.�hasPAKTzAOurServerSftpClientTests.test_extendedAttributes.<locals>.hasPAKT�sZ�����{�?����
����'��,��+���T�G�#���$��
�D��Kr0c����j|dd|djd��dD]}�j||d��y)Nrrr��asciir�)r;r r_)r�ir-s  �r.r8z?OurServerSftpClientTests.test_extendedAttributes.<locals>.check�sM������V�A�Y��6�!�9�+;�+;�G�+D�E��
,���
�
�a����+�

,r0c���td|��S)Nrm)r)r|r�s �r.r`zBOurServerSftpClientTests.test_extendedAttributes.<locals>.<lambda>�s���#;�F�D�#�#N�r0)�dictrPrQrrr�r�r�r�r#rwrTr�r�rr�)
r-r�rwr�r}r8r�rUrvr�s
`     @@@@r.�test_extendedAttributesz0OurServerSftpClientTests.test_extendedAttributes�s�����2�:�:���
�[�[�]��
�"�c�]�	"�a�
�G�G�L�!�	"��{�{�"�"�$�)�)��.�8�8�
�	�
	
�
�
�,�k�9�E�59������2�
�E�#Q�SV�W��	�2	,�	
�
�
�g��	�
�
�N�O��}�}�U�#�#�s	"�	"�s�D�DN)rArBrCrDr/r�r�rEr0r.roro�s���"�!�F$r0ro)RrDr�rsrVrPr�r�rM�iorr�unittestr�zope.interfacer�
twisted.conchr�twisted.conch.interfacesr�$twisted.conch.test.test_filetransferr	r
�twisted.credr�twisted.internetrr
rrr�twisted.internet.taskr�twisted.internet.testingr�twisted.internet.utilsrr�twisted.pythonr�twisted.python.fakepwdr�twisted.python.filepathr�twisted.python.procutilsr�twisted.python.reflectr�twisted.trial.unittestrr�unix�twisted.conch.scriptsr�twisted.conch.scripts.cftpr�twisted.conch.sshr�twisted.conch.ssh.connectionr�twisted.conch.testr r!�twisted.conch.test.test_conchr"r#�ImportError�	skipTests�IReactorProcessr%rGr�r�r�r�r�r[�ProcessProtocolrfr�r�rNrorEr0r.�<module>r�s=��
��
��	�
�
��%��&��.�U��H�H�'�4�L��/�,�*�0�+��^�,���)�*���	
�.�9�2�E�;�;�R�
�	��D�,� :�
� :� :�7�D� I�J�J��I��	�?�@�$
�h�$
�A�$
�N_
�8�_
�D
��
� #.�#.�L9�9�6
�Y��/&��/&��/&�d�	�?�@�p
�x�p
�A�p
�f.�.�x�h�.�.�x�v$+��$+�N�	�?�@�K�"4�K�A�K�\�	�?�@�d�0�d�A�d�N�	�?�@��E�%�L��@�A��E�&�M��B�C�R$�1�R$�D�B�A�R$��_+�
��
�s�&,G2�2G;�:G;

Zerion Mini Shell 1.0