
    tf                         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dS )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                   z    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dS )MakeServiceTestsz'
    Tests for L{tap.makeService}.
    zcan't run without cryptographyz can't run on non-posix computers)s   iamusers   thisispasswordreturnNc                    |                                  | _        t          | j        d          5 }|                    d                    | j                             ddd           n# 1 swxY w Y   t          j                    | _        dS )z/
        Create a file with two users.
        zwb+   :N)	mktempfilenameopenwritejoinusernamePasswordr   Optionsoptions)selffs     Z/var/www/surfInsights/venv3-11/lib/python3.11/site-packages/twisted/conch/test/test_tap.pysetUpzMakeServiceTests.setUp(   s     $-'' 	61GGDIId344555	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6{}}s   .A))A-0A-c                 
   t          j                    }t          j        |          }|                     |t                     |                     |j        j        d           |                     |j        t                     dS )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   so     /&))g'BCCC)/444go~>>>>>    c                    d}|                      t          | j        d         d           |                      t          | j        d         d           |                     |t          | j        d                   d|fz             dS )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=   s    
 L)*7	
 	
 	

 	L)*8	
 	
 	

 	^,--4~E	
 	
 	
 	
 	
r/   c                     | j                             dd| j        z   g           |                     t	          | j         d                   d           dS )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   sQ    
 	!!8Wt}-D"EFFFT\.9::A>>>>>r/   c                     | j                             dd| j        z   ddg           |                     t	          | j         d                   d           dS )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\   sc     	!!$-'.		
 	
 	
 	T\.9::A>>>>>r/   c                 B   | j                             dd| j        z   g           | j         d         d         }|                     |t                     t          | j        d         d          }|                     |                    |          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     	!!8Wt}-D"EFFF"&,~">r"Bg~666"4#8#;WEE!!##G,,e.E
 
 	
r/   c                 4     j                             dd j        z   g            j         d         d         }t           j         |                              }dt          t          t          d         f         ddf fd	}|	                    |          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                   d S )N)r(   rK   )rK   correctr    s    r"   checkSuccessz7MakeServiceTests.test_authSuccess.<locals>.checkSuccess   s"    Xw'788888r/   )
r   r=   r   r   r   rE   r   bytesr   addCallback)r    rG   drO   rN   s   `   @r"   test_authSuccessz!MakeServiceTests.test_authSuccess{   s     	!!8Wt}-D"EFFF'+|N'CB'G"D$9:##G,,	95b	)9#: 	9t 	9 	9 	9 	9 	9 	9 	9 }}\***r/   c                     t          j                    }t          j        |          }|j        j        }|                     t          |j                                                  t          t          h           dS )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   sk     /&))'$$&&''.: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      s           0/ 2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      sS    % $ $ $ $ $ $ $ $ $ D D D D D D       E E E E E E E E X X X X X X X X X X + + + + + + 0 0 0 0 0 0 + + + + + +}^,,})**  DD D!!!!!!CCCCCC{
 {
 {
 {
 {
x {
 {
 {
 {
 {
r/   