o
    ¼>h©  ã                   @   sb   d Z ddlmZ ddlmZ ddlmZ G dd„ dejƒZG dd„ dejƒZ	G d	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d„ZdS )Ú
PlainTestszL
    Tests for L{twisted.words.protocols.jabber.sasl_mechanisms.Plain}.
    ÚreturnNc                 C   s"   t  ddd¡}|  | ¡ d¡ dS )z,
        Test the initial response.
        NÚtestÚsecrets    test secret)r   ÚPlainÚassertEqualÚgetInitialResponse©ÚselfÚm© r   úŒ/var/www/vedio/testing/chatpythonscript.ninositsolution.com/env/lib/python3.10/site-packages/twisted/words/test/test_jabbersaslmechanisms.pyÚtest_getInitialResponse   s   z"PlainTests.test_getInitialResponse©r   N©Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r   r      ó    r   c                   @   r   )ÚAnonymousTestszP
    Tests for L{twisted.words.protocols.jabber.sasl_mechanisms.Anonymous}.
    r   Nc                 C   s   t  ¡ }|  | ¡ d¡ dS )z8
        Test the initial response to be empty.
        N)r   Ú	Anonymousr   r   r   r   r   r   r       s   z&AnonymousTests.test_getInitialResponser   r   r   r   r   r   r      r   r   c                   @   sj   e Zd ZdZddd„Zddd„Zddd	„Zdd
d„Zddd„Zddd„Z	ddd„Z
ddd„Zddd„ZdS )ÚDigestMD5TestszP
    Tests for L{twisted.words.protocols.jabber.sasl_mechanisms.DigestMD5}.
    r   Nc                 C   s   t  ddd dd¡| _d S )NÚxmppzexample.orgr   r	   )r   Ú	DigestMD5Ú	mechanism©r   r   r   r   ÚsetUp-   s   

ÿzDigestMD5Tests.setUpc                 C   s   |   | j ¡ d¡ dS )z=
        Test that no initial response is generated.
        N)ÚassertIdenticalr   r   r    r   r   r   r   2   s   z&DigestMD5Tests.test_getInitialResponsec              
   C   óF   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Ú
directivesr   r   r   Útest_getResponse8   ó   ÿù	özDigestMD5Tests.test_getResponsec              
   C   r#   )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(   r)   r*   ó   Ã©chec.example.orgr+   r,   Nr1   r4   r   r   r   Útest_getResponseNonAsciiRealmP   r8   z,DigestMD5Tests.test_getResponseNonAsciiRealmc                 C   s,   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-sessr0   s   example.orgNr1   r4   r   r   r   Útest_getResponseNoRealmh   s   z&DigestMD5Tests.test_getResponseNoRealmc                 C   s@   t  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	   r;   r0   r9   )r   r   r   r2   r3   r   r4   r   r   r   Útest_getResponseNoRealmIDNq   s   
ÿz)DigestMD5Tests.test_getResponseNoRealmIDNc                 C   s    d}| j  |¡}|  d|¡ dS )zW
        If the challenge just has a rspauth directive, the response is empty.
        s@   rspauth=cnNwYXV0aD1lYTQwZjYwMzM1YzQyN2I1NTI3Yjg0ZGJhYmNkZmZmZA==ó    N)r   r3   r   )r   r5   Úresponser   r   r   Útest_getResponseRspauth~   s   z&DigestMD5Tests.test_getResponseRspauthc              
   C   sx   d}d}t dd›ƒ}d}d}d}d}d	 |¡}t 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   r?   r   r   r   Útest_calculateResponse†   s&   
ù	z%DigestMD5Tests.test_calculateResponsec                 C   s4   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'   r*   r)   s	   auth-confs   dess   3des)s	   algorithmr-   r/   r.   s   cipherN)r   r2   r   r4   r   r   r   Ú
test_parse¡   s   ÿûøzDigestMD5Tests.test_parser   )r   r   r   r   r!   r   r7   r:   r<   r=   r@   rM   rN   r   r   r   r   r   (   s    





	

r   N)r   Útwisted.python.compatr   Útwisted.trialr   Útwisted.words.protocols.jabberr   ÚTestCaser   r   r   r   r   r   r   Ú<module>   s   