5Xc@s dZddlmZddlZejeZddlZddlm Z ddl m Z ddl m Z ddlmZmZmZmZddlmZmZdd lmZmZe d Zd Zd efd YZdefdYZdeefdYZdeefdYZdeefdYZdeefdYZ deefdYZ!ee j"j#ddeefdYZ$ee j"j#ddeefdYZ%ddl&m'Z'ee j(j#d d!eefd"YZ)dS(#sFpasslib.tests.test_handlers_django - tests for passlib hash algorithmsi(twith_statementN(thash(t repeat_string(tu(tTestCaset HandlerCaset skipUnlesstSkipTest(t UPASS_USDt UPASS_TABLE(tDJANGO_VERSIONtMIN_DJANGO_VERSIONsltmeincCsdjd|DS(Nt.css|]}t|VqdS(N(tstr(t.0te((sF/usr/lib/python2.7/site-packages/passlib/tests/test_handlers_django.pys s(tjoin(tversion((sF/usr/lib/python2.7/site-packages/passlib/tests/test_handlers_django.pytvstrst _DjangoHelpercBsQeZeZeZdZdZe j dZ dZ dZ eZdZRS(cCsit|jkr.|jdt|jn|jret|jkre|jdt|jntS(NsDjango >= %s not installedsDjango <= %s not installed(R tmin_django_versiontskipTestRtmax_django_versiontTrue(tself((sF/usr/lib/python2.7/site-packages/passlib/tests/test_handlers_django.pyt_require_django_support&s tfuzz_verifier_djangocsIyjWntk r"dSXddlmfd}|S(Ni(tcheck_passwordcsmjjdkr6|jdr6|jdd}njr`t|tr`|jd}n||S(sdjango/check_passwordt django_bcrypts bcrypt$$2y$s$$2y$s$$2a$sutf-8(thandlertnamet startswithtreplacetdjango_has_encoding_glitcht isinstancetbytestdecode(tsecretR(RR(sF/usr/lib/python2.7/site-packages/passlib/tests/test_handlers_django.pyt verify_django8s !(RRtNonetdjango.contrib.auth.hashersR(RR&((RRsF/usr/lib/python2.7/site-packages/passlib/tests/test_handlers_django.pyR1s  cCs|jddlm}xd|jD]V\}}|j|||d||f|j|d||d||fq'WdS(s:run known correct hashes through Django's check_password()i(Rs"secret=%r hash=%r failed to verifytxs,mangled secret=%r hash=%r incorrect verifiedN(RR(Rtiter_known_hashest assertTruet assertFalse(RRR%R((sF/usr/lib/python2.7/site-packages/passlib/tests/test_handlers_django.pyttest_90_django_referenceDs c Cs|jddlm}ddlm}|jj}||jd}|j||j }x||kr|j \}}|sqen|j rt |t r|jd}n||d|}|j|j||j|j|||j|j||qeWdS(s/test against output of Django's make_password()i(ttick(t make_passwordisutf-8thasherN(Rt passlib.utilsR.R(R/Rt django_namet max_fuzz_timetFuzzHashGeneratort getRandomtrandom_password_pairR!R"R#R$R+t do_identifyt do_verifyR,( RR.R/Rtendt generatorR%totherR((sF/usr/lib/python2.7/site-packages/passlib/tests/test_handlers_django.pyttest_91_django_generationUs   N(sfuzz_verifier_django(t__name__t __module__Rt_DjangoHelper__unittest_skipR RR'RRRtfuzz_verifierstextra_fuzz_verifiersRR-tFalseR!R<(((sF/usr/lib/python2.7/site-packages/passlib/tests/test_handlers_django.pyRs   tdjango_disabled_testcBs;eZdZejZeZddedfgZ dgZ RS(stest django_disabledtpasswordt!ts!9wa845vn7098ythaehasldkfj(RDRE(RFRE(s!9wa845vn7098ythaehasldkfjRDRE( R=R>t__doc__Rtdjango_disabledRRtdisabled_contains_saltR tknown_correct_hashestknown_alternate_hashes(((sF/usr/lib/python2.7/site-packages/passlib/tests/test_handlers_django.pyRCls tdjango_des_crypt_testcBsqeZdZejZdZdddedfed fe d d fdgZ dgZ dgZ dddgZ RS(stest django_des_cryptii RDscrypt$c2$c2M87q...WWcUscrypt$c2e86$c2M87q...WWcUtpasswordignoremescrypt$c2.AZ$c2M87q...WWcUscrypt$c2e86$c2hN1Bxd6ZiWsscrypt$0.aQs$0.wB.TT0Czvlos hell\u00D6scrypt$sa$saykDgk3BPZ9Etfoos!crypt$MNVY.9ajgdvDQ$MNVY.9ajgdvDQscrypt$$c2M87q...WWcUs sha1$aa$bbscrypt$c2$c2M87qscrypt$f$c2M87q...WWcUscrypt$ffe86$c2M87q...WWcU(ii (spasswordscrypt$c2$c2M87q...WWcU(spasswordscrypt$c2e86$c2M87q...WWcU(RMscrypt$c2.AZ$c2M87q...WWcU(RNs!crypt$MNVY.9ajgdvDQ$MNVY.9ajgdvDQ(scrypt$$c2M87q...WWcUspasswordscrypt$c2$c2M87q...WWcU(R=R>RGRtdjango_des_cryptRRRR RRJRKtknown_unidentified_hashestknown_malformed_hashes(((sF/usr/lib/python2.7/site-packages/passlib/tests/test_handlers_django.pyRL}s      tdjango_salted_md5_testcBsleZdZejZd ZeZdde dfe dfgZ d gZ d gZ d ejfd YZRS(stest django_salted_md5ii RDs.md5$123abcdef$c8272612932975ee80e8a35995708e80ttests1md5$3OpqnFAHW5CT$54b29300675271049a1ebae07b395e20s*md5$c2e86$92105508419a81a6babfaecf876a2fa0s*md5$d9eb8$01495b32852bffb27cf5d4394fe7a54cs sha1$aa$bbs md5$aa$bbR4cBseZdZRS(cCsE|j}|j}d}|jp(|d}|j||||dS(Niig?(Rtdefault_salt_sizet max_salt_sizet randintgauss(RRtdefaulttlowertupper((sF/usr/lib/python2.7/site-packages/passlib/tests/test_handlers_django.pytrandom_salt_sizes   (R=R>RZ(((sF/usr/lib/python2.7/site-packages/passlib/tests/test_handlers_django.pyR4s(ii (spasswords.md5$123abcdef$c8272612932975ee80e8a35995708e80(RSs1md5$3OpqnFAHW5CT$54b29300675271049a1ebae07b395e20(R=R>RGRtdjango_salted_md5RRRR!RR RJRPRQRR4(((sF/usr/lib/python2.7/site-packages/passlib/tests/test_handlers_django.pyRRs    tdjango_salted_sha1_testcBs_eZdZejZd ZeZdde dfe dfdgZ d gZ d gZ ejZRS(stest django_salted_sha1ii RDs7sha1$123abcdef$e4a1877b0e35c47329e7ed7e58014276168a37baRSs:sha1$bcwHF9Hy8lxS$6b4cfa0651b43161c6f1471ce9523acf1f751ba3s3sha1$c2e86$0f75c5d7fbd100d587c127ef0b693cde611b4adas3sha1$6d853$ef13a4d8fb57aed0cb573fe9c82e28dc7fd372d4t MyPasswords3sha1$54123$893cf12e134c3c215f3a76bd50d13f92404a54d3s md5$aa$bbssha1$c2e86$0f75(ii (spasswords7sha1$123abcdef$e4a1877b0e35c47329e7ed7e58014276168a37ba(stests:sha1$bcwHF9Hy8lxS$6b4cfa0651b43161c6f1471ce9523acf1f751ba3(R]s3sha1$54123$893cf12e134c3c215f3a76bd50d13f92404a54d3(R=R>RGRtdjango_salted_sha1RRRR!RR RJRPRQRRR4(((sF/usr/lib/python2.7/site-packages/passlib/tests/test_handlers_django.pyR\s      tdjango_pbkdf2_sha256_testcBs)eZdZejZdedfgZRS(stest django_pbkdf2_sha256snot a passwordsMpbkdf2_sha256$10000$kjVJaVz6qsnJ$5yPHw3rwJGECpUf70daLGhOrQ5+AMxIJdz1c3bqK1Rs=sMpbkdf2_sha256$10000$bEwAfNrH1TlQ$OgYUblFNUX1B8GfMqaCYUK/iHyO0pa7STTDdaEJBuY0=(snot a passwordsMpbkdf2_sha256$10000$kjVJaVz6qsnJ$5yPHw3rwJGECpUf70daLGhOrQ5+AMxIJdz1c3bqK1Rs=(R=R>RGRtdjango_pbkdf2_sha256RR RJ(((sF/usr/lib/python2.7/site-packages/passlib/tests/test_handlers_django.pyR_s  tdjango_pbkdf2_sha1_testcBs)eZdZejZdedfgZRS(stest django_pbkdf2_sha1snot a passwords;pbkdf2_sha1$10000$wz5B6WkasRoF$atJmJ1o+XfJxKq1+Nu1f1i57Z5I=s;pbkdf2_sha1$10000$KZKWwvqb8BfL$rw5pWsxJEU4JrZAQhHTCO+u0f5Y=(snot a passwords;pbkdf2_sha1$10000$wz5B6WkasRoF$atJmJ1o+XfJxKq1+Nu1f1i57Z5I=(R=R>RGRtdjango_pbkdf2_sha1RR RJ(((sF/usr/lib/python2.7/site-packages/passlib/tests/test_handlers_django.pyRas  sno bcrypt backends availabletdjango_bcrypt_testcBsTeZdZejZeZd d edfgZ dZ de j fdYZ RS( stest django_bcryptRFsCbcrypt$$2a$06$DCq7YPn5Rq63x1Lad4cll.TV4S6ytwfsfvkgY8jIucDrjc8deX1s.tabcdefghijklmnopqrstuvwxyzsCbcrypt$$2a$10$fVH8e28OQRj9tqiDXs1e1uxpsjN0c7II7YPKXua2NAKYvM6iQk7dqsCbcrypt$$2a$05$Z17AXnnlpzddNUvnC6cZNOSwMA/8oNiKnHTHTwLlBijfucQQlHjaGcCs*|jddtt|j|dS(Ntroundsi(t setdefaulttsuperRctpopulate_settings(Rtkwds((sF/usr/lib/python2.7/site-packages/passlib/tests/test_handlers_django.pyRh"sR4cBseZdZdZRS(cCs|jddddS(Niiii(RV(R((sF/usr/lib/python2.7/site-packages/passlib/tests/test_handlers_django.pyt random_rounds)scCsdS(N(R'(R((sF/usr/lib/python2.7/site-packages/passlib/tests/test_handlers_django.pyt random_ident-s(R=R>RjRk(((sF/usr/lib/python2.7/site-packages/passlib/tests/test_handlers_django.pyR4's (RFsCbcrypt$$2a$06$DCq7YPn5Rq63x1Lad4cll.TV4S6ytwfsfvkgY8jIucDrjc8deX1s.(RdsCbcrypt$$2a$10$fVH8e28OQRj9tqiDXs1e1uxpsjN0c7II7YPKXua2NAKYvM6iQk7dq( R=R>RGRRRRtfuzz_salts_need_bcrypt_repairR RJRhRR4(((sF/usr/lib/python2.7/site-packages/passlib/tests/test_handlers_django.pyRcs   tdjango_bcrypt_sha256_testcBseZdZejZdZeZ de dfe dfe dddfe dddd fe ddd d fgZ d gZd ZdejfdYZRS(stest django_bcrypt_sha256RFsJbcrypt_sha256$$2a$06$/3OeRpbOf8/l6nPPRdZPp.nRiyYqPobEZGdNRBWihQhiFDh1ws1tusJbcrypt_sha256$$2a$08$NDjSAIcas.EcoxCRiArvT.MkNiPYVhrsrnJsRkLueZOoV1bsQqlmCsJbcrypt_sha256$$2a$06$kCXUnRFQptGg491siDKNTu8RxjBGSjALHRuvhPYNFsa4Ea5d9M48utabc123iHsJbcrypt_sha256$$2a$06$Tg/oYyZTyAf.Nb3qSgN61OySmyXA8FoY4PjGizjE1QSDfuL5MXNnitqwrsJbcrypt_sha256$$2a$06$Tg/oYyZTyAf.Nb3qSgN61Ocy0BEz1RK6xslSNi8PlaLX2pe7x/KQGtxyzsJbcrypt_sha256$$2a$06$Tg/oYyZTyAf.Nb3qSgN61OvY2zoRVUa2Pugv2ExVOUT2YmhvxUFUasMbcrypt_sha256$xyz$2a$06$/3OeRpbOf8/l6nPPRdZPp.nRiyYqPobEZGdNRBWihQhiFDh1ws1tucCs*|jddtt|j|dS(NRei(RfRgRmRh(RRi((sF/usr/lib/python2.7/site-packages/passlib/tests/test_handlers_django.pyRhTsR4cBseZdZdZRS(cCs|jddddS(Niiii(RV(R((sF/usr/lib/python2.7/site-packages/passlib/tests/test_handlers_django.pyRj[scCsdS(N(R'(R((sF/usr/lib/python2.7/site-packages/passlib/tests/test_handlers_django.pyRk_s(R=R>RjRk(((sF/usr/lib/python2.7/site-packages/passlib/tests/test_handlers_django.pyR4Ys N(RFsJbcrypt_sha256$$2a$06$/3OeRpbOf8/l6nPPRdZPp.nRiyYqPobEZGdNRBWihQhiFDh1ws1tu(R=R>RGRtdjango_bcrypt_sha256RR'tforbidden_charactersRRlt UPASS_LETMEINR RRJtknown_malformed_hashersRhRR4(((sF/usr/lib/python2.7/site-packages/passlib/tests/test_handlers_django.pyRm2s&     (t_base_argon2_testsno argon2 backends availabletdjango_argon2_testcBsceZdZejZd d edfgZdZd dZ dZ de j fd YZ RS( stest django_bcryptRDsDargon2$argon2i$v=19$m=256,t=1,p=1$c29tZXNhbHQ$AJFIsNZTMKTAewB4+ETN1AsDargon2$argon2i$v=19$m=380,t=2,p=2$c29tZXNhbHQ$SrssP8n7m/12VWPM8dvNrwsIargon2$argon2i$v=19$m=512,t=2,p=2$V25jN1l4UUJZWkR1$MxpA1BD2Gh7+D79gaAw6sQcCs'tt|jtjdddS(Ntignores.*Using argon2pure backend.*(RgRvt setUpWarningstwarningstfilterwarnings(R((sF/usr/lib/python2.7/site-packages/passlib/tests/test_handlers_django.pyRxxscKsI|p |jj|}|jdt}|j|_|j|jS(Nt use_defaults(RtusingtwrappedRt_stub_checksumtchecksumt _wrap_hasht to_string(RRtsettings((sF/usr/lib/python2.7/site-packages/passlib/tests/test_handlers_django.pytdo_stub_encrypt|s cCs|jddS(Ns!legacy 1.6 workflow not supported(R(R((sF/usr/lib/python2.7/site-packages/passlib/tests/test_handlers_django.pyttest_03_legacy_hash_workflowsR4cBseZdZRS(cCs|jddddS(Niii(RV(R((sF/usr/lib/python2.7/site-packages/passlib/tests/test_handlers_django.pyRjs(R=R>Rj(((sF/usr/lib/python2.7/site-packages/passlib/tests/test_handlers_django.pyR4s(spasswordsDargon2$argon2i$v=19$m=256,t=1,p=1$c29tZXNhbHQ$AJFIsNZTMKTAewB4+ETN1A(spasswordsDargon2$argon2i$v=19$m=380,t=2,p=2$c29tZXNhbHQ$SrssP8n7m/12VWPM8dvNrwN(R=R>RGRt django_argon2RRsRJRxR'RRRuR4(((sF/usr/lib/python2.7/site-packages/passlib/tests/test_handlers_django.pyRvfs   (*RGt __future__Rtloggingt getLoggerR=tlogRytpasslibRR1Rtpasslib.utils.compatRtpasslib.tests.utilsRRRRtpasslib.tests.test_handlersRR tpasslib.tests.test_ext_djangoR R RsRRRCRLRRR\R_Ratbcryptt has_backendRcRmt"passlib.tests.test_handlers_argon2Rutargon2Rv(((sF/usr/lib/python2.7/site-packages/passlib/tests/test_handlers_django.pyts4  "  O)*"#1