Xc@s=dZddlZejeZddlZddlmZddlm Z ddl m Z m Z ddl mZde fdYZd e fd YZd e fd YZd e fdYZde fdYZde fdYZde fdYZde fdYZde fdYZdS(s?passlib.tests.test_handlers - tests for passlib hash algorithmsiN(thash(tu(tTestCaset HandlerCase(t UPASS_WAVtldap_pbkdf2_testcBseZdZRS(cCsX|jtjjdd|jtjjdd|jtjjdddS(stest ldap pbkdf2 wrapperstpasswords?{PBKDF2}1212$OB.dtnSEXZK8U5cgxU/GYQ$y5LKPOplRmok7CZp/aqVDVg8zGIsV{PBKDF2-SHA256}1212$4vjV83LKPjQzk31VI4E0Vw$hsYF68OiOUPdDZ1Fg.fJPeq1h/gXXY7acBp9/6c.tmQs{PBKDF2-SHA512}1212$RHY0Fr3IDMSVO/RSZyb5ow$eNLfBK.eVozomMr.1gYa17k9B7KIK25NOEshvhrSX.esqY3s.FvWZViXz4KoLlQI.BzY/YTNJOiKc5gBYFYGwwN(t assertTrueRtldap_pbkdf2_sha1tverifytldap_pbkdf2_sha256tldap_pbkdf2_sha512(tself((sF/usr/lib/python2.7/site-packages/passlib/tests/test_handlers_pbkdf2.pyt test_wrapperss     (t__name__t __module__R (((sF/usr/lib/python2.7/site-packages/passlib/tests/test_handlers_pbkdf2.pyRstatlassian_pbkdf2_sha1_testcBs,eZejZdedfgZdgZRS(tadminsI{PKCS5S2}c4xaeTQM0lUieMS3V5voiexyX9XhqC2dBd5ecVy60IPksHChwoTAVYFrhsgoq8/psI{PKCS5S2}cE9Yq6Am5tQGdHSHhky2XLeOnURwzaLBG2sur7FHKpvy2u0qDn6GcVGRjlmJoIUys{PKCS5S2}c4xaeTQM0lUieMS3V5voiexyX9XhqC2dBd5ecVy!0IPksHChwoTAVYFrhsgoq8/p{PKCS5S2}c4xaeTQM0lUieMS3V5voiexyX9XhqC2dBd5ecVy60IPksHChwoTAVYFrhsgoq8/{PKCS5S2}c4xaeTQM0lUieMS3V5voiexyX9XhqC2dBd5ecVy60IPksHChwoTAVYFrhsgoq8/=(RsI{PKCS5S2}c4xaeTQM0lUieMS3V5voiexyX9XhqC2dBd5ecVy60IPksHChwoTAVYFrhsgoq8/p(RRRtatlassian_pbkdf2_sha1thandlerRtknown_correct_hashestknown_malformed_hashes(((sF/usr/lib/python2.7/site-packages/passlib/tests/test_handlers_pbkdf2.pyR6s   tpbkdf2_sha1_testcBs2eZejZdedfgZdddgZRS(Rs?$pbkdf2$1212$OB.dtnSEXZK8U5cgxU/GYQ$y5LKPOplRmok7CZp/aqVDVg8zGIs?$pbkdf2$1212$THDqatpidANpadlLeTeOEg$HV3oi1k5C5LQCgG1BMOL.BX4YZcs@$pbkdf2$01212$THDqatpidANpadlLeTeOEg$HV3oi1k5C5LQCgG1BMOL.BX4YZcs;$pbkdf2$$THDqatpidANpadlLeTeOEg$HV3oi1k5C5LQCgG1BMOL.BX4YZcs@$pbkdf2$1212$THDqatpidANpadlLeTeOEg$HV3oi1k5C5LQCgG1BMOL.BX4YZc$(spasswords?$pbkdf2$1212$OB.dtnSEXZK8U5cgxU/GYQ$y5LKPOplRmok7CZp/aqVDVg8zGI(RRRt pbkdf2_sha1RRRR(((sF/usr/lib/python2.7/site-packages/passlib/tests/test_handlers_pbkdf2.pyRMs  tpbkdf2_sha256_testcBs#eZejZdedfgZRS(RsV$pbkdf2-sha256$1212$4vjV83LKPjQzk31VI4E0Vw$hsYF68OiOUPdDZ1Fg.fJPeq1h/gXXY7acBp9/6c.tmQsV$pbkdf2-sha256$1212$3SABFJGDtyhrQMVt1uABPw$WyaUoqCLgvz97s523nF4iuOqZNbp5Nt8do/cuaa7AiI(spasswordsV$pbkdf2-sha256$1212$4vjV83LKPjQzk31VI4E0Vw$hsYF68OiOUPdDZ1Fg.fJPeq1h/gXXY7acBp9/6c.tmQ(RRRt pbkdf2_sha256RRR(((sF/usr/lib/python2.7/site-packages/passlib/tests/test_handlers_pbkdf2.pyR`s  tpbkdf2_sha512_testcBs#eZejZdedfgZRS(Rs$pbkdf2-sha512$1212$RHY0Fr3IDMSVO/RSZyb5ow$eNLfBK.eVozomMr.1gYa17k9B7KIK25NOEshvhrSX.esqY3s.FvWZViXz4KoLlQI.BzY/YTNJOiKc5gBYFYGwws$pbkdf2-sha512$1212$KkbvoKGsAIcF8IslDR6skQ$8be/PRmd88Ps8fmPowCJttH9G3vgxpG.Krjt3KT.NP6cKJ0V4Prarqf.HBwz0dCkJ6xgWnSj2ynXSV7MlvMa8Q(spasswords$pbkdf2-sha512$1212$RHY0Fr3IDMSVO/RSZyb5ow$eNLfBK.eVozomMr.1gYa17k9B7KIK25NOEshvhrSX.esqY3s.FvWZViXz4KoLlQI.BzY/YTNJOiKc5gBYFYGww(RRRt pbkdf2_sha512RRR(((sF/usr/lib/python2.7/site-packages/passlib/tests/test_handlers_pbkdf2.pyRks  tcta_pbkdf2_sha1_testcBs2eZejZeddfdedfgZRS(shashy the \N{SNOWMAN}s4$p5k2$1000$ZxK4ZBJCfQg=$jJZVscWtO--p1-xIZl6jhO2LKR0=Rs%$p5k2$1$$h1TDLGSw9ST8UMAPeIE13i0t12c=s4$p5k2$4321$OTg3NjU0MzIx$jINJrSvZ3LXeIbUdrJkRpN62_WQ=(spasswords%$p5k2$1$$h1TDLGSw9ST8UMAPeIE13i0t12c=(RRRtcta_pbkdf2_sha1RRRR(((sF/usr/lib/python2.7/site-packages/passlib/tests/test_handlers_pbkdf2.pyRxs  tdlitz_pbkdf2_sha1_testcBs,eZejZd d d d edfgZRS( tcloadms,$p5k2$$exec$r1EWMCMk7Rlv3L/RNcFXviDefYa0hlqltgnus1$p5k2$c$u9HvcT4d$Sd1gwSVCLZYAuqZ25piRnbBEoAesaa/gtdcls1$p5k2$d$tUsch7fU$nqDkaxMDOFBeJsTSfABsyn.PYUXilHwLtspams3$p5k2$3e8$H0NX9mT/$wk/sE8vv6OMKuMaqazCJYDSUhWY9YB2Js0$p5k2$$KosHgqNo$9mjN8gqjt02hDoP0c2J0ABtLIwtot8cQ(Rs,$p5k2$$exec$r1EWMCMk7Rlv3L/RNcFXviDefYa0hlql(R s1$p5k2$c$u9HvcT4d$Sd1gwSVCLZYAuqZ25piRnbBEoAesaa/g(R!s1$p5k2$d$tUsch7fU$nqDkaxMDOFBeJsTSfABsyn.PYUXilHwL(R"s3$p5k2$3e8$H0NX9mT/$wk/sE8vv6OMKuMaqazCJYDSUhWY9YB2J(RRRtdlitz_pbkdf2_sha1RRR(((sF/usr/lib/python2.7/site-packages/passlib/tests/test_handlers_pbkdf2.pyRs tgrub_pbkdf2_sha512_testcBs#eZejZedfdgZRS(sgrub.pbkdf2.sha512.10000.BCAC1CEC5E4341C8C511C5297FA877BE91C2817B32A35A3ECF5CA6B8B257F751.6968526A2A5B1AEEE0A29A9E057336B48D388FFB3F600233237223C2104DE1752CEC35B0DD1ED49563398A282C0F471099C2803FBA47C7919CABC43192C68F60ttoomanysecretssgrub.pbkdf2.sha512.10000.9B436BB6978682363D5C449BBEAB322676946C632208BC1294D51F47174A9A3B04A7E4785986CD4EA7470FAB8FE9F6BD522D1FC6C51109A8596FB7AD487C4493.0FE5EF169AFFCB67D86E2581B1E251D88C777B98BA2D3256ECC9F765D84956FC5CA5C4B6FD711AA285F0A04DCF4634083F9A20F4B6F339A52FBD6BED618E527B(R%sgrub.pbkdf2.sha512.10000.9B436BB6978682363D5C449BBEAB322676946C632208BC1294D51F47174A9A3B04A7E4785986CD4EA7470FAB8FE9F6BD522D1FC6C51109A8596FB7AD487C4493.0FE5EF169AFFCB67D86E2581B1E251D88C777B98BA2D3256ECC9F765D84956FC5CA5C4B6FD711AA285F0A04DCF4634083F9A20F4B6F339A52FBD6BED618E527B(RRRtgrub_pbkdf2_sha512RRR(((sF/usr/lib/python2.7/site-packages/passlib/tests/test_handlers_pbkdf2.pyR$s  t scram_testc BseZejZdd eddfeddfeddfgZddd d d d d ddddg ZdZdZ dZ dZ dZ dZ dZddZdZdZdZdZRS(!tpencils>$scram$4096$QSXCR.Q6sek8bf92$sha-1=HZbuOlKbWl.eR8AfIposuKbhX30s$scram$4096$QSXCR.Q6sek8bf92$sha-1=HZbuOlKbWl.eR8AfIposuKbhX30,sha-256=qXUXrlcvnaxxWG00DdRgVioR2gnUpuX5r.3EZ1rdhVY,sha-512=lzgniLFcvglRLS0gt.C4gy.NurS3OIOVRAU1zZOV4P.qFiVFO2/edGQSu/kD1LwdX0SNV/KsPdHSwEl5qRTuZQsIX s>$scram$6400$0BojBCBE6P2/N4bQ$sha-1=YniLes.b8WFMvBhtSACZyyvxeCcs\u2168\u3000a\u0300s \u00ADIX s?$scram$04096$QSXCR.Q6sek8bf92$sha-1=HZbuOlKbWl.eR8AfIposuKbhX30s>$scram$409A$QSXCR.Q6sek8bf92$sha-1=HZbuOlKbWl.eR8AfIposuKbhX30s>$scram$4096$QSXCR.Q6sek8bf9-$sha-1=HZbuOlKbWl.eR8AfIposuKbhX30s>$scram$4096$QSXCR.Q6sek8bf92$sha-1=HZbuOlKbWl.eR8AfIposuKbhX3-s$scram$4096$QSXCR.Q6sek8bf92s$scram$4096$QSXCR.Q6sek8bf92$s?$scram$4096$QSXCR.Q6sek8bf92$sha-1=HZbuOlKbWl.eR8AfIposuKbhX30$sq$scram$4096$QSXCR.Q6sek8bf92$sha-1=HZbuOlKbWl.eR8AfIposuKbhX30sha-256=qXUXrlcvnaxxWG00DdRgVioR2gnUpuX5r.3EZ1rdhVYse$scram$4096$QSXCR.Q6sek8bf92$sha-1=HZbuOlKbWl.eR8AfIposuKbhX30,shaxxx-190=HZbuOlKbWl.eR8AfIposuKbhX30s@$scram$4096$QSXCR.Q6sek8bf92$sha-256=HZbuOlKbWl.eR8AfIposuKbhX30s=$scram$4096$QSXCR.Q6sek8bf92$sha1=HZbuOlKbWl.eR8AfIposuKbhX30cCs1tt|j|jtjdddS(Ntignores norm_hash_name\(\): unknown hash(tsuperR'tsetUptrequire_stringpreptwarningstfilterwarnings(R ((sF/usr/lib/python2.7/site-packages/passlib/tests/test_handlers_pbkdf2.pyR+s cs(tddddfd}j|ddttjjjt|dj|dd gj|d d d d gj|d d gd d gjt |d gjt |dgdtjt |d dgjt |d gdidd 6dS(stest parsing of 'algs' settingtsalttAi troundsics;x"D]}|j||qWjd||jS(Ntalgs(t setdefaultRR2(R2tkwdstk(tdefaultsR (sF/usr/lib/python2.7/site-packages/passlib/tests/test_handlers_pbkdf2.pytparses t use_defaultstsha1ssha-1ssha1, sha256, md5tmd5ssha-256tsha256R2s shaxxx-190tchecksumtiNt AAAAAAAAAAt( tdictt assertEqualtNonetTrueRtscramt default_algst assertRaisest TypeErrort ValueErrort RuntimeError(R R7((R6R sF/usr/lib/python2.7/site-packages/passlib/tests/test_handlers_pbkdf2.pyt test_90_algss""c Cs^|jt|jdtditddd6|jt|jdtdiddd6dS( s+test internal parsing of 'checksum' keywordR8R<tXissha-1i ssha-256N(RFRGRRCRRH(R ((sF/usr/lib/python2.7/site-packages/passlib/tests/test_handlers_pbkdf2.pyttest_90_checksumsscCs|jj}d}d}|j||d|ddf|j||d|ddf|j||d |dd f|jt||d d }|jt||d |jt||d|jt||d dS(s test scram.extract_digest_info()s'$scram$10$AAAAAA$sha-1=AQ,bbb=Ag,ccc=AwR=itSHA1i stbbbstcccstddds$scram$10$....$sha-1,bbb,cccssha-1Nt(Rtextract_digest_infoRARFtKeyErrorRH(R tedithtstc((sF/usr/lib/python2.7/site-packages/passlib/tests/test_handlers_pbkdf2.pyttest_91_extract_digest_info*s """cCsg|jj}|j|ddg|j|ddddg|j|ddddgd S( s test scram.extract_digest_algs()s>$scram$4096$QSXCR.Q6sek8bf92$sha-1=HZbuOlKbWl.eR8AfIposuKbhX30ssha-1tformatthashlibR9s$scram$4096$QSXCR.Q6sek8bf92$sha-1=HZbuOlKbWl.eR8AfIposuKbhX30,sha-256=qXUXrlcvnaxxWG00DdRgVioR2gnUpuX5r.3EZ1rdhVY,sha-512=lzgniLFcvglRLS0gt.C4gy.NurS3OIOVRAU1zZOV4P.qFiVFO2/edGQSu/kD1LwdX0SNV/KsPdHSwEl5qRTuZQssha-256ssha-512N(Rtextract_digest_algsRA(R teda((sF/usr/lib/python2.7/site-packages/passlib/tests/test_handlers_pbkdf2.pyttest_92_extract_digest_algs<s   cCs)|jj}d}d}|j|td|dd||j|d|dd||j|td|dd ||j|d|dd ||j|d|dd d |jt|d|dd |jt|d|dd|j|td|jddd |dS(stest scram.derive_digest()ss[tNuPnIZZns\u2168issha-1sⅨsSHA-1tIXR9RMR:s3/ŽModssha-666islatin-1N(Rt derive_digestRARRFRHtdecode(R Rts1td1((sF/usr/lib/python2.7/site-packages/passlib/tests/test_handlers_pbkdf2.pyttest_93_derive_digestNs %%cCs|jtd}|j|jtd||j|jtd||jtd}|j|jtd||j|jtd||jt|jtd|jt|jtd|dS( stest hash/verify use saslprepsI\u00ADXR^s\u2168sso\u0301s \u200Do\u0301s\uFDD0N(t do_encryptRRt do_verifyRFRH(R RU((sF/usr/lib/python2.7/site-packages/passlib/tests/test_handlers_pbkdf2.pyttest_94_saslprepgsREcCs|j}t|j}|jid|6}|j|j||j|jddg|jd}|j|j|ddgdS(s#using() -- 'default_algs' parameterssha1,md5R:ssha-1tdummyN(RtlistREtusingRARR[(R tparamRtorigtsubclsth1((sF/usr/lib/python2.7/site-packages/passlib/tests/test_handlers_pbkdf2.pyttest_94_using_w_default_algs{s cCs|jdddS(susing() -- 'algs' parameterRjR2N(Rn(R ((sF/usr/lib/python2.7/site-packages/passlib/tests/test_handlers_pbkdf2.pyttest_94_using_w_algsscCs|jjdd}|jd}|j|j||jdd}|j|j||jdd}|j|j|dS(sneeds_update() -- algs settingR2ssha1,md5RgR9s sha1,sha256N(RRiRt assertFalset needs_updateR(R thandler1Rmthandler2thandler3((sF/usr/lib/python2.7/site-packages/passlib/tests/test_handlers_pbkdf2.pyttest_94_needs_update_algsscCs|j}ddlm}|dgdd}|jd}|j|j|ddg|j|j||jdd }|j|j||jdd }|j |j|d S( s)test handling of 'algs' in context objecti(t CryptContextRDt scram__algsssha1,md5RgR:ssha-1R9s sha1,sha256N( Rtpasslib.contextRvRRAR[RpRqtcopyR(R RRvtc1RUtc2((sF/usr/lib/python2.7/site-packages/passlib/tests/test_handlers_pbkdf2.pyttest_95_context_algss csfd}fd}d}j|d|j|d|d}jt|d|d}jt|d|d}j|d|j|d|jt|d|jt|d|d S( stest verify(full=True) flagcsjj||S(N(RR (RVRU(R (sF/usr/lib/python2.7/site-packages/passlib/tests/test_handlers_pbkdf2.pytvpartscsjj||dtS(Ntfull(RR RC(RVRU(R (sF/usr/lib/python2.7/site-packages/passlib/tests/test_handlers_pbkdf2.pytvfullss$scram$4096$QSXCR.Q6sek8bf92$sha-1=HZbuOlKbWl.eR8AfIposuKbhX30,sha-256=qXUXrlcvnaxxWG00DdRgVioR2gnUpuX5r.3EZ1rdhVY,sha-512=lzgniLFcvglRLS0gt.C4gy.NurS3OIOVRAU1zZOV4P.qFiVFO2/edGQSu/kD1LwdX0SNV/KsPdHSwEl5qRTuZQR(ttapes$scram$4096$QSXCR.Q6sek8bf92$sha-1=HZbuOlKbWl.eR8AfIposuKbhX30,sha-256=qXUXrlcvnaxxWG00DdRgVioR2gnUpuX5r.3EZ1rdhV,sha-512=lzgniLFcvglRLS0gt.C4gy.NurS3OIOVRAU1zZOV4P.qFiVFO2/edGQSu/kD1LwdX0SNV/KsPdHSwEl5qRTuZQs$scram$4096$QSXCR.Q6sek8bf92$sha-1=HZbuOlKbWl.eR8AfIposuKbhX30,sha-256=qXUXrlcvnaxxWG00DdRgVioR2gnUpuX5r.3EZ1rdhVYa,sha-512=lzgniLFcvglRLS0gt.C4gy.NurS3OIOVRAU1zZOV4P.qFiVFO2/edGQSu/kD1LwdX0SNV/KsPdHSwEl5qRTuZQs$scram$4096$QSXCR.Q6sek8bf92$sha-1=HZbuOlKbWl.eR8AfIposuKbhX30,sha-256=R7RJDWIbeKRTFwhE9oxh04kab0CllrQ3kCcpZUcligc,sha-512=lzgniLFcvglRLS0gt.C4gy.NurS3OIOVRAU1zZOV4P.qFiVFO2/edGQSu/kD1LwdX0SNV/KsPdHSwEl5qRTuZQN(RRpRFRH(R R}RRU((R sF/usr/lib/python2.7/site-packages/passlib/tests/test_handlers_pbkdf2.pyttest_96_full_verifys(spencils>$scram$4096$QSXCR.Q6sek8bf92$sha-1=HZbuOlKbWl.eR8AfIposuKbhX30(spencils$scram$4096$QSXCR.Q6sek8bf92$sha-1=HZbuOlKbWl.eR8AfIposuKbhX30,sha-256=qXUXrlcvnaxxWG00DdRgVioR2gnUpuX5r.3EZ1rdhVY,sha-512=lzgniLFcvglRLS0gt.C4gy.NurS3OIOVRAU1zZOV4P.qFiVFO2/edGQSu/kD1LwdX0SNV/KsPdHSwEl5qRTuZQ(RRRRDRRRRR+RJRLRXR]RcRfRnRoRuR|R(((sF/usr/lib/python2.7/site-packages/passlib/tests/test_handlers_pbkdf2.pyR's:           (t__doc__tloggingt getLoggerRtlogR-tpasslibRtpasslib.utils.compatRtpasslib.tests.utilsRRtpasslib.tests.test_handlersRRRRRRRRR$R'(((sF/usr/lib/python2.7/site-packages/passlib/tests/test_handlers_pbkdf2.pyts