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

�

Ϫ�f2�����dZddlZddlmZmZmZddlmZddl	m
Z
ddlmZm
Z
mZddlmZddlmZdd	lmZdd
lmZddlmZddlmZdd
lmZed�r#ddlmZddlm Z m!Z!m"Z"m#Z#m$Z$ddl%m&Z&m'Z'ddl(m)Z)ndZ*dZ+dZ,dZ-dZ.ee+�Z/ee,�Z0ee-�Z1ee.�Z2de+zdzZ3de,zdzZ4de+zdzZ5de+zdzZ6Gd�d�Z7Gd�d e7e�Z8Gd!�d"e8�Z9Gd#�d$e7ee�Z:Gd%�d&e:�Z;Gd'�d(ee7�Z<Gd)�d*e�Z=Gd+�d,e�Z>Gd-�d.�Z?Gd/�d0e�Z@Gd1�d2�ZAGd3�d4�ZBeed5�j��d6�Gd7�d8e��ZDy)9z/
Tests for L{twisted.conch.client.knownhosts}.
�N)�Error�
a2b_base64�
b2a_base64)�skipIf)�verifyObject)�HostKeyChanged�InvalidEntry�UserRejectedKey)�IKnownHostEntry)�Deferred)�
networkString)�FilePath)�
requireModule)�ComparisonTestsMixin)�TestCase�cryptography)�default)�	ConsoleUI�HashedEntry�KnownHostsFile�
PlainEntry�
UnparsedEntry)�BadKeyError�Key)�keydataz3cryptography required for twisted.conch.knownhosts.stAAAAB3NzaC1yc2EAAAABIwAAAQEAsV0VMRbGmzhqxxayLRHmvnFvtyNqgbNKV46dU1bVFB+3ytNvue4Riqv/SVkPRNwMb7eWH29SviXaBxUhYyzKkDoNUq3rTNnH1Vnif6d6X4JCrUb5d3W+DmYClyJrZ5HgD/hUpdSkTRqdbQ2TrvSAxRacj+vHHT4F4dm1bJSewm3B2D8HVOoi/CbVh3dsIiCdp8VltdZx4qYVfYe2LwVINCbAa3d3tj9ma7RVfw3OH2Mfb+toLd1N5tBQFb7oqTt2nC6I/6Bd4JwPUld+IEitw/suElq/AIJVQXXujeyiZlea90HE65U2mF1ytr17HTAIT2ySokJWyuBANGACk6iIaw==s�AAAAB3NzaC1yc2EAAAABIwAAAIEAwaeCZd3UCuPXhX39+/p9qO028jTF76DMVd9mPvYVDVXufWckKZauF7+0b7qm+ChT7kan6BzRVo4++gCVNfAlMzLysSt3ylmOR48tFpAfygg9UCX3DjHz0ElOOUKh3iifc9aUShD0OPaK3pR5JJ8jfiBfzSYWt/hDi/iZ4igsSs8=stAAAAB3NzaC1yc2EAAAABIwAAAQEAl/TQakPkePlnwCBRPitIVUTg6Z8VzN1en+DGkyo/evkmLw7o4NWR5qbysk9A9jXW332nxnEuAnbcCam9SHe1su1liVfyIK0+3bdn0YRB0sXIbNEtMs2LtCho/aV3cXPS+Cf1yut3wvIpaRnAzXxuKPCTXQ7/y0IXa8TwkRBH58OJa3RqfQ/NsSp5SAfdsrHyH2aitiVKm2jfbTKzSEqOQG/zq4J9GXTkq61gZugory/Tvl5/yPgSnOR6C9jVOMHf27ZPoRtyj9SY343Hd2QHiIE0KPZJEgCynKeWoKz8v6eTSK8n4rBnaqWdp8MnGZK1WGy05MguXbyCDuTC8AmJXQ==s�AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBIFwh3/zBANyPPIE60SMMfdKMYo3OvfvzGLZphzuKrzSt0q4uF+/iYqtYiHhryAwU/fDWlUQ9kck9f+IlpsNtY4=swww.twistedmatrix.com ssh-rsa �
sdivmod.com ssh-rsa s-www.twistedmatrix.com,198.49.126.131 ssh-rsa sE|1|gJbSEPBG9ZSBoZpHNtZBD1bHKBA=|bQv+0Xa0dByrwkA1EB0E7Xop/Fo= ssh-rsa c�(�eZdZdZd�Zd�Zd�Zd�Zy)�EntryTestsMixina<
    Tests for implementations of L{IKnownHostEntry}.  Subclasses must set the
    'entry' attribute to a provider of that interface, the implementation of
    that interface under test.

    @ivar entry: a provider of L{IKnownHostEntry} with a hostname of
    www.twistedmatrix.com and an RSA key of sampleKey.
    c�8�tt|j�y)zA
        The given entry should provide IKnownHostEntry.
        N)rr�entry��selfs �D/usr/lib/python3/dist-packages/twisted/conch/test/test_knownhosts.py�test_providesInterfacez&EntryTestsMixin.test_providesInterfacebs��	�_�d�j�j�1�c��|j}|j|jtjt
��|j|jd�y)a�
        Constructing a plain text entry from an unhashed known_hosts entry will
        result in an L{IKnownHostEntry} provider with 'keyString', 'hostname',
        and 'keyType' attributes.  While outside the interface in question,
        these attributes are held in common by L{PlainEntry} and L{HashedEntry}
        implementations; other implementations should override this method in
        subclasses.
        �ssh-rsaN)r �assertEqual�	publicKeyr�
fromString�	sampleKey�keyType)r"r s  r#�test_fromStringzEntryTestsMixin.test_fromStringhs>���
�
��������#�.�.��*C�D�������
�3r%c��tjt�}tjt�}|j	d|j
j
|��|j	d|j
j
|��y)zj
        L{IKnownHostEntry.matchesKey} checks to see if an entry matches a given
        SSH key.
        TFN)rr*r+�otherSampleKeyr(r �
matchesKey)r"�twistedmatrixDotCom�divmodDotComs   r#�test_matchesKeyzEntryTestsMixin.test_matchesKeyus`��
"�n�n�Y�7���~�~�n�5������t�z�z�4�4�5H�I�J������
�
� 5� 5�l� C�Dr%c��|j|jjd��|j|jjd��y)zl
        L{IKnownHostEntry.matchesHost} checks to see if an entry matches a
        given hostname.
        �www.twistedmatrix.comswww.divmod.comN)�
assertTruer �matchesHost�assertFalser!s r#�test_matchesHostz EntryTestsMixin.test_matchesHosts>��
	
����
�
�.�.�/G�H�I�������/�/�0A�B�Cr%N)�__name__�
__module__�__qualname__�__doc__r$r-r3r9�r%r#rrXs���2�4�E�Dr%rc�*�eZdZdZeZeZd�Zd�Z	d�Z
y)�PlainEntryTestsz'
    Test cases for L{PlainEntry}.
    c�L�tj|j�|_y)zU
        Set 'entry' to a sample plain-text entry with sampleKey as its key.
        N)rr*�
plaintextLiner r!s r#�setUpzPlainEntryTests.setUp�s�� �*�*�4�+=�+=�>��
r%c��tj|j�|_|j	|jjd��|j
�y)zU
        A "hostname,ip" formatted line will match both the host and the IP.
        s198.49.126.131N)rr*�
hostIPLiner r6r7r9r!s r#�test_matchesHostIPz"PlainEntryTests.test_matchesHostIP�sB�� �*�*�4�?�?�;��
�����
�
�.�.�/@�A�B����r%c�:�|j|jj�|jj	d��tj|j�}|j|j�|jj	d��y)z|
        L{PlainEntry.toString} generates the serialized OpenSSL format string
        for the entry, sans newline.
        rN)r(r �toStringrB�rstriprr*rE)r"�multiHostEntrys  r#�
test_toStringzPlainEntryTests.test_toString�sn��
	
������,�,�.��0B�0B�0I�0I�%�0P�Q�#�.�.�t���?������0�0�2�D�O�O�4J�4J�5�4Q�Rr%N)r:r;r<r=�samplePlaintextLinerB�sampleHostIPLinerErCrFrKr>r%r#r@r@�s#���(�M�!�J�?� �Sr%r@c�0�eZdZdZedddzZedddzZy)�PlainTextWithCommentTests�N
    Test cases for L{PlainEntry} when parsed from a line with a comment.
    N���� plain text comment.
s text following host/IP line
)r:r;r<r=rLrBrMrEr>r%r#rOrO�s-���(���,�/H�H�M�!�#�2�&�)J�J�Jr%rOc�&�eZdZdZeZd�Zd�Zd�Zy)�HashedEntryTestsaF
    Tests for L{HashedEntry}.

    This suite doesn't include any tests for host/IP pairs because hashed
    entries store IP addresses the same way as hostnames and does not support
    comma-separated lists.  (If you hash the IP and host together you can't
    tell if you've got the key already for one or the other.)
    c�L�tj|j�|_y)zo
        Set 'entry' to a sample hashed entry for twistedmatrix.com with
        sampleKey as its key.
        N)rr*�
hashedLiner r!s r#rCzHashedEntryTests.setUp�s��
!�+�+�D�O�O�<��
r%c��|j|jj�|jj	d��y)z�
        L{HashedEntry.toString} generates the serialized OpenSSL format string
        for the entry, sans the newline.
        rN)r(r rHrVrIr!s r#rKzHashedEntryTests.test_toString�s0��
	
������,�,�.����0F�0F�u�0M�Nr%c�N�d}d}tjt�}t|j	��}d}t|||||�}t|||||�}|j
||t|ddd�||||��|j
||t||ddd�|||��|j
||t|||ddd�||��|j
||t|||tjt�|��|j
||t|||||ddd���y)z�
        Two L{HashedEntry} instances compare equal if and only if they represent
        the same host and key in exactly the same way: the host salt, host hash,
        public key type, public key, and comment fields must all be equal.
        sgJbSEPBG9ZSBoZpHNtZBD1bHKBAsbQv+0Xa0dByrwkA1EB0E7Xop/Foshello, worldNrQ)rr*r+r
�typer�"assertNormalEqualityImplementationr/)r"�hostSalt�hostHashr)r,�commentr �	duplicates        r#�
test_equalityzHashedEntryTests.test_equality�s@��2��1���N�N�9�-�	��	��� 0�1��!���H�h���G�L����(�G�Y��P�	�	
�/�/������2����'�9�g�N�	
�	
�/�/�����(�4�R�4�.�'�9�g�N�	
�	
�/�/�����(�G�D�b�D�M�9�g�N�	
�	
�/�/�����(�G�S�^�^�N�-K�W�
�	
�	
�/�/�����(�G�Y���"��
�N�	
r%N)	r:r;r<r=�sampleHashedLinerVrCrKr_r>r%r#rTrT�s���"�J�=�O�2
r%rTc� �eZdZdZedddzZy)�HashedEntryWithCommentTestsrPNrQrR)r:r;r<r=r`rVr>r%r#rbrbs���"�#�2�&�)B�B�Jr%rbc�.�eZdZdZd�Zd�Zd�Zd�Zd�Zy)�UnparsedEntryTestsz$
    Tests for L{UnparsedEntry}
    c�$�td�|_y)zR
        Set up the 'entry' to be an unparsed entry for some random text.
        �    This is a bogus entry.  
N)rr r!s r#rCzUnparsedEntryTests.setUp
s��#�#D�E��
r%c�P�|jd|jj�y)ze
        Creating an L{UnparsedEntry} should simply record the string it was
        passed.
        rfN)r(r �_stringr!s r#r-z"UnparsedEntryTests.test_fromStrings��
	
���:�D�J�J�<N�<N�Or%c�X�|j|jjd��y)z:
        An unparsed entry can't match any hosts.
        r5N)r8r r7r!s r#r9z#UnparsedEntryTests.test_matchesHosts"��	
������/�/�0H�I�Jr%c��|j|jjtjt
���y)z9
        An unparsed entry can't match any keys.
        N)r8r r0rr*r+r!s r#r3z"UnparsedEntryTests.test_matchesKey s*��	
������.�.�s�~�~�i�/H�I�Jr%c�X�|jd|jj��y)zd
        L{UnparsedEntry.toString} returns its input string, sans trailing
        newline.
        s    This is a bogus entry.  N)r(r rHr!s r#rKz UnparsedEntryTests.test_toString&s"��
	
���8�$�*�*�:M�:M�:O�Pr%N)	r:r;r<r=rCr-r9r3rKr>r%r#rdrds%���F�P�K�K�Qr%rdc�F�eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zd
�Zy)�ParseErrorTestsa�
    L{HashedEntry.fromString} and L{PlainEntry.fromString} can raise a variety
    of errors depending on misformattings of certain strings.  These tests make
    sure those errors are caught.  Since many of the ways that this can go
    wrong are in the lower-level APIs being invoked by the parsing logic,
    several of these are integration tests with the C{base64} and
    L{twisted.conch.ssh.keys} modules.
    c�F�|jt|jd�y)zm
        If there are fewer than three elements, C{fromString} should raise
        L{InvalidEntry}.
        sinvalidN)�assertRaisesr	r*�r"�clss  r#�invalidEntryTestz ParseErrorTests.invalidEntryTest8s��
	
���,����
�Cr%c�F�|jt|jd�y)zX
        If the key is not base64, C{fromString} should raise L{BinasciiError}.
        sx x xN)ro�
BinasciiErrorr*rps  r#�
notBase64TestzParseErrorTests.notBase64Test?s��	
���-�����Br%c��|jt|jdj|dt	d�j�g��y)z�
        If the key portion of the entry is valid base64, but is not actually an
        SSH key, C{fromString} should raise L{BadKeyError}.
        � r'sHey, this isn't an SSH key!N)rorr*�joinr�strip)r"rq�prefixs   r#�
badKeyTestzParseErrorTests.badKeyTestEsA��
	
�����N�N��I�I���Z�0N�%O�%U�%U�%W�X�
�	
r%c�.�|jt�y)z�
        If there are fewer than three whitespace-separated elements in an
        entry, L{PlainEntry.fromString} should raise L{InvalidEntry}.
        N)rrrr!s r#�test_invalidPlainEntryz&ParseErrorTests.test_invalidPlainEntryRs��
	
���j�)r%c	���|jt�tj�\}}}|j	t
tjdj|dz||g��y)z�
        If there are fewer than three whitespace-separated elements in an
        entry, or the hostname salt/hash portion has more than two elements,
        L{HashedEntry.fromString} should raise L{InvalidEntry}.
        rws||N)rrrr`�splitror	r*rx�r"�a�b�cs    r#�test_invalidHashedEntryz'ParseErrorTests.test_invalidHashedEntryYsU��	
���k�*�"�(�(�*���1�a�����+�0�0�$�)�)�Q��Y��1�<M�2N�	
r%c�.�|jt�y)z�
        If the key portion of a plain entry is not decodable as base64,
        C{fromString} should raise L{BinasciiError}.
        N)rurr!s r#�test_plainNotBase64z#ParseErrorTests.test_plainNotBase64es��
	
