%PDF- %PDF-
Mini Shell

Mini Shell

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

�

Ϫ�fv}��v�dZddlZddlZddlZddlmZddlmZmZddl	m
Z
ddlmZddl
mZddlmZdd	lmZdd
lmZddlmZ	ddlmZeZ	dd
lmZeZ	ddlZeZ	ddl m!Z"e"Z!	ddl$m%Z%m&Z&m'Z'm(Z(Gd�de!�Z)Gd�de)�Z*Gd�d�Z+e�ddl,Z,e,jZde�d��n)Gd�de�Z.ej^e.e)e'j`�Gd�de�Z1eed�Gd�de1��Z2Gd�d �Z3eed�Gd!�d"e��Z4eed#�Gd$�d%e��Z5eed�eed#�Gd&�d'e���Z6eed#�Gd(�d)e��Z7y#e$rdZY��1wxYw#e$rdZY��6wxYw#e$rdZY��=wxYw#e$re#Z!Y��BwxYw#e$rY��AwxYw)*z.
Tests for L{twisted.conch.ssh.filetransfer}.
�N)�skipIf)�assert_that�equal_to)�defer)�ConnectionLost)�StringTransport)�loopback)�
components)�FilePath)�TestCase)�unix)�SFTPServerForUnixConchUser)�	ConchUser)�common�
connection�filetransfer�sessionc��eZdZd�Zd�Zy)�
TestAvatarc��tj|�tj|jd<t
j|jd<y)N�session�sftp)r�__init__r�
SSHSession�
channelLookupr�FileTransferServer�subsystemLookup��selfs �F/usr/lib/python3/dist-packages/twisted/conch/test/test_filetransfer.pyrzTestAvatar.__init__>s<�����4� �)0�);�);����:�&�(4�(G�(G����W�%�c���	t|�}|D]A}|d}t|�dkDxr|dxsd}t|�dkDxr|dxsi}||i|��}�CS#t$r	|||fg}Y�YwxYw)Nr���)�iter�	TypeError�len)r�f�args�kw�i�func�rs       r �
_runAsUserzTestAvatar._runAsUserCs���	 ��Q��A��	"�A��Q�4�D��q�6�A�:�&�!�A�$�,�"�D��Q��!��$��!��*��B��d�!�b�!�A�		"�
����	 ��T�2���A�	 �s�A�A'�&A'N)�__name__�
__module__�__qualname__rr/r$r!r rr=s
��H�

r!rc��eZdZd�Zd�Zy)�FileTransferTestAvatarc�<�tj|�||_y�N)rr�homeDir)rr7s  r rzFileTransferTestAvatar.__init__Qs�����D�!���r!c��ttj��j|jj
�Sr6)r�os�getcwd�preauthChildr7�pathrs r �
getHomeDirz!FileTransferTestAvatar.getHomeDirUs(����	�	��$�1�1�$�,�,�2C�2C�D�Dr!N)r0r1r2rr=r$r!r r4r4Ps
���Er!r4c��eZdZd�Zy)�ConchSessionForTestAvatarc��||_yr6��avatar)rrBs  r rz"ConchSessionForTestAvatar.__init__Zs	����r!N)r0r1r2rr$r!r r?r?Ys��r!r?ztwisted.conch.unix imported z0, but doesn't define SFTPServerForUnixConchUser'c��eZdZd�Zd�Zy)�FileTransferForTestAvatarc�
�ddiS)N�	conchTest�ext datar$)r�version�otherExts   r �
gotVersionz$FileTransferForTestAvatar.gotVersionms
�� �+�.�.r!c��|dk(ryt�)N�testExtendedRequest�bar)�NotImplementedError)r�extName�extDatas   r �extendedRequestz)FileTransferForTestAvatar.extendedRequestps���0�0��%�%r!N)r0r1r2rJrQr$r!r rDrDls��	/�	&r!rDc��eZdZd�Zy)�SFTPTestBasec�6�t|j��|_|jjd�|_|jjd�j	d�|jjd�jd��5}|j
d�tdd	�5}|j
|jd
��ddd�ddd�|jjd�jd�|jjd�jd��5}|j
d
�ddd�|jjd�jd��5}|j
d
�ddd�|jjd�jd��5}|j
d
�ddd�y#1swY��xYw#1swY��xYw#1swY��xYw#1swY�uxYw#1swYyxYw)N�extra�
testDirectoryT�	testfile1�wb)�mode�aaaaaaaaaabbbbbbbbbbz/dev/urandom�rbii��testRemoveFile�a�testRenameFilez.testHiddenFile)	r�mktemp�testDir�child�makedirs�open�write�read�chmod)rr)�f2s   r �setUpzSFTPTestBase.setUp{s�������
�.����|�|�)�)�'�2��������?�+�4�4�T�:�
�\�\�
�
��
,�
1�
1�t�
1�
<�	,��
�G�G�)�*��n�d�+�
,�r�������	�*�+�
,�	,�	
�����;�'�-�-�e�4�
�\�\�
�
� 0�
1�
6�
6�D�
6�
A�	�Q�
�G�G�D�M�	�
�\�\�
�
� 0�
1�
6�
6�D�
6�
A�	�Q�
�G�G�D�M�	�
�\�\�
�
� 1�
2�
7�
7�T�
7�
B�	�a�
�G�G�D�M�	�	�
,�
,��	,�	,��
	�	��	�	��	�	�sH�G*�2!G�G*�8G7�=H�H�G'	�"G*�*G4�7H�H�HN)r0r1r2rhr$r!r rSrSzs��r!rSz can't run on non-posix computersc���eZdZd�Zd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zd
