5Xc@sdZddlmZddlZddlZddlmZmZddlm Z m Z de fdYZ de fd YZ d e fd YZ dS( s passlib.tests -- tests for passlib.utils.pbkdf2 .. warning:: This module & it's functions have been deprecated, and superceded by the functions in passlib.crypto. This file is being maintained until the deprecated functions are removed, and is only present prevent historical regressions up to that point. New and more thorough testing is being done by the replacement tests in ``test_utils_crypto.py``. i(twith_statementN(tutJYTHON(tTestCasethbt UtilsTestc BsPeZdZdZddgZd d!d"d#d$d%d&d'gZdZdZRS((stest various utils functionsspasslib.utils.pbkdf2thashlibtianatmd5sSCRAM-MD5-PLUSsMD-5tsha1ssha-1s SCRAM-SHA-1tSHA1tsha256ssha-256tSHA_256ssha2-256tripemds SCRAM-RIPEMDtRIPEMDt ripemd160s ripemd-160sSCRAM-RIPEMD-160t RIPEmd160ttest128stest-128tTEST128ttest2sTEST-2t test3_128s test3-128s TEST-3-128cCs*tt|jtjddtdS(Ntignores".*passlib.utils.pbkdf2.*deprecated(tsuperRtsetUptwarningstfilterwarningstDeprecationWarning(tself((sC/usr/lib/python2.7/site-packages/passlib/tests/test_utils_pbkdf2.pyR.sc Csmddlm}ddlm}ddlm}x|jD]}|d|q:W|jt|dd |jt|dd|j |t dd|j |dd|jt |d t jt jdd x|||jD]m}xdt|jD]S\}}||}x:|D]2}|||} |j | |d ||fq%WqWqWWd QXd S( snorm_hash_name()i(tchain(tnorm_hash_name(t_known_hash_namestmd4tfaketMD4Rs.*unknown hashsname=%r, format=%r:N(t itertoolsRtpasslib.utils.pbkdf2Rtpasslib.crypto.digestRt ndn_formatst assertRaisest ValueErrortNonet assertEqualRt TypeErrorRtcatch_warningsRt ndn_valuest enumerate( RRRRtformattrowtidxtcorrecttvaluetresult((sC/usr/lib/python2.7/site-packages/passlib/tests/test_utils_pbkdf2.pyttest_norm_hash_name2s(    (smd5smd5sSCRAM-MD5-PLUSsMD-5(R ssha-1s SCRAM-SHA-1R (R ssha-256R ssha2-256(R R s SCRAM-RIPEMDR(Rs ripemd-160sSCRAM-RIPEMD-160R(Rstest-128R(RRsTEST-2(Rs test3-128s TEST-3-128(t__name__t __module__t__doc__tdescriptionPrefixR%R,RR4(((sC/usr/lib/python2.7/site-packages/passlib/tests/test_utils_pbkdf2.pyRs   t Pbkdf1_Testc BseZdZdZdeddddedfddddd d ed fddddd edfddddd edfddddd edfdddddedfgZesejdddddedfndZ dZ dZ RS(stest kdf helpersspasslib.utils.pbkdf2.pbkdf1()tpasswordt78578E5A5D63CB06iiR t dc19847e05c64d2faf10ebfb4a3d2a20tsaltiRtit84it8475c6a8531a5d27t 8475c6a8531a5d27e386cd496457812ct(4a8fd48e426ed081b535be5769892fa396293efbRt f7f2e91100a8f96190f2dd177cb26453cCs*tt|jtjddtdS(NRs".*passlib.utils.pbkdf2.*deprecated(RR9RRRR(R((sC/usr/lib/python2.7/site-packages/passlib/tests/test_utils_pbkdf2.pyRmsc Csbddlm}xK|jD]@\}}}}}}||||||}|j||qWdS(stest reference vectorsi(tpbkdf1N(R#RDt pbkdf1_testsR)( RRDtsecretR=troundstkeylentdigestR1R3((sC/usr/lib/python2.7/site-packages/passlib/tests/test_utils_pbkdf2.pyt test_knownqs"csddlmdddddfd}||jt|dd|jt|dd|jt|dd |jt|d d |jt|d d |jt|d d|jt|d ddd|jt|d d dS(stest border casesi(RDRFR=iRcs|||||S(N((RFR=RGRHthash(RD(sC/usr/lib/python2.7/site-packages/passlib/tests/test_utils_pbkdf2.pythelper{sRKtmissingRGit1RHiN(R#RDR&R*R'(RRL((RDsC/usr/lib/python2.7/site-packages/passlib/tests/test_utils_pbkdf2.pyt test_borderxs(R:ssaltiismd5R>N( R5R6R7R8RR(RERtappendRRJRO(((sC/usr/lib/python2.7/site-packages/passlib/tests/test_utils_pbkdf2.pyR9Rs!!"  t Pbkdf2_TestcBseZdZdZedddddfedddddfed dddd fed ddd d fed dddd feddddd d feddddd d fedddddfedddddfedddddfeddddd fed!d"d#ddfed$d%ed&d'dd(fed)d*dd+dd,fed-d*dd+d3d,fgZd.Zd/Zd0Z d1Z d2Z RS(4stest pbkdf2() supportspasslib.utils.pbkdf2.pbkdf2()t cdedb5281bb2f801565a1122b2563515R:sATHENA.MIT.EDUraeburniit 01dbee7f4a9e243e988b62c73cda935dit@01dbee7f4a9e243e988b62c73cda935da05378b93244ec8f48a99e61ad799d86i t@5c08eb61fdf71e4e4ec3cf6ba1f5512ba7e52ddbc5e5142f708a31e2e62b1e13it@d1daa78615f287e6a1c8b120d7062a493f98d203e6be49a6adf4fa574b6e64ees4VxxV4it@139c30c0966bc32ba55fdbf212530ac9c5ec59f1a452f5cc9ad940fea0598ed1tXi@spass phrase equals block sizet@9ccad6d468770cd51b10e6a68721be611a8b4d282601db3b36be9246915ec82aiAspass phrase exceeds block sizet(0c60c80f961f0e71f3a9b524af6012062fe037a6R=it(ea6c014dc72d6f8ccd1ed92ace1d41f0d8de8957t(4b007901b765489abead49d926f721d065a429c1it23d2eec4fe41c849b80c8d83662c0e44a8b291a964cf2f07038tpasswordPASSWORDpasswordt$saltSALTsaltSALTsaltSALTsaltSALTsaltit 56fa6aa75548099dcc37d7f03425e0c3t passwordtsaltt887CFF169EA8335235D8004242AA7D6187A41E3187DF0CE14E256D85ED97A97357AAA8FF0A3871AB9EEFF458392F462F495487387F685B7472FC6C29E293F0A0thellot9290F727ED06C38BA4549EF7DE25CF5642659211B7FC076F2D28FEFD71784BB8D8F6FB244A8CC5C06240631B97008565A120764C0EE9C2CB0073994D79080136i's hmac-sha512t e248fb6b13365146f8ac6307cc222812RFi s hmac-sha1t(e248fb6b13365146f8ac6307cc2228127872da6dcCs*tt|jtjddtdS(NRs".*passlib.utils.pbkdf2.*deprecated(RRQRRRR(R((sC/usr/lib/python2.7/site-packages/passlib/tests/test_utils_pbkdf2.pyRsc Csddlm}xt|jD]i}|d \}}}}}t|dkrU|dnd}||||||} |j| |qWdS(stest reference vectorsi(tpbkdf2iis hmac-sha1N(R#Rhtpbkdf2_test_vectorstlenR)( RRhR/R1RFR=RGRHtprfR3((sC/usr/lib/python2.7/site-packages/passlib/tests/test_utils_pbkdf2.pyRJ s "csVddlmdddddfd}||jt|dd|jt|dd |jt|dd |jt|d d|jt|d d |d d|jt|d d dd|jt|d d |jt|dd|jt|dd|jt|dd|jt|dd|jt|dddS(stest border casesi(RhR:R=is hmac-sha1cs|||||S(N((RFR=RGRHRk(Rh(sC/usr/lib/python2.7/site-packages/passlib/tests/test_utils_pbkdf2.pyRLsRGitxRHiii iRFRkshmac-footfooNII(R#RhR(R&R'R*t OverflowErrortNotImplementedError(RRL((RhsC/usr/lib/python2.7/site-packages/passlib/tests/test_utils_pbkdf2.pyROs  cspddlmdddd dfd}|jt|ddd |jt|dd d d S( stest keylen==Nonei(RhR:R=is hmac-sha1cs|||||S(N((RFR=RGRHRk(Rh(sC/usr/lib/python2.7/site-packages/passlib/tests/test_utils_pbkdf2.pyRL4sRkis hmac-sha256i N(R#RhR(R)Rj(RRL((RhsC/usr/lib/python2.7/site-packages/passlib/tests/test_utils_pbkdf2.pyttest_default_keylen1scCs<ddlm}d}|jt|dddd|dS( stest custom prf functioni(RhcSstj||djS(Ntfooey(RRRI(tkeytmsg((sC/usr/lib/python2.7/site-packages/passlib/tests/test_utils_pbkdf2.pyRk<sRFR=iiN(R#RhR&Ro(RRhRk((sC/usr/lib/python2.7/site-packages/passlib/tests/test_utils_pbkdf2.pyttest_custom_prf9s N( R5R6R7R8RR(RiRRJRORpRt(((sC/usr/lib/python2.7/site-packages/passlib/tests/test_utils_pbkdf2.pyRQsR                     (R7t __future__RRRtpasslib.utils.compatRRtpasslib.tests.utilsRRRR9RQ(((sC/usr/lib/python2.7/site-packages/passlib/tests/test_utils_pbkdf2.pyt s  6@