���:�&r%c
�2�|jt�tj�\}}}|j	t
tjdjdtd�j�z||g��|j	t
tjdjtjtd�j�zdz||g��|j	t
tjdjd||g��y)z�
        If the key, host salt, or host hash portion of a hashed entry is not
        encoded, it will raise L{BinasciiError}.
        rws|1|x|�stuffs|xs|1|x|xN)rurr`rrortr*rxrry�MAGICr�s    r#�test_hashedNotBase64z$ParseErrorTests.test_hashedNotBase64ls���
	
���;�'�"�(�(�*���1�a������"�"��I�I�x�*�X�"6�"<�"<�">�>��1�E�F�	
�	
�����"�"��I�I�{�(�(�:�h�+?�+E�+E�+G�G�%�O�QR�TU�V�W�	
�	
����;�1�1�4�9�9�i��A�=N�3O�	
r%c�`�tj�\}}}|jt|�y)z�
        If the key portion of the entry is valid base64, but is not actually an
        SSH key, C{HashedEntry.fromString} should raise L{BadKeyError}.
        N)r`rr{rr�s    r#�test_hashedBadKeyz!ParseErrorTests.test_hashedBadKey�s&��
#�(�(�*���1�a�����Q�'r%c�0�|jtd�y)z�
        If the key portion of the entry is valid base64, but is not actually an
        SSH key, C{PlainEntry.fromString} should raise L{BadKeyError}.
        shostnameN)r{rr!s r#�test_plainBadKeyz ParseErrorTests.test_plainBadKey�s��
	
���
�K�0r%N)
r:r;r<r=rrrur{r}r�r�r�r�r�r>r%r#rmrm.s6���D�C�
�*�

�'�
�0(�1r%rmc��eZdZdZd�Zeezdzfd�Zd�Zd�Z	d�Z
d�Zd	�Zd
�Z
d�Zd�Zd
�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Z d�Z!d�Z"d �Z#d!�Z$d"�Z%d#�Z&d$�Z'd%�Z(d&�Z)y')(�KnownHostsDatabaseTestsz&
    Tests for L{KnownHostsFile}.
    c�Z�t|j��}|j|�|S)zC
        Return a FilePath with the given initial content.
        )r�mktemp�
setContent)r"�content�fps   r#�pathWithContentz'KnownHostsDatabaseTests.pathWithContent�s%���d�k�k�m�
$��
�
�
�g���	r%sN
# That was a blank line.
This is just unparseable.
|1|This also unparseable.
c�J�tj|j|��S)zq
        Return a sample hosts file, with keys for www.twistedmatrix.com and
        divmod.com present.
        )r�fromPathr�)r"r�s  r#�loadSampleHostsFilez+KnownHostsDatabaseTests.loadSampleHostsFile�s ���&�&�t�';�';�G�'D�E�Er%c���t|j��}t|j��}t|�}|jtt
|d|�|j
||j�y)z�
        L{KnownHostsFile.savePath} is read-only; if an assignment is made to
        it, L{AttributeError} is raised and the value is unchanged.
        �savePathN)rr�rro�AttributeError�setattrr(r�)r"�path�new�	hostsFiles    r#�test_readOnlySavePathz-KnownHostsDatabaseTests.test_readOnlySavePath�sZ��
����
�&���t�{�{�}�%��"�4�(�	����.�'�9�j�#�N�����y�1�1�2r%c��t|jt��}|jgt	|j���y)zz
        The default initializer for L{KnownHostsFile} disregards any existing
        contents in the save path.
        N)rr�r`r(�list�iterentries�r"r�s  r#�&test_defaultInitializerIgnoresExistingz>KnownHostsDatabaseTests.test_defaultInitializerIgnoresExisting�s8��
#�4�#7�#7�8H�#I�J�	�����T�)�"7�"7�"9�:�;r%c�l�|jt�}t|�}|jdt	j
t��}|j�|j|gt|j���|j|j�dz|j��y)z�
        After using the default initializer for L{KnownHostsFile}, the first use
        of L{KnownHostsFile.save} overwrites any existing contents in the save
        path.
        �www.example.comrN)
r�r`r�
addHostKeyrr*r/�saver(r�r�rH�
getContent)r"r�r�r s    r#�'test_defaultInitializerClobbersExistingz?KnownHostsDatabaseTests.test_defaultInitializerClobbersExisting�s����#�#�$4�5��"�4�(�	��$�$�%7�����9W�X���������%��$�y�'<�'<�'>�"?�@�������)�E�1�4�?�?�3D�Er%c�z�t|jt��}|jdt	j
t��}|j�|jdt	j
t��}|j�|j||gt|j���y)z�
        After L{KnownHostsFile.save} is used once with an instance initialized
        by the default initializer, contents of the save path are respected and
        preserved.
        r�sanother.example.comN)rr�r`r�rr*r/r��thirdSampleKeyr(r�r�)r"r��preSave�postSaves    r#�test_saveResetsClobberStatez3KnownHostsDatabaseTests.test_saveResetsClobberState�s���#�4�#7�#7�8H�#I�J�	��&�&�����~� >�
��	�����'�'�"�C�N�N�>�$B�
��	�������'�8�,�d�9�3H�3H�3J�.K�Lr%c	��|j�}|jdtt|j	����y)z�
        Loading a L{KnownHostsFile} from a path with six entries in it will
        result in a L{KnownHostsFile} object with six L{IKnownHostEntry}
        providers in it.
        �N)r�r(�lenr�r�r�s  r#�test_loadFromPathz)KnownHostsDatabaseTests.test_loadFromPath�s5���,�,�.�	�����C��Y�%:�%:�%<� =�>�?r%c	��tt|j���}|jdt	j
t��|jdtt|j����y)z�
        If the save path for a L{KnownHostsFile} does not exist,
        L{KnownHostsFile.iterentries} still returns added but unsaved entries.
        r��N)rrr�r�rr*r+r(r�r�r�r�s  r#�test_iterentriesUnsavedz/KnownHostsDatabaseTests.test_iterentriesUnsaved�sV��
#�8�D�K�K�M�#:�;�	����/����	�1J�K�����C��Y�%:�%:�%<� =�>�?r%c��|jt�}t|j��}|j	|dt
�|j
|djd��|jdt|��y)z�
        Loading a L{KnownHostsFile} from a path containing a single valid
        L{HashedEntry} entry will result in a L{KnownHostsFile} object
        with one L{IKnownHostEntry} provider.
        rr5r�N)