�Zd�Z
d�Zd
�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zej4d��Zej4d��Zy)�OurServerOurClientTestsc�L��tj��t�j��_tj�j���_tj�j�}tj��_d�_d�_
�fd�}|�j_tj�j�}�jj|��jj|�|�_|�_�j%�y)NrAc�"��|�_|�_yr6)�_serverVersion�_extData)�
serverVersionrPrs  �r �_z(OurServerOurClientTests.setUp.<locals>._�s���"/�D��#�D�Mr!)rSrhr4r`rBrr�serverr	�
LoopbackRelay�FileTransferClient�clientrmrn�gotServerVersion�makeConnection�clientTransport�serverTransport�
_emptyBuffers)rrwrprxs`   r rhzOurServerOurClientTests.setUp�s�������4� �,�T�\�\�:���"�5�5�T�[�[�I���"�0�0����=��"�5�5�7���"�����
�	$�()����$�"�0�0����=�����"�"�?�3����"�"�?�3�.���.������r!c�"�|jjs|jjrc|jj�|jj�|jjr�K|jjr�byyr6)rx�bufferrw�clearBufferrs r ryz%OurServerOurClientTests._emptyBuffers�sb���"�"�)�)�T�-A�-A�-H�-H�� � �,�,�.�� � �,�,�.��"�"�)�)�T�-A�-A�-H�-Hr!c���|jj�|jj�|jj�|jj�yr6)rx�loseConnectionrwr|rs r �tearDownz OurServerOurClientTests.tearDown�sJ�����+�+�-����+�+�-����(�(�*����(�(�*r!c�x�|j|jd�|j|jddi�y)N�rFrG)�assertEqualrmrnrs r �test_serverVersionz*OurServerOurClientTests.test_serverVersion�s1������,�,�a�0��������{�(C�Dr!c��|jtjj|jj
�d|jj
���y)z:
        It implements the ISFTPServer interface.
        zISFTPServer not provided by N)�
assertTruer�ISFTPServer�
providedByrqrtrs r �test_interface_implementationz5OurServerOurClientTests.test_interface_implementation�sC��	
����$�$�/�/����0B�0B�C�*�4�;�;�+=�+=�*@�A�	
r!c�0�����jjdtjtjzi�}�j�tj�g���fd�}�jtd|���fd�}|j|�|S)zW
        A file opened with C{openFile} is closed when the connection is lost.
        �	testfile1c�8���j|��|�yr6��append)�fd�closed�oldCloses ��r �closezJOurServerOurClientTests.test_openedFileClosedWithConnection.<locals>.close�s����M�M�"���R�Lr!r�c����jj|jddj}�jj��jj��jj��jj��j�jji��j|��y)N�)
rq�	openFiles�handler�rxr~rwr|r��assertIn)�openFiler�r�rs  ��r �_fileOpenedzPOurServerOurClientTests.test_openedFileClosedWithConnection.<locals>._fileOpened�s�������&�&�x���q�r�':�;�>�>�B�� � �/�/�1�� � �/�/�1�� � �,�,�.�� � �,�,�.����T�[�[�2�2�B�7��M�M�"�f�%r!)
rtr�r�FXF_READ�	FXF_WRITEryr9r��patch�addCallback)r�dr�r�r�r�s`   @@r �#test_openedFileClosedWithConnectionz;OurServerOurClientTests.test_openedFileClosedWithConnection�s|���
�K�K� � ��,�/�/�,�2H�2H�H�"�
��	
�����8�8����	�	
�
�
�2�w��&�	&�	
�
�
�k�"��r!c����jjd�}�j��fd�}|j|�|S)zh
        A directory opened with C{openDirectory} is close when the connection
        is lost.
        �c�"���jj��jj��jj��jj��j	�j
