j^Xc@s!dZddlmZddlmZer?ddlmZnddlmZddlZddl m Z ddl Z e j e ZddlZddlZddlmZddlmZmZdd lmZmZdd lmZmZdd lmZmZmZmZm Z m!Z!ddl"j#j$Z%dd l&m'Z'm(Z(m)Z)m*Z*m+Z+m,Z,dd l-m.Z.m/Z0m1Z2m3Z3ej4j5ej4j6e7Z8dZ9de'fdYZ:ddl;Z;ddl<Z<de%j=fdYZ>de%j=fdYZ?de'fdYZ@dS(stests for passlib.contexti(twith_statement(tPY3(tNoSectionErrorN(tpartial(thash(t CryptContexttLazyCryptContext(tPasslibConfigWarningtPasslibHashWarning(ttickt to_unicode(tirangetutunicodet str_to_uasciitPY2tPY26(tTestCasetset_filetTICK_RESOLUTIONt quicksleept time_callthandler_derived_from(tregister_crypt_handler_patht_has_crypt_handlert_unload_handler_nametget_crypt_handlercOsD|j}x|D]}|j|qW|r@|j|n|S(N(tcopytupdate(tfirsttargstkwdsttargettarg((s>/usr/lib/python2.7/site-packages/passlib/tests/test_context.pyt merge_dicts&s   tCryptContextTestcBseZdZddddgZgeD]Zee^q%Zededdddd d d d d dddZe edeZ e dZ e dZ ejjedZe je de dZejjedZe je de djdZejjedZerNeee eeeeeeneddd dd dddZd Ze eeZeddZe eeZedddd!dd"gd#dgdd"d d$d d%d&d'd(d)d*d+d,d)d-d.d/d0 Z d1Z!d2Z"d3Z#d4Z$d5Z%d6Z&d7Z'd8Z(d9Z)d:Z*d;Z+d<Z,d=Z-d>Z.dZd?Z0d@Z1dAZ2dBZ3dCZ4dDZ5dEZ6dZifdZiddF6fdGifd[ifgZ7dHZ8dIZ9dJZ:dKZ;edLZ<dMZ=dNZ>dOZ?dPZ@dQZAdRZBdSZCdTZDdUZEdVZFdWZGdXZHdYZIRS(\Rt des_cryptt md5_cryptt bsdi_cryptt sha512_crypttschemestdefaulttall__vary_roundsg?tbsdi_crypt__max_roundsi1utbsdi_crypt__default_roundsiatsha512_crypt__max_roundsiPtsha512_crypt__min_roundsi@s[passlib] schemes = des_crypt, md5_crypt, bsdi_crypt, sha512_crypt default = md5_crypt ; this is using %... all__vary_rounds = 10%% bsdi_crypt__default_rounds = 25001 bsdi_crypt__max_rounds = 30001 sha512_crypt__max_rounds = 50000 sha512_crypt__min_rounds = 40000 s[passlib] schemes = des_crypt, md5_crypt, bsdi_crypt, sha512_crypt default = md5_crypt all__vary_rounds = 0.1 bsdi_crypt__default_rounds = 25001 bsdi_crypt__max_rounds = 30001 sha512_crypt__max_rounds = 50000 sha512_crypt__min_rounds = 40000 s sample1.cfgs s s sample1b.cfgs [passlib]s [mypolicy]sutf-16s sample1c.cfgtbsdi_crypt__min_roundsiIqiiyiȯs[passlib] bsdi_crypt__min_rounds = 29001 bsdi_crypt__max_rounds = 35001 bsdi_crypt__default_rounds = 31001 sha512_crypt__min_rounds = 45000 tphpasst sha256_cryptt deprecatediitbsdi_crypt__vary_roundsitsha256_crypt__max_roundsi tsha256_crypt__min_roundsitsha256_crypt__default_roundst phpass__identtHtphpass__default_roundsicCs7tt|jtjddtjdddS(Ntignores The 'all' scheme is deprecated.*s4.*'scheme' keyword is deprecated as of Passlib 1.7.*(tsuperR#tsetUptwarningstfilterwarnings(tself((s>/usr/lib/python2.7/site-packages/passlib/tests/test_context.pyR<scCst}|j|jit|j}|j|j|jt|j}|j|j|jt|j}|j|j|jt|j}|j|j|jtdtdg}|j|jddS(stest class constructorR(R1N(s sha256_crypt( Rt assertEqualtto_dictt sample_1_dicttsample_1_resolved_dictt sample_2_dictt sample_3_dictR R((R?tctx((s>/usr/lib/python2.7/site-packages/passlib/tests/test_context.pyttest_01_constructors cCs%tj|j}|j|j|jtj|j}|j|j|jtj|jjd}|j|j|jtj|j}|j|j|jtj|j dddd}|j|j|j|j t tjd|j t tj|jdddS(stest from_string() constructorsutf-8tsectiontmypolicytencodingsutf-16t fakesectionN(Rt from_stringtsample_1_unicodeR@RARBtsample_1_unnormalizedtencodetsample_1b_unicodetsample_1c_bytest assertRaisest TypeErrortNoneR(R?RF((s>/usr/lib/python2.7/site-packages/passlib/tests/test_context.pyttest_02_from_strings cCstjj|js+td|jntj|j}|j|j|j tj|j }|j|j|j tj|j dddd}|j|j|j |j t tjtjjtd|j ttj|jdddS( stest from_path() constructorscan't find data file: %rRHRIRJsutf-16ssample1xxx.cfgRKN(tostpathtexistst sample_1_patht RuntimeErrorRt from_pathR@RARBtsample_1b_pathtsample_1c_pathRRtEnvironmentErrortjointhereR(R?RF((s>/usr/lib/python2.7/site-packages/passlib/tests/test_context.pyttest_03_from_paths cCsVt|j}|j|j}|j|j|j|j|j|j|j|j}|j|j|j|j|j|j|j|j}|j|j|j|j}|j |||j|j|j|j|j|j|j |j|j|j|j|j|j|jdS(stest copy() methodN( RRBRRDR@RAtsample_12_dictREtsample_123_dictt assertIsNotR(R?tcc1tcc2tcc2btcc3tcc4((s>/usr/lib/python2.7/site-packages/passlib/tests/test_context.pyt test_04_copys  cCs)t|j}|jt|ddS(s test repr()s!^$N(RRBt assertRegextrepr(R?Re((s>/usr/lib/python2.7/site-packages/passlib/tests/test_context.pyt test_09_repr+scCs$t}|j|j|j|j|j|j|j|j|j|j|j|jjd|j|j|j|jt|jdt|j}|jidt |j|j|jt}|j|j|j|j |j|j|j dS(s test load() / load_path() methodsutf-8RN( RtloadRBR@RARMRORRRSRTtTrueRD(R?RF((s>/usr/lib/python2.7/site-packages/passlib/tests/test_context.pyt test_10_load4s   cCstddgdddd}|j}|jt|jdt|j|j||jt|jdt|j|j||jt|jd d |j|j|d S( s$test load() errors restore old stateR$R1R6iR*g?ttoo__many__key__partstfake_context_optionR5i'N( Rt to_stringRRRSRRoR@tKeyErrort ValueError(R?tcctresult((s>/usr/lib/python2.7/site-packages/passlib/tests/test_context.pyttest_11_load_rollback_s  cCsUt|j}|j|j|j|jt|j}|j|j|j|j|j|j|j|j|j|jt|j}|j|j|j|j|jt|j}|j|j |j|j|j|j t |jii|j t |jiddg|j t |jddS(stest update() methodR(R$N( RRBRR@RARDRbRERctsample_2_unicodeRRRSRT(R?RF((s>/usr/lib/python2.7/site-packages/passlib/tests/test_context.pyttest_12_updatews" cCsd}|jttdd|jttdd|jttdd|jttdd|jttdd|jttd d |jt|id d 6tid d6dd6}|j|jddtdd }|j|dd ||j|dd ||j|dd ||j|id d6||j|id d6|tdd }|j|dd ||j|id d6|tdd}|j|dd||j|dd||j|idd6||j|idd6|tdd}|j|dd||j|idd6|tdd gd d!}|jt|jd"d!|jttddgd#d$|jttddgd%d$d&S('stest basic option parsingc[st|jS(N(RRA(R((s>/usr/lib/python2.7/site-packages/passlib/tests/test_context.pytparsest__g?tdefault__scheme__txt__optiontdefault____optiont__scheme__optiont!category__scheme__option__invalidi0uR%sadmin.context__schemessmd5_crypt,des_cryptR(R$sadmin.context__defaulttadminR)tcontext__defaulttdefault__context__defaultscontext.defaultsdefault.context.defaulttadmin__context__defaultsadmin.context.defaultR*tdefault__all__vary_roundssall.vary_roundssdefault.all.vary_roundstadmin__all__vary_roundssadmin.all.vary_roundsR0R7tPtmd5_crypt__identtdes_crypt__salttxxt all__saltN(RRRSRRtR@tdefault_schemetdictR(R?R{RFRw((s>/usr/lib/python2.7/site-packages/passlib/tests/test_context.pyttest_20_optionssH    cCsFtdd }|j|jd tdddg}|j|jd tdd}|j|jd tdtjtjg}|j|jd|jttdt j gdt j fdY}|jt td|gdt j fdY}|jt td||g|jt td dgd S(s%test 'schemes' context option parsingR(R$R%s des_crypt, md5_crypt, tnamelesscBseZdZRS(N(t__name__t __module__RTtname(((s>/usr/lib/python2.7/site-packages/passlib/tests/test_context.pyRstdummy_1cBseZdZRS(R(RRR(((s>/usr/lib/python2.7/site-packages/passlib/tests/test_context.pyRstadmin__context__schemesN((s des_crypts md5_crypt(s des_crypts md5_crypt(s des_crypts md5_crypt( RRTR@R(RR$R%RRRStuht StaticHandlerRuRt(R?RvRR((s>/usr/lib/python2.7/site-packages/passlib/tests/test_context.pyttest_21_schemessc Csdd}tddg}|jdddg|j||dgtddgdddg}|j||dg|jttdtjgdddgtddddddg}|j||ddg|jttddgddg|jt tddgddg|jt tdddgdddg|jt tdddgd ddd|jt tdddgd ddd|jt tdddgd ddd|jt tdddgd dddtdddgddd ddg|jttdd tddgdddgddg}|j||dg|j||d dg|j||d dgtddgdddgdg}|j||dg|j||d dg|j||d gdS(s(test 'deprecated' context option parsingcSs2g|jD]!}|j||jr |^q S(N(R(thandlerR2(RFtcategoryR((s>/usr/lib/python2.7/site-packages/passlib/tests/test_context.pytgetdepsR2R%R(R$smd5_crypt,des_cryptR1tadmin__context__deprecatedR)Ri{tuserRN( RTRRR@RRRSRR%RtRu(R?RRv((s>/usr/lib/python2.7/site-packages/passlib/tests/test_context.pyttest_22_deprecated sh                cCs|jtddjtddtdddddg}|j|jdtdtjdddg}|j|jdtdddg}|j|jd|jdd|j|jd|jt tddgdd|jt tddtdddddgdd}|j|jd|j|jdd|j|jd dd S( s%test 'default' context option parsingR)R%R(R$R2iRRRN( R@RRARRRR%RRRRtRS(R?RF((s>/usr/lib/python2.7/site-packages/passlib/tests/test_context.pyttest_23_defaulths&   cCs{d}|j|dd|j|dd|j|dd|j|dd|j|dddS(s&test 'vary_rounds' hash option parsingcSstd|jdS(NR*(RRA(tv((s>/usr/lib/python2.7/site-packages/passlib/tests/test_context.pyR{sg?s0.1s10%it1000N(R@(R?R{((s>/usr/lib/python2.7/site-packages/passlib/tests/test_context.pyttest_24_vary_roundss  cCs |jt||d|dS(Ntmsg(t assertTrueR(R?RtbaseR((s>/usr/lib/python2.7/site-packages/passlib/tests/test_context.pytassertHandlerDerivedFromscCst}|j|jd|j|jdtdt|j}|j|jt|j|j|jdtdtt|jxBt|jdt|jD]"\}}|j t ||qWt|j }|j|jddS(stest schemes() methodtresolvet unconfiguredN(((( RR@R(RoRBttupletsample_1_schemestsample_1_handlerstzipRRRD(R?RFRwtcorrect((s>/usr/lib/python2.7/site-packages/passlib/tests/test_context.pyttest_30_schemess ++cCst}|jt|jt|j}|j|jd|j|jdtdttj|j |jdttjt|j }|jt|jtd|j }|j|jddS(stest default_scheme() methodR%RRR(R$N( RRRRtRRBR@RoRR%RRDR(R?RF((s>/usr/lib/python2.7/site-packages/passlib/tests/test_context.pyttest_31_default_schemes %cCst}|jt|j|jt|jdt|j}|j|jdttj|j |jtj|j|jddttj |j |jdtj |jt|jdtddd}|j|jdttj |j |jtj |j|jdddttj |j |jddtj |j|jdd dttj|j |jddtj t r|j|jdt ddttj |j|jdt d dttjnd S( stest handler() methodR%RR$tmysql323ssha256_crypt,md5_cryptRRtstaffRN(RRRRtRRBR@RoRR%RR$R1RR (R?RF((s>/usr/lib/python2.7/site-packages/passlib/tests/test_context.pyttest_32_handlers& "%%+cCsdd}tdtddddgdddgdd d d d d dddgdddddd }|j|jjd|j||dtdtdd dd |j||ddtdtdd dd |j||ddtdddd|j||dtdtdt|j||ddtdtdt|j||ddtdtdt|j||dtdd |j||ddtdd |j||ddtdddtdS(s*test internal _get_record_options() methodcSs|jj||dS(Ni(t_configt_get_record_options_with_flag(RFtschemeR((s>/usr/lib/python2.7/site-packages/passlib/tests/test_context.pytoptionssttruncate_errorR(R'R$R&R2R*g?R3g?R-i NRRg?tadmin__bsdi_crypt__vary_roundsg333333?tadmin__sha512_crypt__max_roundsi@Rt vary_roundst max_roundsRN(sadmin(RTRRoR@Rt categoriesR(R?RRi((s>/usr/lib/python2.7/site-packages/passlib/tests/test_context.pyttest_33_optionssP            cCsKt|j}|j|j|j|j|jdt|jdS(stest to_dict() methodRN(RRBR@RARoRC(R?RF((s>/usr/lib/python2.7/site-packages/passlib/tests/test_context.pyttest_34_to_dictCscCst|j}|j}ts7|j||jntj|}|j|j|j|jdd}|j||jddddl m }t|dg}|j}|j |dd S( stest to_string() methodRHspassword-securitys [passlib]s[password-security]i(t UnsaltedHashR%sM# NOTE: the 'unsalted_test_hash' handler\(s\) are not registered with PasslibN( RRBRsRR@RMRLRAtreplacet!passlib.tests.test_utils_handlersRRk(R?RFtdumptctx2totherRtctx3((s>/usr/lib/python2.7/site-packages/passlib/tests/test_context.pyttest_35_to_stringJs  RicCstjtjtjg}t|dd}x|D]}|jdd|j}|j|j||j|j|j|dtdt||j |j|dt||j |j d||j |j d|q1W|jd}|j|j|d|j d |j}|j|j|d|j d |jdd}|j|j|d|jt|j d |jdd d S( s-test basic hash/identify/verify functionalityR,ittestRRRtnotestR%tsecretR$N(RR%R$R&RRR@tidentifyRoRRtverifyt assertFalsetgenhasht genconfigRRRu(R?thandlersRvtcryptth((s>/usr/lib/python2.7/site-packages/passlib/tests/test_context.pyt test_40_basicqs  %c Cstdddgdddddd }|j|jjd |j|jd djd |j|jd dd djd|j|jd dd djd |j|jd ddddddd dtrN|jdd}|j|jd tdjd|j|jd tdjd n|jt tj|jt tjd d|jt |jd d|jt |jd dd d|jt |jd d|jt |jd ddS(stest genconfig() methodR(R%R0R7R8R9itadmin__phpass__identRs$1$Rs$H$5RRs$P$5Rtsaltt.itroundstidents"$P$6........22zGEuacuPOqEpYPDeR0R/R)tfakeiNs........( RRRt startswithR@RRR RRRtRS(R?Rvtc2((s>/usr/lib/python2.7/site-packages/passlib/tests/test_context.pyttest_41_genconfigs* "((! (+cCsPtdg}|jd}x3|jD](\}}|jt|j|||q(Wtdg}xE|jD]:\}}|d krqmn|jt|jd||qmWtdg}|jt|jdd |jttjdd|jt|jd|dd|jt|jd|dd|jt|jd|d dd S( stest genhash() methodR$tstubRRRRRiRN( RRtnonstring_vectorsRRRSRRTRtR(R?RvRRRtconfig((s>/usr/lib/python2.7/site-packages/passlib/tests/test_context.pyttest_42_genhashs   cCst|j}|jd}|j|jd|j|jd||j|jd||jt|j ddtdg}x0|j D]%\}}|jt |j||qW|jt tjd|jt |jddd d S( stest hash() methodtpasswords$5$rounds=3000$t passwordxR6iR$RRiN( Rt sample_4_dictRRRRRRRRuRRRSRt(R?RvRRR((s>/usr/lib/python2.7/site-packages/passlib/tests/test_context.pyt test_43_hashscCsIt|j}|jdg*|j|jddddddWd QX|jdg0|j|jdddddd d d Wd QX|jdg*|j|jdd ddddWd QX|jdg*|j|jdd ddddWd QX|jt|jddd|jt|jdddd S(s;test hash() method -- legacy 'scheme' and settings keywordss"passing settings to.*is deprecatedRRR0RRis"$H$5........De04R5Egz0aq8Tf.1eVhY/NRRs"$P$5........De04R5Egz0aq8Tf.1eVhY/Ritnacls?$5$rounds=1999$nacl$nmfwJIxqj0csloAAvSER0B8LU0ERCAbhmMug4Twl609is?$5$rounds=2001$nacl$8PdeoPL4aXQnJ0woHhqgIw/efyfCKC2WHneOpnvF.31RRis........s........(RRtassertWarningListR@RRRRtRS(R?t use_16_legacyRv((s>/usr/lib/python2.7/site-packages/passlib/tests/test_context.pyttest_43_hash_legacys&    cCsdddg}t|dd}|j|jdd |jt|jddttdg}x0|jD]%\}}|jt|j||qoWt}|j |jdd |jt |jddt|jt|jd d d d S( stest identify() border casesR%R$R&R,is$9$232323123$1287319827trequiredRRiN( RR@RRTRRRuRoRRStassertIsRt(R?RRvRR((s>/usr/lib/python2.7/site-packages/passlib/tests/test_context.pyttest_44_identify.s cCs"dddg}t|dd}tjjd}|j|jd||j|jd| |j|jd|dd|j|jd|dd |jt|jd|dd|jt|jd d tdg}|jd }}x3|jD](\}}|jt|j|||q W|j |j|dtdg}xE|jD]:\}}|dkrqgn|jt|jd ||qgW|jt tjd d |jt |jd |dd |jt|jd |dd|jt|jd |dddS(stest verify() scheme kwdR%R$R&R,iRRRRs$6$232323123$1287319827RRRiRN( RRR%RRRRRuRRSRRTRt(R?RRvRtrefhashRR((s>/usr/lib/python2.7/site-packages/passlib/tests/test_context.pyttest_45_verifyHs.    cs2t|j}|j|jd|j|jd|j|jd|j|jd|j|jd|j|jdgdtjffdY}t|g}|jd }}|j|j||j|dfg2|j|j|d d |j|d fg2|j|j|d d |j|d fg2td g}x0|j D]%\}}|j t |j||qW|j t tjd|j t |j|dd|j t |j|dd|j t |j|dddS(stest needs_update() methodt 9XXD4trGYeGJAs"$1$J8HC2RCr$HcmM.7NxB2weSvlw2FgzU0sK$5$rounds=1999$jD81UCoo.zI.UETs$Y7qSTQ6mTiU9qZB4fRr43wRgQq4V.5AAf7F97Pzxey/sK$5$rounds=2000$228SSRje04cnNCaQ$YGV4RYu.5sNiBvorQDlO0WWQjyJVGKBcJXz3OtyQ2u8sK$5$rounds=3000$fS9iazEwTKi7QPW4$VasgBC8FqlOvD7x2HhABaMXCTh9jwHclPA9j5YQdns.sK$5$rounds=3001$QlFHHifXvpFX4PLs$/0ekt7lSs/lOikSerQ0M/1porEHxYq7W/2hdFpxA3fAtdummycs5eZdZdZedfdZdZRS(Rt@csj||f|dkS(Ntnu(tappend(tclsRR(t check_state(s>/usr/lib/python2.7/site-packages/passlib/tests/test_context.pyt needs_updatescSsGddlm}t|tr1|jd}nt||jS(Ni(tmd5sutf-8(thashlibRt isinstanceR RORt hexdigest(R?RR((s>/usr/lib/python2.7/site-packages/passlib/tests/test_context.pyt_calc_checksumsN(RRRt _hash_prefixt classmethodRTRR((R(s>/usr/lib/python2.7/site-packages/passlib/tests/test_context.pyRs RRtbobRR$RRRiRN(RRRRRRRRR@RTRRRRSRt(R?RvRRFRRR((Rs>/usr/lib/python2.7/site-packages/passlib/tests/test_context.pyttest_46_needs_update{s6c Csjt|j}|jdjd}|jdjd}|jd|\}}|j||j|d |jd|\}}|j||j|d |jd|\}}|j||j|j |d|jd|\}}|j||j|d tdg}|jd}}x3|j D](\}} |j t |j||| qHW|j |j|d td ftdg}xE|j D]:\}} |d krqn|j t |jd|| qW|j ttjdd|j t|jd|dd |j t |jd|dd |j t |jd|d d d S( stest verify_and_update()R$RR1t wrongpassRRRRRiRN(RRRRtverify_and_updateRRRTRRRRRRSR@tFalseRt( R?Rvth1th2toktnew_hashRRRR((s>/usr/lib/python2.7/site-packages/passlib/tests/test_context.pyttest_47_verify_and_updates:     "  c Csddlm}m}m}|jd}|jddd}|jddd}t||g}|j|jt|j |j |jdd|j |j d||j|j d|t d f|jdg!|jt|jdddWd QX|jt|j d|dd|jt|j d|ddt||g}|j|jtdg|j |j |jdd|j |j d||j|j d|t d f|j |j |jdddd|j |j d|dd|j|j d|ddt d f|jdg!|jt|jdd dWd QX|jt|j d|d d|jt|j d|d dt||gd d } |j| jtdg|jt| jd|jt| j d||jt| j d||j| jddd||j | j d|dd|j| j d|ddt d f|j| j d|ddtd f|j| j d|ddt |fd S( sLhash(), verify(), and verify_and_update() -- discard unused context keywordsi(R$R%t postgres_md5RRtrootRR$s"passing settings to.*is deprecatedNtbadkwdR2tauto(t passlib.hashR$R%RRRR@t context_kwdstsetRRRRRoRTRRRRSR( R?R$R%Rtdes_hasht pg_root_hasht pg_admin_hashReRfRh((s>/usr/lib/python2.7/site-packages/passlib/tests/test_context.pyttest_48_context_kwdssH"""""(("((cCsGtddgdddddd}d }|jdd }|j|jd|j|jd|j|jd|jtgd #|j dd dd dd }Wd QX|j|j d dd||jg+|j|j ddd dd|Wd QX|j|j ddd dd||j|j ddd dd||jtgd 7|j dt dd dd dt dd }Wd QX|j|j d dd||jg+|j|j ddd dd|Wd QX|j|j ddd dd||j|j ddd dd||j|j d dd|t j j}|j dd d|d>}|j|j d dd||f|j dd dd}|j|j d dd||jt|j dd|j dd|j dd|jt|j ddtddg}|jt|j dddd|jttdd |jttdd |jttd!d |jttdd tjj}|jttdd||jttdd||jttdd!||jttdd|d S("stest rounds limitsR(R1R5iR4i R6i s+...........................................iiNRRs$5$rounds=1000$nacl$Ris$5$rounds=1999$nacl$s$5$rounds=2000$nacl$is$5$rounds=2001$nacl$geAs$5$rounds=999999999$nacl$i s$5$rounds=3001$nacl$s$5$rounds=3000$nacl$i s$5$rounds=2999$nacl$s$5$rounds=2500$nacl$is$5$rounds=%d$nacl$%sR~R*(Rt _get_recordRTR@tmin_desired_roundstmax_desired_roundstdefault_roundsRRRRtintRR1RRRutdatetimetnowRS(R?RvtSTUBtcustom_handlerRtdftbad((s>/usr/lib/python2.7/site-packages/passlib/tests/test_context.pyttest_50_rounds_limitsQsj  &   &    & c Cstddgdddddd}|jt|jd d |jt|jd d |jt|jd d |jd d }|j|jddjd |j|ddd|jd d}|j|jddjd |j|ddd|jd d}|j|jddjd|j|ddd|jd d}|j|jddjd|j|ddd|jd d}|j|jddjd|j|ddd|jd d}|j|jddjd|j|ddddS(stest linear vary roundsR(R1R5iR4iR6iR*is-1%s101%is0%iiiids0.1%gMbP?iis100%g?N( RRRRuRR@RRTRtassert_rounds_range(R?RvR((s>/usr/lib/python2.7/site-packages/passlib/tests/test_context.pyttest_51_linear_vary_roundss2 c Cstddgdddddd}|jt|jd d |jt|jd d |jt|jd d |jd d }|j|jddjd |j|ddd|jd d}|j|jddjd |j|ddd|jd d}|j|jddjd|j|ddd|jd d}|j|jddjd|j|ddd|jd d}|j|jddjd|j|ddd|jd d}|j|jddjd|j|ddd|jd d}|j|jddjd|j|ddd|jd d}|j|jddjd|j|ddddS(stest log2 vary roundsR(tbcrypttbcrypt__min_roundsitbcrypt__max_roundsitbcrypt__default_roundsiR*is-1%s101%is0%iiiids1%g{Gz?s49%g\(\?s50%g?s100%g?N( RRRRuRR@RRTRR(R?RvR((s>/usr/lib/python2.7/site-packages/passlib/tests/test_context.pyttest_52_log2_vary_roundss> c Cs|j|}|jdd!|j}t}xHtdD]:}|j|d|} |j| j} |j| q<W|j t ||d|j t ||ddS(s2helper to check vary_rounds covers specified rangeiii,Rs"vary_rounds had wrong lower limit:s"vary_rounds had wrong upper limit:N( Rtdefault_salt_charst max_salt_sizeR R RRLRtaddR@tmintmax( R?tcontextRtlowertupperRRtseentiRtr((s>/usr/lib/python2.7/site-packages/passlib/tests/test_context.pyRs cCstjdddttddg}|j|jd |j|jddjd |j|jddjd |j|jdd jd d S( sharden_verify -- parsingR:s.*harden_verify.*RR(R1t harden_verifytttruetfalseN(R=R>tDeprecationWarningRR@R0RTtusing(R?RF((s>/usr/lib/python2.7/site-packages/passlib/tests/test_context.pyttest_harden_verify_parsing-scCspd}d}tj}||_td|g}|jt|j\}}|j||d||dS(s' dummy_verify() method g?g?R(tdeltaN(t DelayHashR5tdelayRt dummy_verifyRtassertAlmostEqual(R?texpectedtaccuracyRRFtelapsedt_((s>/usr/lib/python2.7/site-packages/passlib/tests/test_context.pyttest_dummy_verify9s   cCsdd}tddd}|j||dtttg|j||dtttg|jdd|j||dtttg|j||dtttg|jdd |j||dtttg|j||dtttgtd gdd}|j||dtg|j||dtg|jttd dd |jttd dd dS(s+test deprecated='auto' is handled correctlycSs,g|jD]}|j||j^q S(N(R(RR2(RFRR((s>/usr/lib/python2.7/site-packages/passlib/tests/test_context.pytgetstatePss sha256_crypt,md5_crypt,des_cryptR2R RR)R%RR$R1ssha256_crypt,md5_cryptsauto,md5_cryptsmd5_crypt,autoN(RTRR@RRoRRRRu(R?RARF((s>/usr/lib/python2.7/site-packages/passlib/tests/test_context.pyttest_61_autodeprecateMs" """"""c Cs ddlm}m}tdg}tddg}|jd}|jd}|jtd|j|jtd|j||jtd|j||j}|j||j |j|}|j||j ||j|} |j| |j ||j|j|||j |j |d} |jt | |j ||jt | |j ||jt | |j ||j |j ||jt | |j ||j |j ||j |j ||jt | |jd|jt|jd |j|j|||jt | |j||jt | |j||jt | |j||jt | |jd|jt|jd |j|j|||jt | |j||jt d |j||j|j||d S( sdisabled hash supporti(R%t unix_disabledR$RCtfoosno disabled hasher presentshash could not be identifiedR1scannot restore original hashN(R R%RCRRtassertRaisesRegexRZtdisableR@tdefault_markerRt is_enabledRuRtenableRRRSRT( R?R%RCRFRth_refth_otherth_dist h_dis_reft h_dis_othertHASH_NOT_IDENTIFIED((s>/usr/lib/python2.7/site-packages/passlib/tests/test_context.pyttest_disabled_hashesmsd                             N((JRRtdescriptionPrefixRRRRRRBR"RCR RNRMRVRWR_R`RYRRPR\RORQR]RRRDRyRbRERcRR<RGRURaRjRmRpRxRzRRRRRRTRRRRRRRRRRRRRRRRRRRRR$RR6R@RBRP(((s>/usr/lib/python2.7/site-packages/passlib/tests/test_context.pyR#1s                    +  % L $ \ %     $ O  !    1 $  1  3 G : U v & /   R8cBs>eZdZdZejZdZdZe dZ dZ RS(s-dummy hasher which delays by specified amountt delay_hashi(is$x$cCsNtj|jt|tr1|jd}nttjd|j S(Nsutf-8tprefix( ttimetsleepR9RR RORRtsha1R(R?R((s>/usr/lib/python2.7/site-packages/passlib/tests/test_context.pyRs( RRt__doc__RRtLOWER_HEX_CHARStchecksum_charst checksum_sizeR9R RR(((s>/usr/lib/python2.7/site-packages/passlib/tests/test_context.pyR8s  tdummy_2cBseZdZRS(R[(RRR(((s>/usr/lib/python2.7/site-packages/passlib/tests/test_context.pyR[stLazyCryptContextTestcBs)eZdZdZdZdZRS(RcCstd|jtddS(NR[(tunload_handler_namet addCleanup(R?((s>/usr/lib/python2.7/site-packages/passlib/tests/test_context.pyR<s cCs|jtdtddttddgddg}|jtdt|j|jd|j|j dj |jtdtdS(stest plain kwdsR[spasslib.tests.test_contextR$R2N(sdummy_2s des_crypt( Rthas_crypt_handlerRRtiterRoR@R(RRR2(R?Rv((s>/usr/lib/python2.7/site-packages/passlib/tests/test_context.pyttest_kwd_constructors !csjtdtddtfd}td|dt}jtdtj|jdj|j dj jtdtdS(NR[spasslib.tests.test_contextcs/j|tdtddgddgS(NR(R[R$R2(RRR`(tflag(R?(s>/usr/lib/python2.7/site-packages/passlib/tests/test_context.pytonloads RcRbR$(sdummy_2s des_crypt( RR_RRRRoR@R(RRR2(R?RcRv((R?s>/usr/lib/python2.7/site-packages/passlib/tests/test_context.pyttest_callable_constructors (RRRQR<RaRd(((s>/usr/lib/python2.7/site-packages/passlib/tests/test_context.pyR\s  (ARWt __future__Rtpasslib.utils.compatRt configparserRt ConfigParserRt functoolsRtloggingt getLoggerRtlogRVR=tpasslibRtpasslib.contextRRt passlib.excRRt passlib.utilsR R R R R RRRtpasslib.utils.handlerstutilsRRtpasslib.tests.utilsRRRRRRtpasslib.registryRRR_RR]RRWtabspathtdirnamet__file__R`R"R#RRTRR8R[R\(((s>/usr/lib/python2.7/site-packages/passlib/tests/test_context.pyts@    .."