AnonSec Shell
Server IP : 209.38.156.173  /  Your IP : 216.73.216.122   [ Reverse IP ]
Web Server : Apache/2.4.52 (Ubuntu)
System : Linux lakekumayuhotel 5.15.0-136-generic #147-Ubuntu SMP Sat Mar 15 15:53:30 UTC 2025 x86_64
User : root ( 0)
PHP Version : 8.1.2-1ubuntu2.22
Disable Function : NONE
Domains : 2 Domains
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : ON
Directory :  /lib/python3/dist-packages/twisted/conch/test/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ HOME ]     [ BACKUP SHELL ]     [ JUMPING ]     [ MASS DEFACE ]     [ SCAN ROOT ]     [ SYMLINK ]     

Current File : /lib/python3/dist-packages/twisted/conch/test/__pycache__/test_filetransfer.cpython-310.pyc
o

�bm��@s�dZddlZddlZddlZddlmZddlmZmZddl	m
Z
ddlmZddl
mZddlmZdd	lmZdd
lmZddlmZddlmZzdd
lmZWney_dZYnweZzddlmZWneyudZYnweZzddl Z!Wney�dZ Ynwe!Z zddl"m#Z$Wney�e%Z#Ynwe$Z#zddl&m'Z'm(Z(m)Z)m*Z*Wn	ey�YnwGdd�de#�Z+Gdd�de+�Z,Gdd�d�Z-edur�ddl.Z.e.�/def�nGdd�de�Z0e�1e0e+e)j2�Gdd�de�Z3eed�Gdd�de3��Z4Gdd �d �Z5eed�Gd!d"�d"e��Z6ee d#�Gd$d%�d%e��Z7ee d#�Gd&d'�d'e��Z8ee d#�Gd(d)�d)e��Z9dS)*z.
Tests for L{twisted.conch.ssh.filetransfer}.
�N)�skipIf)�assert_that�equal_to)�defer)�ConnectionLost)�loopback)�
components)�	_PY37PLUS)�FilePath)�StringTransport)�TestCase)�unix)�SFTPServerForUnixConchUser)�	ConchUser)�common�
connection�filetransfer�sessionc@�eZdZdd�Zdd�ZdS)�
TestAvatarcCs&t�|�tj|jd<tj|jd<dS)N�session�sftp)r�__init__r�
SSHSession�
channelLookupr�FileTransferServer�subsystemLookup��self�r�F/usr/lib/python3/dist-packages/twisted/conch/test/test_filetransfer.pyr?s
zTestAvatar.__init__cOs�zt|�}Wnty|||fg}Ynw|D]%}|d}t|�dkr(|dp)d}t|�dkr4|dp5i}||i|��}q|S)Nr�r�)�iter�	TypeError�len)r�f�args�kw�i�func�rrrr �
_runAsUserDs�zTestAvatar._runAsUserN)�__name__�
__module__�__qualname__rr,rrrr r>src@r)�FileTransferTestAvatarcCst�|�||_dS�N)rr�homeDir)rr2rrr rRs

