3
,sY4b              ,   @   sP  d dl Z d dlZd dlZd dlZd dlmZ d dlmZ d dlm	Z	 e	dZ
d dlmZ e
r~d dlmZ d dlmZmZmZ nd d	lmZ G d
d dZd dlmZ d dlmZmZmZ d dlmZ d dlmZ d dlmZ d dl m!Z!m"Z"m#Z# d dl$m%Z% d dl&m'Z' yd dl(mZ) W n2 e*k
rJ Z+ zdZ)e,e+Z-[+W Y ddZ+[+X nX d dl.m/Z/ d dl0m1Z1 d dl2m3Z3m4Z4 d dl2m5Z5m6Z6 yd dl.m7Z7m8Z8 W n e*k
r   Y nX yd dl
Z
W n e*k
r   dZ
Y nX yd dl9Z9W n e*k
r   dZ9Y nX dd Z:e: Z;G dd de<Z=G dd de'j>Z?G d d! d!ej@ZAG d"d# d#ejBZCG d$d% d%ejDZEG d&d' d'ejDZFG d(d) d)ej@ZGdAd+d,ZHG d-d. d.ZIG d/d0 d0eIZJeeG d1d2 d2eZKG d3d4 d4ZLG d5d6 d6eIZMG d7d8 d8ZNG d9d: d:eIeNe'j>ZOG d;d< d<eJeNe'j>ZPG d=d> d>eMeNe'j>ZQG d?d@ d@eJe'j>ZRdS )B    N)count)implementer)requireModulecryptography)
ConchError)	ConchUser)ISession
SSHSessionwrapProtocol)r   c               @   s   e Zd ZdS )r   N)__name__
__module____qualname__ r   r   ?/usr/lib/python3/dist-packages/twisted/conch/test/test_conch.pyr      s    r   )portal)reactordeferprotocol)ProcessExitedAlready)LoopingCall)getProcessValue)filepathlogruntime)unicode)unittest)r	   )ConchTestRealm)which)publicRSA_opensshprivateRSA_openssh)publicDSA_opensshprivateDSA_openssh)ConchTestServerFactoryconchTestPublicKeyCheckerc              C   sN   d} d}yt j t j} | jd d}W n t jk
r<   Y nX | rJ| j  |S )z5 Returns True if the system can bind an IPv6 address.NF::1r   T)r$   r   )socketZAF_INET6binderrorclose)ZsockZhas_ipv6r   r   r   	_has_ipv6<   s    
r)   c               @   s   e Zd ZdZdZdd ZdS )	FakeStdioz
    A fake for testing L{twisted.conch.scripts.conch.SSHSession.eofReceived} and
    L{twisted.conch.scripts.cftp.SSHSession.eofReceived}.

    @ivar writeConnLost: A flag which records whether L{loserWriteConnection}
        has been called.
    Fc             C   s
   d| _ dS )z9
        Record the call to loseWriteConnection.
        TN)writeConnLost)selfr   r   r   loseWriteConnectionZ   s    zFakeStdio.loseWriteConnectionN)r   r   r   __doc__r+   r-   r   r   r   r   r*   P   s   r*   c               @   s$   e Zd ZdZedkreZdd ZdS )StdioInteractingSessionTestsz>
    Tests for L{twisted.conch.scripts.conch.SSHSession}.
    Nc             C   s*   t  }t }||_|j  | j|j dS )z}
        L{twisted.conch.scripts.conch.SSHSession.eofReceived} loses the
        write half of its stdio connection.
        N)r*   StdioInteractingSessionstdioZeofReceivedZ
