
    Vh                     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      O/home/dcms/DCMS/lib/python3.12/site-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)TW[[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      ~~"DGKK@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      ~~	II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   