ji�yr6)rxr~rwr|r�rq�openDirs)�openDirrs �r �	_getFileszSOurServerOurClientTests.test_openedDirectoryClosedWithConnection.<locals>._getFiles�se���� � �/�/�1�� � �/�/�1�� � �,�,�.�� � �,�,�.����T�[�[�1�1�2�6r!�rt�
openDirectoryryr�)rr�r�s`  r �(test_openedDirectoryClosedWithConnectionz@OurServerOurClientTests.test_openedDirectoryClosedWithConnection�s=���

�K�K�%�%�b�)������	7�	
�
�
�i� ��r!c�������jjdtjtjzi�}�j����fd�}�fd����fd���fd��|j
|�|S)Nr�c����j|tj|���|�}|j�|�|Sr6)r�r�	ISFTPFiler�)r�r��
_readChunk�_writeChunkrs  ���r r�z<OurServerOurClientTests.test_openFileIO.<locals>._fileOpened�s;������X�|�'=�'=�h�'G�H��8�$�A�
�M�M�+�x�0��Hr!c���|jdd�}�j�|j�jd�|S)Nr�rZ��	readChunkryr�r�)r�r�rs  �r r�z;OurServerOurClientTests.test_openFileIO.<locals>._readChunk�s;����"�"�1�b�)�A���� �
�M�M�$�*�*�,A�B��Hr!c�p��|jdd�}�j�|j�|�|S)Nr�s
cccccccccc)�
writeChunkryr�)rpr�r��_readChunk2rs   ��r r�z<OurServerOurClientTests.test_openFileIO.<locals>._writeChunks4����#�#�B�	�2�A���� �
�M�M�+�x�0��Hr!c���|jdd�}�j�|j�jd�|S)Nr�saaaaaaaaaabbbbbbbbbbccccccccccr��rpr�r�rs   �r r�z<OurServerOurClientTests.test_openFileIO.<locals>._readChunk2
s;����"�"�1�b�)�A���� �
�M�M�$�*�*�,M�N��Hr!�rtr�rr�r�ryr�)rr�r�r�r�r�s`  @@@r �test_openFileIOz'OurServerOurClientTests.test_openFileIO�sd����K�K� � ��,�/�/�,�2H�2H�H�"�
��	
����	�	�	�	�	
�
�
�k�"��r!c�������jjdtjtjzi�}�j��fd���fd�����fd�}|j
|�|S)Nr�c�H��|j�}�j�|Sr6)�getAttrsryr�s   �r �	_getAttrszBOurServerOurClientTests.test_closedFileGetAttrs.<locals>._getAttrss"����!�!�#�A���� ��Hr!c�(���j�|Sr6)�flushLoggedErrors)r)rs �r �_errz=OurServerOurClientTests.test_closedFileGetAttrs.<locals>._errs����"�"�$��Hr!c����|j�}�j�|j�|�|j���j	|t
j�Sr6)r�ryr��
addErrback�
assertFailurer�	SFTPError)r�r�r�r�rs  ���r �_closez?OurServerOurClientTests.test_closedFileGetAttrs.<locals>._close"sN������ �A���� �
�M�M�)�X�.�
�L�L����%�%�a��)?�)?�@�@r!r�)rr�r�r�r�s`  @@r �test_closedFileGetAttrsz/OurServerOurClientTests.test_closedFileGetAttrss`����K�K� � ��,�/�/�,�2H�2H�H�"�
��	
����	�
	�	A�	
�
�
�f���r!c������jjdtjtjzi�}�j���fd�}�fd��|j
|�S)Nr�c�j��|j�}�j�|j��|Sr6�r�ryr�)r�r��
_getAttrs2rs  ��r r�zBOurServerOurClientTests.test_openFileAttributes.<locals>._getAttrs2s.����!�!�#�A���� �
�M�M�*�%��Hr!c����jjd�}�j�|j�j|�|S�Nr��rtr�ryr�r�)�attrs1r�rs  �r r�zCOurServerOurClientTests.test_openFileAttributes.<locals>._getAttrs28s<������$�$�\�2�A���� �
�M�M�$�*�*�F�3��Hr!r�)rr�r�r�s`  @r �test_openFileAttributesz/OurServerOurClientTests.test_openFileAttributes,sX����K�K� � ��,�/�/�,�2H�2H�H�"�
��	
����	�	��}�}�Y�'�'r!c�������jjdtjtjzi�}�j���fd�}��fd���fd��|j
|�|S)Nr�c�j��|j�}�j�|j��|Sr6r�)r�r��	_setAttrsrs  ��r r�z@OurServerOurClientTests.test_openFileSetAttrs.<locals>._getAttrsHs.����!�!�#�A���� �
�M�M�)�$��Hr!c����d|d<�jjd|�}�j�|j��|j�j|�|S)Nr�atimer�)rt�setAttrsryr�r�)�attrsr�r�rs  ��r r�z@OurServerOurClientTests.test_openFileSetAttrs.<locals>._setAttrsNsS����E�'�N����$�$�\�5�9�A���� �
�M�M�*�%�
�M�M�$�*�*�E�2��Hr!c�^���jjd�}�j�|Sr��rtr�ry�rpr�rs  �r r�zAOurServerOurClientTests.test_openFileSetAttrs.<locals>._getAttrs2Vs(������$�$�\�2�A���� ��Hr!r�)rr�r�r�r�s`  @@r �test_openFileSetAttrsz-OurServerOurClientTests.test_openFileSetAttrs@sa���
�K�K� � ��,�/�/�,�2H�2H�H�"�
��	
����	�	�	�
	