assertTruer+   )r,   r1   Zchannelr   r   r   test_eofReceivedj   s
    z-StdioInteractingSessionTests.test_eofReceived)r   r   r   r.   r0   _reasonskipr2   r   r   r   r   r/   b   s   r/   c               @   s$   e Zd Zdd Zdd Zdd ZdS )Echoc             C   s   t jd d S )NzECHO CONNECTION MADE)r   msg)r,   r   r   r   connectionMadex   s    zEcho.connectionMadec             C   s   t jd d S )NzECHO CONNECTION DONE)r   r6   )r,   reasonr   r   r   connectionLost|   s    zEcho.connectionLostc             C   s"   | j j| d|kr| j j  d S )N   
)	transportwriteloseConnection)r,   datar   r   r   dataReceived   s    zEcho.dataReceivedN)r   r   r   r7   r9   r?   r   r   r   r   r5   w   s   r5   c               @   s   e Zd ZeZdS )EchoFactoryN)r   r   r   r5   r   r   r   r   r   r@      s   r@   c               @   s0   e Zd ZdZdZdZdd Zdd Zdd	 ZdS )
ConchTestOpenSSHProcessa  
    Test protocol for launching an OpenSSH client process.

    @ivar deferred: Set by whatever uses this object. Accessed using
    L{_getDeferred}, which destroys the value so the Deferred is not
    fired twice. Fires when the process is terminated.
    N    c             C   s   | j d  }| _ |S )N)deferred)r,   dr   r   r   _getDeferred   s    z$ConchTestOpenSSHProcess._getDeferredc             C   s   |  j |7  _ d S )N)buf)r,   r>   r   r   r   outReceived   s    z#ConchTestOpenSSHProcess.outReceivedc             C   sJ   |j jdkr*| j jtdj|j j n| jjdd}| j j| dS )z~
        Called when the process has ended.

        @param reason: a Failure giving the reason for the process' end.
        r   zexit code was not 0: {}s   
r:   N)	valueZexitCoderE   Zerrbackr   formatrF   replacecallback)r,   r8   rF   r   r   r   processEnded   s    z$ConchTestOpenSSHProcess.processEnded)	r   r   r   r.   rC   rF   rE   rG   rL   r   r   r   r   rA      s   rA   c               @   sT   e Zd ZdZdZdd Zdd Zdd Zd	d
 Zdd Z	dd Z
dd Zdd ZdS )ConchTestForwardingProcessa  
    Manages a third-party process which launches a server.

    Uses L{ConchTestForwardingPort} to connect to the third-party server.
    Once L{ConchTestForwardingPort} has disconnected, kill the process and fire
    a Deferred with the data received by the L{ConchTestForwardingPort}.

    @ivar deferred: Set by whatever uses this object. Accessed using
    L{_getDeferred}, which destroys the value so the Deferred is not
    fired twice. Fires when the process is terminated.
    Nc             C   s   || _ d| _|| _dS )aF  
        @type port: L{int}
        @param port: The port on which the third-party server is listening.
        (it is assumed that the server is running on localhost).

        @type data: L{str}
        @param data: This is sent to the third-party server. Must end with '
'
        in order to trigger a disconnect.
        N)portbufferr>   )r,   rN   r>   r   r   r   __init__   s    
z#ConchTestForwardingProcess.__init__c             C   s   | j d  }| _ |S )N)rC   )r,   rD   r   r   r   rE      s    z'ConchTestForwardingProcess._getDeferredc             C   s   | j   d S )N)_connect)r,   r   r   r   r7      s    z)ConchTestForwardingProcess.connectionMadec             C   s0   t jtt| | j}|jd| j}|j| j |S )a  
        Connect to the server, which is often a third-party process.
        Tries to reconnect if it fails because we have no way of determining
        exactly when the port becomes available for listening -- we can only
        know when the process starts.
        z	127.0.0.1)	r   ZClientCreatorr   ConchTestForwardingPortr>   Z
connectTCPrN   Z
addErrback
_ebConnect)r,   ZccrD   r   r   r   rQ      s
    
z#ConchTestForwardingProcess._connectc             C   s   t jd| j d S )Ng?)r   	callLaterrQ   )r,   fr   r   r   rS      s    z%ConchTestForwardingProcess._ebConnectc             C   s.   || _ | jjd | jj  tjd| j dS )z
        The network connection has died; save the buffer of output
        from the network and attempt to quit the process gracefully,
        and then (after the reactor has spun) send it a KILL signal.
           r   N)rO   r;   r<   r=   r   rT   
