+
    Dfjp                    V   R t ^ RIHt ^ RIt^ RIHtHtHt ^ RI	H
t
 ^ RIHt ^ RIHtHtHt ^ RIHt ^ RIHt ^ R	IHt ^ R
IHt ^ RIHt ^ RIHt ^ RIHt ]! R4      '       d$   ^ RIH t  ^ RI!H"t"H#t#H$t$H%t%H&t& ^ RI'H(t(H)t) ^ RI*H+t+ M],t"Rt-Rt.Rt/Rt0Rt1]! ].4      t2]! ]/4      t3]! ]04      t4]! ]14      t5R].,           R,           t6R]/,           R,           t7R].,           R,           t8R].,           R,           t9 ! R R4      t: ! R R ]:]4      t; ! R! R"];4      t< ! R# R$]:]]4      t= ! R% R&]=4      t> ! R' R(]]:4      t? ! R) R*]4      t@ ! R+ R,]4      tA ! R- R.4      tB ! R/ R0]4      tC ! R1 R2]"4      tD ! R3 R44      tE]
! ]! R54      P                  4       '       * R64       ! R7 R8]4      4       tGR# )9z/
Tests for L{twisted.conch.client.knownhosts}.
)annotationsN)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.st  AAAAB3NzaC1yc2EAAAABIwAAAQEAsV0VMRbGmzhqxxayLRHmvnFvtyNqgbNKV46dU1bVFB+3ytNvue4Riqv/SVkPRNwMb7eWH29SviXaBxUhYyzKkDoNUq3rTNnH1Vnif6d6X4JCrUb5d3W+DmYClyJrZ5HgD/hUpdSkTRqdbQ2TrvSAxRacj+vHHT4F4dm1bJSewm3B2D8HVOoi/CbVh3dsIiCdp8VltdZx4qYVfYe2LwVINCbAa3d3tj9ma7RVfw3OH2Mfb+toLd1N5tBQFb7oqTt2nC6I/6Bd4JwPUld+IEitw/suElq/AIJVQXXujeyiZlea90HE65U2mF1ytr17HTAIT2ySokJWyuBANGACk6iIaw==s   AAAAB3NzaC1yc2EAAAABIwAAAIEAwaeCZd3UCuPXhX39+/p9qO028jTF76DMVd9mPvYVDVXufWckKZauF7+0b7qm+ChT7kan6BzRVo4++gCVNfAlMzLysSt3ylmOR48tFpAfygg9UCX3DjHz0ElOOUKh3iifc9aUShD0OPaK3pR5JJ8jfiBfzSYWt/hDi/iZ4igsSs8=st  AAAAB3NzaC1yc2EAAAABIwAAAQEAl/TQakPkePlnwCBRPitIVUTg6Z8VzN1en+DGkyo/evkmLw7o4NWR5qbysk9A9jXW332nxnEuAnbcCam9SHe1su1liVfyIK0+3bdn0YRB0sXIbNEtMs2LtCho/aV3cXPS+Cf1yut3wvIpaRnAzXxuKPCTXQ7/y0IXa8TwkRBH58OJa3RqfQ/NsSp5SAfdsrHyH2aitiVKm2jfbTKzSEqOQG/zq4J9GXTkq61gZugory/Tvl5/yPgSnOR6C9jVOMHf27ZPoRtyj9SY343Hd2QHiIE0KPZJEgCynKeWoKz8v6eTSK8n4rBnaqWdp8MnGZK1WGy05MguXbyCDuTC8AmJXQ==s   AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBIFwh3/zBANyPPIE60SMMfdKMYo3OvfvzGLZphzuKrzSt0q4uF+/iYqtYiHhryAwU/fDWlUQ9kck9f+IlpsNtY4=s   www.twistedmatrix.com ssh-rsa    
s   divmod.com ssh-rsa s-   www.twistedmatrix.com,198.49.126.131 ssh-rsa sE   |1|gJbSEPBG9ZSBoZpHNtZBD1bHKBA=|bQv+0Xa0dByrwkA1EB0E7Xop/Fo= ssh-rsa c                  D    ] tR t^Zt$ RtR]R&   R R ltR tR tR t	R	t
R
# )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.
r   entryc                   V ^8  d   QhRR/#    returnNone )formats   "D/usr/lib/python3/dist-packages/twisted/conch/test/test_knownhosts.py__annotate__EntryTestsMixin.__annotate__f   s     2 2 2    c                :    \        \        V P                  4       R# )z1
The given entry should provide IKnownHostEntry.
N)r   r   r   selfs   &r'   test_providesInterface&EntryTestsMixin.test_providesInterfacef   s     	_djj1r*   c                    V P                   pV P                  VP                  \        P                  ! \
        4      4       V P                  VP                  R4       R# )an  
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_fromStringEntryTestsMixin.test_fromStringl   s>     

#..*CD
3r*   c                   \         P                  ! \        4      p\         P                  ! \        4      pV P	                  RV P
                  P                  V4      4       V P	                  RV P
                  P                  V4      4       R# )zR
L{IKnownHostEntry.matchesKey} checks to see if an entry matches a given
SSH key.
TFN)r   r4   r5   otherSampleKeyr2   r   
matchesKey)r-   twistedmatrixDotComdivmodDotComs   &  r'   test_matchesKeyEntryTestsMixin.test_matchesKeyy   s`    
 "nnY7~~n5tzz445HIJ

 5 5l CDr*   c                    V P                  V P                  P                  R4      4       V P                  V P                  P                  R4      4       R# )zT
L{IKnownHostEntry.matchesHost} checks to see if an entry matches a
given hostname.
   www.twistedmatrix.coms   www.divmod.comN)
assertTruer   matchesHostassertFalser,   s   &r'   test_matchesHost EntryTestsMixin.test_matchesHost   s>    
 	

../GHI//0ABCr*   r%   N)__name__
__module____qualname____firstlineno____doc____annotations__r.   r7   r>   rE   __static_attributes__r%   r*   r'   r   r   Z   s%     24EDr*   r   c                  F    ] tR t^tRt]t]tR R lt	R R lt
R R ltRtR	# )
PlainEntryTestsz
Test cases for L{PlainEntry}.
c                   V ^8  d   QhRR/# r!   r%   )r&   s   "r'   r(   PlainEntryTests.__annotate__   s     ? ?t ?r*   c                P    \         P                  ! V P                  4      V n        R# )zE
Set 'entry' to a sample plain-text entry with sampleKey as its key.
N)r   r4   plaintextLiner   r,   s   &r'   setUpPlainEntryTests.setUp   s      **4+=+=>
r*   c                   V ^8  d   QhRR/# r!   r%   )r&   s   "r'   r(   rQ      s        D  r*   c                    \         P                  ! V P                  4      V n        V P	                  V P                  P                  R4      4       V P                  4        R# )zE
A "hostname,ip" formatted line will match both the host and the IP.
s   198.49.126.131N)r   r4   
hostIPLiner   rB   rC   rE   r,   s   &r'   test_matchesHostIP"PlainEntryTests.test_matchesHostIP   sB      **4??;