�
�
�i� ��r!c�X����i��jjj���fd�}|�jj_�jjdtjtj
zddi�}�j
���fd�}|j|�S)z�
        Check that L{filetransfer.FileTransferClient.openFile} can send
        extended attributes, that should be extracted server side. By default,
        they are ignored, so we just verify they are correctly parsed.
        c�:���j|��|||�Sr6)�update)�filename�flagsr��oldOpenFile�savedAttributess   ��r r�zIOurServerOurClientTests.test_openFileExtendedAttributes.<locals>.openFilegs ����"�"�5�)��x���6�6r!r��ext_foorMc�.���j�ddi�y)Nr�rM�r�)�ignr�rs ��r �checkzFOurServerOurClientTests.test_openFileExtendedAttributes.<locals>.checkts������_�y�&�.A�Br!)rqrtr�rr�r�ryr�)rr�r�r�r�r�s`   @@r �test_openFileExtendedAttributesz7OurServerOurClientTests.test_openFileExtendedAttributes^s�������k�k�(�(�1�1��	7�'/������#��K�K� � ���!�!�L�$:�$:�:�
���
��
	
����	C��}�}�U�#�#r!c�����jjd�}�j��fd�}|j|�|j|��j	|t
j�S)N�testRemoveFilec�^���jjd�}�j�|S)Nr�)rt�
removeFilery)�ignoredr�rs  �r �_removeFilez<OurServerOurClientTests.test_removeFile.<locals>._removeFile}s)������&�&�'8�9�A���� ��Hr!)rtr�ryr�r�rr�)rr�r�s`  r �test_removeFilez'OurServerOurClientTests.test_removeFileys\����K�K� � �!2�3������	�
	
�
�
�k�"�	�
�
�k�"��!�!�!�\�%;�%;�<�<r!c�����jjd�}�j���fd�}�fd��|j|�S)N�testRenameFilec����jjdd�}�j�|j�|�|S)Nr��testRenamedFile)rt�
renameFileryr�)r�r��_testRenamedrs  ��r �_renamez8OurServerOurClientTests.test_renameFile.<locals>._rename�s:������&�&�'8�:L�M�A���� �
�M�M�,��.��Hr!c����jjd�}�j�|j�j|�y)Nr�r�)rpr�r�rs   �r r�z=OurServerOurClientTests.test_renameFile.<locals>._testRenamed�s8������$�$�%7�8�A���� �
�M�M�$�*�*�E�2r!)rtr�ryr�)rr�r�r�s`  @r �test_renameFilez'OurServerOurClientTests.test_renameFile�s?����K�K� � �!2�3������	�	3�
�}�}�W�%�%r!c��|jjd�}|j�|j|tj
�S�N�testMakeDirectory�rtr�ryr�rr��rr�s  r �test_directoryBadz)OurServerOurClientTests.test_directoryBad�s<���K�K� � �!5�6�������!�!�!�\�%;�%;�<�<r!c����jjdi�}�j��fd�}�fd�}|j|�|j|�|j|��j	|t
j�S)Nr�c�^���jjd�}�j�|Sr�r�r�s  �r r�zAOurServerOurClientTests.test_directoryCreation.<locals>._getAttrs�s)������$�$�%9�:�A���� ��Hr!c�^���jjd�}�j�|Sr�)rt�removeDirectoryryr�s  �r �_removeDirectoryzHOurServerOurClientTests.test_directoryCreation.<locals>._removeDirectory�s)������+�+�,@�A�A���� ��Hr!)rt�
makeDirectoryryr�r�rr�)rr�r�rs`   r �test_directoryCreationz.OurServerOurClientTests.test_directoryCreation�sp����K�K�%�%�&:�B�?������	�	�
	
�
�
�i� �	�
�
�&�'�	�
�
�i� ��!�!�!�\�%;�%;�<�<r!c��������jjd�}�j�g�����fd����fd�}�fd��|j��|j|�|S)Nr!c�������fd�}tj�j�}�j�|j	|�|j	��|j���|S)Nc�*���j|��Sr6r�)r)�filesr�s ��r r�zMOurServerOurClientTests.test_openDirectory.<locals>._getFiles.<locals>.append�s������Q���r!)r�
maybeDeferred�nextryr�r�)r�r�r�r�r�rrs`  ����r r�z=OurServerOurClientTests.test_openDirectory.<locals>._getFiles�sU���
��#�#�G�L�L�1�A���� �
�M�M�&�!�
�M�M�)�$�
�L�L���)��Hr!c���ttt���d�}|j��j|gd��y)Nr)s.testHiddenFiles
testDirectoryr�r�r�)�list�zip�sortr�)r��fsrrs  ��r �_checkFilesz?OurServerOurClientTests.test_openDirectory.<locals>._checkFiles�s:����d�3��;�'��*�+�B��G�G�I������	
r!c�H��|j�}�j�|Sr6)r�ry)rpr�r�rs   �r r�z:OurServerOurClientTests.test_openDirectory.<locals>._close�s����
�
��A���� ��Hr!r�)rr�rr�r�rs`  @@@r �test_openDirectoryz*OurServerOurClientTests.test_openDirectory�sV����K�K�%�%�c�*��������
	�	�	�
	