_reallyDie)r,   rO   r   r   r   forwardingPortDisconnected   s    
z5ConchTestForwardingProcess.forwardingPortDisconnectedc             C   s*   y| j jd W n tk
r$   Y nX d S )NZKILL)r;   ZsignalProcessr   )r,   r   r   r   rW      s    z%ConchTestForwardingProcess._reallyDiec             C   s   | j  j| j dS )z
        Fire the Deferred at self.deferred with the data collected
        from the L{ConchTestForwardingPort} connection, if any.
        N)rE   rK   rO   )r,   r8   r   r   r   rL      s    z'ConchTestForwardingProcess.processEnded)r   r   r   r.   rC   rP   rE   r7   rQ   rS   rX   rW   rL   r   r   r   r   rM      s   rM   c               @   s0   e Zd ZdZdd Zdd Zdd Zdd	 Zd
S )rR   z
    Connects to server launched by a third-party process (managed by
    L{ConchTestForwardingProcess}) sends data, then reports whatever it
    received back to the L{ConchTestForwardingProcess} once the connection
    is ended.
    c             C   s   || _ || _dS )z
        @type protocol: L{ConchTestForwardingProcess}
        @param protocol: The L{ProcessProtocol} which made this connection.

        @type data: str
        @param data: The data to be sent to the third-party server.
        N)r   r>   )r,   r   r>   r   r   r   rP     s    z ConchTestForwardingPort.__init__c             C   s   d| _ | jj| j d S )NrB   )rO   r;   r<   r>   )r,   r   r   r   r7     s    z&ConchTestForwardingPort.connectionMadec             C   s   |  j |7  _ d S )N)rO   )r,   r>   r   r   r   r?     s    z$ConchTestForwardingPort.dataReceivedc             C   s   | j j| j d S )N)r   rX   rO   )r,   r8   r   r   r   r9   #  s    z&ConchTestForwardingPort.connectionLostN)r   r   r   r.   rP   r7   r?   r9   r   r   r   r   rR     s
   rR   conchc             C   sJ   t jd| g}g }x2|t|  D ]"}t|tr8|jd}|j| q W |S )Na$  -c
### Twisted Preamble
import sys, os
path = os.path.abspath(sys.argv[0])
while os.path.dirname(path) != path:
    if os.path.basename(path).startswith('Twisted'):
        sys.path.insert(0, path)
        break
    path = os.path.dirname(path)

from twisted.conch.scripts.%s import run
run()zutf-8)sys
executablelist
isinstancer   encodeappend)argsmodstartZmadeArgsargr   r   r   	_makeArgs(  s    

rd   c               @   sP   e Zd ZesdZesdZedd Zdd Zdd Z	d	d
 Z
dd Zdd ZdS )ConchServerSetupMixinzcan't run without cryptographyzCannot run without PyASN1c               C   s   t dS )Ns   testuser)r   r   r   r   r   <lambda>F  s    zConchServerSetupMixin.<lambda>c          &   C   s   x"d	D ]}t jj|rt j| qW tdd}|jt W d Q R X tdd}|jt W d Q R X tdd}|jt W d Q R X tdd}|jt	 W d Q R X t j
dd t j
dd tdd}|jdt  W d Q R X d S )
Nrsa_testrsa_test.pubdsa_testdsa_test.pubkh_testwbi  s
   127.0.0.1 )rg   rh   ri   rj   rk   )ospathexistsremoveopenr<   r   r   r    r!   chmod)r,   rU   r   r   r   _createFilesH  s     z"ConchServerSetupMixin._createFilesc             C   s*   t j  }|jd |j d }|j  |S )N r      )rt   r   )r%   r&   Zgetsocknamer(   )r,   srN   r   r   r   _getFreePort[  s
    