../@ABr*   c                   V ^8  d   QhRR/# r!   r%   )r&   s   "r'   r(   rQ      s     S St Sr*   c                >   V P                  V P                  P                  4       V P                  P	                  R4      4       \
        P                  ! V P                  4      pV P                  VP                  4       V P                  P	                  R4      4       R# )zd
L{PlainEntry.toString} generates the serialized OpenSSL format string
for the entry, sans newline.
r   N)r2   r   toStringrS   rstripr   r4   rX   )r-   multiHostEntrys   & r'   test_toStringPlainEntryTests.test_toString   sn    
 	,,.0B0B0I0I%0PQ#..t?002DOO4J4J54QRr*   r   N)rG   rH   rI   rJ   rK   samplePlaintextLinerS   sampleHostIPLinerX   rT   rY   r`   rM   r%   r*   r'   rO   rO      s)     (M!J? S Sr*   rO   c                  J    ] tR t^tRt]RR R,           t]RR R,           tRt	R# )PlainTextWithCommentTestsF
Test cases for L{PlainEntry} when parsed from a line with a comment.
N    plain text comment.
s    text following host/IP line
r%   )
rG   rH   rI   rJ   rK   rc   rS   rd   rX   rM   r%   r*   r'   rf   rf      s-     (,/HHM!#2&)JJJr*   rf   c                  B    ] tR t^tRt]tR R ltR R ltR R lt	Rt
R	# )
HashedEntryTestsa.  
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                   V ^8  d   QhRR/# r!   r%   )r&   s   "r'   r(   HashedEntryTests.__annotate__   s     = =t =r*   c                P    \         P                  ! V P                  4      V n        R# )zW
Set 'entry' to a sample hashed entry for twistedmatrix.com with
sampleKey as its key.
N)r   r4   
hashedLiner   r,   s   &r'   rT   HashedEntryTests.setUp   s    
 !++DOO<
r*   c                   V ^8  d   QhRR/# r!   r%   )r&   s   "r'   r(   rm      s     O Ot Or*   c                    V P                  V P                  P                  4       V P                  P	                  R4      4       R# )zi
L{HashedEntry.toString} generates the serialized OpenSSL format string
for the entry, sans the newline.
r   N)r2   r   r]   ro   r^   r,   s   &r'   r`   HashedEntryTests.test_toString   s0    
 	,,.0F0Fu0MNr*   c                   V ^8  d   QhRR/# r!   r%   )r&   s   "r'   r(   rm      s     2
 2
t 2
r*   c                Z   RpRp\         P                  ! \        4      p\        VP	                  4       4      pRp\        WWCV4      p\        WWCV4      pV P                  VV\        VRRR1,          W$W54      4       V P                  VV\        WRRR1,          WCV4      4       V P                  VV\        WVRRR1,          W54      4       V P                  VV\        WV\         P                  ! \        4      V4      4       V P                  VV\        WWCVRRR1,          4      4       R# )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.
s   gJbSEPBG9ZSBoZpHNtZBD1bHKBAs   bQv+0Xa0dByrwkA1EB0E7Xop/Fos   hello, worldNri   )r   r4   r5   r   typer   "assertNormalEqualityImplementationr:   )r-   hostSalthostHashr3   r6   commentr   	duplicates   &       r'   test_equalityHashedEntryTests.test_equality   s&    21NN9-		 01!HGLGP	 	//29N	
 	//4R4.'gN	
 	//GDbDM9N	
 	//GS^^N-KW	
 	//G"N	