r�r`r�r��assertIsInstancerr6r7r(r��r"r��entriess   r#�test_verifyHashedEntryz.KnownHostsDatabaseTests.test_verifyHashedEntry�sl���,�,�-=�>�	��y�,�,�.�/�����g�a�j�+�6������
�.�.�/G�H�I�����C��L�)r%c��|jt�}t|j��}|j	|dt
�|j
|djd��|jdt|��y)z�
        Loading a L{KnownHostsFile} from a path containing a single valid
        L{PlainEntry} entry will result in a L{KnownHostsFile} object
        with one L{IKnownHostEntry} provider.
        r�
divmod.comr�N)
r��otherSamplePlaintextLiner�r�r�rr6r7r(r�r�s   r#�test_verifyPlainEntryz-KnownHostsDatabaseTests.test_verifyPlainEntrysk���,�,�-E�F�	��y�,�,�.�/�����g�a�j�*�5������
�.�.�}�=�>�����C��L�)r%c��|jd�}t|j��}|j|dt�|j|dj
�d�|jdt|��y)z�
        Loading a L{KnownHostsFile} from a path that only contains '
' will
        result in a L{KnownHostsFile} object containing a L{UnparsedEntry}
        object.
        rrr%r�N�r�r�r�r�rr(rHr�r�s   r#�test_verifyUnparsedEntryz0KnownHostsDatabaseTests.test_verifyUnparsedEntrysl���,�,�U�3�	��y�,�,�.�/�����g�a�j�-�8�������,�,�.��4�����C��L�)r%c���|jd�}t|j��}|j|dt�|j|dj
�d�y)z�
        Loading a L{KnownHostsFile} from a path that contains a comment will
        result in a L{KnownHostsFile} object containing a L{UnparsedEntry}
        object.
        s# That was a blank line.
rs# That was a blank line.N)r�r�r�r�rr(rHr�s   r#�test_verifyUnparsedCommentz2KnownHostsDatabaseTests.test_verifyUnparsedCommentsZ���,�,�-J�K�	��y�,�,�.�/�����g�a�j�-�8�������,�,�.�0K�Lr%c��|jd�}t|j��}|j|dt�|j|dj
�d�|jdt|��y)z�
        Loading a L{KnownHostsFile} from a path that contains an unparseable
        line will be represented as an L{UnparsedEntry} instance.
        sThis is just unparseable.
rsThis is just unparseable.r�Nr�r�s   r#�test_verifyUnparsableLinez1KnownHostsDatabaseTests.test_verifyUnparsableLine&sn��
�,�,�-K�L�	��y�,�,�.�/�����g�a�j�-�8�������,�,�.�0L�M�����C��L�)r%c��|jd�}t|j��}|j|dt�|j|dj
�d�|jdt|��y)z�
        Loading a L{KnownHostsFile} from a path containing an unparseable line
        that starts with an encryption marker will be represented as an
        L{UnparsedEntry} instance.
        s|1|This is unparseable.
rs|1|This is unparseable.r�Nr�r�s   r#�%test_verifyUnparsableEncryptionMarkerz=KnownHostsDatabaseTests.test_verifyUnparsableEncryptionMarker1sn���,�,�-I�J�	��y�,�,�.�/�����g�a�j�-�8�������,�,�.�0J�K�����C��L�)r%c�v�|j�}tjt|��}t	|j��}|j
g|�|jt|�j��|j�|jt|�j��y)z�
        Loading a L{KnownHostsFile} from a path that does not exist should
        result in an empty L{KnownHostsFile} that will save back to that path.
        N)r�rr�rr�r�r(r8�existsr�r6)r"�pn�knownHostsFiler�s    r#�test_loadNonExistentz,KnownHostsDatabaseTests.test_loadNonExistent=s���
�[�[�]��'�0�0��"��>���~�1�1�3�4������W�%�����"��,�,�.�/�����������+�+�-�.r%c� �t|j��}|jd�jd�}tj|�}|j�|j
d�|j|j��y)z�
        Loading a L{KnownHostsFile} from a path whose parent directory does not
        exist should result in an empty L{KnownHostsFile} that will save back
        to that path, creating its parent directory(ies) in the process.
        �foosknown_hostsFN)	rr��childrr�r��restatr6r�)r"�thePath�knownHostsPathr�s    r#�test_loadNonExistentParentz2KnownHostsDatabaseTests.test_loadNonExistentParentJsl���4�;�;�=�)�� ���u�-�3�3�N�C��'�0�0��@���������e�$�����-�-�/�0r%c�F�|jttz�}tj|�}|jdt
jt��}ttztjzt|j�j�zdzt|j�j�zdztzdz}|j!d|j#d��|j%�|j!||j'��y)zq
        L{KnownHostsFile.save} will write out a new file with any entries
        that have been added.
        �some.example.com�|s	 ssh-rsa r�N)r�r`r�rr�r�rr*r�rr�r�	_hostSaltry�	_hostHash�thirdSampleEncodedKeyr(�countr�r�)r"r�r��newEntry�expectedContents     r#�test_savingAddsEntryz,KnownHostsDatabaseTests.test_savingAddsEntryWs
��
�#�#�$4�7O�$O�P��'�0�0��6��!�,�,������!?�
��
�&�
'����
 ���+�+�,�2�2�4�
5��	
�
��+�+�,�2�2�4�
5��

�$�
$��
�	�	
����O�1�1�%�8�9���������$�/�/�*;�<r%c�\�t|j��}t|�}|jdt	j
t��}|j�|j�tj|�}|j|gt|j���y)z�
        L{KnownHostsFile.save} only writes new entries to the save path, not
        entries which were added and already written by a previous call to
        C{save}.
        r�N)rr�rr�rr*r+r�r�r(r�r�)r"r��
