Ë
    ojÆ  ã                   óZ   — 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y)	z9
Tests for L{twisted.cred}'s implementation of CRAM-MD5.
é    N)Úhexlify)ÚHMAC)ÚCramMD5CredentialsÚIUsernameHashedPassword)ÚTestCasec                   ó@   — e Zd ZdZd	d„Zd	d„Zd	d„Zd	d„Zd	d„Zd	d„Z	y)
ÚCramMD5CredentialsTestsz*
    Tests for L{CramMD5Credentials}.
    Nc                 óx   — t        «       }|j                  «       }| j                  ||j                  «       «       y)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      úA/usr/lib/python3/dist-packages/twisted/cred/test/test_cramauth.pyÚtest_idempotentChallengez0CramMD5CredentialsTests.test_idempotentChallenge   s/   € ô
 Ó ˆØ�~‰~ÓˆØ×Ñ˜˜qŸ~™~Ó/Õ0ó    c                 óè   — t        «       }|j                  «       }t        t        d|t        j
                  ¬«      j                  «       «      |_        | j                  |j                  d«      «       y)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   sO   € ô Ó ˆØ�~‰~ÓˆÜœT )¨T¼W¿[¹[ÔI×PÑPÓRÓSˆŒ
Ø�‰˜Ÿ™¨	Ó2Õ3r   c                 óX   — t        «       }| j                  |j                  d«      «       y)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+   s#   € ô
 Ó ˆØ×Ñ˜Ÿ™¨Ó3Õ4r   c                 óè   — t        «       }|j                  «       }t        t        d|t        j
                  ¬«      j                  «       «      |_        | j                  |j                  d«      «       y)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   sW   € ô Ó ˆØ�~‰~ÓˆÜÜÐ" D´G·K±KÔ@×GÑGÓIó
ˆŒ
ð 	×Ñ˜Ÿ™¨Ó3Õ4r   c                 óV  — t        «       }|j                  «       }|j                  dj                  dt	        t        d|t        j                  ¬«      j                  «       «      f«      «       | j                  |j                  d«      «       | j                  |j                  d«       y)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×TÑTÓVÓWðóô	
ð 	�‰˜Ÿ™¨Ó7Ô8Ø×Ñ˜Ÿ™ [Õ1r   c                 óT   — | j                  t        j                  t        «      «       y)zd
        L{CramMD5Credentials} implements the L{IUsernameHashedPassword}
        interface.
        N)r   r   ÚimplementedByr   )r   s    r   Útest_interfacez&CramMD5CredentialsTests.test_interfaceT   s   € ð
 	�‰Ô/×=Ñ=Ô>PÓQÕRr   )ÚreturnN)
Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r!   r#   r)   r,   © r   r   r	   r	      s&   „ ñó1ó
4ó5ó5ó2ô&Sr   r	   )r1   r   Úbinasciir   Úhmacr   Útwisted.cred.credentialsr   r   Útwisted.trial.unittestr   r	   r2   r   r   ú<module>r7      s+   ðñó
 Ý Ý ç PÝ +ôHS˜hõ HSr   