r*   rb   N)rG   rH   rI   rJ   rK   sampleHashedLinero   rT   r`   r|   rM   r%   r*   r'   rk   rk      s#     "J=O2
 2
r*   rk   c                  2    ] tR tRtRt]RR R,           tRtR# )HashedEntryWithCommentTestsi  rg   Nrh   r%   ri   )rG   rH   rI   rJ   rK   r~   ro   rM   r%   r*   r'   r   r     s     "#2&)BBJr*   r   c                  V    ] tR tRtRtR R ltR R ltR R ltR	 R
 ltR R lt	Rt
R# )UnparsedEntryTestsi  z
Tests for L{UnparsedEntry}
c                   V ^8  d   QhRR/# r!   r%   )r&   s   "r'   r(   UnparsedEntryTests.__annotate__  s     F Ft Fr*   c                &    \        R4      V n        R# )zB
Set up the 'entry' to be an unparsed entry for some random text.
s       This is a bogus entry.  
N)r   r   r,   s   &r'   rT   UnparsedEntryTests.setUp  s     ##DE
r*   c                   V ^8  d   QhRR/# r!   r%   )r&   s   "r'   r(   r     s     Q Q Qr*   c                Z    V P                  RV P                  P                  4       4       R# )zM
Creating an L{UnparsedEntry} should simply record the string it was
passed.
       This is a bogus entry.  Nr2   r   r]   r,   s   &r'   r7   "UnparsedEntryTests.test_fromString  "    
 	8$**:M:M:OPr*   c                   V ^8  d   QhRR/# r!   r%   )r&   s   "r'   r(   r     s     K K$ Kr*   c                Z    V P                  V P                  P                  R4      4       R# )z*
An unparsed entry can't match any hosts.
rA   N)rD   r   rC   r,   s   &r'   rE   #UnparsedEntryTests.test_matchesHost  s"     	//0HIJr*   c                   V ^8  d   QhRR/# r!   r%   )r&   s   "r'   r(   r   $  s     K K Kr*   c                    V P                  V P                  P                  \        P                  ! \
        4      4      4       R# )z)
An unparsed entry can't match any keys.
N)rD   r   r;   r   r4   r5   r,   s   &r'   r>   "UnparsedEntryTests.test_matchesKey$  s*     	..s~~i/HIJr*   c                   V ^8  d   QhRR/# r!   r%   )r&   s   "r'   r(   r   *  s     Q Qt Qr*   c                Z    V P                  RV P                  P                  4       4       R# )zL
L{UnparsedEntry.toString} returns its input string, sans trailing
newline.
r   Nr   r,   s   &r'   r`    UnparsedEntryTests.test_toString*  r   r*   rb   N)rG   rH   rI   rJ   rK   rT   r7   rE   r>   r`   rM   r%   r*   r'   r   r     s+    FQKKQ Qr*   r   c                      ] tR tRtRtR R ltR R ltR R ltR	 R
 ltR R lt	R R lt
R R ltR R ltR R ltRtR# )ParseErrorTestsi2  a  
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                    V ^8  d   QhRRRR/# r"   clstype[HashedEntry | PlainEntry]r#   r$   r%   )r&   s   "r'   r(   ParseErrorTests.__annotate__<  s     D D$B Dt Dr*   c                H    V P                  \        VP                  R4       R# )zU
If there are fewer than three elements, C{fromString} should raise
L{InvalidEntry}.
s   invalidN)assertRaisesr	   r4   r-   r   s   &&r'   invalidEntryTest ParseErrorTests.invalidEntryTest<  s    
 	,
Cr*   c                    V ^8  d   QhRRRR/# r   r%   )r&   s   "r'   r(   r   C  s     C C!? CD Cr*   c                H    V P                  \        VP                  R4       R# )zH
If the key is not base64, C{fromString} should raise L{BinasciiError}.
s   x x xN)r   BinasciiErrorr4   r   s   &&r'   notBase64TestParseErrorTests.notBase64TestC  s     	-Br*   c               $    V ^8  d   QhRRRRRR/# )r"   r   r   prefixbytesr#   r$   r%   )r&   s   "r'   r(   r   I  s#     
 
< 
e 
PT 
r*   c                    V P                  \        VP                  RP                  VR\	        R4      P                  4       .4      4       R# )z}
If the key portion of the entry is valid base64, but is not actually an
SSH key, C{fromString} should raise L{BadKeyError}.
    r1   s   Hey, this isn't an SSH key!N)r   r   r4   joinr   strip)r-   r   r   s   &&&r'   
badKeyTestParseErrorTests.badKeyTestI  sA    
 	NNIIZ0N%O%U%U%WX	
r*   c                   V ^8  d   QhRR/# r!   r%   )r&   s   "r'   r(   r   V  s     * * *r*   c                0    V P                  \        4       R# )z
If there are fewer than three whitespace-separated elements in an
entry, L{PlainEntry.fromString} should raise L{InvalidEntry}.
N)r   r   r,   s   &r'   test_invalidPlainEntry&ParseErrorTests.test_invalidPlainEntryV  s    
 	j)r*   c                   V ^8  d   QhRR/# r!   r%   )r&   s   "r'   r(   r   ]  s     

 

 

r*   c           	         V P                  \        4       \        P                  4       w  rpV P	                  \
        \        P                  RP                  VR,           W#.4      4       R# )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}.
r   s   ||N)r   r   r~   splitr   r	   r4   r   r-   abcs   &   r'   test_invalidHashedEntry'ParseErrorTests.test_invalidHashedEntry]  sQ     	k*"((*a+00$))QY<M2N	
r*   c                   V ^8  d   QhRR/# r!   r%   )r&   s   "r'   r(   r   i  s     ' 'T 'r*   c                0    V P                  \        4       R# )zn
If the key portion of a plain entry is not decodable as base64,
C{fromString} should raise L{BinasciiError}.
N)r   r   r,   s   &r'   test_plainNotBase64#ParseErrorTests.test_plainNotBase64i  s    
 	:&r*   c                   V ^8  d   QhRR/# r!   r%   )r&   s   "r'   r(   r   p  s     
 
d 
r*   c           
     D   V P                  \        4       \        P                  4       w  rpV P	                  \
        \        P                  RP                  R\        R4      P                  4       ,           W#.4      4       V P	                  \
        \        P                  RP                  \        P                  \        R4      P                  4       ,           R,           W#.4      4       V P	                  \
        \        P                  RP                  RW#.4      4       R# )zo
If the key, host salt, or host hash portion of a hashed entry is not
encoded, it will raise L{BinasciiError}.
r   s   |1|x|   stuffs   |xs   |1|x|xN)r   r   r~   r   r   r   r4   r   r   r   MAGICr   s   &   r'   test_hashedNotBase64$ParseErrorTests.test_hashedNotBase64p  s    
 	;'"((*a""IIx*X"6"<"<">>EF	
 	""II{((:h+?+E+E+GG%OQRVW	
 	;11499i=N3O	
r*   c                   V ^8  d   QhRR/# r!   r%   )r&   s   "r'   r(   r     s     ( (4 (r*   c                `    \         P                  4       w  rpV P                  \        V4       R# )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~   r   r   r   r   s   &   r'   test_hashedBadKey!ParseErrorTests.test_hashedBadKey  s$    
 #((*aQ'r*   c                   V ^8  d   QhRR/# r!   r%   )r&   s   "r'   r(   r     s     1 1$ 1r*   c                2    V P                  \        R4       R# )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}.
s   hostnameN)r   r   r,   s   &r'   test_plainBadKey ParseErrorTests.test_plainBadKey  s    
 	
K0r*   r%   N)rG   rH   rI   rJ   rK   r   r   r   r   r   r   r   r   r   rM   r%   r*   r'   r   r   2  s;    DC
*

'
0(1 1r*   r   c                  ,   ] tR tRtRtR R lt]],           R,           3R R lltR t	R	 t
R
 tR tR tR tR tR tR tR tR tR tR tR tR tR tR tR tR tR tR tR tR tR t R  t!R! t"R" t#R# t$R$ t%R% t&R& t'R' t(R( R) lt)R* R+ lt*R,t+R-# ).KnownHostsDatabaseTestsi  z
Tests for L{KnownHostsFile}.
c                    V ^8  d   QhRRRR/# )r"   contentr   r#   zFilePath[str]r%   )r&   s   "r'   r(   $KnownHostsDatabaseTests.__annotate__  s      u  r*   c                Z    \        V P                  4       4      pVP                  V4       V# )z3
Return a FilePath with the given initial content.
)r   mktemp
setContent)r-   r   fps   && r'   pathWithContent'KnownHostsDatabaseTests.pathWithContent  s%     dkkm$
g	r*   sN   
# That was a blank line.
This is just unparseable.
|1|This also unparseable.
c                    V ^8  d   QhRRRR/# )r"   r   r   r#   r   r%   )r&   s   "r'   r(   r     s"     F FF 
Fr*   c                L    \         P                  ! V P                  V4      4      # )zY
Return a sample hosts file, with keys for www.twistedmatrix.com and
divmod.com present.
)r   fromPathr   )r-   r   s   &&r'   loadSampleHostsFile+KnownHostsDatabaseTests.loadSampleHostsFile  s      &&t';';G'DEEr*   c                    \        V P                  4       4      p\        V P                  4       4      p\        V4      pV P                  \        \
        VRV4       V P                  WP                  4       R# )z