knownHostsr s    r#�test_savingAvoidsDuplicationz4KnownHostsDatabaseTests.test_savingAvoidsDuplicationss~������
�&��#�D�)�
��%�%�&9�3�>�>�)�;T�U����������#�,�,�T�2�
����%��$�z�'=�'=�'?�"@�Ar%c
�X�|jt�}tj|�}|j	d�5}|jt�ddd�tjt�}|jd|�|j�tj|�}|jgd�|jdtjt��|jdtjt��|jd|�g�y#1swY��xYw)z�
        L{KnownHostsFile.save} will not overwrite existing entries in its save
        path, even if they were only added after the L{KnownHostsFile} instance
        was initialized.
        r�N�brandnew.example.com)TTTr5r�)r�r`rr��open�writer�rr*r�r�r�r(�
hasHostKeyr+r/)r"r�r��hostsFileObj�keys     r#�test_savingsPreservesExistingz5KnownHostsDatabaseTests.test_savingsPreservesExisting�s����#�#�$4�5��#�,�,�T�2�
��Y�Y�s�^�	9�|����7�8�	9��n�n�^�,�����5�s�;�����$�,�,�T�2�
������%�%�,�c�n�n�Y�.G���%�%�m�S�^�^�N�5S�T��%�%�&=�s�C�
�		
�	9�	9�s�D � D)c��|j�}|j|jdtjt
���y)z�
        L{KnownHostsFile.hasHostKey} returns C{True} when a key for the given
        hostname is present and matches the expected key.
        r5N)r�r6r�rr*r+r�s  r#�test_hasPresentKeyz*KnownHostsDatabaseTests.test_hasPresentKey�s8��
�,�,�.�	����� � �!9�3�>�>�)�;T�U�	
r%c�t�|j�}|j|jdtjt
���|j
|jdtjt
���|j|jdtjt���y)zy
        L{KnownHostsFile.hasHostKey} returns C{False} when a key for the given
        hostname is not present.
        snon-existent.example.comr5N)r�r8r�rr*r+r6�ecdsaSampleKeyr�s  r#�test_notPresentKeyz*KnownHostsDatabaseTests.test_notPresentKey�s���
�,�,�.�	����� � �!<�c�n�n�Y�>W�X�	
�	
���� � �!9�3�>�>�)�;T�U�	
�	
���� � �(�#�.�.��*H�
�	
r%c�x�tjt�}tdg|j	�|d�}|j�}|jjd�5}|j|j�dz�ddd�|jd|jd|��y#1swY�,xYw)z�
        L{KnownHostsFile.hasHostKey} returns C{True} when a key for the given
        hostname is present in the file, even if it is only added to the file
        after the L{KnownHostsFile} instance is initialized.
        r�r%r�rNT)rr*r+r�sshTyper�r�r�r�rHr(r�)r"r�r r�r�s     r#�test_hasLaterAddedKeyz-KnownHostsDatabaseTests.test_hasLaterAddedKey�s����n�n�Y�'���3�4�c�k�k�m�S�#�N���,�,�.�	�
�
�
�
$�
$�S�
)�	9�\����u�~�~�/�%�7�8�	9�����y�3�3�4K�S�Q�R�	9�	9�s�"#B0�0B9c��|j�}t|j��}|jt|j
dt
jt��}|j|j|d�|j|jd�|j|j|j�y)a
        L{KnownHostsFile.hasHostKey} raises L{HostKeyChanged} if the host key is
        present in the underlying file, but different from the expected one.
        The resulting exception should have an C{offendingEntry} indicating the
        given entry.
        r5rr�N)r�r�r�rorr�rr*r/r(�offendingEntry�linenor�r�)r"r�r��	exceptions    r#�test_savedEntryHasKeyMismatchz5KnownHostsDatabaseTests.test_savedEntryHasKeyMismatch�s����,�,�.�	��y�,�,�.�/���%�%��� � �$��N�N�>�*�	
�	�	
����1�1�7�1�:�>�����)�)�1�-��������);�);�<r%c�l�|j�}|jdtjt��|jt|jdtjt��}|j|jd�|j|j|j�y)ai
        Even after a new entry has been added in memory but not yet saved, the
        L{HostKeyChanged} exception raised by L{KnownHostsFile.hasHostKey} has a
        C{lineno} attribute which indicates the 1-based line number of the
        offending entry in the underlying file when the given host key does not
        match the expected host key.
        r�r5r�N)r�r�rr*r/rorr�r(r�r�r�)r"r�r�s   r#�%test_savedEntryAfterAddHasKeyMismatchz=KnownHostsDatabaseTests.test_savedEntryAfterAddHasKeyMismatch�s����,�,�.�	����/�����1O�P��%�%��� � �$��N�N�>�*�	
�	�	
����)�)�1�-��������);�);�<r%c��tt|j���}|jdt	j
t��}|jt|jdt	j
t��}|j|j|�|j|j�|j|j�y)az
        L{KnownHostsFile.hasHostKey} raises L{HostKeyChanged} if the host key is
        present in memory (but not yet saved), but different from the expected
        one.  The resulting exception has a C{offendingEntry} indicating the
        given entry, but no filename or line number information (reflecting the
        fact that the entry exists only in memory).
        r�N)rrr�r�rr*r/rorr�r�r(r��assertIsNoner�r�)r"r�r r�s    r#�test_unsavedEntryHasKeyMismatchz7KnownHostsDatabaseTests.test_unsavedEntryHasKeyMismatch�s���#�8�D�K�K�M�#:�;�	��$�$�%7�����9W�X���%�%��� � ���N�N�>�*�	
�	�	
����1�1�5�9����)�*�*�+����)�.�.�)r%c��|j�}tjt�}|j	d|jd|��|j
d|�}|j	dt|j��|j	d|jd��|j	|jd�|j	||j�|j	d|jd|��y)zr
        L{KnownHostsFile.addHostKey} adds a new L{HashedEntry} to the host
        file, and returns it.
        F�somewhere.example.com�Tr'N)r�rr*r�r(r�r�r�r�r7r,r))r"r��aKeyr�s    r#�test_addHostKeyz'KnownHostsDatabaseTests.test_addHostKeys���
�,�,�.�	��~�~�n�-������	� 4� 4�5M�t� T�U��'�'�(@�$�G��
	
����S��!3�!3�4�5�����x�3�3�4L�M�N�����)�)�:�6�����x�1�1�2�����y�3�3�4L�d�S�Tr%c���|j�}tjt�}|j	|jd|�j|jd|�j�y)z�
        L{KnownHostsFile.addHostKey} generates a random salt for each new key,
        so subsequent salts will be different.
        rssomewhere-else.example.comN)r�rr*r��assertNotEqualr�r�)r"r�rs   r#�test_randomSaltsz(KnownHostsDatabaseTests.test_randomSaltss\��
�,�,�.�	��~�~�n�-������ � �!9�4�@�J�J�� � �!>��E�O�O�	
r%c�@�|j�}|jdtjt��t�}|j
|ddtjt��}g}|j|j�|j|dg�y)zb
        Verifying a valid key should return a L{Deferred} which fires with
        True.
        �1.2.3.4r5TN)
r�r�rr*r+�FakeUI�
verifyHostKey�addCallback�appendr()r"r��ui�d�ls     r#�test_verifyValidKeyz+KnownHostsDatabaseTests.test_verifyValidKey%s~��
�,�,�.�	����Z����	�)B�C�
�X���#�#��(�*�c�n�n�Y�6O�
��
��	�
�
�a�h�h������T�F�#r%c��|j�}tjt�}t	�}|jdtjt��|j|dd|�}|j|t�S)z|
        Verifying an invalid key should return a L{Deferred} which fires with a
        L{HostKeyChanged} failure.
        rr5)
r�rr*r�r	r�r+r
�
assertFailurer�r"r��wrongKeyr
rs     r#�test_verifyInvalidKeyz-KnownHostsDatabaseTests.test_verifyInvalidKey4sj��
�,�,�.�	��>�>�.�1��
�X�����Z����	�)B�C��#�#�B�(@�*�h�W���!�!�!�^�4�4r%c�0�|j�}tjt�}t	�}g}|j|dd|�}|j
|j�|jg|�|j|jd�|||fS)a
        Set up a test to verify a key that isn't present.  Return a 3-tuple of
        the UI, a list set up to collect the result of the verifyHostKey call,
        and the sample L{KnownHostsFile} being used.

        This utility method avoids returning a L{Deferred}, and records results
        in the returned list instead, because the events which get generated
        here are pre-recorded in the 'ui' object.  If the L{Deferred} in
        question does not fire, the it will fail quickly with an empty list.
        �sample-host.example.com�4.3.2.1s�The authenticity of host 'sample-host.example.com (4.3.2.1)' can't be established.
RSA key fingerprint is SHA256:mS7mDBGhewdzJkaKRkx+wMjUdZb/GzvgcdoYjX5Js9I=.
Are you sure you want to continue connecting (yes/no)? )
r�rr*r�r	r
�addBothrr(�
promptText)r"r��	absentKeyr
rrs      r#�verifyNonPresentKeyz+KnownHostsDatabaseTests.verifyNonPresentKey@s����,�,�.�	��N�N�>�2�	�
�X�����#�#��*�J�	�
��	
�	�	�!�(�(������Q������M�M�
G�	
��1�i��r%c	��|j�\}}}|jjd�|jdg|�t	j
|j�}|jd|jdtjt���|jd|jdtjt���y)z�
        Verifying a key where neither the hostname nor the IP are present
        should result in the UI being prompted with a message explaining as
        much.  If the UI says yes, the Deferred should fire with True.
        TrrN)r�promptDeferred�callbackr(rr�r�r�rr*r�)r"r
rr��reloadeds     r#�test_verifyNonPresentKey_Yesz4KnownHostsDatabaseTests.test_verifyNonPresentKey_Yes^s���!%� 8� 8� :���A�~�
���"�"�4�(����$���#�!�*�*�>�+B�+B�C������(�%�%�j�#�.�.��2P�Q�	
�	
�������*�C�N�N�>�,J�
�	
r%c��|j�\}}}|jjd�|djt�y)z�
        Verifying a key where neither the hostname nor the IP are present
        should result in the UI being prompted with a message explaining as
        much.  If the UI says no, the Deferred should fail with
        UserRejectedKey.
        FrN)rrr�trapr
)r"r
rr�s    r#�test_verifyNonPresentKey_Noz3KnownHostsDatabaseTests.test_verifyNonPresentKey_Nors=��!%� 8� 8� :���A�~�
���"�"�5�)�	�!��	�	�/�"r%c��tjtjdtjdtjdtjd��}|j	�}t�}g}|j
|dd|�}|j|j�|jg|�|j|jd�y	)
z�
        Set up a test to verify an ECDSA key that isn't present.
        Return a 3-tuple of the UI, a list set up to collect the result
        of the verifyHostKey call, and the sample L{KnownHostsFile} being used.
        �x�y�privateValue�curve)r&r'r(r)rrs�The authenticity of host 'sample-host.example.com (4.3.2.1)' can't be established.
ECDSA key fingerprint is SHA256:fJnSpgCcYoYYsaBbnWj1YBghGh/QTDgfe4w4U5M5tEo=.
Are you sure you want to continue connecting (yes/no)? N)r�_fromECComponentsr�ECDatanistp256r�r	r
rrr(r)r"�ecObjr�r
rrs      r#�test_verifyNonPresentECKeyz2KnownHostsDatabaseTests.test_verifyNonPresentECKey}s����%�%��$�$�S�)��$�$�S�)� �/�/��?��(�(��1�	
���,�,�.�	�
�X�����#�#�B�(B�J�PU�V��	�	�	�!�(�(������Q������M�M�
G�	
r%c��|j�}tjt�}t	�}|j|dd|�}|j
|t�S)z�
        Verifying a key where the host is present (and correct), but the IP is
        present and different, should result the deferred firing in a
        HostKeyChanged failure.
        r5r)r�rr*r�r	r
rrrs     r#�test_verifyHostIPMismatchz1KnownHostsDatabaseTests.test_verifyHostIPMismatch�sQ���,�,�.�	��>�>�.�1��
�X���#�#�B�(@�*�h�W���!�!�!�^�4�4r%c�J�t�}|j�}tjt�}|j|dd|�|j
dtj|j�jd|��|j
dg|j�y)z�
        Verifying a key where the hostname is present but the IP is not should
        result in the key being added for the IP and the user being warned
        about the change.
        r5s5.4.3.2Tz`Warning: Permanently added the RSA host key for IP address '5.4.3.2' to the list of known hosts.N)r	r�rr*r+r
