
    Yf                         d Z ddlmZ ddlmZ ddlmZ  G d dej                  Z G d dej                  Z	 G d	 d
ej                  Z
dS )z>
Tests for L{twisted.words.protocols.jabber.sasl_mechanisms}.
    )networkString)unittest)sasl_mechanismsc                       e Zd ZdZddZdS )
PlainTestszL
    Tests for L{twisted.words.protocols.jabber.sasl_mechanisms.Plain}.
    returnNc                     t          j        ddd          }|                     |                                d           dS )z,
        Test the initial response.
        Ntestsecrets    test secret)r   PlainassertEqualgetInitialResponseselfms     ^/var/www/html/env/lib/python3.11/site-packages/twisted/words/test/test_jabbersaslmechanisms.pytest_getInitialResponsez"PlainTests.test_getInitialResponse   sA     !$99--//1FGGGGG    r   N__name__
__module____qualname____doc__r    r   r   r   r      s8         H H H H H Hr   r   c                       e Zd ZdZddZdS )AnonymousTestszP
    Tests for L{twisted.words.protocols.jabber.sasl_mechanisms.Anonymous}.
    r   Nc                 |    t          j                    }|                     |                                d           dS )z8
        Test the initial response to be empty.
        N)r   	Anonymousr   r   r   s     r   r   z&AnonymousTests.test_getInitialResponse    s:     %''--//66666r   r   r   r   r   r   r   r      s2         7 7 7 7 7 7r   r   c                   Z    e Zd ZdZddZddZddZddZddZdd	Z	dd
Z
ddZddZdS )DigestMD5TestszP
    Tests for L{twisted.words.protocols.jabber.sasl_mechanisms.DigestMD5}.
    r   Nc                 @    t          j        ddd dd          | _        d S )Nxmppzexample.orgr
   r   )r   	DigestMD5	mechanismr   s    r   setUpzDigestMD5Tests.setUp-   s%    (2M4
 
r   c                 `    |                      | j                                        d           dS )z=
        Test that no initial response is generated.
        N)assertIdenticalr%   r   r&   s    r   r   z&DigestMD5Tests.test_getInitialResponse2   s.     	T^>>@@$GGGGGr   c           
          d}| j                             | j                             |                    }|d= |d= |                     ddddgdd	d
d|           dS )zl
        The response to a Digest-MD5 challenge includes the parameters from the
        challenge.
        sJ   realm="localhost",nonce="1234",qop="auth",charset=utf-8,algorithm=md5-sess   cnonce   response   test   1234   00000001   auth   utf-8s	   localhost   xmpp/example.orgs   username   nonces   nc   qop   charset   realms
   digest-uriNr%   _parsegetResponser   r   	challenge
directivess      r   test_getResponsezDigestMD5Tests.test_getResponse8   s    " 	 ^**4>+E+Ei+P+PQQ
y!:k#:$!" 	$&2  	
 	
 	
 	
 	
r   c           
          d}| j                             | j                             |                    }|d= |d= |                     ddddgdd	d
d|           dS )zs
        Bytes outside the ASCII range in the challenge are nevertheless
        included in the response.
        sS   realm="échec.example.org",nonce="1234",qop="auth",charset=utf-8,algorithm=md5-sessr+   r,   r-   r.   r/   r0   r1      échec.example.orgr2   r3   Nr8   r;   s      r   test_getResponseNonAsciiRealmz,DigestMD5Tests.test_getResponseNonAsciiRealmP   s    ; 	 ^**4>+E+Ei+P+PQQ
y!:k#:$!" 	$52  	
 	
 	
 	
 	
r   c                     d}| j                             | j                             |                    }|                     |d         d           dS )zq
        The response to a challenge without a realm uses the host part of the
        JID as the realm.
        8   nonce="1234",qop="auth",charset=utf-8,algorithm=md5-sessr7   s   example.orgNr8   r;   s      r   test_getResponseNoRealmz&DigestMD5Tests.test_getResponseNoRealmh   sP    
 P	^**4>+E+Ei+P+PQQ
H-~>>>>>r   c                     t          j        ddddd          | _        d}| j                            | j                            |                    }|                     |d         d           dS )	z
        If the challenge does not include a realm and the host part of the JID
        includes bytes outside of the ASCII range, the response still includes
        the host part of the JID as the realm.
        r#   u   échec.example.orgNr
   r   rC   r7   r@   )r   r$   r%   r9   r:   r   r;   s      r   test_getResponseNoRealmIDNz)DigestMD5Tests.test_getResponseNoRealmIDNq   ss     )2,dFH
 
 P	^**4>+E+Ei+P+PQQ
H-/JKKKKKr   c                 j    d}| j                             |          }|                     d|           dS )zW
        If the challenge just has a rspauth directive, the response is empty.
        s@   rspauth=cnNwYXV0aD1lYTQwZjYwMzM1YzQyN2I1NTI3Yjg0ZGJhYmNkZmZmZA==r   N)r%   r:   r   )r   r<   responses      r   test_getResponseRspauthz&DigestMD5Tests.test_getResponseRspauth~   s;     X	>--i88h'''''r   c           
      n   d}d}t          dd          }d}d}d}d}d	                    |          }t          j        d
|d||          }	|	                    ||||                    |          |                    |          |                    |          |          }
|                     |
d           dS )zc
        The response to a Digest-MD5 challenge is computed according to RFC
        2831.
        zutf-8s   OA6MG9tEQGm2hh   08xs   OA6MHXh6VqTrRku   Иchrisu   Иsecretu   Иelwood.innosoft.comu   imap/Иelwood.innosoft.coms   imapNs    7928f233258be88392424d094453c5e3)r   encoder   r$   _calculateResponser   )r   charsetnoncenccnonceusernamepasswordhost	digestURIr%   rH   s              r   test_calculateResponsez%DigestMD5Tests.test_calculateResponse   s    
 !a::&&" !*4;;GDD	#-gtT8XVV	//OOG$$OOG$$KK  
 
 	#FGGGGGr   c                 ~    d}| j                             |          }|                     dddddgddgd	|           d
S )zc
        A challenge can be parsed into a L{dict} with L{bytes} or L{list}
        values.
        sT   nonce="1234",qop="auth,auth-conf",charset=utf-8,algorithm=md5-sess,cipher="des,3des"s   md5-sessr.   r1   r0   s	   auth-confs   dess   3des)s	   algorithmr4   r6   r5   s   cipherN)r%   r9   r   r;   s      r   
test_parsezDigestMD5Tests.test_parse   sm    4 	 ^**955
)!$ ,/"G,  		
 		
 		
 		
 		
r   r   )r   r   r   r   r'   r   r>   rA   rD   rF   rI   rW   rY   r   r   r   r!   r!   (   s         
 
 
 

H H H H
 
 
 
0
 
 
 
0? ? ? ?L L L L( ( ( (H H H H6
 
 
 
 
 
r   r!   N)r   twisted.python.compatr   twisted.trialr   twisted.words.protocols.jabberr   TestCaser   r   r!   r   r   r   <module>r^      s    
 0 / / / / / " " " " " " : : : : : :
H 
H 
H 
H 
H" 
H 
H 
H
7 
7 
7 
7 
7X& 
7 
7 
7L
 L
 L
 L
 L
X& L
 L
 L
 L
 L
r   