L{KnownHostsFile.savePath} is read-only; if an assignment is made to
it, L{AttributeError} is raised and the value is unchanged.
savePathN)r   r   r   r   AttributeErrorsetattrr2   r   )r-   pathnew	hostsFiles   &   r'   test_readOnlySavePath-KnownHostsDatabaseTests.test_readOnlySavePath  sX    
 &t{{}%"4(	.'9j#N112r*   c                    \        V P                  \        4      4      pV P                  . \	        VP                  4       4      4       R# )zb
The default initializer for L{KnownHostsFile} disregards any existing
contents in the save path.
N)r   r   r~   r2   listiterentriesr-   r   s   & r'   &test_defaultInitializerIgnoresExisting>KnownHostsDatabaseTests.test_defaultInitializerIgnoresExisting  s8    
 #4#7#78H#IJ	T)"7"7"9:;r*   c                x   V P                  \        4      p\        V4      pVP                  R\        P
                  ! \        4      4      pVP                  4        V P                  V.\        VP                  4       4      4       V P                  VP                  4       R,           VP                  4       4       R# )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.comr   N)r   r~   r   
addHostKeyr   r4   r:   saver2   r   r   r]   
getContent)r-   r   r   r   s   &   r'   'test_defaultInitializerClobbersExisting?KnownHostsDatabaseTests.test_defaultInitializerClobbersExisting  s     ##$45"4(	$$%79WX%$y'<'<'>"?@)E14??3DEr*   c                ~   \        V P                  \        4      4      pVP                  R\        P
                  ! \        4      4      pVP                  4        VP                  R\        P
                  ! \        4      4      pVP                  4        V P                  W#.\        VP                  4       4      4       R# )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   s   another.example.comN)r   r   r~   r   r   r4   r:   r   thirdSampleKeyr2   r   r   )r-   r   preSavepostSaves   &   r'   test_saveResetsClobberState3KnownHostsDatabaseTests.test_saveResetsClobberState  s     #4#7#78H#IJ	&&~ >
 	''"CNN>$B
 	',d93H3H3J.KLr*   c           	         V P                  4       pV P                  ^\        \        VP	                  4       4      4      4       R# )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   r2   lenr   r   r   s   & r'   test_loadFromPath)KnownHostsDatabaseTests.test_loadFromPath  s5     ,,.	CY%:%:%< =>?r*   c           	        \        \        V P                  4       4      4      pVP                  R\        P
                  ! \        4      4       V P                  ^\        \        VP                  4       4      4      4       R# )z
If the save path for a L{KnownHostsFile} does not exist,
L{KnownHostsFile.iterentries} still returns added but unsaved entries.
r   N)r   r   r   r   r   r4   r5   r2   r   r   r   r   s   & r'   test_iterentriesUnsaved/KnownHostsDatabaseTests.test_iterentriesUnsaved  sV    
 #8DKKM#:;	/	1JKCY%:%:%< =>?r*   c                    V P                  \        4      p\        VP                  4       4      pV P	                  V^ ,          \
        4       V P                  V^ ,          P                  R4      4       V P                  ^\        V4      4       R# )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.
rA   N)
r   r~   r   r   assertIsInstancer   rB   rC   r2   r   r-   r   entriess   &  r'   test_verifyHashedEntry.KnownHostsDatabaseTests.test_verifyHashedEntry  sl     ,,-=>	y,,./gaj+6
../GHICL)r*   c                    V P                  \        4      p\        VP                  4       4      pV P	                  V^ ,          \
        4       V P                  V^ ,          P                  R4      4       V P                  ^\        V4      4       R# )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.

   divmod.comN)
r   otherSamplePlaintextLiner   r   r  r   rB   rC   r2   r   r  s   &  r'   test_verifyPlainEntry-KnownHostsDatabaseTests.test_verifyPlainEntry  sk     ,,-EF	y,,./gaj*5
..}=>CL)r*   c                   V P                  R4      p\        VP                  4       4      pV P                  V^ ,          \        4       V P                  V^ ,          P                  4       R4       V P                  ^\        V4      4       R# )z
        Loading a L{KnownHostsFile} from a path that only contains '
' will
        result in a L{KnownHostsFile} object containing a L{UnparsedEntry}
        object.
        r   r*   Nr   r   r   r  r   r2   r]   r   r  s   &  r'   test_verifyUnparsedEntry0KnownHostsDatabaseTests.test_verifyUnparsedEntry  sl     ,,U3	y,,./gaj-8,,.4CL)r*   c                    V P                  R4      p\        VP                  4       4      pV P                  V^ ,          \        4       V P                  V^ ,          P                  4       R4       R# )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.
s   # That was a blank line.N)r   r   r   r  r   r2   r]   r  s   &  r'   test_verifyUnparsedComment2KnownHostsDatabaseTests.test_verifyUnparsedComment  sZ     ,,-JK	y,,./gaj-8,,.0KLr*   c                   V P                  R4      p\        VP                  4       4      pV P                  V^ ,          \        4       V P                  V^ ,          P                  4       R4       V P                  ^\        V4      4       R# )z
Loading a L{KnownHostsFile} from a path that contains an unparseable
line will be represented as an L{UnparsedEntry} instance.
s   This is just unparseable.
s   This is just unparseable.Nr  r  s   &  r'   test_verifyUnparsableLine1KnownHostsDatabaseTests.test_verifyUnparsableLine*  sn    
 ,,-KL	y,,./gaj-8,,.0LMCL)r*   c                   V P                  R4      p\        VP                  4       4      pV P                  V^ ,          \        4       V P                  V^ ,          P                  4       R4       V P                  ^\        V4      4       R# )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.
s   |1|This is unparseable.Nr  r  s   &  r'   %test_verifyUnparsableEncryptionMarker=KnownHostsDatabaseTests.test_verifyUnparsableEncryptionMarker5  sn     ,,-IJ	y,,./gaj-8,,.0JKCL)r*   c                z   V P                  4       p\        P                  ! \        V4      4      p\	        VP                  4       4      pV P                  . V4       V P                  \        V4      P                  4       4       VP                  4        V P                  \        V4      P                  4       4       R# )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   r   r   r   r   r   r2   rD   existsr   rB   )r-   pnknownHostsFiler  s   &   r'   test_loadNonExistent,KnownHostsDatabaseTests.test_loadNonExistentA  s    
 [[]'00">~1134W%",,./++-.r*   c                $   \        V P                  4       4      pVP                  R4      P                  R4      p\        P                  ! V4      pVP                  4        VP                  R4       V P                  VP                  4       4       R# )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.
foos   known_hostsFN)	r   r   childr   r   r   restatrB   r  )r-   thePathknownHostsPathr  s   &   r'   test_loadNonExistentParent2KnownHostsDatabaseTests.test_loadNonExistentParentN  sl     4;;=) u-33NC'00@e$--/0r*   c                   V P                  \        \        ,           4      p\        P                  ! V4      pVP                  R\        P                  ! \        4      4      p\        \        ,           \        P                  ,           \        VP                  4      P                  4       ,           R,           \        VP                  4      P                  4       ,           R,           \        ,           R,           pV P!                  ^VP#                  R4      4       VP%                  4        V P!                  WAP'                  4       4       R# )zY
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
  r   r   r   r   r4   r   r   r   r   	_hostSaltr   	_hostHashthirdSampleEncodedKeyr2   countr   r   )r-   r   r  newEntryexpectedContents   &    r'   test_savingAddsEntry,KnownHostsDatabaseTests.test_savingAddsEntry[  s   
 ##$47O$OP'006!,,!?
 &'  ++,2245 	
 ++,2245  $$  	 	O11%89//*;<r*   c                b   \        V P                  4       4      p\        V4      pVP                  R\        P
                  ! \        4      4      pVP                  4        VP                  4        \        P                  ! V4      pV P                  V.\        VP                  4       4      4       R# )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)r   r   r   r   r   r4   r5   r   r   r2   r   r   )r-   r   
