Ë
    oj¡  ã                   óÒ   — d Z ddlmZmZmZ ddlmZ ddlmZ ddl	m
Z
mZ ddlmZmZmZ ddlmZ ddlmZ dd	lmZ  ed
«      Z ed«      ZererddlmZ ddlmZ  G d„ de«      Zy)z!
Tests for L{twisted.conch.tap}.
é    )ÚAnyÚTupleÚUnion)ÚStreamServerEndpointService)Úerror)ÚFilePasswordDBÚICredentialsChecker)ÚISSHPrivateKeyÚIUsernamePasswordÚUsernamePassword)ÚDeferred)ÚrequireModule)ÚTestCaseÚcryptographyztwisted.conch.unix)Útap)ÚOpenSSHFactoryc                   ór   — e Zd ZdZesdZesdZdZdd„Zdd„Z	dd	„Z
dd
„Zdd„Zdefd„Zded   fd„Zdd„Zy)ÚMakeServiceTestsz'
    Tests for L{tap.makeService}.
    zcan't run without cryptographyz can't run on non-posix computers)s   iamusers   thisispasswordÚreturnNc                 ó
  — | j                  «       | _        t        | j                  d«      5 }|j                  dj	                  | j
                  «      «       ddd«       t        j                  «       | _        y# 1 sw Y   Œ#xY w)z/
        Create a file with two users.
        zwb+ó   :N)	ÚmktempÚfilenameÚopenÚwriteÚjoinÚusernamePasswordr   ÚOptionsÚoptions)ÚselfÚfs     ú=/usr/lib/python3/dist-packages/twisted/conch/test/test_tap.pyÚsetUpzMakeServiceTests.setUp(   s^   € ð Ÿ™›ˆŒÜ�$—-‘- Ó'ð 	6¨1Ø�G‰G�D—I‘I˜d×3Ñ3Ó4Ô5÷	6ä—{‘{“}ˆ�÷	6ð 	6ús   ¬+A9Á9Bc                 ó  — t        j                  «       }t        j                  |«      }| j                  |t        «       | j                  |j                  j                  d«       | j                  |j                  t        «       y)zÃ
        L{tap.makeService} returns a L{StreamServerEndpointService} instance
        running on TCP port 22, and the linked protocol factory is an instance
        of L{OpenSSHFactory}.
        é   N)
r   r   ÚmakeServiceÚassertIsInstancer   ÚassertEqualÚendpointÚ_portÚfactoryr   )r    ÚconfigÚservices      r"   Ú
test_basiczMakeServiceTests.test_basic1   s^   € ô —‘“ˆÜ—/‘/ &Ó)ˆØ×Ñ˜gÔ'BÔCØ×Ñ˜×)Ñ)×/Ñ/°Ô4Ø×Ñ˜gŸo™o¬~Õ>ó    c                 óò   — d}| j                  t        | j                  d   d«       | j                  t        | j                  d   d«       | j	                  |t        | j                  d   «      d|fz  «       y)z¡
        Make sure that if the C{--auth} command-line option is not passed,
        the default checkers are (for backwards compatibility): SSH and UNIX
        é   ÚcredInterfacesz)SSH should be one of the default checkersz*UNIX should be one of the default checkersÚcredCheckersz&There should be %d checkers by defaultN)ÚassertInr
   r   r   r(   Úlen)r    ÚnumCheckerss     r"   Útest_defaultAuthsz"MakeServiceTests.test_defaultAuths=   sw   € ð
 ˆà�‰ÜØ�L‰LÐ)Ñ*Ø7ô	
ð
 	�‰ÜØ�L‰LÐ)Ñ*Ø8ô	
ð
 	×ÑØÜ�—‘˜^Ñ,Ó-Ø4¸°~ÑEõ	
r/   c                 ó¨   — | j                   j                  dd| j                  z   g«       | j                  t	        | j                   d   «      d«       y)zŽ
        The C{--auth} command-line option will add a checker to the list of
        checkers, and it should be the only auth checker
        ú--authúfile:r3   é   N©r   ÚparseOptionsr   r(   r5   ©r    s    r"   Útest_authAddedzMakeServiceTests.test_authAddedT   sB   € ð
 	�‰×!Ñ! 8¨W°t·}±}Ñ-DÐ"EÔFØ×Ñœ˜TŸ\™\¨.Ñ9Ó:¸AÕ>r/   c                 ó¬   — | j                   j                  dd| j                  z   ddg«       | j                  t	        | j                   d   «      d«       y)zÍ
        Multiple C{--auth} command-line options will add all checkers specified
        to the list ofcheckers, and there should only be the specified auth
        checkers (no default checkers).
        r9   r:   zmemory:testuser:testpasswordr3   r1   Nr<   r>   s    r"   Útest_multipleAuthAddedz'MakeServiceTests.test_multipleAuthAdded\   sP   € ð 	�‰×!Ñ!àØ˜$Ÿ-™-Ñ'ØØ.ð	ô	
