5Xc@sdZddlmZddlmZddlZddlmZddlm Z ddl m Z ddl m Z mZmZmZdd l mZdd lmZeeZd d Zd e fdYZde fdYZdS(s@tests for passlib.apache -- (c) Assurance Technologies 2008-2011i(twith_statement(t getLoggerN(tapache(tMissingBackendError(tirange(tTestCasetget_filetset_filetensure_mtime_changed(tu(tto_bytesi cCsBtjj|}tjj||}tj|||fdS(s)backdate file's mtime by specified amountN(tostpathtgetatimetgetmtimetutime(R toffsettatimetmtime((s=/usr/lib/python2.7/site-packages/passlib/tests/test_apache.pytbackdate_file_mtimestHtpasswdFileTestcBseZdZdZdZdZdZdZdZdZ dZ d Z d Z d Z d Zd ZdZdZdZdZdZdZdZdZdZdZdZdZdZRS(stest HtpasswdFile classt HtpasswdFilestuser2:2CHkkwa2AtqGs user3:{SHA}3ipNV1GrBtxPmHFC21fCbVCSXIo= user4:pass4 user1:$apr1$t4tc7jTh$GPIWVUo8sQKJlUdV8V5vu0 s4user3:{SHA}3ipNV1GrBtxPmHFC21fCbVCSXIo= user4:pass4 syuser2:pass2x user3:{SHA}3ipNV1GrBtxPmHFC21fCbVCSXIo= user4:pass4 user1:$apr1$t4tc7jTh$GPIWVUo8sQKJlUdV8V5vu0 user5:pass5 suseræ:2CHkkwa2AtqGs suser:2CHkkwa2AtqGs suser1:pass1 user1:pass2 s user2:2CHkkwa2AtqGs user3:{SHA}3ipNV1GrBtxPmHFC21fCbVCSXIo= user4:pass4 user1:$apr1$t4tc7jTh$GPIWVUo8sQKJlUdV8V5vu0 user5:$2a$12$yktDxraxijBZ360orOyCOePFGhuis/umyPNJoL5EbsLk.s6SWdrRO user6:$5$rounds=110000$cCRp/xUUGVgwR4aP$p0.QKFS5qLNRqw1/47lXYiAcgIjJK.WjCO8nrEKuUK. cCst|j}t||jtj|}|j|j|j|j|j||j|j |d|_|j|j|d|j |j tj|dt }|j|jd|j|j||j |j |j dtj|dt }WdQX|j|jd|j|j||j |j tj||jttj|dS(stest constructor autoloadtxtnewts ``autoload=False`` is deprecatedtautoloadN(tmktempRt sample_01RRt assertEqualt to_stringR t assertTrueRt assertFalsetTruetassertWarningListtFalseR tremovet assertRaisestIOError(tselfR tht((s=/usr/lib/python2.7/site-packages/passlib/tests/test_apache.pyttest_00_constructor_autoloadBs(   cCsn|j}t||jtjj|}|j|j|j|j|jd|j |j dS(N( RRRRRt from_pathRRR tNoneRR(R&R R'((s=/usr/lib/python2.7/site-packages/passlib/tests/test_apache.pyttest_00_from_pathds  cCstjj|j}|j|jd|j|jd|j|jd|j|j|j |j t |jddS(s test delete()tuser1tuser2tuser5suser:N( RRt from_stringRRtdeleteRRRt sample_02R$t ValueError(R&R'((s=/usr/lib/python2.7/site-packages/passlib/tests/test_apache.pyttest_01_deletels cCs|j}d}t||tj|}|jd|jt||tj|dt}|jd|jt|ddS(Nsuser1:pass1 user2:pass2 R,tautosaves user2:pass2 (RRRRR0RRR (R&R tsampleR'((s=/usr/lib/python2.7/site-packages/passlib/tests/test_apache.pyttest_01_delete_autosavews    cCs>tjj|jdd}|j|jdd|j|jdd|j|j|j |j d tjj|jdd}Wd QX|j|jdd|j|jdd|j|j|j |j t |jd d |j d |j dd Wd QX|j|jdd d S(stest set_password()tdefault_schemet plaintextR-tpass2xR.tpass5s``default`` is deprecatedtdefaultNsuser:tpasssupdate\(\) is deprecatedttest(RRR/RRt set_passwordRRRt sample_03R!R$R2tupdatetcheck_password(R&R'((s=/usr/lib/python2.7/site-packages/passlib/tests/test_apache.pyttest_02_set_passwords !cCs|j}d}t||tj|}|jdd|jt||tj|dddt}|jdd|jt|ddS(Ns user1:pass1 R,tpass2R7R8R4s user1:pass2 (RRRRR>RRR (R&R R5R'((s=/usr/lib/python2.7/site-packages/passlib/tests/test_apache.pyttest_02_set_password_autosaves  cCsd}|j|dd|j|dd|jt|d|j|dtjd|j|dtjd|j|dtjd|j|dtjddS( s%test set_password() -- default_schemecSs;tjd|}|jdd|jj|jdS(NR7R,tpass1(RRR>tcontexttidentifytget_hash(tschemeR'((s=/usr/lib/python2.7/site-packages/passlib/tests/test_apache.pytcheckst sha256_cryptt des_crypttxxxtportabletportable_apache_22thost_apache_22N(RR$tKeyErrorRthtpasswd_defaultsR*(R&RJ((s=/usr/lib/python2.7/site-packages/passlib/tests/test_apache.pyt#test_02_set_password_default_schemes cCsqtjj|j}|jdd|jd|jdd|jt|jdddddgdS( s test users()R.R:tuser3tpass3R,R-tuser4N( RRR/RR>R0Rtsortedtusers(R&R'((s=/usr/lib/python2.7/site-packages/passlib/tests/test_apache.pyt test_03_userss  cCsPtjj|j}|jt|jdd|j|jdddkxt ddD]}t |}yH|j|jd|d||j|jd|dt kWq]t k r|dkrq]nq]Xq]W|jt |jdd|jd gd 7|j|jd d |j|jd d WdQXdS(stest check_password()itpass9tuser9ituserR<t5suser:sverify\(\) is deprecatediR,RERCN(RRR/t sample_05R$t TypeErrorRARR*RtstrR"RR2R!tverifyR(R&R'ti((s=/usr/lib/python2.7/site-packages/passlib/tests/test_apache.pyttest_04_check_passwords  !'   cCs_|j}t|dt|dtj|dd}|j|jd|jdd|j|j|jdt||j |j|j|j|j |jdd |j |j|j|j tj}|j t |j |j t |jt||j tj}|j ||j|jddd S( s test load()RiR7R8R,REs user1:pass1 R.R:N(RRRRRRRR>tload_if_changedRtloadR$t RuntimeErrort sample_dupRRA(R&R thathbthc((s=/usr/lib/python2.7/site-packages/passlib/tests/test_apache.pyt test_05_loads*         cCs|j}t||jtj|}|jd|jd|j|jt||j tjdd}|j dd|j t |j|j||jt|ddS(s test save()R,R-R7R8REs user1:pass1 N( RRRRRR0tsaveRRR1R>R$Rf(R&R R'Ri((s=/usr/lib/python2.7/site-packages/passlib/tests/test_apache.pyt test_06_saves     cCs|jttjddtjj|jdddt}|j|jt dg|j d tjj|jdd}WdQX|j|jdgtjj|j dd dt}|j|jt dgdS( stest 'encoding' kwdtencodingsutf-16sutf-8treturn_unicodes user\u00e6s``encoding=None`` is deprecatedNsuseræslatin-1( R$R2RRR/tsample_04_utf8R RRXR R!R*tsample_04_latin1(R&R'((s=/usr/lib/python2.7/site-packages/passlib/tests/test_apache.pyttest_07_encodingss !cCstjj|j}|j|jdd|j|jdd|j|jdd|jd|j|jddWdQXdS(stest get_hash()RTs!{SHA}3ipNV1GrBtxPmHFC21fCbVCSXIo=RVtpass4R.sfind\(\) is deprecatedN( RRR/RRRHR*R!tfind(R&R'((s=/usr/lib/python2.7/site-packages/passlib/tests/test_apache.pyttest_08_get_hash0s cCsTtjj|j}|j|j|jtj}|j|jddS(stest to_stringRN(RRR/RRR(R&R'((s=/usr/lib/python2.7/site-packages/passlib/tests/test_apache.pyttest_09_to_string:s cCs/tjddtdtdd}t|dS(NtfakepathR4RRnslatin-1(RRR trepr(R&R'((s=/usr/lib/python2.7/site-packages/passlib/tests/test_apache.pyt test_10_reprEs!cCs6|jttjjd|jttjjddS(Nsrealm:user1:pass1 spass1 (R$R2RRR/(R&((s=/usr/lib/python2.7/site-packages/passlib/tests/test_apache.pyttest_11_malformedIscCs#|jttjjddddS(NRR (R$R_RRR/R*(R&((s=/usr/lib/python2.7/site-packages/passlib/tests/test_apache.pyttest_12_from_stringOscCs td}tjj|}|jt|jdddddg|jdd|jt|jdddddg|jdd |jt|jddddddg|jd|jt|jdddddgtd }|j|j |d S( swhitespace & comment handlings` user2:pass2 user4:pass4 user7:pass7 user1:pass1 # legacy users #user6:pass6 user5:pass5 R,R-RVR.tuser7talthash4tuser6talthash6sd user2:pass2 user4:althash4 user1:pass1 # legacy users #user6:pass6 user5:pass5 user6:althash6 N( R RRR/RRWRXtset_hashR0R(R&tsourceR'ttarget((s=/usr/lib/python2.7/site-packages/passlib/tests/test_apache.pyttest_13_whitespaceTs ++. + (t__name__t __module__t__doc__tdescriptionPrefixRR1R?RpRqRgR^R(R+R3R6RBRDRSRYRcRkRmRrRuRvRyRzR{R(((s=/usr/lib/python2.7/site-packages/passlib/tests/test_apache.pyRs6 "      %     tHtdigestFileTestcBseZdZdZdZdZdZdZdZdZ dZ d Z d Z d Z d Zd ZdZdZdZdZdZdZRS(stest HtdigestFile classt HtdigestFilesuser2:realm:549d2a5f4659ab39a80dac99e159ab19 user3:realm:a500bb8c02f6a9170ae46af10c898744 user4:realm:ab7b5d5f28ccc7666315f508c7358519 user1:realm:2a6cf53e7d8f8cf39d946dc880b14128 sZuser3:realm:a500bb8c02f6a9170ae46af10c898744 user4:realm:ab7b5d5f28ccc7666315f508c7358519 suser2:realm:5ba6d8328943c23c64b50f8b29566059 user3:realm:a500bb8c02f6a9170ae46af10c898744 user4:realm:ab7b5d5f28ccc7666315f508c7358519 user1:realm:2a6cf53e7d8f8cf39d946dc880b14128 user5:realm:03c55fdc6bf71552356ad401bdb9af19 s0useræ:realmæ:549d2a5f4659ab39a80dac99e159ab19 s.user:realm:549d2a5f4659ab39a80dac99e159ab19 cCs|j}t||jtj|}|j|j|jtj|dt}|j|jdtj ||j t tj|dS(stest constructor autoloadRRN( RRRRRRRR R R#R$R%(R&R R'((s=/usr/lib/python2.7/site-packages/passlib/tests/test_apache.pyR(s  cCstjj|j}|j|jdd|j|jdd|j|jdd|j|jdd|j|j|j |j t |jdd|j t |jdd d S( s test delete()R,trealmR-R.RTtrealm5suser:R\srealm:N( RRR/RRR0RRRR1R$R2(R&R'((s=/usr/lib/python2.7/site-packages/passlib/tests/test_apache.pyR3scCs|j}t||jtj|}|j|jdd|j|jdd|j|jdd|jt ||jt |_ |j|jdd|jt ||j dS(NR,RRTRR.R-( RRRRRRR0RRRR R4R1(R&R R'((s=/usr/lib/python2.7/site-packages/passlib/tests/test_apache.pyR6s  cCsitjj|j}|j|jddd|j|jddd|j|j|j |j t |jddd|_ |jdd|j ddd|j t|jddd |j t|jd d dd |j t|jd d d |j t|jd dd d |jd|jdddWdQX|j|j dddS(s test update()R-RR9R.R:RUtrealm2suser:R<R iR\srealm:trsupdate\(\) is deprecatedR=N(RRR/RRR>RRRR?R$R_t default_realmRAR2R!R@(R&R'((s=/usr/lib/python2.7/site-packages/passlib/tests/test_apache.pyRBs   cCstjj|j}|jddd|jdd|jddd|jt|jddddddg|j t |jd d S( s test users()R.RR:RTRUR,R-RViN( RRR/RR>R0RRWRXR$R_(R&R'((s=/usr/lib/python2.7/site-packages/passlib/tests/test_apache.pyRYs .c Cstjj|j}|jt|jddd|jt|jddd|j|jdddd xjt ddD]Y}t |}|j |jd|dd||j|jd|ddt q|W|jt|jddd|_ |j |jdd |j|jddd |jd gd =|j |jddd |j|jddd Wd QX|jt|jdddd S(stest check_password()iRR:R\R.iR<R,REsverify\(\) is deprecatediRCNsuser:(RRR/RR$R_RAtassertIsR*RR`RR"RR!RaRR2(R&R'Rb((s=/usr/lib/python2.7/site-packages/passlib/tests/test_apache.pyRcs  $' "cCs|j}t|dt|dtj|}|j|jd|jddd|j|j|jdt||j |j|j|j|j |jddd|j |j|j|j tj}|j t |j |j t |jtj}|j ||j|j|j t |t|d|jd |j d tWd QX|j|jdd S( s test load()RiR,RREs-user1:realm:2a6cf53e7d8f8cf39d946dc880b14128 R.R:s!load\(force=False\) is deprecatedtforceN(RRRRRRRR>RdRReR$RfRR!R"(R&R RhRiRj((s=/usr/lib/python2.7/site-packages/passlib/tests/test_apache.pyRks2           cCs|j}t||jtj|}|jdd|jdd|j|jt||j tj}|j ddd|j t |j|j||jt||j dS(s test save()R,RR-REN(RRRRRR0RlRRR1R>R$RfR(R&R R'Ri((s=/usr/lib/python2.7/site-packages/passlib/tests/test_apache.pyRm:s    cCstjj|j}|j|jdd|j|jdg|j|jdd|j|jg|j|jddS(stest realms() & delete_realm()RiRiRN(RRR/RRt delete_realmtrealmsR(R&R'((s=/usr/lib/python2.7/site-packages/passlib/tests/test_apache.pyttest_07_realmsPs cCstjj|j}|j|jddd|j|jddd|j|jddd|jd!|j|jdddWdQXdS( stest get_hash()RTRt a500bb8c02f6a9170ae46af10c898744RVt ab7b5d5f28ccc7666315f508c7358519R.sfind\(\) is deprecatedN( RRR/RRRHR*R!Rt(R&R'((s=/usr/lib/python2.7/site-packages/passlib/tests/test_apache.pyRu[s cCs|jttjddtjj|jdddt}|j|jt dg|j|j t dt dgtjj|j dddt}|j|jt dg|j|j t dt dgdS( stest encoding parameterRnsutf-16sutf-8Ros realm\u00e6s user\u00e6slatin-1N( R$R2RRR/RpR RRR RXRq(R&R'((s=/usr/lib/python2.7/site-packages/passlib/tests/test_apache.pyttest_09_encodingses!(!cCsTtjj|j}|j|j|jtj}|j|jddS(stest to_string()RN(RRR/RRR(R&R'((s=/usr/lib/python2.7/site-packages/passlib/tests/test_apache.pyttest_10_to_stringts cCs6|jttjjd|jttjjddS(Nsrealm:user1:pass1:other s user1:pass1 (R$R2RRR/(R&((s=/usr/lib/python2.7/site-packages/passlib/tests/test_apache.pyRzs(RRRRRR1R?RpRqR(R3R6RBRYRcRkRmRRuRRRz(((s=/usr/lib/python2.7/site-packages/passlib/tests/test_apache.pyRs(      )   (Rt __future__RtloggingRR tpasslibRt passlib.excRtpasslib.utils.compatRtpasslib.tests.utilsRRRRR t passlib.utilsR RtlogRRR(((s=/usr/lib/python2.7/site-packages/passlib/tests/test_apache.pyts "  l