r(rr�r�r��userWarnings)r"r
r��expectedKeys    r#�test_verifyKeyForHostAndIPz2KnownHostsDatabaseTests.test_verifyKeyForHostAndIP�s����X���,�,�.�	��n�n�Y�/������$<�j�+�V������#�#�I�$6�$6�7�B�B��K�
�	
�	
���8�
�
�O�O�	
r%c�v�|j�}|jdtjt��|jdtjt
��|j
�i}|jj|d<tjd|�}ddg}|j||�y)zn
        For a given host, get the host key algorithms for that
        host in the known_hosts file.
        r5�known-hostsr'secdsa-sha2-nistp256N)r�r�rr*r/r�r�r�r�r�getHostKeyAlgorithmsr()r"r��options�
algorithms�expectedAlgorithmss     r#�test_getHostKeyAlgorithmsz1KnownHostsDatabaseTests.test_getHostKeyAlgorithms�s���
�,�,�.�	����5�s�~�~�n�7U�V����5�s�~�~�n�7U�V�������!*�!3�!3�!8�!8��
���1�1�2J�G�T�
�(�*@�A������%7�8r%N)*r:r;r<r=r�r`r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrrrrr!r$r-r/r3r:r>r%r#r�r��s�����
�&�
'�+�
+�F� 	3�<�
F�M�$@�@�
*�
*�
*�	M�	*�
*�/�1�=�8
B�
�B
�
�$S�=�&=�&*�(U�&

�
$�
5� �<
�(	#�
�8
5�
�0
9r%r�c�(�eZdZdZd�Zd�Zd�Zd�Zy)�FakeFilez[
    A fake file-like object that acts enough like a file for
    L{ConsoleUI.prompt}.
    c�.�g|_g|_d|_y)NF)�inlines�	outchunks�closedr!s r#�__init__zFakeFile.__init__�s����������r%c�8�|jjd�S)z8
        Return a line from the 'inlines' list.
        r)r>�popr!s r#�readlinezFakeFile.readline�s���|�|����"�"r%c�h�|jrtd��|jj|�y)z@
        Append the given item to the 'outchunks' list.
        zthe file was closedN)r@�OSErrorr?r)r"�chunks  r#r�zFakeFile.write�s)���;�;��/�0�0������e�$r%c��d|_y)zd
        Set the 'closed' flag to True, explicitly marking that it has been
        closed.
        TN)r@r!s r#�closezFakeFile.close�s��
��r%N)r:r;r<r=rArDr�rIr>r%r#r<r<�s���
�
#�%�r%r<c�F�eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zd
�Zy)�ConsoleUITestsz&
    Test cases for L{ConsoleUI}.
    c�V�t�|_t|j�|_y)zA
        Create a L{ConsoleUI} pointed at a L{FakeFile}.
        N)r<�fakeFiler�openFiler
r!s r#rCzConsoleUITests.setUp�s��!�
��
��D�M�M�*��r%c��|jS)z/
        Return the current fake file.
        )rMr!s r#rNzConsoleUITests.openFile�s���}�}�r%c�D�t�|_||j_y)z�
        Create a new fake file (the next file that self.ui will open) with the
        given list of lines to be returned from readline().
        N)r<rMr>)r"�liness  r#�newFilezConsoleUITests.newFiles��
!�
��
� %��
�
�r%c�`�dD]�}|j|g�g}|jjd�j|j�|jdg|jj�|jdg|�|j|jj���y)z�
        L{ConsoleUI.prompt} writes a message to the console, then reads a line.
        If that line is 'yes', then it returns a L{Deferred} that fires with
        True.
        )�yessYessyes