z"ConchServerSetupMixin._getFreePortc             C   s.   | j  }tj|}|jt  t }||_|S )z
        Make a L{ConchTestServerFactory}, which allows us to start a
        L{ConchTestServer} -- i.e. an actually listening conch.
        )realmFactoryr   ZPortalZregisterCheckerr#   r"   )r,   Zrealmpfactoryr   r   r   _makeConchFactoryc  s    
z'ConchServerSetupMixin._makeConchFactoryc             C   sv   | j   | j | _d| j_tjd| jdd| _tjdt | _| jj	 j
| _trrtjdt dd| _| jj	 j
| _d S )Nru   r   z	127.0.0.1)Z	interfacez::1)rs   r{   conchFactoryZexpectedLoseConnectionr   Z	listenTCPconchServerr@   
echoServergetHostrN   echoPortHAS_IPV6echoServerV6
echoPortV6)r,   r   r   r   setUpp  s    


zConchServerSetupMixin.setUpc             C   sp   yd| j j_W n tk
r"   Y nX | j jjj  tj| jj	tj| j
j	g}trf|jtj| jj	 tj|S )Nru   )r|   protodoneAttributeErrorr;   r=   r   ZmaybeDeferredr}   ZstopListeningr~   r   r_   r   ZgatherResults)r,   Z	deferredsr   r   r   tearDown}  s    zConchServerSetupMixin.tearDownN)r   r   r   r   r4   pyasn1staticmethodrx   rs   rw   r{   r   r   r   r   r   r   re   ?  s   re   c               @   s(   e Zd ZdZdd Zdd Zdd ZdS )	ForwardingMixina  
    Template class for tests of the Conch server's ability to forward arbitrary
    protocols over SSH.

    These tests are integration tests, not unit tests. They launch a Conch
    server, a custom TCP server (just an L{EchoProtocol}) and then call
    L{execute}.

    L{execute} is implemented by subclasses of L{ForwardingMixin}. It should
    cause an SSH client to connect to the Conch server, asking it to forward
    data to the custom TCP server.
    c             C   s   | j dt }|j| jdS )z
        Test that we can use whatever client to send the command "echo goodbye"
        to the Conch server. Make sure we receive "goodbye" back from the
        server.
        zecho goodbyes   goodbye
)executerA   addCallbackassertEqual)r,   rD   r   r   r   	test_exec  s    zForwardingMixin.test_execc             C   s>   | j  }t|d}| jd|d|| jf d}|j| jd |S )zy
        Test that we can use whatever client to forward a local port to a
        specified port on the server.
        s   test
rt   z-N -L%i:127.0.0.1:%i)sshArgs)rw   rM   r   r   r   r   )r,   	localPortprocessrD   r   r   r   test_localToRemoteForwarding  s    
z,ForwardingMixin.test_localToRemoteForwardingc             C   s>   | j  }t|d}| jd|d|| jf d}|j| jd |S )zs
        Test that we can use whatever client to forward a port from the server
        to a port locally.
        s   test
rt   z-N -R %i:127.0.0.1:%i)r   )rw   rM   r   r   r   r   )r,   r   r   rD   r   r   r   test_remoteToLocalForwarding  s    
z,ForwardingMixin.test_remoteToLocalForwardingN)r   r   r   r.   r   r   r   r   r   r   r   r     s   
r   c               @   s(   e Zd ZdZdd Zdd Zdd ZdS )	RekeyAvatara#  
    This avatar implements a shell which sends 60 numbered lines to whatever
    connects to it, then closes the session with a 0 exit status.

    60 lines is selected as being enough to send more than 2kB of traffic, the
    amount the client is configured to initiate a rekey after.
    c             C   s   t j|  t| jd< d S )Ns   session)r   rP   r	   ZchannelLookup)r,   r   r   r   rP     s    
zRekeyAvatar.__init__c                sH   t j }|j jt|  fdd}t|t   jd dS )zE
        Write 60 lines of data to the transport, then exit.
        c                sX   t | }|dkr6 j  jjjjdd j  nd|f }|jd}j| d S )N<   s   exit-statuss       zline #%02d
