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


W[@-�@s*dZddlmZmZddlZddlmZed�rzed�rzddlmZddl	m
Z
dd	lmZdd
l
mZddlmZdZndZdd
lmZddlmZddlmZddlmZddlmZddlmZddlmZe� �r�dZ!neZ!dZ"ej#�$�s�dZ"ej%�$��sdZ"Gdd�de�Z&Gdd�de�Z'dS)z,
Tests for L{twisted.conch.client.default}.
�)�absolute_import�divisionN)�
requireModuleZcryptographyZpyasn1)�SSHAgentClient)�SSHUserAuthClient)�ConchOptions)�default)�KeyzBcryptography and PyASN1 required for twisted.conch.client.default.)�TestCase)�FilePath)�
ConchError)�keydata)�StringTransport)�nativeString)�platformzlgenericAnswers and getPassword does not work on Windows. Should be fixed as part of fixing bug 6409 and 6410z#sys.stdin is not an interactive ttyz$sys.stdout is not an interactive ttyc@s�eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Ze
pZee_dd�Ze
plee_dd�Ze
p~ee_dd�Ze
p�ee_dS)�SSHUserAuthClientTestszm
    Tests for L{SSHUserAuthClient}.

    @type rsaPublic: L{Key}
    @ivar rsaPublic: A public RSA key.
    cCsZt�tj�|_t|���|_|j��|j�	d�|_
|j
�tj�|j�	d��tj�dS)NZid_rsa�
id_rsa.pub)
r	�
fromStringr
ZpublicRSA_openssh�	rsaPublicrZmktemp�tmpdir�makedirs�child�rsaFile�
setContent�privateRSA_openssh��self�r�A/usr/lib/python3/dist-packages/twisted/conch/test/test_default.py�setUp7s
zSSHUserAuthClientTests.setUpcCsftdt�d�}t�}t�}|�|�||_d}|�|j|�|�|�	�d|j�
�d|d�dS)z�
        When connected to an agent, L{SSHUserAuthClient} can use it to
        request signatures of particular data with a particular L{Key}.
        �userNs	Sign heres	-
s	s)rrrrZmakeConnection�keyAgentZsignDatar�assertEqual�value�blob)r�client�agent�	transportZ	cleartextrrr�test_signDataWithAgent@s"
����z-SSHUserAuthClientTests.test_signDataWithAgentcCsJt�}|j��g|_|��}|�|���|�||j�|�|���dS)a
        L{SSHUserAuthClient} looks up public keys from the agent using the
        L{SSHAgentClient} class.  That L{SSHAgentClient.getPublicKey} returns a
        L{Key} object with one of the public keys in the agent.  If no more
        keys are present, it returns L{None}.
        N)	rrr$Zblobs�getPublicKey�
assertTrue�isPublicr"ZassertIsNone)rr&�keyrrr�test_agentGetPublicKeySsz-SSHUserAuthClientTests.test_agentGetPublicKeycCsFt�}|jjg|_td|d�}|��}|�|���|�||j	�dS)z�
        L{SSHUserAuthClient.getPublicKey()} is able to get a public key from
        the first file described by its options' C{identitys} list, and return
        the corresponding public L{Key} object.
        r N)
rr�path�	identitysrr)r*r+r"r)r�optionsr%r,rrr�test_getPublicKeyFromFilebsz0SSHUserAuthClientTests.test_getPublicKeyFromFilecCsRt�}|jjg|_t�}td|d�}||_|��}|�|�	��|�
||j�dS)z�
        If an agent is present, but doesn't return a key,
        L{SSHUserAuthClient.getPublicKey} continue with the normal key lookup.
        r N)rrr.r/rrr!r)r*r+r"r)rr0r&r%r,rrr�test_getPublicKeyAgentFallbackpsz5SSHUserAuthClientTests.test_getPublicKeyAgentFallbackcCs�t�}|j�d��tj�|j�d�}|�tj�|jj|jg|_	|j�d��d�t