knownHostsr   s   &   r'   test_savingAvoidsDuplication4KnownHostsDatabaseTests.test_savingAvoidsDuplicationw  s~     &#D)
%%&93>>);TU#,,T2
%$z'='='?"@Ar*   c           
        V P                  \        4      p\        P                  ! V4      pVP	                  R4      ;_uu_ 4       pVP                  \        4       RRR4       \        P                  ! \        4      pVP                  RV4       VP                  4        \        P                  ! V4      pV P                  . ROVP                  R\        P                  ! \        4      4      VP                  R\        P                  ! \        4      4      VP                  RV4      .4       R#   + '       g   i     L; i)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.comrA   r	  )TTT)r   r~   r   r   openwriter
  r   r4   r   r   r   r2   
hasHostKeyr5   r:   )r-   r   r4  hostsFileObjkeys   &    r'   test_savingsPreservesExisting5KnownHostsDatabaseTests.test_savingsPreservesExisting  s     ##$45#,,T2
 YYs^^|78  nn^,5s; $,,T2
%%,cnnY.G %%mS^^N5ST%%&=sC		
 ^s   D..D>	c                    V P                  4       pV P                  VP                  R\        P                  ! \
        4      4      4       R# )zy
L{KnownHostsFile.hasHostKey} returns C{True} when a key for the given
hostname is present and matches the expected key.
rA   N)r   rB   r;  r   r4   r5   r   s   & r'   test_hasPresentKey*KnownHostsDatabaseTests.test_hasPresentKey  s8    
 ,,.	  !93>>);TU	
r*   c                |   V P                  4       pV P                  VP                  R\        P                  ! \
        4      4      4       V P                  VP                  R\        P                  ! \
        4      4      4       V P                  VP                  R\        P                  ! \        4      4      4       R# )za
L{KnownHostsFile.hasHostKey} returns C{False} when a key for the given
hostname is not present.
s   non-existent.example.comrA   N)r   rD   r;  r   r4   r5   rB   ecdsaSampleKeyr   s   & r'   test_notPresentKey*KnownHostsDatabaseTests.test_notPresentKey  s    
 ,,.	  !<cnnY>WX	
 	  !93>>);TU	
 	  (#..*H	
r*   c                   \         P                  ! \        4      p\        R.VP	                  4       VR4      pV P                  4       pVP                  P                  R4      ;_uu_ 4       pVP                  VP                  4       R,           4       RRR4       V P                  RVP                  RV4      4       R#   + '       g   i     L4; i)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.
r8  r*   r   r   NT)r   r4   r5   r   sshTyper   r   r9  r:  r]   r2   r;  )r-   r=  r   r   r<  s   &    r'   test_hasLaterAddedKey-KnownHostsDatabaseTests.test_hasLaterAddedKey  s     nnY'34ckkmS#N,,.	$$S))\u~~/%78 *y334KSQR *)s   +'B>>C	c                   V P                  4       p\        VP                  4       4      pV P                  \        VP
                  R\        P                  ! \        4      4      pV P                  VP                  V^ ,          4       V P                  VP                  ^4       V P                  VP                  VP                  4       R# )z
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.
rA   N)r   r   r   r   r   r;  r   r4   r:   r2   offendingEntrylinenor   r   )r-   r   r  	exceptions   &   r'   test_savedEntryHasKeyMismatch5KnownHostsDatabaseTests.test_savedEntryHasKeyMismatch  s     ,,.	y,,./%%  $NN>*	
	 	1171:>))1-););<r*   c                r   V P                  4       pVP                  R\        P                  ! \        4      4       V P                  \        VP                  R\        P                  ! \        4      4      pV P                  VP                  ^4       V P                  VP                  VP                  4       R# )a9  
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   rA   N)r   r   r   r4   r:   r   r   r;  r2   rM  r   r   )r-   r   rN  s   &  r'   %test_savedEntryAfterAddHasKeyMismatch=KnownHostsDatabaseTests.test_savedEntryAfterAddHasKeyMismatch  s     ,,.	/1OP%%  $NN>*	
	 	))1-););<r*   c                   \        \        V P                  4       4      4      pVP                  R\        P
                  ! \        4      4      pV P                  \        VP                  R\        P
                  ! \        4      4      pV P                  VP                  V4       V P                  VP                  4       V P                  VP                  4       R# )aJ  
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)r   r   r   r   r   r4   r:   r   r   r;  r   r2   rL  assertIsNonerM  r   )r-   r   r   rN  s   &   r'   test_unsavedEntryHasKeyMismatch7KnownHostsDatabaseTests.test_unsavedEntryHasKeyMismatch  s     #8DKKM#:;	$$%79WX%%  NN>*	
	 	1159)**+)..)r*   c                    V P                  4       p\        P                  ! \        4      pV P	                  RVP                  RV4      4       VP                  RV4      pV P	                  ^\        VP                  4      4       V P	                  RVP                  R4      4       V P	                  VP                  R4       V P	                  W#P                  4       V P	                  RVP                  RV4      4       R# )zZ
L{KnownHostsFile.addHostKey} adds a new L{HashedEntry} to the host
file, and returns it.
F   somewhere.example.comTr1   N)r   r   r4   r   r2   r;  r   r   r+  rC   r6   r3   )r-   r   aKeyr/  s   &   r'   test_addHostKey'KnownHostsDatabaseTests.test_addHostKey
  s    
 ,,.	~~n-	 4 45Mt TU''(@$G
 	S!3!345x334LMN)):6112y334LdSTr*   c                    V P                  4       p\        P                  ! \        4      pV P	                  VP                  RV4      P                  VP                  RV4      P                  4       R# )zo
L{KnownHostsFile.addHostKey} generates a random salt for each new key,
so subsequent salts will be different.
rY  s   somewhere-else.example.comN)r   r   r4   r   assertNotEqualr   r+  )r-   r   rZ  s   &  r'   test_randomSalts(KnownHostsDatabaseTests.test_randomSalts  s\    
 ,,.	~~n-  !94@JJ  !>EOO	