z
Hello, world!TN�
rRr
�promptrrr(rMr?r6r@)r"�okYesrs   r#�test_promptYeszConsoleUITests.test_promptYess���0�	2�E��L�L�%��!��A��G�G�N�N�?�+�7�7����A����o�.��
�
�0G�0G�H����d�V�Q�'��O�O�D�M�M�0�0�1�
	2r%c�`�dD]�}|j|g�g}|jjd�j|j�|jdg|jj�|jdg|�|j|jj���y)z�
        L{ConsoleUI.prompt} writes a message to the console, then reads a line.
        If that line is 'no', then it returns a L{Deferred} that fires with
        False.
        )�nosNosno
zGoodbye, world!FNrU)r"�okNors   r#�
test_promptNozConsoleUITests.test_promptNos���,�	2�D��L�L�$�� ��A��G�G�N�N�,�-�9�9�!�(�(�C����/�0�$�-�-�2I�2I�J����e�W�a�(��O�O�D�M�M�0�0�1�
	2r%c��|jgd��g}|jjd�j|j�|jdg|�|j|jjdgdgdzz�|j|jj�|jgd��g}|jjd�j|j�|jdg|�|j|jjdgdgdzz�|j|jj�y	)
a,
        L{ConsoleUI.prompt} writes a message to the console, then reads a line.
        If that line is neither 'yes' nor 'no', then it says "Please enter
        'yes' or 'no'" until it gets a 'yes' or a 'no', at which point it
        returns a Deferred that answers either True or False.
        )swhatsuhsokayrTsPlease say something useful.TsPlease type 'yes' or 'no': r�)sblahr�sfehrZsPlease say something negative.FNrU�r"rs  r#�test_promptRepeatedlyz$ConsoleUITests.test_promptRepeatedly$s��	
���6�7��������6�7�C�C�A�H�H�M����$���#�����M�M�#�#�
,�-�1O�0P�ST�0T�T�	
�	
����
�
�,�,�-����7�8��������8�9�E�E�a�h�h�O����%��!�$�����M�M�#�#�
.�/�3Q�2R�UV�2V�V�	
�	
����
�
�,�,�-r%c�l�d�}t|�}|jd�}|j|t�S)z�
        If the C{opener} passed to L{ConsoleUI} raises an exception, that
        exception will fail the L{Deferred} returned from L{ConsoleUI.prompt}.
        c��t���N)rFr>r%r#�raiseItz5ConsoleUITests.test_promptOpenFailed.<locals>.raiseItDs	���)�Or%zThis is a test.)rrVr�IOError)r"rcr
rs    r#�test_promptOpenFailedz$ConsoleUITests.test_promptOpenFailed>s5��	��w�
���I�I�'�(���!�!�!�W�-�-r%c���|jjd�|jdg|jj�|j|jj�y)zR
        L{ConsoleUI.warn} should output a message to the console object.
        z
Test message.N)r
�warnr(rMr?r6r@r!s r#�	test_warnzConsoleUITests.test_warnKsG��	
�����_�%����/�*�D�M�M�,C�,C�D�����
�
�,�,�-r%c��d�}t|�}|jd�|jt|j	t
��d�y)zY
        L{ConsoleUI.warn} should log a traceback if the output can't be opened.
        c��ddzy)Nr�rr>r>r%r#rcz3ConsoleUITests.test_warnOpenFailed.<locals>.raiseItXs	��
��Er%zThis message never makes it.r�N)rrgr(r��flushLoggedErrors�ZeroDivisionError)r"rcr
s   r#�test_warnOpenFailedz"ConsoleUITests.test_warnOpenFailedSsA��
	��w�
��
���.�/�����T�3�3�4E�F�G��Kr%N)
r:r;r<r=rCrNrRrXr\r_rerhrmr>r%r#rKrK�s5���+��&�2�2�.�4.�.�
Lr%rKc�"�eZdZdZd�Zd�Zd�Zy)r	a
    A fake UI object, adhering to the interface expected by
    L{KnownHostsFile.verifyHostKey}

    @ivar userWarnings: inputs provided to 'warn'.

    @ivar promptDeferred: last result returned from 'prompt'.

    @ivar promptText: the last input provided to 'prompt'.
    c�.�g|_d|_d|_yrb)r1rrr!s r#rAzFakeUI.__init__ls�����"�����r%c�F�||_t�|_|jS)zV
        Issue the user an interactive prompt, which they can accept or deny.
        )rrr�r"�texts  r#rVz
FakeUI.promptqs!�����&�j����"�"�"r%c�:�|jj|�y)z>
        Issue a non-interactive warning to the user.
        N)r1rrqs  r#rgzFakeUI.warnys��	
��� � ��&r%N)r:r;r<r=rArVrgr>r%r#r	r	`s��	��
#�'r%r	c��eZdZdZy)�
FakeObjectzw
    A fake object that can have some attributes.  Used to fake
    L{SSHClientTransport} and L{SSHClientFactory}.
    N)r:r;r<r=r>r%r#ruru�s��r%ru�/dev/ttyzPlatform lacks /dev/ttyc�R�eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zd
�Zd�Z
d�Zy
)�DefaultAPITestsz�
    The API in L{twisted.conch.client.default.verifyHostKey} is the integration
    point between the code in the rest of conch and L{KnownHostsFile}.
    c��|j|d�|j|d�|j|dd�|jS)z
        The patched version of 'open'; this returns a L{FakeFile} that the
        instantiated L{ConsoleUI} can use.
        rvzr+b�	bufferingr)r(rM)r"�fname�mode�kwargss    r#�patchedOpenzDefaultAPITests.patchedOpen�sC��
	
����
�+�����u�%������,�a�0��}�}�r%c�$�t�|_|jtd|j�|j�|_i|_tt|j��}dD]:}|j|tjt��}||j|<�<|j�t�|_t�|j _d|jd�x|_|j j"_y)z0
        Patch 'open' in verifyHostKey.
        �_open)�exists.example.comrr�)�hostr5N)r<rM�patchrr~r��hostsOption�
hashedEntriesrrr�rr*r+r�ru�
fakeTransport�factoryr7)r"r�r�r s    r#rCzDefaultAPITests.setUp�s���!�
��
��
�
�7�G�T�%5�%5�6��;�;�=������'���1A�1A�(B�C��7�	-�D�"�-�-�d�C�N�N�9�4M�N�E�',�D���t�$�	-�	����'�\���%/�\����"�)��+�+�=
�	
���t�)�)�1�1�9r%c��g}tj|jdtd�j	|j
�|j
dg|�y)z�
        L{default.verifyHostKey} should return a L{Deferred} which fires with
        C{1} when passed a host, IP, and key which already match the
        known_hosts file it is supposed to check.
        r�
I don't care.r�N)rr
r�r+rrr(r^s  r#�test_verifyOKKeyz DefaultAPITests.test_verifyOKKey�sG��
��������
�I�7G�	
�
�+�a�h�h�
����!��a� r%c���tjjd���fd�}|j|�|tjd<y)aC
        Replace the HOME environment variable until the end of the current
        test, with the given new home-directory, so that L{os.path.expanduser}
        will yield controllable, predictable results.

        @param tempHome: the pathname to replace the HOME variable with.

        @type tempHome: L{str}
        �HOMEc�T����tjd=y�tjd<y)Nr�)�os�environ)�oldHomes�r#�cleanupHomez0DefaultAPITests.replaceHome.<locals>.cleanupHome�s"������J�J�v�&�%,��
�
�6�"r%N)r�r��get�
addCleanup)r"�tempHomer�r�s   @r#�replaceHomezDefaultAPITests.replaceHome�s8����*�*�.�.��(��	-�	
����$�%��
�
�6�r%c���g}|j�}|j}t|�jd�jd�}|j	�j�t|�j
|�|j|�d|jd<tj|jdtd�j|j�|jdg|�y)z�
        L{default.verifyHostKey} should find your known_hosts file in
        ~/.ssh/known_hosts if you don't specify one explicitly on the command
        line.
        z.ssh�known_hostsNr5rr�r�)r�r�rr��parent�makedirs�moveTor�r7rr
r�r+rrr()r"r�tmpdir�oldHostsOption�hostsNonOptions     r#�test_noKnownHostsOptionz'DefaultAPITests.test_noKnownHostsOption�s���
��������)�)��!�&�)�/�/��7�=�=�m�L������(�(�*��� �'�'��7����� �&*����]�#�������
�I�7G�	
�
�+�a�h�h�
����!��a� r%c��g}tj|jdtd�j	|j
�|j
dg|jj�|j
dg|�tjt|j��}|j|jdtj t���y)a
        L{default.verifyHostKey} should return a L{Deferred} which fires with
        C{1} when passed a host which matches with an IP is not present in its
        known_hosts file, and should also warn the user that it has added the
        IP address.
        s8.7.6.5sFingerprint not required.z`Warning: Permanently added the RSA host key for IP address '8.7.6.5' to the list of known hosts.r�N)rr
r�r+rrr(rMr?rr�rr�r6r�rr*)r"rr�s   r#�test_verifyHostButNotIPz'DefaultAPITests.test_verifyHostButNotIP�s���
��������
�I�7S�	
�
�+�a�h�h�
����8�
�
�M�M�#�#�	
�	
���!��a� �'�0�0��$�:J�:J�1K�L������%�%�j�#�.�.��2K�L�	
r%c�X�d|jjjd<|jjjd�t
j|jdtd�}|jdg|jj�|j|t�S)z�
        L{default.verifyHostKey} should return a L{Default} which fires with
        C{0} when passed an unknown host that the user refuses to acknowledge.
        sfake.example.comr�rZs9.8.7.6sNo fingerprint!s�The authenticity of host 'fake.example.com (9.8.7.6)' can't be established.
RSA key fingerprint is SHA256:vD0YydsNIUYJa7yLZl3tIL8h0vZvQ8G+HPG7JLmQV0s=.
Are you sure you want to continue connecting (yes/no)? )
r�r�r7rMr>rrr
r/r(r?rr
�r"rs  r#�test_verifyQuestionz#DefaultAPITests.test_verifyQuestion�s���
6I����"�"�*�*�6�2��
�
���$�$�U�+��!�!����
�N�<N�
��	
���K�
�
�M�M�#�#�		
��!�!�!�_�5�5r%c�z�tj|jdtd�}|j	|t
�S)z�
        L{default.verifyHostKey} should return a L{Deferred} which fails with
        L{HostKeyChanged} if the host key is incorrect.
        rzAgain, not required.)rr
r�r/rrr�s  r#�test_verifyBadKeyz!DefaultAPITests.test_verifyBadKeys9��

�!�!����
�N�<R�
���!�!�!�^�4�4r%c�:�|jdj�j�d}tj|tjt�j�dt|j�ji�}|jd|�y)zy
        L{default.isInKnownHosts} should return C{1} when a host with a key
        is in the known hosts file.
        rrr5r�N)
r�rHrr�isInKnownHostsrr*r+�blobrr�r�r(�r"r��rs   r#�test_inKnownHostsz!DefaultAPITests.test_inKnownHostss~��
�!�!�*�-�6�6�8�>�>�@��C���"�"���N�N�9�%�*�*�,�
�H�T�%5�%5�6�;�;�<�
��
	
����A�r%c��tjdddt|j�ji�}|jd|�y)z}
        L{default.isInKnownHosts} should return C{0} when a host with a key
        is not in the known hosts file.
        z	not.theres
irrelevantr5rN)rr�rr�r�r()r"r�s  r#�test_notInKnownHostsz$DefaultAPITests.test_notInKnownHosts%sC��

�"�"������AQ�AQ�8R�8W�8W�(X�
��	
����A�r%c�:�|jdj�j�d}tj|tjt�j�dt|j�ji�}|jd|�y)z�
        L{default.isInKnownHosts} should return C{2} when a host with a key
        other than the given one is in the known hosts file.
        rrr5�N)
r�rHrrr�rr*r/r�rr�r�r(r�s   r#�test_inKnownHostsKeyChangedz+DefaultAPITests.test_inKnownHostsKeyChanged/s~��
�!�!�*�-�6�6�8�>�>�@��C���"�"���N�N�>�*�/�/�1�
�H�T�%5�%5�6�;�;�<�
��
	
����A�r%N)r:r;r<r=r~rCr�r�r�r�r�r�r�r�r�r>r%r#rxrx�s>���
�
�(
!�&�*!�&
�06�,5���r%rx)Er=r��binasciirrtrr�unittestr�zope.interface.verifyr�twisted.conch.errorrr	r
�twisted.conch.interfacesr�twisted.internet.deferr�twisted.python.compatr
�twisted.python.filepathr�twisted.python.reflectr�twisted.test.testutilsr�twisted.trial.unittestr�twisted.conch.clientr�twisted.conch.client.knownhostsrrrrr�twisted.conch.ssh.keysrr�twisted.conch.testr�skip�sampleEncodedKey�otherSampleEncodedKeyr��ecdsaSampleEncodedKeyr+r/r�r�rLr�rMr`rr@rOrTrbrdrmr�r<rKr	rur�rxr>r%r#�<module>r�s����

�C�C��.�M�M�4�+�/�,�0�7�+��� �,���8�*�@�D���>��
��N��

�'�(�	��1�2���1�2���1�2��7�:J�J�U�R��1�4I�I�E�Q��5�7G�G�%�O��
M������-D�-D�`S�o�x�S�@K��K�L
��(<�h�L
�^C�"2�C�#Q��?�#Q�Lc1�h�c1�Lv9�h�v9�r��BoL�X�oL�d'�'�@���H�Z� �'�'�)�)�+D�E�r�h�r�F�rr%

Zerion Mini Shell 1.0