d|d�}|��}|�|�
��|�|t�tj��|�|j|jj|jg�dS)z�
        If L{keys.Key.fromFile} raises a L{keys.BadKeyError}, the
        L{SSHUserAuthClient.getPublicKey} tries again to get a public key by
        calling itself recursively.
        z
id_dsa.pubZid_dsars
not a key!r N)rrrrr
ZpublicDSA_opensshZprivateDSA_opensshrr.r/rr)r*r+r"r	rZ	usedFiles)rr0ZdsaFiler%r,rrr�test_getPublicKeyBadKeyErrorsz3SSHUserAuthClientTests.test_getPublicKeyBadKeyErrorcsNt�tj��t�}�jjg|_td|d�}|�	���fdd�}|�
��|�S)z�
        L{SSHUserAuthClient.getPrivateKey} will load a private key from the
        last used file populated by L{SSHUserAuthClient.getPublicKey}, and
        return a L{Deferred} which fires with the corresponding private L{Key}.
        r Ncs��|�����|��dS�N�ZassertFalser+r"�r,��
rsaPrivaterrr�_cbGetPrivateKey�szCSSHUserAuthClientTests.test_getPrivateKey.<locals>._cbGetPrivateKey)r	rr
rrrr.r/rr)�
getPrivateKey�addCallback)rr0r%r9rr7r�test_getPrivateKey�sz)SSHUserAuthClientTests.test_getPrivateKeycs�t�tj��d��j���d���t�}�jjg|_	t
d|d�}|����fdd�}��fdd�}��|d	|�|�
��|�S)
z�
        L{SSHUserAuthClient} can get a private key from a file, and return a
        Deferred called back with a private L{Key} object, even if the key is
        encrypted.
        sthis is the passphraseZopensshr Ncs��|d�jjf�t��S)NzEnter passphrase for key '%s': )r"rr.r��prompt)�
passphraserrr�_getPassword�s
�zISSHUserAuthClientTests.test_getPrivateKeyPassphrase.<locals>._getPasswordcs��|�����|��dSr4r5r6r7rrr9�szMSSHUserAuthClientTests.test_getPrivateKeyPassphrase.<locals>._cbGetPrivateKeyr@)r	rr
rrrZtoStringrr.r/rr)�patchr:r;)rr0r%r@r9r)r?r8rr�test_getPrivateKeyPassphrase�sz3SSHUserAuthClientTests.test_getPrivateKeyPassphrasecs`Gdd�d�}t�}td|d�}|d�|_�fdd�}��tjd|�|��}|��jd	�|S)
zn
        Get the password using
        L{twisted.conch.client.default.SSHUserAuthClient.getPassword}
        c@seZdZdd�Zdd�ZdS)z>SSHUserAuthClientTests.test_getPassword.<locals>.FakeTransportcSs||_||_dSr4)r'�host)rrCrrr�__init__�szGSSHUserAuthClientTests.test_getPassword.<locals>.FakeTransport.__init__cSs|Sr4rrrrr�getPeer�szFSSHUserAuthClientTests.test_getPassword.<locals>.FakeTransport.getPeerN)�__name__�
__module__�__qualname__rDrErrrr�
FakeTransport�srIr Nz	127.0.0.1cs��|d�dS)Nzuser@127.0.0.1's password: �bad password�r"r=rrr�getpass�sz8SSHUserAuthClientTests.test_getPassword.<locals>.getpassrL�bad password)	rrr'rArrL�getPasswordr;r")rrIr0r%rL�drrr�test_getPassword�s
z'SSHUserAuthClientTests.test_getPasswordcsPt�}td|d�}d���fdd�}��tjd|�|���}|��jd�|S)z�
        Get the password using
        L{twisted.conch.client.default.SSHUserAuthClient.getPassword}
        using a different prompt.
        r NsGive up your passwordcs��|t���dS)NrJ)r"r)�p�r>rrrrL�sz>SSHUserAuthClientTests.test_getPasswordPrompt.<locals>.getpassrLrM)rrrArrLrNr;r")rr0r%rLrOrrRr�test_getPasswordPrompt�s
z-SSHUserAuthClientTests.test_getPasswordPromptcsht�}td|d�}dd�}��tjd|�tjtj��|�d�}|j	���fdd��}��
|t�dS)	z�
        Get the password using
        L{twisted.conch.client.default.SSHUserAuthClient.getPassword}
        and trigger a {twisted.conch.error import ConchError}.
        r NcSstd��dS)NzUser pressed CTRL-C)�KeyboardInterruptr=rrrrL�szBSSHUserAuthClientTests.test_getPasswordConchError.<locals>.getpassrL�?cs����gtjtjg�|Sr4)r"�sys�stdout�stdin)Zfail�rrXrWrr�	check_syss

�zDSSHUserAuthClientTests.test_getPasswordConchError.<locals>.check_sys)rrrArrLrVrWrXrNZ
addErrbackZ
assertFailurer)rr0r%rLrOrZrrYr�test_getPasswordConchError�s
z1SSHUserAuthClientTests.test_getPasswordConchErrorcspt�}td|d�}�fdd�}��tjd|��fdd�}��td|�|�d	d
ddg�}|��jddg�|S)
zU
        L{twisted.conch.client.default.SSHUserAuthClient.getGenericAnswers}
        r Ncs��|d�dS)Nzpass promptrLrKr=rrrrLsz>SSHUserAuthClientTests.test_getGenericAnswers.<locals>.getpassrLcs��|d�dS)Nzraw_input prompt�	raw_inputrKr=rrrr\sz@SSHUserAuthClientTests.test_getGenericAnswers.<locals>.raw_inputr\sNamesInstruction)spass promptF)sraw_input promptT)rrrArrLZgetGenericAnswersr;ZassertListEqual)rr0r%rLr\rOrrr�test_getGenericAnswerss$���z-SSHUserAuthClientTests.test_getGenericAnswersN)rFrGrH�__doc__rr(r-r1r2r3r<rBrP�windowsSkip�ttySkip�skiprSr[r]rrrrr/s"	


rc@s eZdZdZdd�Zdd�ZdS)�ConchOptionsParsingz
    Options parsing.
    cCs�t�}|�t|jd�}|�d|j�t�}|�d�|�|ddg�|�d�|�|ddg�|�d�|�|dddd	g�d
S)z)
        Specify MAC algorithms.
        zinvalid-maczUnknown mac typez
hmac-sha2-512Zmacss
hmac-sha2-512z hmac-sha2-256,hmac-sha1,hmac-md5s
hmac-sha2-256s	hmac-sha1shmac-md5N)r�assertRaises�
SystemExitZopt_macs�assertIn�coder"�rZopts�errr�	test_macs0s


zConchOptionsParsing.test_macscCs�t�}|�t|jd�}|�d|j�t�}|�d�|�|ddg�|�d�|�|ddg�|�d�|�|dddg�dS)	z.
        Specify host key algorithms.
        zinvalid-keyzUnknown host key typezssh-rsazhost-key-algorithmssssh-rsasssh-dsszssh-rsa,ssh-dssN)rrcrdZopt_host_key_algorithmsrerfr"rgrrr�test_host_key_algorithms@s


z,ConchOptionsParsing.test_host_key_algorithmsN)rFrGrHr^rirjrrrrrb,srb)(r^Z
__future__rrrVZtwisted.python.reflectrZtwisted.conch.client.agentrZtwisted.conch.client.defaultrZtwisted.conch.client.optionsrZtwisted.conch.clientrZtwisted.conch.ssh.keysr	raZtwisted.trial.unittestr
Ztwisted.python.filepathrZtwisted.conch.errorrZtwisted.conch.testr
Ztwisted.test.proto_helpersrZtwisted.python.compatrZtwisted.python.runtimerZ	isWindowsr_r`rX�isattyrWrrbrrrr�<module>s<�
~