r*   c                F   V P                  4       pVP                  R\        P                  ! \        4      4       \        4       pVP                  VRR\        P                  ! \        4      4      p. pVP                  VP                  4       V P                  VR.4       R# )zJ
Verifying a valid key should return a L{Deferred} which fires with
True.
   1.2.3.4rA   TN)
r   r   r   r4   r5   FakeUIverifyHostKeyaddCallbackappendr2   )r-   r   uidls   &    r'   test_verifyValidKey+KnownHostsDatabaseTests.test_verifyValidKey)  s~    
 ,,.	Z	)BCX##(*cnnY6O
 	ahhTF#r*   c                   V P                  4       p\        P                  ! \        4      p\	        4       pVP                  R\        P                  ! \        4      4       VP                  VRRV4      pV P                  V\        4      # )zd
Verifying an invalid key should return a L{Deferred} which fires with a
L{HostKeyChanged} failure.
rb  rA   )
r   r   r4   r   rc  r   r5   rd  assertFailurer   r-   r   wrongKeyrg  rh  s   &    r'   test_verifyInvalidKey-KnownHostsDatabaseTests.test_verifyInvalidKey8  sj    
 ,,.	>>.1XZ	)BC##B(@*hW!!!^44r*   c                0   V P                  4       p\        P                  ! \        4      p\	        4       p. pVP                  VRRV4      pVP                  VP                  4       V P                  . V4       V P                  VP                  R4       W4V3# )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   r   r4   r   rc  rd  addBothrf  r2   
promptText)r-   r   	absentKeyrg  ri  rh  s   &     r'   verifyNonPresentKey+KnownHostsDatabaseTests.verifyNonPresentKeyD  s     ,,.	NN>2	X##*J	
 	
		!((QMMG	
 ir*   c           	        V P                  4       w  rpVP                  P                  R4       V P                  R.V4       \        P
                  ! VP                  4      pV P                  RVP                  R\        P                  ! \        4      4      4       V P                  RVP                  R\        P                  ! \        4      4      4       R# )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.
Trt  rs  N)rx  promptDeferredcallbackr2   r   r   r   r;  r   r4   r   )r-   rg  ri  r  reloadeds   &    r'   test_verifyNonPresentKey_Yes4KnownHostsDatabaseTests.test_verifyNonPresentKey_Yesb  s     !% 8 8 :~
""4($#!**>+B+BC(%%j#..2PQ	
 	*CNN>,J	
r*   c                    V P                  4       w  rpVP                  P                  R4       V^ ,          P                  \        4       R# )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.
FN)rx  r{  r|  trapr
   )r-   rg  ri  r  s   &   r'   test_verifyNonPresentKey_No3KnownHostsDatabaseTests.test_verifyNonPresentKey_Nov  s;     !% 8 8 :~
""5)	!		/"r*   c                   \         P                  ! \        P                  R,          \        P                  R,          \        P                  R,          \        P                  R,          R7      pV P	                  4       p\        4       p. pVP                  VRRV4      pVP                  VP                  4       V P                  . V4       V P                  VP                  R4       R	# )
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  rs  rt  s   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   rc  rd  ru  rf  r2   rv  )r-   ecObjr   rg  ri  rh  s   &     r'   test_verifyNonPresentECKey2KnownHostsDatabaseTests.test_verifyNonPresentECKey  s     %%$$S)$$S) //?((1	
 ,,.	X##B(BJPUV			!((QMMG	
r*   c                    V P                  4       p\        P                  ! \        4      p\	        4       pVP                  VRRV4      pV P                  V\        4      # )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.
rA   rt  )r   r   r4   r   rc  rd  rm  r   rn  s   &    r'   test_verifyHostIPMismatch1KnownHostsDatabaseTests.test_verifyHostIPMismatch  sQ     ,,.	>>.1X##B(@*hW!!!^44r*   c                   V ^8  d   QhRR/# r!   r%   )r&   s   "r'   r(   r     s     
 
D 
r*   c                P   \        4       pV P                  4       p\        P                  ! \        4      pVP                  VRRV4       V P                  R\        P                  ! VP                  4      P                  RV4      4       V P                  R.VP                  4       R# )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.
rA   s   5.4.3.2Tsa   Warning: Permanently added the RSA host key for IP address '5.4.3.2' to the list of known hosts.
N)rc  r   r   r4   r5   rd  r2   r   r   r   r;  userWarnings)r-   rg  r   expectedKeys   &   r'   test_verifyKeyForHostAndIP2KnownHostsDatabaseTests.test_verifyKeyForHostAndIP  s     X,,.	nnY/$<j+V##I$6$67BBK	
 	; OO	
r*   c                   V ^8  d   QhRR/# r!   r%   )r&   s   "r'   r(   r     s     9 94 9r*   c                |   V P                  4       pVP                  R\        P                  ! \        4      4       VP                  R\        P                  ! \
        4      4       VP                  4        / pVP                  P                  VR&   \        P                  ! RV4      pRR.pV P                  W44       R# )zV
For a given host, get the host key algorithms for that
host in the known_hosts file.
rA   known-hostsr1   s   ecdsa-sha2-nistp256N)r   r   r   r4   r:   rD  r   r   r   r   getHostKeyAlgorithmsr2   )r-   r   options
algorithmsexpectedAlgorithmss   &    r'   test_getHostKeyAlgorithms1KnownHostsDatabaseTests.test_getHostKeyAlgorithms  s    
 ,,.	5s~~n7UV5s~~n7UV!*!3!3!8!8112JGT
(*@A8r*   r%   N),rG   rH   rI   rJ   rK   r   r~   r
  r   r   r   r   r   r   r   r  r  r  r  r  r  r  r&  r1  r5  r>  rA  rE  rI  rO  rR  rV  r[  r_  rj  rp  rx  r~  r  r  r  r  r  rM   r%   r*   r'   r   r     s     &'++F 	3<FM$@@
*
*
*	M	*
*/1=8B
B

$S=&=&*(U&

$
5 <
(	#
8
5
09 9r*   r   c                  2    ] tR tRtRtR tR tR tR tRt	R# )	FakeFilei  zO
A fake file-like object that acts enough like a file for
L{ConsoleUI.prompt}.
c                	0    . V n         . V n        R V n        R# )FN)inlines	outchunksclosedr,   s   &r'   __init__FakeFile.__init__  s    r*   c                8    V P                   P                  ^ 4      # )z(
Return a line from the 'inlines' list.
)r  popr,   s   &r'   readlineFakeFile.readline  s     ||""r*   c                v    V P                   '       d   \        R4      hV P                  P                  V4       R# )z0
Append the given item to the 'outchunks' list.
zthe file was closedN)r  OSErrorr  rf  )r-   chunks   &&r'   r:  FakeFile.write  s+     ;;;/00e$r*   c                    RV n         R# )zL
Set the 'closed' flag to True, explicitly marking that it has been
closed.
TN)r  r,   s   &r'   closeFakeFile.close  s    
 r*   )r  r  r  N)