zutf-8)nextstopZsessionZconnZsendRequestr=   r^   r<   )Zcounteriline)callr;   r   r   r<     s    


z$RekeyAvatar.openShell.<locals>.writeg{Gz?N)r   ProtocolZmakeConnectionr
   r   r   rb   )r,   r;   r   r<   r   )r   r;   r   	openShell  s    
zRekeyAvatar.openShellc             C   s   dS )z2
        Ignore the close of the session.
        Nr   )r,   r   r   r   closed  s    zRekeyAvatar.closedN)r   r   r   r.   rP   r   r   r   r   r   r   r     s   !r   c               @   s   e Zd ZdZdd ZdS )
RekeyRealmzS
    This realm gives out new L{RekeyAvatar} instances for any avatar request.
    c             G   s   |d t  dd fS )Nr   c               S   s   d S )Nr   r   r   r   r   rf     s    z*RekeyRealm.requestAvatar.<locals>.<lambda>)r   )r,   ZavatarIDZmindZ
interfacesr   r   r   requestAvatar  s    zRekeyRealm.requestAvatarN)r   r   r   r.   r   r   r   r   r   r     s   r   c               @   s   e Zd ZdZeZdd ZdS )RekeyTestsMixinzp
    TestCase mixin which defines tests exercising L{SSHTransportBase}'s handling
    of rekeying messages.
    c                s.   t  } jd|d} fdd}|j| |S )z
        After a client-initiated rekey is completed, application data continues
        to be passed over the SSH connection.
        rt   z-o RekeyLimit=2Kc                s6   dj dd tdD d }|jd} j| | d S )N
c             S   s   g | ]}d |f qS )z
line #%02dr   ).0r   r   r   r   
<listcomp>  s    zFRekeyTestsMixin.test_clientRekey.<locals>.finished.<locals>.<listcomp>r   zutf-8)joinranger^   r   )resultZexpectedResult)r,   r   r   finished  s    
z2RekeyTestsMixin.test_clientRekey.<locals>.finished)rA   r   r   )r,   r   rD   r   r   )r,   r   test_clientRekey  s
    
z RekeyTestsMixin.test_clientRekeyN)r   r   r   r.   r   rx   r   r   r   r   r   r     s   r   c               @   s"   e Zd ZedsdZdddZdS )OpenSSHClientMixinsshz$no ssh command-line client availablert   c                s.   t tdd d} fdd}|j|S )	a  
        Connects to the SSH server started in L{ConchServerSetupMixin.setUp} by
        running the 'ssh' command line tool.

        @type remoteCommand: str
        @param remoteCommand: The command (with arguments) to run on the
        remote end.

        @type process: L{ConchTestOpenSSHProcess}

        @type sshArgs: str
        @param sshArgs: Arguments to pass to the 'ssh' process.

        @return: L{defer.Deferred}
        r   r   -oPubkeyAcceptedKeyTypes=ssh-dss-Vc                s   | dkrd}nd}t j  _d|  d  }jj j}|| j }g }x*|D ]"}t|trj|j	d}|j
| qRW tj tdd |  jS )Nr   z!-oPubkeyAcceptedKeyTypes=ssh-dss rt   zssh -2 -l testuser -p %i -F /dev/null -oUserKnownHostsFile=kh_test -oPasswordAuthentication=no -oHostKeyAlgorithms=ssh-rsa -a -i dsa_test z 127.0.0.1 zutf-8r   )r   DeferredrC   r}   r   rN   splitr]   r   r^   r_   r   spawnProcessr   )ZstatusZoptsZcmdlinerN   cmdsencodedCmdscmd)r   remoteCommandr,   r   r   r   hasPAKT8  s    



z+OpenSSHClientMixin.execute.<locals>.hasPAKT)r   r   r   )r   r   r   )r,   r   r   r   rD   r   r   )r   r   r,   r   r   r   "  s    zOpenSSHClientMixin.executeN)rt   )r   r   r   r   r4   r   r   r   r   r   r     s   r   c               @   sP   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d Zdd Z	dd Z
dd ZdS )OpenSSHKeyExchangeTestsz\
    Tests L{SSHTransportBase}'s key exchange algorithm compatibility with
    OpenSSH.
    c             C   s   g }y>t jtdd ddgt jd}t|ts8|jd}|j }W n   Y nX ||krhtj	dj
