
    Yf                     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      Q/var/www/html/env/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)TW[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       ~~"DGK@@@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       ~~	II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   