§
    ÈtºfÆ  ã                   ób   — d Z ddlZddlmZ ddlmZ ddlmZmZ ddl	m
Z
  G d„ de
¦  «        ZdS )	z9
Tests for L{twisted.cred}'s implementation of CRAM-MD5.
é    N)Úhexlify)ÚHMAC)ÚCramMD5CredentialsÚIUsernameHashedPassword)ÚTestCasec                   óB   — 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S )ÚCramMD5CredentialsTestsz*
    Tests for L{CramMD5Credentials}.
    ÚreturnNc                 óš   — t          ¦   «         }|                     ¦   «         }|                      ||                     ¦   «         ¦  «         dS )z‡
        The same L{CramMD5Credentials} will always provide the same challenge,
        no matter how many times it is called.
        N)r   ÚgetChallengeÚassertEqual©ÚselfÚcÚchals      ú^/var/www/surfInsights/venv3-11/lib/python3.11/site-packages/twisted/cred/test/test_cramauth.pyÚtest_idempotentChallengez0CramMD5CredentialsTests.test_idempotentChallenge   sD   € õ
 Ñ Ô ˆØ�~Š~ÑÔˆØ×Ò˜˜qŸ~š~Ñ/Ô/Ñ0Ô0Ð0Ð0Ð0ó    c                 ó  — t          ¦   «         }|                     ¦   «         }t          t          d|t          j        ¬¦  «                             ¦   «         ¦  «        |_        |                      | 	                    d¦  «        ¦  «         dS )a2  
        When a valid response (which is a hex digest of the challenge that has
        been encrypted by the user's shared secret) is set on the
        L{CramMD5Credentials} that created the challenge, and C{checkPassword}
        is called with the user's shared secret, it will return L{True}.
        ó   secret©Ú	digestmodN)
r   r   r   r   ÚhashlibÚmd5ÚdigestÚresponseÚ
assertTrueÚcheckPasswordr   s      r   Útest_checkPasswordz*CramMD5CredentialsTests.test_checkPassword   sn   € õ Ñ Ô ˆØ�~Š~ÑÔˆÝ�T )¨T½W¼[ÐIÑIÔI×PÒPÑRÔRÑSÔSˆŒ
Ø�Š˜Ÿš¨	Ñ2Ô2Ñ3Ô3Ð3Ð3Ð3r   c                 ór   — t          ¦   «         }|                      |                     d¦  «        ¦  «         dS )zg
        When there is no response set, calling C{checkPassword} will return
        L{False}.
        r   N)r   ÚassertFalser   )r   r   s     r   Útest_noResponsez'CramMD5CredentialsTests.test_noResponse+   s5   € õ
 Ñ Ô ˆØ×Ò˜Ÿš¨Ñ3Ô3Ñ4Ô4Ð4Ð4Ð4r   c                 ó  — t          ¦   «         }|                     ¦   «         }t          t          d|t          j        ¬¦  «                             ¦   «         ¦  «        |_        |                      | 	                    d¦  «        ¦  «         dS )a   
        When an invalid response is set on the L{CramMD5Credentials} (one that
        is not the hex digest of the challenge, encrypted with the user's shared
        secret) and C{checkPassword} is called with the user's correct shared
        secret, it will return L{False}.
        s   thewrongsecretr   r   N)
r   r   r   r   r   r   r   r   r!   r   r   s      r   Útest_wrongPasswordz*CramMD5CredentialsTests.test_wrongPassword3   sx   € õ Ñ Ô ˆØ�~Š~ÑÔˆÝÝÐ" DµG´KÐ@Ñ@Ô@×GÒGÑIÔIñ
ô 
ˆŒ
ð 	×Ò˜Ÿš¨Ñ3Ô3Ñ4Ô4Ð4Ð4Ð4r   c                 ó–  — t          ¦   «         }|                     ¦   «         }|                     d                     dt	          t          d|t          j        ¬¦  «                             ¦   «         ¦  «        f¦  «        ¦  «         |  	                    | 
                    d¦  «        ¦  «         |                      |j        d¦  «         dS )zÂ
        When C{setResponse} is called with a string that is the username and
        the hashed challenge separated with a space, they will be set on the
        L{CramMD5Credentials}.
        ó    s   squirrels   supersecretr   N)r   r   ÚsetResponseÚjoinr   r   r   r   r   r   r   r   Úusernamer   s      r   Útest_setResponsez(CramMD5CredentialsTests.test_setResponseA   s³   € õ Ñ Ô ˆØ�~Š~ÑÔˆØ	�ŠØ�IŠIàÝ�D °ÅÄÐMÑMÔM×TÒTÑVÔVÑWÔWðñô ñ	
ô 	
ð 	
ð 	�Š˜Ÿš¨Ñ7Ô7Ñ8Ô8Ð8Ø×Ò˜œ [Ñ1Ô1Ð1Ð1Ð1r   c                 ó^   — |                       t          j        t          ¦  «        ¦  «         dS )zd
        L{CramMD5Credentials} implements the L{IUsernameHashedPassword}
        interface.
        N)r   r   ÚimplementedByr   )r   s    r   Útest_interfacez&CramMD5CredentialsTests.test_interfaceT   s)   € ð
 	�ŠÕ/Ô=Õ>PÑQÔQÑRÔRÐRÐRÐRr   )r
   N)
Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r"   r$   r*   r-   © r   r   r	   r	      sœ   € € € € € ðð ð1ð 1ð 1ð 1ð
4ð 
4ð 
4ð 
4ð5ð 5ð 5ð 5ð5ð 5ð 5ð 5ð2ð 2ð 2ð 2ð&Sð Sð Sð Sð Sð Sr   r	   )r1   r   Úbinasciir   Úhmacr   Útwisted.cred.credentialsr   r   Útwisted.trial.unittestr   r	   r2   r   r   ú<module>r7      s°   ððð ð
 €€€Ø Ð Ð Ð Ð Ð Ø Ð Ð Ð Ð Ð à PÐ PÐ PÐ PÐ PÐ PÐ PÐ PØ +Ð +Ð +Ð +Ð +Ð +ðHSð HSð HSð HSð HS˜hñ HSô HSð HSð HSð HSr   