
    Vh                         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
y)z>
Tests for L{twisted.words.protocols.jabber.sasl_mechanisms}.
    )networkString)unittest)sasl_mechanismsc                       e Zd ZdZddZy)
PlainTestszL
    Tests for L{twisted.words.protocols.jabber.sasl_mechanisms.Plain}.
    Nc                 r    t        j                  ddd      }| j                  |j                         d       y)z,
        Test the initial response.
        Ntestsecrets    test secret)r   PlainassertEqualgetInitialResponseselfms     \/home/dcms/DCMS/lib/python3.12/site-packages/twisted/words/test/test_jabbersaslmechanisms.pytest_getInitialResponsez"PlainTests.test_getInitialResponse   s2     !!$9--/1FG    returnN__name__
__module____qualname____doc__r    r   r   r   r      s    Hr   r   c                       e Zd ZdZddZy)AnonymousTestszP
    Tests for L{twisted.words.protocols.jabber.sasl_mechanisms.Anonymous}.
    Nc                 l    t        j                         }| j                  |j                         d       y)z8
        Test the initial response to be empty.
        N)r   	Anonymousr   r   r   s     r   r   z&AnonymousTests.test_getInitialResponse    s+     %%'--/6r   r   r   r   r   r   r   r      s    7r   r   c                   X    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y)DigestMD5TestszP
    Tests for L{twisted.words.protocols.jabber.sasl_mechanisms.DigestMD5}.
    Nc                 @    t        j                  ddd dd      | _        y )Nxmppzexample.orgr	   r
   )r   	DigestMD5	mechanismr   s    r   setUpzDigestMD5Tests.setUp-   s    (22M4
r   c                 X    | j                  | j                  j                         d       y)z=
        Test that no initial response is generated.
        N)assertIdenticalr%   r   r&   s    r   r   z&DigestMD5Tests.test_getInitialResponse2   s!     	T^^>>@$Gr   c           
          d}| j                   j                  | j                   j                  |            }|d= |d= | j                  ddddgdd	d
d|       y)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   so    " 	 ^^**4>>+E+Ei+PQ
y!:k#:$!" 	$&2 	
r   c           
          d}| j                   j                  | j                   j                  |            }|d= |d= | j                  ddddgdd	d
d|       y)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   so    ; 	 ^^**4>>+E+Ei+PQ
y!:k#:$!" 	$52 	
r   c                     d}| j                   j                  | j                   j                  |            }| j                  |d   d       y)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   sB    
 P	^^**4>>+E+Ei+PQ
H-~>r   c                     t        j                  ddddd      | _        d}| j                  j                  | j                  j	                  |            }| j                  |d   d       y)	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   sc     )22,dFH
 P	^^**4>>+E+Ei+PQ
H-/JKr   c                 b    d}| j                   j                  |      }| j                  d|       y)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h'r   c           
      6   d}d}t        dd      }d}d}d}d}d	j                  |      }t        j                  d
|d||      }	|	j	                  ||||j                  |      |j                  |      |j                  |      |      }
| j                  |
d       y)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W&" !*4;;GD	#--gtT8XV	//OOG$OOG$KK 
 	#FGr   c                 v    d}| j                   j                  |      }| j                  dddddgddgd	|       y
)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   sS    4 	 ^^**95
)!$ ,/"G, 		
r   r   )r   r   r   r   r'   r   r>   rA   rD   rF   rI   rW   rY   r   r   r   r!   r!   (   s7    

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