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}|js)txd|jD]V\}}|j|||d||f|j|d||d||fq6WdS(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(Rtknown_correct_hashestAssertionErrortiter_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.utilsR0R(R1Rt django_namet max_fuzz_timetFuzzHashGeneratort getRandomtrandom_password_pairR!R"R#R$R-t do_identifyt do_verifyR.( RR0R1Rtendt 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(RFRG(RHRG(s!9wa845vn7098ythaehasldkfjRFRG( R?R@t__doc__Rtdjango_disabledRRtdisabled_contains_saltR R*tknown_alternate_hashes(((sF/usr/lib/python2.7/site-packages/passlib/tests/test_handlers_django.pyREls tdjango_des_crypt_testcBsqeZdZejZdZdddedfed fe d d fdgZ dgZ dgZ dddgZ RS(stest django_des_cryptii RFscrypt$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(RNscrypt$c2.AZ$c2M87q...WWcU(ROs!crypt$MNVY.9ajgdvDQ$MNVY.9ajgdvDQ(scrypt$$c2M87q...WWcUspasswordscrypt$c2$c2M87q...WWcU(R?R@RIRtdjango_des_cryptRRRR RR*RLtknown_unidentified_hashestknown_malformed_hashes(((sF/usr/lib/python2.7/site-packages/passlib/tests/test_handlers_django.pyRM}s      tdjango_salted_md5_testcBsleZdZejZd ZeZdde dfe dfgZ d gZ d gZ d ejfd YZRS(stest django_salted_md5ii RFs.md5$123abcdef$c8272612932975ee80e8a35995708e80ttests1md5$3OpqnFAHW5CT$54b29300675271049a1ebae07b395e20s*md5$c2e86$92105508419a81a6babfaecf876a2fa0s*md5$d9eb8$01495b32852bffb27cf5d4394fe7a54cs sha1$aa$bbs md5$aa$bbR6cBseZdZRS(cCsZ|j}|j}|jdks'td}|jp=|d}|j||||dS(Niiig?(Rtdefault_salt_sizet min_salt_sizeR+t max_salt_sizet randintgauss(RRtdefaulttlowertupper((sF/usr/lib/python2.7/site-packages/passlib/tests/test_handlers_django.pytrandom_salt_sizes   (R?R@R\(((sF/usr/lib/python2.7/site-packages/passlib/tests/test_handlers_django.pyR6s(ii (spasswords.md5$123abcdef$c8272612932975ee80e8a35995708e80(RTs1md5$3OpqnFAHW5CT$54b29300675271049a1ebae07b395e20(R?R@RIRtdjango_salted_md5RRRR!RR R*RQRRRR6(((sF/usr/lib/python2.7/site-packages/passlib/tests/test_handlers_django.pyRSs    tdjango_salted_sha1_testcBs_eZdZejZd ZeZdde dfe dfdgZ d gZ d gZ ejZRS(stest django_salted_sha1ii RFs7sha1$123abcdef$e4a1877b0e35c47329e7ed7e58014276168a37baRTs: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@RIRtdjango_salted_sha1RRRR!RR R*RQRRRSR6(((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@RIRtdjango_pbkdf2_sha256RR R*(((sF/usr/lib/python2.7/site-packages/passlib/tests/test_handlers_django.pyRas  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@RIRtdjango_pbkdf2_sha1RR R*(((sF/usr/lib/python2.7/site-packages/passlib/tests/test_handlers_django.pyRcs  sno bcrypt backends availabletdjango_bcrypt_testcBsTeZdZejZeZd d edfgZ dZ de j fdYZ RS( stest django_bcryptRHsCbcrypt$$2a$06$DCq7YPn5Rq63x1Lad4cll.TV4S6ytwfsfvkgY8jIucDrjc8deX1s.tabcdefghijklmnopqrstuvwxyzsCbcrypt$$2a$10$fVH8e28OQRj9tqiDXs1e1uxpsjN0c7II7YPKXua2NAKYvM6iQk7dqsCbcrypt$$2a$05$Z17AXnnlpzddNUvnC6cZNOSwMA/8oNiKnHTHTwLlBijfucQQlHjaGcCs*|jddtt|j|dS(Ntroundsi(t setdefaulttsuperRetpopulate_settings(Rtkwds((sF/usr/lib/python2.7/site-packages/passlib/tests/test_handlers_django.pyRj"sR6cBseZdZdZRS(cCs|jddddS(Niiii(RX(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@RlRm(((sF/usr/lib/python2.7/site-packages/passlib/tests/test_handlers_django.pyR6's (RHsCbcrypt$$2a$06$DCq7YPn5Rq63x1Lad4cll.TV4S6ytwfsfvkgY8jIucDrjc8deX1s.(RfsCbcrypt$$2a$10$fVH8e28OQRj9tqiDXs1e1uxpsjN0c7II7YPKXua2NAKYvM6iQk7dq( R?R@RIRRRRtfuzz_salts_need_bcrypt_repairR R*RjRR6(((sF/usr/lib/python2.7/site-packages/passlib/tests/test_handlers_django.pyRes   tdjango_bcrypt_sha256_testcBseZdZejZdZeZ de dfe dfe dddfe dddd fe ddd d fgZ d gZd ZdejfdYZRS(stest django_bcrypt_sha256RHsJbcrypt_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(NRgi(RhRiRoRj(RRk((sF/usr/lib/python2.7/site-packages/passlib/tests/test_handlers_django.pyRjTsR6cBseZdZdZRS(cCs|jddddS(Niiii(RX(R((sF/usr/lib/python2.7/site-packages/passlib/tests/test_handlers_django.pyRl[scCsdS(N(R'(R((sF/usr/lib/python2.7/site-packages/passlib/tests/test_handlers_django.pyRm_s(R?R@RlRm(((sF/usr/lib/python2.7/site-packages/passlib/tests/test_handlers_django.pyR6Ys N(RHsJbcrypt_sha256$$2a$06$/3OeRpbOf8/l6nPPRdZPp.nRiyYqPobEZGdNRBWihQhiFDh1ws1tu(R?R@RIRtdjango_bcrypt_sha256RR'tforbidden_charactersRRnt UPASS_LETMEINR RR*tknown_malformed_hashersRjRR6(((sF/usr/lib/python2.7/site-packages/passlib/tests/test_handlers_django.pyRo2s&     (t_base_argon2_testsno argon2 backends availabletdjango_argon2_testcBsceZdZejZd d edfgZdZd dZ dZ de j fd YZ RS( stest django_bcryptRFsDargon2$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.*(RiRxt setUpWarningstwarningstfilterwarnings(R((sF/usr/lib/python2.7/site-packages/passlib/tests/test_handlers_django.pyRzxscKsX|p |jj|}|jdt}|j|_|jsEt|j|jS(Nt use_defaults( RtusingtwrappedRt_stub_checksumtchecksumR+t _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_workflowsR6cBseZdZRS(cCs|jddddS(Niii(RX(R((sF/usr/lib/python2.7/site-packages/passlib/tests/test_handlers_django.pyRls(R?R@Rl(((sF/usr/lib/python2.7/site-packages/passlib/tests/test_handlers_django.pyR6s(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@RIRt django_argon2RRuR*RzR'RRRwR6(((sF/usr/lib/python2.7/site-packages/passlib/tests/test_handlers_django.pyRxfs   (*RIt __future__Rtloggingt getLoggerR?tlogR{tpasslibRR3Rtpasslib.utils.compatRtpasslib.tests.utilsRRRRtpasslib.tests.test_handlersRR tpasslib.tests.test_ext_djangoR R RuRRRERMRSR^RaRctbcryptt has_backendReRot"passlib.tests.test_handlers_argon2Rwtargon2Rx(((sF/usr/lib/python2.7/site-packages/passlib/tests/test_handlers_django.pyts4  "  O)*"#1