�
�
�i� �	�
�
�k�"��r!c��|jjd�}|j�|j|tj
�S)N�testLinkr�r�s  r �test_linkDoesntExistz,OurServerOurClientTests.test_linkDoesntExist�s;���K�K� � ��-�������!�!�!�\�%;�%;�<�<r!c����jjdd�}�j��fd�}�fd�}|j|�|j|�S)Nrr�c�`���jjdd�}�j�|S)Nrr#r�r�s  �r �_getFirstAttrszDOurServerOurClientTests.test_linkSharesAttrs.<locals>._getFirstAttrs�s*������$�$�[�!�4�A���� ��Hr!c����jjd�}�j�|j�j|�|Sr�r�)�
firstAttrsr�rs  �r �_getSecondAttrszEOurServerOurClientTests.test_linkSharesAttrs.<locals>._getSecondAttrs�s<������$�$�\�2�A���� �
�M�M�$�*�*�J�7��Hr!�rt�makeLinkryr�)rr�rrs`   r �test_linkSharesAttrsz,OurServerOurClientTests.test_linkSharesAttrs�sL����K�K� � ��l�;������	�
	�	
�
�
�n�%��}�}�_�-�-r!c����jjdd�}�j��fd�}�fd�}|j|�|j|�|S)Nrr�c�L���jjd�}�j�tt	j
��j
�jj�}|jd�}|j�j|j�|S�NrrW)rt�readLinkryrr9r:r;r`r<rar�r�)rpr��testFilers   �r �	_readLinkz8OurServerOurClientTests.test_linkPath.<locals>._readLink��s������$�$�[�1�A���� ���	�	��,�9�9�$�,�,�:K�:K�L�H��~�~�k�2�H�
�M�M�$�*�*�H�M�M�:��Hr!c�L���jjd�}�j�tt	j
��j
�jj�}|jd�}|j�j|j�|Sr )rt�realPathryrr9r:r;r`r<rar�r�)rpr��testLinkrs   �r �	_realPathz8OurServerOurClientTests.test_linkPath.<locals>._realPath�r$r!r)rr�r#r(s`   r �
test_linkPathz%OurServerOurClientTests.test_linkPath�sN����K�K� � ��l�;������	�	�	
�
�
�i� �	�
�
�i� ��r!c���|jjdd�}|j�|j|jd�|j|j
�|S)NrLsfoorM)rtrQryr�r��_cbTestExtendedRequestr�s  r �test_extendedRequestz,OurServerOurClientTests.test_extendedRequest
sP���K�K�'�'�(>��G������	�
�
�d�&�&��/�	�
�
�d�1�1�2��r!c��|jjdd�}|j�|j|t�S)NstestBadRequestr!)rtrQryr�rN)rr�r�s   r r+z.OurServerOurClientTests._cbTestExtendedRequests9���K�K�'�'�(9�3�?�������!�!�!�%8�9�9r!c#�tK�|jjd�}|j�|��}|j�}|j�|��|j	�}d}|jdt
|��|jt|dd�|j||dd�y�w)zJ
        Using client.openDirectory as an iterator is deprecated.
        r!zeUsing twisted.conch.ssh.filetransfer.ClientDirectory as an iterator was deprecated in Twisted 18.9.0.r#r�category�messageN)rtr�ryr	�
flushWarningsr�r(�DeprecationWarning)rr�r��oneFile�warningsr0s      r �$test_openDirectoryIteratorDeprecatedz<OurServerOurClientTests.test_openDirectoryIteratorDeprecateds�����

�K�K�%�%�c�*�������'���,�,�.�������
��%�%�'��
@�	�	
����C��M�*����+�X�a�[��-D�E�����(�1�+�i�"8�9�s�B6B8c#���K��jjdtji�}�j	�|��}g���fd�}�j
jj�\}||_~|jdd�}�j	��jt��d��j|��jj��jj��jj��j	��j!�jj"��j%|t&�|j)�}�j%|t&�y�w)z{
        If there are requests outstanding when the connection
        is closed for any reason, they should fail.
        r�c�v���j�g�tj�}�j|�|Sr6)r�r�Deferredr�)�offset�lengthr��gotReadRequestrs   ��r �	_slowReadzOOurServerOurClientTests.test_closedConnectionCancelsRequests.<locals>._slowRead9s2������^�R�0���� �A��!�!�&�)��Hr!�d��r#N)rtr�rr�ryrqr��valuesr�r�r(�assertNoResultrxr~r|rw�assertFalse�	connected�failureResultOfrr�)rr��fhr<�serverSideFhr;s`    @r �$test_closedConnectionCancelsRequestsz<OurServerOurClientTests.test_closedConnectionCancelsRequests+s7�����
�K�K� � ��|�/D�/D�b�I�������W����	����.�.�5�5�7���!*����
�L�L��c�"����������^�,�a�0����A��	
���+�+�-����(�(�*����(�(�*�����������.�.�/����Q��/�
�K�K�M�����Q��/�s�FFN)r0r1r2rhryrr�r�r�r�r�r�r�r�r�r�r�r�rrrrr)r,r+r�inlineCallbacksr5rFr$r!r rjrj�s����2/�
+�E�
��<�$�B�2(�(�<$�6=�&�"=�
=�.&�P=�
.�$�0�:�
���:��:�(���*0��*0r!rjc��eZdZd�Zy)�FakeConnc��yr6r$)r�channels  r �	sendClosezFakeConn.sendCloseZs��r!N)r0r1r2rLr$r!r rIrIYs��
r!rIc�6�eZdZd�Zd�Zd�Zd�Zd�Zd�Zd�Z	y)	�FileTransferCloseTestsc�"�t�|_yr6)rrBrs r rhzFileTransferCloseTests.setUp`s�� �l��r!c��tj�}Gd�d�}|�|_|j|j_|S)Nc��eZdZd�Zd�Zd�Zy)�DFileTransferCloseTests.buildServerConnection.<locals>.DummyTransportc��||_yr6)�	transportrs r rzMFileTransferCloseTests.buildServerConnection.<locals>.DummyTransport.__init__is	��!%��r!c��yr6r$)r�kind�datas   r �
sendPacketzOFileTransferCloseTests.buildServerConnection.<locals>.DummyTransport.sendPacketls��r!c��y)Nzdummy transportr$rs r �	logPrefixzNFileTransferCloseTests.buildServerConnection.<locals>.DummyTransport.logPrefixos��(r!N)r0r1r2rrXrZr$r!r �DummyTransportrRhs��
&�
�
)r!r[)r�
SSHConnectionrTrB)r�connr[s   r �buildServerConnectionz,FileTransferCloseTests.buildServerConnectioncs;���'�'�)��	)�	)�(�)��� $��������r!c�H���d�_|j���fd�}||_y)NFc�$��d�_�|�y)NT)�connectionLostFired)�reason�origConnectionLostrs ��r �connectionLostzFFileTransferCloseTests.interceptConnectionLost.<locals>.connectionLostzs���'+�D�$��v�&r!)rard)r�
sftpServerrdrcs`  @r �interceptConnectionLostz.FileTransferCloseTests.interceptConnectionLostvs&���#(�� �'�6�6��	'�%3�
�!r!c�<�|j|jd�y)Nz*sftpServer's connectionLost was not called)r�rars r �assertSFTPConnectionLostz/FileTransferCloseTests.assertSFTPConnectionLost�s������$�$�&R�	
r!c�@�tjt�|j��}|j	tjd��|jjj}|j|�|j�|j�y)ze
        Closing a session should notify an SFTP subsystem launched by that
        session.
        )r]rBrN)
rrrIrB�request_subsystemr�NSrtrT�protorf�
closeReceivedrh)r�testSessionres   r �test_sessionClosez(FileTransferCloseTests.test_sessionClose�sv���(�(�h�j����M��	�%�%�f�i�i��&8�9� �'�'�1�1�7�7�
�	
�$�$�Z�0�	�!�!�#��%�%�'r!c��|j�}tjd�tjdd�dzz}|j|�|jd}|jtjd��|jjj}|j|�|j|�|jtjdd��|j�y)zy
        A client sending CHANNEL_CLOSE should trigger closeReceived on the
        associated channel instance.
        r�>Lrr�rN)r^rrk�struct�pack�ssh_CHANNEL_OPEN�channelsrjrtrTrlrf�ssh_CHANNEL_CLOSErh�rr]�packet�sessionChannelres     r �%test_clientClosesChannelOnConnnectionz<FileTransferCloseTests.test_clientClosesChannelOnConnnection�s���
�)�)�+�����:�&����T�1�)=��)A�A�����f�%����q�)���(�(����7�);�<�#�*�*�4�4�:�:�
��$�$�Z�0�	
�$�$�Z�0�	
���v�{�{�4��3�4��%�%�'r!c��|j�}tjd�tjdd�dzz}|j|�|jd}|jtjd��|jjj}|j|�|j�|j�y)zP
        Closing an SSH connection should close all sessions within it.
        rrqrr�rN)r^rrkrrrsrtrurjrtrTrlrf�serviceStoppedrhrws     r �'test_stopConnectionServiceClosesChannelz>FileTransferCloseTests.test_stopConnectionServiceClosesChannel�s����)�)�+�����:�&����T�1�)=��)A�A�����f�%����q�)���(�(����7�);�<�#�*�*�4�4�:�:�
��$�$�Z�0�	
�����%�%�'r!N)
r0r1r2rhr^rfrhrorzr}r$r!r rNrN^s%��#��&3�
�
(�((�0(r!rNzCannot run without cryptographyc��eZdZdZgd�Zd�Zy)�ConstantsTestsag
    Tests for the constants used by the SFTP protocol implementation.

    @ivar filexferSpecExcerpts: Excerpts from the
        draft-ietf-secsh-filexfer-02.txt (draft) specification of the SFTP
        protocol.  There are more recent drafts of the specification, but this
        one describes version 3, which is what conch (and OpenSSH) implements.
    )a�
           The following values are defined for packet types.

                #define SSH_FXP_INIT                1
                #define SSH_FXP_VERSION             2
                #define SSH_FXP_OPEN                3
                #define SSH_FXP_CLOSE               4
                #define SSH_FXP_READ                5
                #define SSH_FXP_WRITE               6
                #define SSH_FXP_LSTAT               7
                #define SSH_FXP_FSTAT               8
                #define SSH_FXP_SETSTAT             9
                #define SSH_FXP_FSETSTAT           10
                #define SSH_FXP_OPENDIR            11
                #define SSH_FXP_READDIR            12
                #define SSH_FXP_REMOVE             13
                #define SSH_FXP_MKDIR              14
                #define SSH_FXP_RMDIR              15
                #define SSH_FXP_REALPATH           16
                #define SSH_FXP_STAT               17
                #define SSH_FXP_RENAME             18
                #define SSH_FXP_READLINK           19
                #define SSH_FXP_SYMLINK            20
                #define SSH_FXP_STATUS            101
                #define SSH_FXP_HANDLE            102
                #define SSH_FXP_DATA              103
                #define SSH_FXP_NAME              104
                #define SSH_FXP_ATTRS             105
                #define SSH_FXP_EXTENDED          200
                #define SSH_FXP_EXTENDED_REPLY    201

           Additional packet types should only be defined if the protocol
           version number (see Section ``Protocol Initialization'') is
           incremented, and their use MUST be negotiated using the version
           number.  However, the SSH_FXP_EXTENDED and SSH_FXP_EXTENDED_REPLY
           packets can be used to implement vendor-specific extensions.  See
           Section ``Vendor-Specific-Extensions'' for more details.
        a�
            The flags bits are defined to have the following values:

                #define SSH_FILEXFER_ATTR_SIZE          0x00000001
                #define SSH_FILEXFER_ATTR_UIDGID        0x00000002
                #define SSH_FILEXFER_ATTR_PERMISSIONS   0x00000004
                #define SSH_FILEXFER_ATTR_ACMODTIME     0x00000008
                #define SSH_FILEXFER_ATTR_EXTENDED      0x80000000

        a�
            The `pflags' field is a bitmask.  The following bits have been
           defined.

                #define SSH_FXF_READ            0x00000001
                #define SSH_FXF_WRITE           0x00000002
                #define SSH_FXF_APPEND          0x00000004
                #define SSH_FXF_CREAT           0x00000008
                #define SSH_FXF_TRUNC           0x00000010
                #define SSH_FXF_EXCL            0x00000020
        a�
            Currently, the following values are defined (other values may be
           defined by future versions of this protocol):

                #define SSH_FX_OK                            0
                #define SSH_FX_EOF                           1
                #define SSH_FX_NO_SUCH_FILE                  2
                #define SSH_FX_PERMISSION_DENIED             3
                #define SSH_FX_FAILURE                       4
                #define SSH_FX_BAD_MESSAGE                   5
                #define SSH_FX_NO_CONNECTION                 6
                #define SSH_FX_CONNECTION_LOST               7
                #define SSH_FX_OP_UNSUPPORTED                8
        c��i}|jD]]}|j�D]H}tjd|�}|s�t	|jd�d�||jd�<�J�_|j