rG   rH   rI   rJ   rK   r  r  r:  r  rM   r%   r*   r'   r  r    s    

#%r*   r  c                  P    ] tR tRtRtR tR tR tR tR t	R t
R	 tR
 tR tRtR# )ConsoleUITestsi  z
Test cases for L{ConsoleUI}.
c                X    \        4       V n        \        V P                  4      V n        R# )z1
Create a L{ConsoleUI} pointed at a L{FakeFile}.
N)r  fakeFiler   openFilerg  r,   s   &r'   rT   ConsoleUITests.setUp  s     !
DMM*r*   c                    V P                   # )z
Return the current fake file.
)r  r,   s   &r'   r  ConsoleUITests.openFile  s     }}r*   c                D    \        4       V n        WP                  n        R# )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  r  r  )r-   liness   &&r'   newFileConsoleUITests.newFile  s    
 !
 %r*   c                f   R F  pV P                  V.4       . pV P                  P                  R4      P                  VP                  4       V P                  R.V P                  P                  4       V P                  R.V4       V P                  V P                  P                  4       K  	  R# )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.
zHello, world!TN)   yess   Yess   yes

r  rg  promptre  rf  r2   r  r  rB   r  )r-   okYesri  s   &  r'   test_promptYesConsoleUITests.test_promptYes  s     0ELL%!AGGNN?+77Ao.0G0GHdVQ'OODMM001 0r*   c                f   R F  pV P                  V.4       . pV P                  P                  R4      P                  VP                  4       V P                  R.V P                  P                  4       V P                  R.V4       V P                  V P                  P                  4       K  	  R# )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.
zGoodbye, world!FN)   nos   Nos   no
r  )r-   okNori  s   &  r'   test_promptNoConsoleUITests.test_promptNo  s     ,DLL$ AGGNN,-99!((C/0$--2I2IJeWa(OODMM001 ,r*   c                   V P                  . RO4       . pV P                  P                  R4      P                  VP                  4       V P                  R.V4       V P                  V P                  P                  R.R.^,          ,           4       V P                  V P                  P                  4       V P                  . RO4       . pV P                  P                  R4      P                  VP                  4       V P                  R.V4       V P                  V P                  P                  R.R.^,          ,           4       V P                  V P                  P                  4       R# )	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.
s   Please say something useful.Ts   Please type 'yes' or 'no': s   Please say something negative.FN)s   whats   uhs   okayr  )s   blahr   s   fehr  r  r-   ri  s   & r'   test_promptRepeatedly$ConsoleUITests.test_promptRepeatedly(  s    	6767CCAHHM$#MM##,-1O0PST0TT	
 	,,-7889EEahhO%!$MM##./3Q2RUV2VV	
 	,,-r*   c                l    R p\        V4      pVP                  R4      pV P                  V\        4      # )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                     \        4       hN)r  r%   r*   r'   raiseIt5ConsoleUITests.test_promptOpenFailed.<locals>.raiseItH  s	    )Or*   zThis is a test.)r   r  rm  IOError)r-   r  rg  rh  s   &   r'   test_promptOpenFailed$ConsoleUITests.test_promptOpenFailedB  s5    	 wII'(!!!W--r*   c                    V P                   P                  R4       V P                  R.V P                  P                  4       V P                  V P                  P                  4       R# )zB
L{ConsoleUI.warn} should output a message to the console object.
zTest message.N)rg  warnr2   r  r  rB   r  r,   s   &r'   	test_warnConsoleUITests.test_warnO  sG     	_%/*DMM,C,CD,,-r*   c                    R p\        V4      pVP                  R4       V P                  \        V P	                  \
        4      4      ^4       R# )zI
L{ConsoleUI.warn} should log a traceback if the output can't be opened.
c                     ^^ ,           R# )   Nr%   r%   r*   r'   r  3ConsoleUITests.test_warnOpenFailed.<locals>.raiseIt\  s    EEr*   zThis message never makes it.N)r   r  r2   r   flushLoggedErrorsZeroDivisionError)r-   r  rg  s   &  r'   test_warnOpenFailed"ConsoleUITests.test_warnOpenFailedW  sA    
	 w
./T334EFGKr*   )r  rg  N)rG   rH   rI   rJ   rK   rT   r  r  r  r  r  r  r  r  rM   r%   r*   r'   r  r    s5    +&22.4..
Lr*   r  c                  >    ] tR tRtRtR R ltR R ltR R ltR	tR
# )rc  id  z
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                   V ^8  d   QhRR/# r!   r%   )r&   s   "r'   r(   FakeUI.__annotate__p  s     - -$ -r*   c                	0    . V n         R V n        R V n        R # r  )r  r{  rv  r,   s   &r'   r  FakeUI.__init__p  s    )+59(,r*   c                    V ^8  d   QhRRRR/# )r"   textr   r#   Deferred[bool]r%   )r&   s   "r'   r(   r  u  s     # #5 #^ #r*   c                D    Wn         \        4       V n        V P                  # )zF
Issue the user an interactive prompt, which they can accept or deny.
)rv  r   r{  r-   r  s   &&r'   r  FakeUI.promptu  s     &j"""r*   c                    V ^8  d   QhRRRR/# )r"   r  r   r#   r$   r%   )r&   s   "r'   r(   r  }  s     ' ' '4 'r*   c                <    V P                   P                  V4       R# )z.
Issue a non-interactive warning to the user.
N)r  rf  r  s   &&r'   r  FakeUI.warn}  s     	  &r*   )r{  rv  r  N)	rG   rH   rI   rJ   rK   r  r  r  rM   r%   r*   r'   rc  rc  d  s    	-
#' 'r*   rc  c                      ] tR tRtRtRtR# )
FakeObjecti  zk
A fake object that can have some attributes.  Used to fake
L{SSHClientTransport} and L{SSHClientFactory}.
r%   N)rG   rH   rI   rJ   rK   rM   r%   r*   r'   r  r    s    r*   r  /dev/ttyzPlatform lacks /dev/ttyc                  b    ] tR tRtRtR tR tR tR tR t	R t
R	 R
 ltR tR tR tR tRtR# )DefaultAPITestsi  z
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                    V P                  VR4       V P                  VR4       V P                  VR,          ^ 4       V P                  # )zg
The patched version of 'open'; this returns a L{FakeFile} that the
instantiated L{ConsoleUI} can use.
r  zr+b	buffering)r2   r  )r-   fnamemodekwargss   &&&,r'   patchedOpenDefaultAPITests.patchedOpen  sC    
 	
