Ϫf ZdZddlZddlmZddlmZddlmZmZddl m Z Gdde Z y) z9 Tests for L{twisted.cred}'s implementation of CRAM-MD5. N)hexlify)HMAC)CramMD5CredentialsIUsernameHashedPassword)TestCasec@eZdZdZd dZd dZd dZd dZd dZd dZ y) CramMD5CredentialsTestsz* Tests for L{CramMD5Credentials}. Ncxt}|j}|j||jy)z The same L{CramMD5Credentials} will always provide the same challenge, no matter how many times it is called. N)r getChallenge assertEqualselfcchals A/usr/lib/python3/dist-packages/twisted/cred/test/test_cramauth.pytest_idempotentChallengez0CramMD5CredentialsTests.test_idempotentChallenges/  ~~ q~~/0ct}|j}ttd|tj j |_|j|jdy)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) rr rrhashlibmd5digestresponse assertTrue checkPasswordr s rtest_checkPasswordz*CramMD5CredentialsTests.test_checkPasswordsO  ~~T)TW[[IPPRS   23rcXt}|j|jdy)zg When there is no response set, calling C{checkPassword} will return L{False}. rN)r assertFalser)rrs rtest_noResponsez'CramMD5CredentialsTests.test_noResponse+s#   34rct}|j}ttd|tj j |_|j|jdy)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) rr rrrrrrr rr s rtest_wrongPasswordz*CramMD5CredentialsTests.test_wrongPassword3sW  ~~ "DGKK @ G G I   34rc Vt}|j}|jdjdt t d|t jjf|j|jd|j|jdy)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}.  ssquirrels supersecretrN) rr setResponsejoinrrrrrrrr usernamer s rtest_setResponsez(CramMD5CredentialsTests.test_setResponseAs  ~~ IIDMTTVW   78 [1rcT|jtjty)zd L{CramMD5Credentials} implements the L{IUsernameHashedPassword} interface. N)rr implementedByr)rs rtest_interfacez&CramMD5CredentialsTests.test_interfaceTs /==>PQRr)returnN) __name__ __module__ __qualname____doc__rrr!r#r)r,rrr r s&1 45 52&Srr ) r1rbinasciirhmacrtwisted.cred.credentialsrrtwisted.trial.unittestrr r2rrr7s+ P+HShHSr