t|�dkDd�|j�D]%\}}|j|tt|���'y)z�
        The constants used by the SFTP protocol implementation match those
        found by searching through the spec.
        z)^\s*#define SSH_([A-Z_]+)\s+([0-9x]*)\s*$r%rr#z,No constants found (the test must be buggy).N)�filexferSpecExcerpts�
splitlines�re�match�int�groupr�r(�itemsr��getattrr)r�	constants�excerpt�line�m�k�vs       r �test_constantsAgainstSpecz(ConstantsTests.test_constantsAgainstSpecs���
�	��0�0�	?�G��*�*�,�
?���H�H�I�4�P���,/�����
�A�,>�I�a�g�g�a�j�)�
?�	?�
	
����	�N�Q�� N�	
��O�O�%�	:�D�A�q����Q���a� 8�9�	:r!N)r0r1r2�__doc__r�r�r$r!r rr�s���J��X:r!rc��eZdZdZd�Zd�Zy)�RawPacketDataServerTestsz�
    Tests for L{filetransfer.FileTransferServer} which explicitly craft
    certain less common situations to exercise their handling.
    c�J�tjt���|_y)NrA)rrr�ftsrs r rhzRawPacketDataServerTests.setUp9s���2�2�*�,�G��r!c��t�}|jj|�d}d}tjtdg�|ztj|�z�}|jj
|�tjtdg�|ztgd��ztjd�ztjd�z�}t|j�t|��y)	zl
        A close request with an unknown handle receives an FX_NO_SUCH_FILE error
        response.
        s1234sinvalid handler��e)rrrr%sNo such file or directoryr!N)
rr�rvrrk�bytes�dataReceivedr�valuer)rrT�	requestIdr�r��expecteds      r �test_closeInvalidHandlez0RawPacketDataServerTests.test_closeInvalidHandle<s���
$�%�	������	�*��	�"���	�	�
�1�#�J��
��i�i���
 �
��	
�����e�$��9�9�
�3�%�L�
�
�
�,��

 �
�I�I�2�3�	
4�
�I�I�c�N�

�
��&	��O�O���X��	
r!N)r0r1r2r�rhr�r$r!r r�r�1s���
H�1
r!r�c�:�eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
y	)
�RawPacketDataTestsz�
    Tests for L{filetransfer.FileTransferClient} which explicitly craft certain
    less common protocol messages to exercise their handling.
    c�6�tj�|_yr6)rrs�ftcrs r rhzRawPacketDataTests.setUpws���2�2�4��r!c�n�tj�}|j|j�||jj