+u%,a0}}r*   c                ,   \        4       V n        V P                  \        RV P                  4       V P                  4       V n        / V n        \        \        V P                  4      4      pR F;  pVP                  V\        P                  ! \        4      4      pW0P                  V&   K=  	  VP                  4        \        4       V n        \        4       V P                   n        RRRV P                  /;V n        V P                   P"                  n        R# )z 
Patch 'open' in verifyHostKey.
_open   exists.example.comhostr  N)r  rt  )r  r  patchr   r  r   hostsOptionhashedEntriesr   r   r   r   r4   r5   r   r  fakeTransportfactoryr  )r-   r  r   r   s   &   r'   rT   DefaultAPITests.setUp  s     !


7GT%5%56;;='1A1A(BC7D"--dCNN94MNE',t$ 8 	'\%/\")4++=
 	
t))119r*   c                    . p\         P                  ! V P                  R\        R4      P	                  VP
                  4       V P                  ^.V4       R# )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.
rt     I don't care.N)r   rd  r  r5   re  rf  r2   r  s   & r'   test_verifyOKKey DefaultAPITests.test_verifyOKKey  sG     
I7G	

+ahh
!a r*   c                   a \         P                  P                  R4      oV3R lpV P                  V4       V\         P                  R&   R# )a  
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                 \   < S f   \         P                  R R # S \         P                  R&   R # )Nr  )osenviron)oldHomes   r'   cleanupHome0DefaultAPITests.replaceHome.<locals>.cleanupHome  s"    JJv&%,

6"r*   N)r  r  get
addCleanup)r-   tempHomer  r  s   && @r'   replaceHomeDefaultAPITests.replaceHome  s8     **..(	- 	$%

6r*   c                   . pV P                  4       pV P                  p\        V4      P                  R4      P                  R4      pVP	                  4       P                  4        \        V4      P                  V4       V P                  V4       RV P                  R&   \        P                  ! V P                  R\        R4      P                  VP                  4       V P                  ^.V4       R# )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_hostsNr  rt  r  )r   r  r   r"  parentmakedirsmoveTor  r  r   rd  r  r5   re  rf  r2   )r-   ri  tmpdiroldHostsOptionhostsNonOptions   &    r'   test_noKnownHostsOption'DefaultAPITests.test_noKnownHostsOption  s     ))!&)//7==mL((* ''7 &*]#
I7G	

+ahh
!a r*   c                   . p\         P                  ! V P                  R\        R4      P	                  VP
                  4       V P                  R.V P                  P                  4       V P                  ^.V4       \        P                  ! \        V P                  4      4      pV P                  VP                  R\        P                   ! \        4      4      4       R# )z
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.
s   8.7.6.5s   Fingerprint not required.sa   Warning: Permanently added the RSA host key for IP address '8.7.6.5' to the list of known hosts.
N)r   rd  r  r5   re  rf  r2   r  r  r   r   r   r  rB   r;  r   r4   )r-   ri  r  s   &  r'   test_verifyHostButNotIP'DefaultAPITests.test_verifyHostButNotIP  s     
I7S	

+ahh
; MM##	
 	!a '00$:J:J1KL%%j#..2KL	
r*   c                   V ^8  d   QhRR/# )r"   r#   r  r%   )r&   s   "r'   r(   DefaultAPITests.__annotate__  s     6 6^ 6r*   c                Z   RV P                   P                  P                  R&   V P                  P                  P                  R4       \        P                  ! V P                   R\        R4      pV P                  R.V P                  P                  4       V P                  V\        4      # )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.
s   fake.example.comr   r  s   9.8.7.6zNo 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  r  r  r  rf  r   rd  r:   r2   r  rm  r
   r-   rh  s   & r'   test_verifyQuestion#DefaultAPITests.test_verifyQuestion  s    
 6I""**62$$U+!!
N<M
 	K MM##		
 !!!_55r*   c                |    \         P                  ! V P                  R\        R4      pV P	                  V\
        4      # )zw
L{default.verifyHostKey} should return a L{Deferred} which fails with
L{HostKeyChanged} if the host key is incorrect.
rt  zAgain, not required.)r   rd  r  r:   rm  r   r(  s   & r'   test_verifyBadKey!DefaultAPITests.test_verifyBadKey  s9    
 !!
N<R
 !!!^44r*   c                P   V P                   R,          P                  4       P                  4       ^ ,          p\        P                  ! V\
        P                  ! \        4      P                  4       R\        V P                  4      P                  /4      pV P                  ^V4       R# )za
L{default.isInKnownHosts} should return C{1} when a host with a key
is in the known hosts file.
rt  r  N)r  r]   r   r   isInKnownHostsr   r4   r5   blobr   r  r   r2   r-   r   rs   &  r'   test_inKnownHosts!DefaultAPITests.test_inKnownHosts  s~    
 !!*-668>>@C""NN9%**,HT%5%56;;<

 	Ar*   c                    \         P                  ! RRR\        V P                  4      P                  /4      pV P                  ^ V4       R# )ze
L{default.isInKnownHosts} should return C{0} when a host with a key
is not in the known hosts file.
z	not.theres
   irrelevantr  N)r   r/  r   r  r   r2   )r-   r2  s   & r'   test_notInKnownHosts$DefaultAPITests.test_notInKnownHosts)  sC    
 ""AQAQ8R8W8W(X
 	Ar*   c                P   V P                   R,          P                  4       P                  4       ^ ,          p\        P                  ! V\
        P                  ! \        4      P                  4       R\        V P                  4      P                  /4      pV P                  ^V4       R# )zz
L{default.isInKnownHosts} should return C{2} when a host with a key
other than the given one is in the known hosts file.
rt  r  N)r  r]   r   r   r/  r   r4   r:   r0  r   r  r   r2   r1  s   &  r'   test_inKnownHostsKeyChanged+DefaultAPITests.test_inKnownHostsKeyChanged3  s~    
 !!*-668>>@C""NN>*//1HT%5%56;;<

 	Ar*   )r  r  r  r  r  N)rG   rH   rI   rJ   rK   r  rT   r	  r  r   r#  r)  r,  r3  r6  r9  rM   r%   r*   r'   r  r    s>    

(
!&*!&
06,5r*   r  )HrK   
__future__r   r  binasciir   r   r   r   unittestr   zope.interface.verifyr   twisted.conch.errorr   r	   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.knownhostsr   r   r   r   r   twisted.conch.ssh.keysr   r   twisted.conch.testr   objectskipsampleEncodedKeyotherSampleEncodedKeyr-  ecdsaSampleEncodedKeyr5   r:   r   rD  rc   r
  rd   r~   r   rO   rf   rk   r   r   r   r   r  r  rc  r  r  r  r%   r*   r'   <module>rP     s   # 	 C C  . M M 4 + / , 0 7 +  ,  8*I@D > 
 N 
 '(	1212127:JJUR 14IIEQ  57GG%O 
 M /D /DdSox S@K KL
(<h L
^C"2 C#Q? #QLc1h c1Lv9h v9r BoLX oLd'Y '@  HZ ''))+DErh r Frr*   