zFileTransferTestAvatar.__init__cCstt����|jj�Sr1)r
�os�getcwd�preauthChildr2�pathrrrr �
getHomeDirVsz!FileTransferTestAvatar.getHomeDirN)r-r.r/rr7rrrr r0Qsr0c@�eZdZdd�ZdS)�ConchSessionForTestAvatarcCs
||_dSr1��avatar)rr;rrr r[�
z"ConchSessionForTestAvatar.__init__N)r-r.r/rrrrr r9Z�r9zNtwisted.conch.unix imported %r, but doesn't define SFTPServerForUnixConchUser'c@r)�FileTransferForTestAvatarcCsddiS)N�	conchTest�ext datar)r�version�otherExtrrr �
gotVersionnsz$FileTransferForTestAvatar.gotVersioncCs|dkrdSt�)N�testExtendedRequest�bar)�NotImplementedError)r�extName�extDatarrr �extendedRequestqsz)FileTransferForTestAvatar.extendedRequestN)r-r.r/rCrIrrrr r>msr>c@r8)�SFTPTestBasec	Csxt|���|_|j�d�|_|j�d��d�|j�d�jdd��*}|�d�tdd	��}|�|�d
��Wd�n1s?wYWd�n1sNwY|j�d��d�|j�d�jdd��
}|�d
�Wd�n1svwY|j�d�jdd��
}|�d
�Wd�n1s�wY|j�d�jdd��}|�d
�Wd�dS1s�wYdS)N�extra�
testDirectoryT�	testfile1�wb)�mode�aaaaaaaaaabbbbbbbbbbz/dev/urandom�rbii��testRemoveFile�a�testRenameFilez.testHiddenFile)	r
�mktemp�testDir�child�makedirs�open�write�read�chmod)rr&�f2rrr �setUp|s(
�����"�zSFTPTestBase.setUpN)r-r.r/r^rrrr rJ{r=rJz can't run on non-posix computersc@s�eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�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,�Zejeed-�d.d/���Zejd0d1��Zejd2d3��Zd4S)5�OurServerOurClientTestscs�t���t�j��_tj�jd��_t�	�j�}t�
��_d�_d�_
�fdd�}|�j_t�	�j�}�j�|��j�|�|�_|�_���dS)Nr:cs|�_|�_dSr1)�_serverVersion�_extData)�
serverVersionrHrrr �_�s
z(OurServerOurClientTests.setUp.<locals>._)rJr^r0rVr;rr�serverr�
LoopbackRelay�FileTransferClient�clientr`ra�gotServerVersion�makeConnection�clientTransport�serverTransport�
_emptyBuffers)rrjrcrkrrr r^�s

zOurServerOurClientTests.setUpcCs<|jjs|jjr|j��|j��|jjs|jjsdSdSr1)rk�bufferrj�clearBufferrrrr rl�s

�z%OurServerOurClientTests._emptyBufferscCs,|j��|j��|j��|j��dSr1)rk�loseConnectionrjrnrrrr �tearDown�s


z OurServerOurClientTests.tearDowncCs$|�|jd�|�|jddi�dS)N�r?r@)�assertEqualr`rarrrr �test_serverVersion�sz*OurServerOurClientTests.test_serverVersioncCs&|�tj�|jj�d|jj���dS)z:
        It implements the ISFTPServer interface.
        zISFTPServer not provided by N)�
assertTruer�ISFTPServer�
providedByrdrgrrrr �test_interface_implementation�s�z5OurServerOurClientTests.test_interface_implementationcsb�j�dtjtjBi�}���tj�g���fdd�}��td|���fdd�}|�	|�|S)zW
        A file opened with C{openFile} is closed when the connection is lost.
        �	testfile1cs��|��|�dSr1��append)�fd)�closed�oldCloserr �close��
zJOurServerOurClientTests.test_openedFileClosedWithConnection.<locals>.closer~cs`�jj|jdd�j}�j���j���j���j�����jji���	|��dS)N�)
rd�	openFiles�handler{rkrorjrnrr�assertIn)�openFiler{)r|rrr �_fileOpened�s



zPOurServerOurClientTests.test_openedFileClosedWithConnection.<locals>._fileOpened)
rgr�r�FXF_READ�	FXF_WRITErlr3r~�patch�addCallback)r�dr~r�r)r|r}rr �#test_openedFileClosedWithConnection�s�
	z;OurServerOurClientTests.test_openedFileClosedWithConnectioncs.�j�d�}����fdd�}|�|�|S)zh
        A directory opened with C{openDirectory} is close when the connection
        is lost.
        �cs<�j���j���j���j�����jji�dSr1)rkrorjrnrrrd�openDirs��openDirrrr �	_getFiles�s




zSOurServerOurClientTests.test_openedDirectoryClosedWithConnection.<locals>._getFiles�rg�
openDirectoryrlr�)rr�r�rrr �(test_openedDirectoryClosedWithConnection�s

z@OurServerOurClientTests.test_openedDirectoryClosedWithConnectioncsd�j�dtjtjBi�}������fdd�}�fdd����fdd���fdd	��|�|�|S)
Nrxcs*��|t�|���|�}|��|�|Sr1)rrr�	ISFTPFiler��r�r�)�
_readChunk�_writeChunkrrr r��sz<OurServerOurClientTests.test_openFileIO.<locals>._fileOpenedcs&|�dd�}���|��jd�|S)Nr�rP��	readChunkrlr�rrr�rrr r���z;OurServerOurClientTests.test_openFileIO.<locals>._readChunkcs$|�dd�}���|��|�|S)Nr�s
cccccccccc)�
writeChunkrlr��rcr�r�)�_readChunk2rrr r�sz<OurServerOurClientTests.test_openFileIO.<locals>._writeChunkcs&|�dd�}���|��jd�|S)Nr�saaaaaaaaaabbbbbbbbbbccccccccccr�r�rrr r�r�z<OurServerOurClientTests.test_openFileIO.<locals>._readChunk2�rgr�rr�r�rlr�)rr�r�r)r�r�r�rr �test_openFileIO�s�
z'OurServerOurClientTests.test_openFileIOcsV�j�dtjtjBi�}����fdd���fdd�����fdd�}|�|�|S)Nrxc�|��}���|Sr1)�getAttrsrlr�rrr �	_getAttrs�zBOurServerOurClientTests.test_closedFileGetAttrs.<locals>._getAttrscs���|Sr1)�flushLoggedErrors�r&rrr �_errsz=OurServerOurClientTests.test_closedFileGetAttrs.<locals>._errcs4|��}���|��|�|�����|tj�Sr1)r~rlr��
addErrback�
assertFailurer�	SFTPErrorr��r�r�rrr �_close#s

z?OurServerOurClientTests.test_closedFileGetAttrs.<locals>._closer�)rr�r�rr�r �test_closedFileGetAttrss�
z/OurServerOurClientTests.test_closedFileGetAttrscsD�j�dtjtjBi�}�����fdd�}�fdd��|�|�S)Nrxc�|��}���|���|Sr1�r�rlr�r���
_getAttrs2rrr r�3�
zBOurServerOurClientTests.test_openFileAttributes.<locals>._getAttrsc�&�j�d�}���|��j|�|S�Nrx�rgr�rlr�rr)�attrs1r�rrr r�9r�zCOurServerOurClientTests.test_openFileAttributes.<locals>._getAttrs2r��rr�r�rr�r �test_openFileAttributes-s�
z/OurServerOurClientTests.test_openFileAttributescsV�j�dtjtjBi�}�����fdd�}��fdd���fdd��|�|�|S)Nrxcr�r1r�r�)�	_setAttrsrrr r�Ir�z@OurServerOurClientTests.test_openFileSetAttrs.<locals>._getAttrscs:d|d<�j�d|�}���|���|��j|�|S)Nr�atimerx)rg�setAttrsrlr�rr��attrsr�r�rr r�Os
z@OurServerOurClientTests.test_openFileSetAttrs.<locals>._setAttrsc��j�d�}���|Sr��rgr�rl�rcr�rrr r�W�zAOurServerOurClientTests.test_openFileSetAttrs.<locals>._getAttrs2r�r�r)r�r�rr �test_openFileSetAttrsAs�
z-OurServerOurClientTests.test_openFileSetAttrscsbi��jjj���fdd�}|�jj_�j�dtjtjBddi�}�����fdd�}|�|�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.
        cs��|��|||�Sr1)�update)�filename�flagsr�)�oldOpenFile�savedAttributesrr r�hrzIOurServerOurClientTests.test_openFileExtendedAttributes.<locals>.openFilerx�ext_foorEcs���ddi�dS)Nr�rE�rr)�ign)r�rrr �checku�zFOurServerOurClientTests.test_openFileExtendedAttributes.<locals>.check)rdrgr�rr�r�rlr�)rr�r�r�r)r�r�rr �test_openFileExtendedAttributes_s


�
z7OurServerOurClientTests.test_openFileExtendedAttributescsB�j�d�}����fdd�}|�|�|�|���|tj�S)N�testRemoveFilecr�)Nr�)rg�
removeFilerl)�ignoredr�rrr �_removeFile~r�z<OurServerOurClientTests.test_removeFile.<locals>._removeFile)rgr�rlr�r�rr�)rr�r�rrr �test_removeFilezs

z'OurServerOurClientTests.test_removeFilecs8�j�d�}�����fdd�}�fdd��|�|�S)N�testRenameFilecs&�j�dd�}���|��|�|S)Nr��testRenamedFile)rg�
renameFilerlr�r���_testRenamedrrr �_rename�sz8OurServerOurClientTests.test_renameFile.<locals>._renamecs&�j�d�}���|��j|�dS)Nr�r�)rcr�r�rrr r��sz=OurServerOurClientTests.test_renameFile.<locals>._testRenamed)rgr�rlr�)rr�r�rr�r �test_renameFile�s

z'OurServerOurClientTests.test_renameFilecC�"|j�d�}|��|�|tj�S�N�testMakeDirectory�rgr�rlr�rr��rr�rrr �test_directoryBad��z)OurServerOurClientTests.test_directoryBadcsZ�j�di�}����fdd�}�fdd�}|�|�|�|�|�|���|tj�S)Nr�cr�r�r�r�rrr r��r�zAOurServerOurClientTests.test_directoryCreation.<locals>._getAttrscr�r�)rg�removeDirectoryrlr�rrr �_removeDirectory�r�zHOurServerOurClientTests.test_directoryCreation.<locals>._removeDirectory)rg�
makeDirectoryrlr�r�rr�)rr�r�r�rrr �test_directoryCreation�s	


z.OurServerOurClientTests.test_directoryCreationcs\�j�d�}���g�����fdd����fdd�}�fdd��|���|�|�|S)N�csF��fdd�}t��j�}���|�|�|���|����|S)Ncs��|��Sr1ryr�)�filesr�rr rz�s
zMOurServerOurClientTests.test_openDirectory.<locals>._getFiles.<locals>.append)r�
maybeDeferred�nextrlr�r�)r�rzr��r�r�r�rr�r r��s

z=OurServerOurClientTests.test_openDirectory.<locals>._getFilescs0ttt���d�}|����|gd��dS)Nr)�.testHiddenFile�
testDirectoryr�r�rx)�list�zip�sortrr)r��fs)r�rrr �_checkFiles�s�z?OurServerOurClientTests.test_openDirectory.<locals>._checkFilescr�r1)r~rl)rcr�r�rrr r��r�z:OurServerOurClientTests.test_openDirectory.<locals>._closer�)rr�r�rr�r �test_openDirectory�s

z*OurServerOurClientTests.test_openDirectorycCr�)N�testLinkr�r�rrr �test_linkDoesntExist�r�z,OurServerOurClientTests.test_linkDoesntExistcsB�j�dd�}����fdd�}�fdd�}|�|�|�|�S)Nr�rxcs�j�dd�}���|S)Nr�r!r�r�rrr �_getFirstAttrs�szDOurServerOurClientTests.test_linkSharesAttrs.<locals>._getFirstAttrscr�r�r�)�
firstAttrsr�rrr �_getSecondAttrs�r�zEOurServerOurClientTests.test_linkSharesAttrs.<locals>._getSecondAttrs�rg�makeLinkrlr�)rr�r�r�rrr �test_linkSharesAttrs�s

z,OurServerOurClientTests.test_linkSharesAttrscsF�j�dd�}����fdd�}�fdd�}|�|�|�|�|S)Nr�rxc�H�j�d�}���tt�����jj�}|�	d�}|�
�j|j�|S�Nr�rM)rg�readLinkrlr
r3r4r5rVr6rWr�rr)rcr��testFilerrr �	_readLink��
z8OurServerOurClientTests.test_linkPath.<locals>._readLinkcr�r�)rg�realPathrlr
r3r4r5rVr6rWr�rr)rcr��testLinkrrr �	_realPath�rz8OurServerOurClientTests.test_linkPath.<locals>._realPathr�)rr�r�rrrr �
test_linkPath�s

z%OurServerOurClientTests.test_linkPathcCs4|j�dd�}|��|�|jd�|�|j�|S)NrDsfoorE)rgrIrlr�rr�_cbTestExtendedRequestr�rrr �test_extendedRequests
z,OurServerOurClientTests.test_extendedRequestcCs"|j�dd�}|��|�|t�S)NstestBadRequestr�)rgrIrlr�rF)rr�r�rrr rsz.OurServerOurClientTests._cbTestExtendedRequestz!Broken by PEP 479 and deprecated.ccs��|j�d�}|��|V}t�}z!|D]}|��|V\}}}|�|�qW|��}|��|Vn|��}|��|Vw|��|�|hd��dS)z�
        Check that the object returned by
        L{filetransfer.FileTransferClient.openDirectory} can be used
        as an iterator.
        r�>rxr�r�r�r�N)rgr�rl�set�addr~rr)rr�r��	filenamesr&r�rc�	fileattrsrrr �test_openDirectoryIterators,����z2OurServerOurClientTests.test_openDirectoryIteratorccsz�|j�d�}|��|V}|��}|��|V|��}d}|�dt|��|�t|dd�|�||dd�dS)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)rgr�rlr��
flushWarningsrrr%�DeprecationWarning)rr�r��oneFile�warningsr
rrr �$test_openDirectoryIteratorDeprecatedAs��z<OurServerOurClientTests.test_openDirectoryIteratorDeprecatedc#s���j�dtji�}���|V}g���fdd�}�jj��\}||_~|�dd�}�����	t
��d���|��j�
��j���j��������jj���|t�|��}��|t�dS)z{
        If there are requests outstanding when the connection
        is closed for any reason, they should fail.
        rxcs"���g�t��}��|�|Sr1)rrr�Deferredrz)�offset�lengthr���gotReadRequestrrr �	_slowReadds
zOOurServerOurClientTests.test_closedConnectionCancelsRequests.<locals>._slowRead�d��r!N)rgr�rr�rlrdr��valuesr�rrr%�assertNoResultrkrornrj�assertFalse�	connected�failureResultOfrr�)rr��fhr�serverSideFhrrr �$test_closedConnectionCancelsRequestsVs*�



z<OurServerOurClientTests.test_closedConnectionCancelsRequestsN) r-r.r/r^rlrprsrwr�r�r�r�r�r�r�r�r�r�r�r�r�r�rrrr�inlineCallbacksrr	rrr"rrrr r_�s<	!
((
r_c@r8)�FakeConncC�dSr1r)r�channelrrr �	sendClose��zFakeConn.sendCloseN)r-r.r/r'rrrr r$�r=r$c@sDeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dS)�FileTransferCloseTestscCst�|_dSr1)rr;rrrr r^�szFileTransferCloseTests.setUpcCs,t��}Gdd�d�}|�|_|j|j_|S)Nc@s$eZdZdd�Zdd�Zdd�ZdS)zDFileTransferCloseTests.buildServerConnection.<locals>.DummyTransportcSs
||_dSr1)�	transportrrrr r�r<zMFileTransferCloseTests.buildServerConnection.<locals>.DummyTransport.__init__cSr%r1r)r�kind�datarrr �
sendPacket�r(zOFileTransferCloseTests.buildServerConnection.<locals>.DummyTransport.sendPacketcSsdS)Nzdummy transportrrrrr �	logPrefix�r(zNFileTransferCloseTests.buildServerConnection.<locals>.DummyTransport.logPrefixN)r-r.r/rr-r.rrrr �DummyTransport�sr/)r�
SSHConnectionr*r;)r�connr/rrr �buildServerConnection�s


z,FileTransferCloseTests.buildServerConnectioncs$d�_|j���fdd�}||_dS)NFcsd�_�|�dS)NT)�connectionLostFired)�reason��origConnectionLostrrr �connectionLost�szFFileTransferCloseTests.interceptConnectionLost.<locals>.connectionLost)r3r7)r�
sftpServerr7rr5r �interceptConnectionLost�s
z.FileTransferCloseTests.interceptConnectionLostcCs|�|jd�dS)Nz*sftpServer's connectionLost was not called)rtr3rrrr �assertSFTPConnectionLost�s�z/FileTransferCloseTests.assertSFTPConnectionLostcCsJtjt�|jd�}|�t�d��|jjj	}|�
|�|��|��dS)ze
        Closing a session should notify an SFTP subsystem launched by that
        session.
        )r1r;rN)
rrr$r;�request_subsystemr�NSrgr*�protor9�
closeReceivedr:)r�testSessionr8rrr �test_sessionClose�s

z(FileTransferCloseTests.test_sessionClosecCs�|��}t�d�t�dd�d}|�|�|jd}|�t�d��|jj	j
}|�|�|�|�|�t�dd��|�
�dS)zy
        A client sending CHANNEL_CLOSE should trigger closeReceived on the
        associated channel instance.
        r�>LrrqrN)r2rr<�struct�pack�ssh_CHANNEL_OPEN�channelsr;rgr*r=r9�ssh_CHANNEL_CLOSEr:�rr1�packet�sessionChannelr8rrr �%test_clientClosesChannelOnConnnection�s




z<FileTransferCloseTests.test_clientClosesChannelOnConnnectioncCsn|��}t�d�t�dd�d}|�|�|jd}|�t�d��|jj	j
}|�|�|��|�
�dS)zP
        Closing an SSH connection should close all sessions within it.
        rrArrqrN)r2rr<rBrCrDrEr;rgr*r=r9�serviceStoppedr:rGrrr �'test_stopConnectionServiceClosesChannel�s



z>FileTransferCloseTests.test_stopConnectionServiceClosesChannelN)
r-r.r/r^r2r9r:r@rJrLrrrr r)�s
r)zCannot run without cryptographyc@s eZdZdZgd�Zdd�ZdS)�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
        cCs�i}|jD]}|��D]}t�d|�}|r"t|�d�d�||�d�<qq|�t|�dkd�|��D]
\}}|�	|t
t|��q2dS)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�grouprtr%�itemsrr�getattrr)r�	constants�excerpt�line�m�k�vrrr �test_constantsAgainstSpecHs
����z(ConstantsTests.test_constantsAgainstSpecN)r-r.r/�__doc__rNr\rrrr rM�s	LrMc@s eZdZdZdd�Zdd�ZdS)�RawPacketDataServerTestsz�
    Tests for L{filetransfer.FileTransferServer} which explicitly craft
    certain less common situations to exercise their handling.
    cCstjt�d�|_dS)Nr:)rrr�ftsrrrr r^ar�zRawPacketDataServerTests.setUpcCs�t�}|j�|�d}d}t�tdg�|t�|��}|j�|�t�tdg�|tgd��t�d�t�d��}t|��t	|��dS)	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_rirr<�bytes�dataReceivedr�valuer)rr*�	requestIdr�r~�expectedrrr �test_closeInvalidHandleds6����
�	�
���z0RawPacketDataServerTests.test_closeInvalidHandleN)r-r.r/r]r^rfrrrr r^Zsr^c@sHeZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dS)�RawPacketDataTestsz�
    Tests for L{filetransfer.FileTransferClient} which explicitly craft certain
    less common protocol messages to exercise their handling.
    cCst��|_dSr1)rrf�ftcrrrr r^�szRawPacketDataTests.setUpcCsTt��}|�|j�||jjd<t�ddtj	�t
�d�t
�d�}|j�|�|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)
rrr��_cbTestPacketSTATUSrh�openRequestsrBrCr�FX_OKrr<�
packet_STATUS�rr�r,rrr �test_packetSTATUS�s���z$RawPacketDataTests.test_packetSTATUScC�$|�|dd�|�|dd�dS)z{
        Assert that the result is a two-tuple containing the message and
        language from the STATUS packet.
        rrjr!rkNr��r�resultrrr rl��z&RawPacketDataTests._cbTestPacketSTATUScCs@t��}|�|j�||jjd<t�ddtj	�}|j�
|�|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!ri)rrr��_cbTestPacketSTATUSShortrhrmrBrCrrnrorprrr �test_packetSTATUSShort�s	z)RawPacketDataTests.test_packetSTATUSShortcCs$|�|dd�|�|dd�dS)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�rsrrr rv�ruz+RawPacketDataTests._cbTestPacketSTATUSShortcCsJt��}|�|j�||jjd<t�ddtj	�t
�d�}|j�|�|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!rirj)
rrr��_cbTestPacketSTATUSWithoutLangrhrmrBrCrrnrr<rorprrr �test_packetSTATUSWithoutLang�s
z/RawPacketDataTests.test_packetSTATUSWithoutLangcCrr)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.
        rrjr!r�Nr�rsrrr rx�ruz1RawPacketDataTests._cbTestPacketSTATUSWithoutLangN)r-r.r/r]r^rqrlrwrvryrxrrrr rg�srg):r]r3rPrB�unittestr�hamcrestrr�twisted.internetr�twisted.internet.errorr�twisted.protocolsr�twisted.pythonr�twisted.python.compatr	�twisted.python.filepathr
�twisted.test.proto_helpersr�twisted.trial.unittestr�
twisted.conchr
�_unix�ImportError�twisted.conch.unixr�_SFTPServerForUnixConchUser�cryptography�
_cryptography�twisted.conch.avatarr�
_ConchUser�object�twisted.conch.sshrrrrrr0r9r�warnr>�registerAdapterrurJr_r$r)rMr^rgrrrr �<module>s������	��		�
v

g
h
=

Anon7 - 2022
AnonSec Team