|| jdt d	| }|j| jd
S )aI  
        Call execute() method of L{OpenSSHClientMixin} with an ssh option that
        forces the exclusive use of the key exchange algorithm specified by
        keyExchangeAlgo

        @type keyExchangeAlgo: L{str}
        @param keyExchangeAlgo: The key exchange algorithm to use

        @return: L{defer.Deferred}
        r   r   z-QZkex)stderrzutf-8z{} not supported by ssh clientz
echo helloz-oKexAlgorithms=s   hello
)
subprocessZcheck_outputr   ZSTDOUTr]   strdecoder   r   SkipTestrI   r   rA   r   r   )r,   ZkeyExchangeAlgoZkexAlgorithmsoutputrD   r   r   r   assertExecuteWithKexAlgorithm_  s     




z5OpenSSHKeyExchangeTests.assertExecuteWithKexAlgorithmc             C   s
   | j dS )zb
        The ecdh-sha2-nistp256 key exchange algorithm is compatible with
        OpenSSH
        zecdh-sha2-nistp256)r   )r,   r   r   r   test_ECDHSHA256~  s    z'OpenSSHKeyExchangeTests.test_ECDHSHA256c             C   s
   | j dS )zb
        The ecdh-sha2-nistp384 key exchange algorithm is compatible with
        OpenSSH
        zecdh-sha2-nistp384)r   )r,   r   r   r   test_ECDHSHA384  s    z'OpenSSHKeyExchangeTests.test_ECDHSHA384c             C   s
   | j dS )zb
        The ecdh-sha2-nistp521 key exchange algorithm is compatible with
        OpenSSH
        zecdh-sha2-nistp521)r   )r,   r   r   r   test_ECDHSHA521  s    z'OpenSSHKeyExchangeTests.test_ECDHSHA521c             C   s
   | j dS )zl
        The diffie-hellman-group14-sha1 key exchange algorithm is compatible
        with OpenSSH.
        zdiffie-hellman-group14-sha1)r   )r,   r   r   r   test_DH_GROUP14  s    z'OpenSSHKeyExchangeTests.test_DH_GROUP14c             C   s
   | j dS )zs
        The diffie-hellman-group-exchange-sha1 key exchange algorithm is
        compatible with OpenSSH.
        z"diffie-hellman-group-exchange-sha1)r   )r,   r   r   r   test_DH_GROUP_EXCHANGE_SHA1  s    z3OpenSSHKeyExchangeTests.test_DH_GROUP_EXCHANGE_SHA1c             C   s
   | j dS )zu
        The diffie-hellman-group-exchange-sha256 key exchange algorithm is
        compatible with OpenSSH.
        z$diffie-hellman-group-exchange-sha256)r   )r,   r   r   r   test_DH_GROUP_EXCHANGE_SHA256  s    z5OpenSSHKeyExchangeTests.test_DH_GROUP_EXCHANGE_SHA256c             C   s   | j tj| jd dS )zy
        The list of key exchange algorithms supported
        by OpenSSH client is obtained with C{ssh -Q kex}.
        zunsupported-algorithmN)ZassertRaisesr   r   r   )r,   r   r   r   test_unsupported_algorithm  s    z2OpenSSHKeyExchangeTests.test_unsupported_algorithmN)r   r   r   r.   r   r   r   r   r   r   r   r   r   r   r   r   r   X  s   						r   c               @   s"   e Zd ZdZdd Zesde_dS )OpenSSHClientForwardingTestszR
    Connection forwarding tests run against the OpenSSL command line client.
    c             C   s>   | j  }t|d}| jd|d|| jf d}|j| jd |S )zG
        Forwarding of arbitrary IPv6 TCP connections via SSH.
        s   test
