%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_default.cpython-312.pyc

�

Ϫ�f-���dZddlZddlmZddlmZddlmZddlm	Z	ddl
mZddlm
Z
dd	lmZdd
lmZddlmZdZd
Zed�rddlmZddlmZddlmZddlmZddlmZndZdZeZ ejB�rdZdZejDjG�sdZdZejHjG�sdZdZGd�de�Z%Gd�de�Z&y)z,
Tests for L{twisted.conch.client.default}.
�N)�skipIf)�
ConchError)�keydata)�StringTransport)�nativeString)�FilePath)�
requireModule)�platform)�TestCaseF��cryptography)�default)�SSHAgentClient)�SSHUserAuthClient)�ConchOptions)�KeyTz7cryptography required for twisted.conch.client.default.zlgenericAnswers 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��eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zee
e�d
��Zee
e�d��Zee
e�d��Zee
e�d
��Zy)�SSHUserAuthClientTestszm
    Tests for L{SSHUserAuthClient}.

    @type rsaPublic: L{Key}
    @ivar rsaPublic: A public RSA key.
    c���tjtj�|_t|j
��|_|jj�|jjd�|_
|jjtj�|jjd�jtj�y)N�id_rsa�
id_rsa.pub)
r�
fromStringr�publicRSA_openssh�	rsaPublicr�mktemp�tmpdir�makedirs�child�rsaFile�
setContent�privateRSA_openssh��selfs �A/usr/lib/python3/dist-packages/twisted/conch/test/test_default.py�setUpzSSHUserAuthClientTests.setUp:s�������(A�(A�B����t�{�{�}�-����������{�{�(�(��2��������� :� :�;������,�'�2�2�7�3L�3L�M�c�J�tdt�d�}t�}t�}|j	|�||_d}|j
|j|�|j|j�d|jj�zdz|zdz�y)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)rrrr�makeConnection�keyAgent�signDatar�assertEqual�value�blob)r#�client�agent�	transport�	cleartexts     r$�test_signDataWithAgentz-SSHUserAuthClientTests.test_signDataWithAgentBs���
#�7�L�N�D�A��� ��#�%�	�
���Y�'���� �	�������	�2�����O�O��1��n�n�!�!�#�
$��
 ��
�"�	
"�	
r&c�,�t�}|jj�g|_|j	�}|j|j
��|j||j�|j|j	��y)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.�blobs�getPublicKey�
assertTrue�isPublicr,�assertIsNone)r#r0�keys   r$�test_agentGetPublicKeyz-SSHUserAuthClientTests.test_agentGetPublicKeyWsn��� ���~�~�*�*�,�-���� � �"���������'�����d�n�n�-����%�,�,�.�/r&c��t�}|jjg|_t	d|d�}|j�}|j
|j��|j||j�y)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�	identitysrr6r7r8r,r)r#�optionsr/r:s    r$�test_getPublicKeyFromFilez0SSHUserAuthClientTests.test_getPublicKeyFromFileesb���.��!�\�\�.�.�/���"�7�G�T�:���!�!�#���������'�����d�n�n�-r&c�"�t�}|jjg|_t	�}td|d�}||_|j�}|j|j��|j||j�y)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*r6r7r8r,r)r#r?r0r/r:s     r$�test_getPublicKeyAgentFallbackz5SSHUserAuthClientTests.test_getPublicKeyAgentFallbackrsq��
�.��!�\�\�.�.�/���� ��"�7�G�T�:������!�!�#���������'�����d�n�n�-r&c���t�}|jjd�jtj
�|jjd�}|jtj�|jj|jg|_	|jjd�jd�td|d�}|j�}|j|j��|j|tj tj
��|j|j"|jj|jg�y)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.pub�id_dsars
not a key!r(N)rrrr r�publicDSA_openssh�privateDSA_opensshrr=r>rr6r7r8r,rr�	usedFiles)r#r?�dsaFiler/r:s     r$�test_getPublicKeyBadKeyErrorz3SSHUserAuthClientTests.test_getPublicKeyBadKeyError�s���.�������,�'�2�2�7�3L�3L�M��+�+�#�#�H�-�����7�5�5�6�!�\�\�.�.����=��������,�'�2�2�=�A�"�7�G�T�:���!�!�#���������'�����c�n�n�W�-F�-F�G�H�����)�)�D�L�L�,=�,=�w�|�|�+L�Mr&c����tjtj��t	�}�j
jg|_td|d�}|j���fd�}|j�j|�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(Nc�h���j|j���j|��y�N��assertFalser8r,�r:�
rsaPrivater#s ��r$�_cbGetPrivateKeyzCSSHUserAuthClientTests.test_getPrivateKey.<locals>._cbGetPrivateKey��'������S�\�\�^�,����S�*�-r&)rrrr!rrr=r>rr6�
getPrivateKey�addCallback)r#r?r/rQrPs`   @r$�test_getPrivateKeyz)SSHUserAuthClientTests.test_getPrivateKey�sq����^�^�G�$>�$>�?�
��.��!�\�\�.�.�/���"�7�G�T�:������	.��#�#�%�1�1�2B�C�Cr&c�����tjtj��d��jj�j
d����t�}�jjg|_	td|d�}|j���fd�}��fd�}�j|d|�|j�j|�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 passphrase�openssh)�
passphraser(Nc�n���j|d�jj�d��t��S)NzEnter passphrase for key 'z': )r,rr=r)�promptrXr#s ��r$�_getPasswordzISSHUserAuthClientTests.test_getPrivateKeyPassphrase.<locals>._getPassword�s8�������4�T�\�\�5F�5F�4G�s�K�
� �
�+�+r&c�h���j|j���j|��yrLrMrOs ��r$rQzMSSHUserAuthClientTests.test_getPrivateKeyPassphrase.<locals>._cbGetPrivateKey�rRr&r[)rrrr!rr �toStringrr=r>rr6�patchrSrT)r#r?r/r[rQrXrPs`    @@r$�test_getPrivateKeyPassphrasez3SSHUserAuthClientTests.test_getPrivateKeyPassphrase�s�����^�^�G�$>�$>�?�
�.�
������
� 3� 3�I�*� 3� U�V��.��!�\�\�.�.�/���"�7�G�T�:������	,�	.�	
�
�
�6�>�<�8��#�#�%�1�1�2B�C�Cr&c���Gd�d�}t�}td|d�}|d�|_�fd�}�jtj
d|�|j
�}|j�jd�|S)	zn
        Get the password using
        L{twisted.conch.client.default.SSHUserAuthClient.getPassword}
        c��eZdZd�Zd�Zy)�>SSHUserAuthClientTests.test_getPassword.<locals>.FakeTransportc� �||_||_yrL)r1�host)r#rds  r$�__init__zGSSHUserAuthClientTests.test_getPassword.<locals>.FakeTransport.__init__�s��!%��� ��	r&c��|SrL�r"s r$�getPeerzFSSHUserAuthClientTests.test_getPassword.<locals>.FakeTransport.getPeer�s���r&N)�__name__�
__module__�__qualname__rerhrgr&r$�
FakeTransportrb�s��
!�
r&rlr(Nz	127.0.0.1c�*���j|d�y)Nzuser@127.0.0.1's password: �bad password�r,�rZr#s �r$�getpassz8SSHUserAuthClientTests.test_getPassword.<locals>.getpass�s������V�%B�C�!r&rq�bad password)	rrr1r^rrq�getPasswordrTr,)r#rlr?r/rq�ds`     r$�test_getPasswordz'SSHUserAuthClientTests.test_getPassword�ss���	�	��.��"�7�G�T�:��(��5���	"�	
�
�
�7�?�?�I�w�7���� ��	�
�
�d�&�&��8��r&c�����t�}td|d�}d���fd�}�jtjd|�|j��}|j
�jd�|S)z�
        Get the password using
        L{twisted.conch.client.default.SSHUserAuthClient.getPassword}
        using a different prompt.
        r(NsGive up your passwordc�<���j|t���y)Nrn)r,r)�prZr#s ��r$rqz>SSHUserAuthClientTests.test_getPasswordPrompt.<locals>.getpass�s������Q��V� 4�5�!r&rqrr)rrr^rrqrsrTr,)r#r?r/rqrtrZs`    @r$�test_getPasswordPromptz-SSHUserAuthClientTests.test_getPasswordPrompt�sc����.��"�7�G�T�:��)��	"�	
�
�
�7�?�?�I�w�7����v�&��	�
�
�d�&�&��8��r&c�<����t�}td|d�}d�}�jtjd|�t
jt
jc��|jd�}|j���fd��}�j|t�y)z�
        Get the password using
        L{twisted.conch.client.default.SSHUserAuthClient.getPassword}
        and trigger a {twisted.conch.error import ConchError}.
        r(Nc��td��)NzUser pressed CTRL-C)�KeyboardInterrupt)rZs r$rqzBSSHUserAuthClientTests.test_getPasswordConchError.<locals>.getpass�s��#�$9�:�:r&rq�?c�l���j��gtjtjg�|SrL)r,�sys�stdout�stdin)�failr#r�r�s ���r$�	check_syszDSSHUserAuthClientTests.test_getPasswordConchError.<locals>.check_syss)������f�e�_�s�z�z�3�9�9�.E�F��Kr&)rrr^rrqrr�r�rs�
addErrback�
assertFailurer)r#r?r/rqrtr�r�r�s`     @@r$�test_getPasswordConchErrorz1SSHUserAuthClientTests.test_getPasswordConchError�s�����.��"�7�G�T�:��	;�	
�
�
�7�?�?�I�w�7��
�
�C�I�I�
������t�$��	
���	�
�	�	
���1�j�)r&c� ��t�}td|d�}�fd�}�jtjd|��fd�}�jtd|�|jddd	d
g�}|j
�jddg�|S)zU
        L{twisted.conch.client.default.SSHUserAuthClient.getGenericAnswers}
        r(Nc�*���j|d�y)Nzpass promptrqrorps �r$rqz>SSHUserAuthClientTests.test_getGenericAnswers.<locals>.getpasss������V�]�3�r&rqc�*���j|d�y)Nzraw_input prompt�	raw_inputrorps �r$r�z@SSHUserAuthClientTests.test_getGenericAnswers.<locals>.raw_inputs������V�%7�8�r&�_inputsNamesInstruction)spass promptF)sraw_input promptTr�)rrr^rrq�getGenericAnswersrT�assertListEqual)r#r?r/rqr�rts`     r$�test_getGenericAnswersz-SSHUserAuthClientTests.test_getGenericAnswers	s����
�.��"�7�G�T�:��	�	
�
�
�7�?�?�I�w�7�	�	
�
�
�7�H�i�0��$�$���
$�&A�B�
��
	
�
�
�d�*�*�Y��,D�E��r&N)rirjrk�__doc__r%r3r;r@rBrIrUr_r�doSkip�
skipReasonruryr�r�rgr&r$rr2s����N�
�*0�.�.�N�$D�&D�8�F�J��� ��6�F�J��� ��&�F�J��*� �*�.�F�J��� �r&rc��eZdZdZd�Zd�Zy)�ConchOptionsParsingz
    Options parsing.
    c��t�}|jt|jd�}|j	d|j
�t�}|jd�|j
|ddg�|jd�|j
|ddg�|jd�|j
|dgd��y)	z)
        Specify MAC algorithms.
        zinvalid-maczUnknown mac typez
hmac-sha2-512�macss
hmac-sha2-512z hmac-sha2-256,hmac-sha1,hmac-md5)s
hmac-sha2-256s	hmac-sha1shmac-md5N)r�assertRaises�
SystemExit�opt_macs�assertIn�coder,�r#�opts�es   r$�	test_macszConchOptionsParsing.test_macs*s����~�����j�$�-�-��G���
�
�(�!�&�&�1��~���
�
�o�&�����f��(8�'9�:��
�
�&�'�����f��(8�'9�:��
�
�8�9�����f��'T�Ur&c��t�}|jt|jd�}|j	d|j
�t�}|jd�|j
|ddg�|jd�|j
|ddg�|jd�|j
|dddg�y)	z.
        Specify host key algorithms.
        zinvalid-keyzUnknown host key typezssh-rsazhost-key-algorithmssssh-rsasssh-dsszssh-rsa,ssh-dssN)rr�r��opt_host_key_algorithmsr�r�r,r�s   r$�test_host_key_algorithmsz,ConchOptionsParsing.test_host_key_algorithms9s����~�����j�$�*F�*F�
�V���
�
�-�q�v�v�6��~���$�$�Y�/�����3�4�z�l�C��$�$�Z�0�����3�4�z�l�C��$�$�%6�7�����3�4�z�:�6N�Or&N)rirjrkr�r�r�rgr&r$r�r�%s���
V�
Pr&r�)'r�r�unittestr�twisted.conch.errorr�twisted.conch.testr�twisted.internet.testingr�twisted.python.compatr�twisted.python.filepathr�twisted.python.reflectr	�twisted.python.runtimer
�twisted.trial.unittestrr�r��twisted.conch.clientr�twisted.conch.client.agentr�twisted.conch.client.defaultr�twisted.conch.client.optionsr�twisted.conch.ssh.keysr�skip�	isWindowsr��isattyr�rr�rgr&r$�<module>r�s����
��*�&�4�.�,�0�+�+�	��
�
��� �,�9�>�9�*�
�F�J�J��D��8����
�F�	?��
�y�y����
�F�6�J�
�z�z����
�F�7�J�p�X�p�f!P�(�!Pr&

Zerion Mini Shell 1.0