ð 	×Ñœ˜TŸ\™\¨.Ñ9Ó:¸AÕ>r/   c                 ó6  — | j                   j                  dd| j                  z   g«       | j                   d   d   }| j                  |t        «       t        | j                  d   d«      }| j                  |j                  |«      t        j                  «      S )z×
        The checker created by the C{--auth} command-line option returns a
        L{Deferred} that fails with L{UnauthorizedLogin} when
        presented with credentials that are unknown to that checker.
        r9   r:   r3   éÿÿÿÿr   s   fake)r   r=   r   r'   r   r   r   ÚassertFailureÚrequestAvatarIdr   ÚUnauthorizedLogin)r    ÚcheckerÚinvalids      r"   Útest_authFailurez!MakeServiceTests.test_authFailurel   s‡   € ð 	�‰×!Ñ! 8¨W°t·}±}Ñ-DÐ"EÔFØ"&§,¡,¨~Ñ">¸rÑ"BˆØ×Ñ˜g¤~Ô6Ü" 4×#8Ñ#8¸Ñ#;¸WÓEˆà×!Ñ!Ø×#Ñ# GÓ,¬e×.EÑ.Eó
ð 	
r/   c                 ó$  ‡ ‡— ‰ j                   j                  dd‰ j                  z   g«       ‰ j                   d   d   }t        ‰ j                  Ž Š|j                  ‰«      }dt        t        t        d   f   ddfˆˆ fd	„}|j                  |«      S )
zË
        The checker created by the C{--auth} command-line option returns a
        L{Deferred} that returns the avatar id when presented with credentials
        that are known to that checker.
        r9   r:   r3   rC   Úusername© r   Nc                 ó>   •— ‰j                  | ‰j                  «       y )N)r(   rK   )rK   Úcorrectr    s    €€r"   ÚcheckSuccessz7MakeServiceTests.test_authSuccess.<locals>.checkSuccess†   s   ø€ Ø×Ñ˜X w×'7Ñ'7Õ8r/   )
r   r=   r   r   r   rE   r   Úbytesr   ÚaddCallback)r    rG   ÚdrO   rN   s   `   @r"   Útest_authSuccessz!MakeServiceTests.test_authSuccess{   sŠ   ù€ ð 	�‰×!Ñ! 8¨W°t·}±}Ñ-DÐ"EÔFØ'+§|¡|°NÑ'CÀBÑ'GˆÜ" D×$9Ñ$9Ð:ˆØ×#Ñ# GÓ,ˆð	9¤5¬´°b±	Ð)9Ñ#:ð 	9¸tö 	9ð �}‰}˜\Ó*Ð*r/   c                 óü   — t        j                  «       }t        j                  |«      }|j                  j                  }| j                  t        |j                  j                  «       «      t        t        h«       y)z³
        The L{OpenSSHFactory} built by L{tap.makeService} has a portal with
        L{ISSHPrivateKey} and L{IUsernamePassword} interfaces registered as
        checkers.
        N)r   r   r&   r+   Úportalr(   ÚsetÚcheckersÚkeysr
   r   )r    r,   r-   rU   s       r"   Útest_checkerszMakeServiceTests.test_checkers‹   sW   € ô —‘“ˆÜ—/‘/ &Ó)ˆØ—‘×'Ñ'ˆØ×ÑÜ�—‘×$Ñ$Ó&Ó'¬.Ô:KÐ)Lõ	
r/   )r   N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   ÚskipÚunixr   r#   r.   r7   r?   rA   r   rI   r   rS   rY   rL   r/   r"   r   r      sY   „ ññ Ø/ˆáØ1ˆà6Ðó%ó
?ó
ó.?ó?ð 
 #ó 
ð+ (¨4¡.ó +ô 
r/   r   N)r]   Útypingr   r   r   Útwisted.application.internetr   Útwisted.credr   Útwisted.cred.checkersr   r	   Útwisted.cred.credentialsr
   r   r   Útwisted.internet.deferr   Útwisted.python.reflectr   Útwisted.trial.unittestr   r   r_   Útwisted.conchr   Ú$twisted.conch.openssh_compat.factoryr   r   rL   r/   r"   ú<module>rj      sZ   ðñ÷ %Ñ $å DÝ ß Eß XÑ XÝ +Ý 0Ý +á˜^Ó,€ÙÐ)Ó*€ñ ‘DÝ!ÝCô{
�xõ {
r/   