rt   z-N -L%i:[::1]:%i)r   )rw   rM   r   r   r   r   )r,   r   r   rD   r   r   r   test_localToRemoteForwardingV6  s    
z;OpenSSHClientForwardingTests.test_localToRemoteForwardingV6zRequires IPv6 supportN)r   r   r   r.   r   r   r4   r   r   r   r   r     s   r   c               @   s   e Zd ZdZdS )OpenSSHClientRekeyTestszE
    Rekeying tests run against the OpenSSL command line client.
    N)r   r   r   r.   r   r   r   r   r     s   r   c               @   s8   e Zd ZdZejdkrdZdddZdd	 Zd
d Z	dS )CmdLineClientTestszP
    Connection forwarding tests run against the Conch command line client.
    Zwin32z!can't run cmdline client on win32rt   Nc             C   s   |dkrg }t j |_| jj j}dj|| d | }t||j  }t	j
j }t	jjtj|d< g }	i }
x*|D ]"}t|tr|jd}|	j| qrW xD|D ]<}|| }t|tr|jd}t|tr|jd}||
|< qW tj|tj|	|
d |jS )z{
        As for L{OpenSSHClientTestCase.execute}, except it runs the 'conch'
        command line tool, not 'ssh'.
        Nz[-p {} -l testuser --known-hosts kh_test --user-authentications publickey -a -i dsa_test -v z 127.0.0.1 
PYTHONPATHzutf-8)env)r   r   rC   r}   r   rN   rI   rd   r   rm   environcopypathsepr   rZ   rn   r]   r   r^   r_   r   r   r[   )r,   r   r   r   	conchArgsrN   r   r   r   r   Z
encodedEnvvarvalr   r   r   r     s.    









zCmdLineClientTests.executec                sV    fdd}t jj  jdt dd jddgd}|jjd	 |j| |S )
z4
        It can store logs to a local file.
        c                s    j  }jd| d S )Ns   Log opened.)Z
getContentZassertIn)r   Z
logContent)logPathr,   r   r   cb_check_log  s    z<CmdLineClientTests.test_runWithLogFile.<locals>.cb_check_logzecho goodbyez--logz	--logfilez--host-key-algorithmszssh-rsa)r   r   r   s   goodbye
)r   ZFilePathZmktempr   rA   rn   r   r   )r,   r   rD   r   )r   r,   r   test_runWithLogFile	  s    
z&CmdLineClientTests.test_runWithLogFilec             C   s"   | j dt d}|j| jd |S )zH
        Do not use --host-key-algorithms flag on command line.
        zecho goodbye)r   r   s   goodbye
)r   rA   r   r   )r,   rD   r   r   r   %test_runWithNoHostAlgorithmsSpecified  s
    
z8CmdLineClientTests.test_runWithNoHostAlgorithmsSpecified)rt   N)
r   r   r   r.   r   ZplatformTyper4   r   r   r   r   r   r   r   r     s   

%r   )rY   )Srm   rZ   r%   r   	itertoolsr   Zzope.interfacer   Ztwisted.python.reflectr   r   Ztwisted.conch.errorr   Ztwisted.conch.avatarr   Ztwisted.conch.ssh.sessionr   r	   r
   Ztwisted.conch.interfacesZtwisted.credr   Ztwisted.internetr   r   r   Ztwisted.internet.errorr   Ztwisted.internet.taskr   Ztwisted.internet.utilsr   Ztwisted.pythonr   r   r   Ztwisted.python.compatr   Ztwisted.trialr   Ztwisted.conch.scripts.conchr0   ImportErrorer   r3   Ztwisted.conch.test.test_sshr   Ztwisted.python.procutilsr   Ztwisted.conch.test.keydatar   r   r    r!   r"   r#   r   r)   r   objectr*   ZTestCaser/   r   r5   ZFactoryr@   ZProcessProtocolrA   rM   rR   rd   re   r   r   r   r   r   r   r   r   r   r   r   r   r   <module>   s   

%U"
O95	;f