HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: //lib/python3/dist-packages/twisted/cred/test/__pycache__/test_cramauth.cpython-310.pyc
o

�b��@sTdZddlZddlmZddlmZddlmZmZddl	m
Z
Gdd�de
�ZdS)	z9
Tests for L{twisted.cred}'s implementation of CRAM-MD5.
�N)�hexlify)�HMAC)�CramMD5Credentials�IUsernameHashedPassword)�TestCasec@s@eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dS)�CramMD5CredentialsTestsz*
    Tests for L{CramMD5Credentials}.
    cCs"t�}|��}|�||���dS)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�chal�r�A/usr/lib/python3/dist-packages/twisted/cred/test/test_cramauth.py�test_idempotentChallengesz0CramMD5CredentialsTests.test_idempotentChallengecCs<t�}|��}ttd|tjd����|_|�|�	d��dS)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)
rrrr�hashlib�md5�digest�response�
assertTrue�
checkPasswordr
rrr�test_checkPasswordsz*CramMD5CredentialsTests.test_checkPasswordcCst�}|�|�d��dS)zg
        When there is no response set, calling C{checkPassword} will return
        L{False}.
        rN)r�assertFalser)rrrrr�test_noResponse+sz'CramMD5CredentialsTests.test_noResponsecCs<t�}|��}ttd|tjd����|_|�|�	d��dS)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}.
        sthewrongsecretrrN)
rrrrrrrrrrr
rrr�test_wrongPassword3s�z*CramMD5CredentialsTests.test_wrongPasswordcCsXt�}|��}|�d�dttd|tjd����f��|�	|�
d��|�|jd�dS)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}.
        � ssquirrelssupersecretrN)
rr�setResponse�joinrrrrrrrr	�usernamer
rrr�test_setResponseAs���z(CramMD5CredentialsTests.test_setResponsecCs|�t�t��dS)zd
        L{CramMD5Credentials} implements the L{IUsernameHashedPassword}
        interface.
        N)rr�
implementedByr)rrrr�test_interfaceTsz&CramMD5CredentialsTests.test_interfaceN)
�__name__�
__module__�__qualname__�__doc__rrrrr"r$rrrrrs	r)r(r�binasciir�hmacr�twisted.cred.credentialsrr�twisted.trial.unittestrrrrrr�<module>s