d<t
jddtj�tjd�ztjd�z}|jj|�|S)a/
        A STATUS packet containing a result code, a message, and a language is
        parsed to produce the result of an outstanding request L{Deferred}.

        @see: U{section 9.1<http://tools.ietf.org/html/draft-ietf-secsh-filexfer-13#section-9.1>}
            of the SFTP Internet-Draft.
        r#�!LL�msg�lang)
rr8r��_cbTestPacketSTATUSr��openRequestsrrrsr�FX_OKrrk�
packet_STATUS�rr�rWs   r �test_packetSTATUSz$RawPacketDataTests.test_packetSTATUSzs���
�N�N���	�
�
�d�.�.�/�#$������a� ��K�K��q�,�"4�"4�5��i�i���
 ��i�i�� �
!�	
�
	
�����t�$��r!c�X�|j|dd�|j|dd�y)z{
        Assert that the result is a two-tuple containing the message and
        language from the STATUS packet.
        rr�r#r�Nr��r�results  r r�z&RawPacketDataTests._cbTestPacketSTATUS�s,��
	
������F�+�������G�,r!c��tj�}|j|j�||jj
d<t
jddtj�}|jj|�|S)az
        A STATUS packet containing only a result code can also be parsed to
        produce the result of an outstanding request L{Deferred}.  Such packets
        are sent by some SFTP implementations, though not strictly legal.

        @see: U{section 9.1<http://tools.ietf.org/html/draft-ietf-secsh-filexfer-13#section-9.1>}
            of the SFTP Internet-Draft.
        r#r�)rr8r��_cbTestPacketSTATUSShortr�r�rrrsrr�r�r�s   r �test_packetSTATUSShortz)RawPacketDataTests.test_packetSTATUSShort�se��
�N�N���	�
�
�d�3�3�4�#$������a� ��{�{�5�!�\�%7�%7�8�������t�$��r!c�X�|j|dd�|j|dd�y)z�
        Assert that the result is a two-tuple containing empty strings, since
        the STATUS packet had neither a message nor a language.
        rr!r#Nr�r�s  r r�z+RawPacketDataTests._cbTestPacketSTATUSShort�s,��
	
������C�(�������C�(r!c�B�tj�}|j|j�||jj
d<t
jddtj�tjd�z}|jj|�|S)a�
        A STATUS packet containing a result code and a message but no language
        can also be parsed to produce the result of an outstanding request
        L{Deferred}.  Such packets are sent by some SFTP implementations, though
        not strictly legal.

        @see: U{section 9.1<http://tools.ietf.org/html/draft-ietf-secsh-filexfer-13#section-9.1>}
            of the SFTP Internet-Draft.
        r#r�r�)
rr8r��_cbTestPacketSTATUSWithoutLangr�r�rrrsrr�rrkr�r�s   r �test_packetSTATUSWithoutLangz/RawPacketDataTests.test_packetSTATUSWithoutLang�ss��
�N�N���	�
�
�d�9�9�:�#$������a� ��{�{�5�!�\�%7�%7�8�6�9�9�V�;L�L�������t�$��r!c�X�|j|dd�|j|dd�y)z�
        Assert that the result is a two-tuple containing the message from the
        STATUS packet and an empty string, since the language was missing.
        rr�r#r!Nr�r�s  r r�z1RawPacketDataTests._cbTestPacketSTATUSWithoutLang�s,��
	
������F�+�������C�(r!N)r0r1r2r�rhr�r�r�r�r�r�r$r!r r�r�ps*���
5��&-�� )��")r!r�)8r�r9r�rr�unittestr�hamcrestrr�twisted.internetr�twisted.internet.errorr�twisted.internet.testingr�twisted.protocolsr	�twisted.pythonr
�twisted.python.filepathr�twisted.trial.unittestr�
twisted.conchr
�_unix�ImportError�twisted.conch.unixr�_SFTPServerForUnixConchUser�cryptography�
_cryptography�twisted.conch.avatarr�
_ConchUser�object�twisted.conch.sshrrrrrr4r?r4�warnrD�registerAdapterr�rSrjrIrNrr�r�r$r!r �<module>r�sM��
�

�	�
��*�"�1�4�&�%�,�+��+��D�=��"=��!�(�!�L��<��I�	�K�K�
���&E�Z�E���
�%���H�M�M�
�		��&�$>�&��J���!�:�|�/G�/G��
�8��*�D��4�5�F0�l�F0�6�F0�R
�
�
�D��4�5�d(�X�d(�6�d(�N�L��;�<�e:�X�e:�=�e:�T�D��4�5��L��;�<�:
�x�:
�=�6�:
�z�L��;�<�S)��S)�=�S)��m���D����&�!%��&�����L������I����	��	�sZ�E7�F�F�!F!�*F/�7F�F�F�F�F�F�!F,�+F,�/F8�7F8

Zerion Mini Shell 1.0