
    g2#                    <   S r SSKJr  SSKJr  \(       a  SSKJr  OSSKJr  SSKrSSK	J
r
  SSKr\R                  " \5      rSSKrSSKrSSKJr  SSKJrJr  SS	KJrJr  SS
KJrJr  SSKJrJrJrJrJ r J!r!  SSK"J#s  J$r%  SSK&J'r'J(r(J)r)J*r*J+r+J,r,  SSK-J.r.J/r0J1r2J3r3  \Rh                  Rk                  \Rh                  Rm                  \75      5      r8S r9 " S S\'5      r:SSK;r;SSK<r< " S S\%Rz                  5      r> " S S\%Rz                  5      r? " S S\'5      r@g)ztests for passlib.context    )with_statement)PY3)NoSectionErrorN)partial)hash)CryptContextLazyCryptContext)PasslibConfigWarningPasslibHashWarning)tick
to_unicode)irangeuunicodestr_to_uasciiPY2PY26)TestCaseset_fileTICK_RESOLUTION
quicksleep	time_callhandler_derived_from)register_crypt_handler_path_has_crypt_handler_unload_handler_nameget_crypt_handlerc                     U R                  5       nU H  nUR                  U5        M     U(       a  UR                  U5        U$ N)copyupdate)firstargskwdstargetargs        S/home/matz/Project1/venv/lib/python3.13/site-packages/passlib/tests/test_context.pymerge_dictsr(   &   s7    ZZ\Fc dM    c                     ^ \ rS rSrSr/ SQr\ V VVs/ s H  n[        U5      PM     snnn r\" \SSSSSS	S
9r	\
" \	\S9r\" S5      r\" S5      r\R                   R#                  \S5      r\R)                  \" S5      \" S5      5      r\R                   R#                  \S5      r\R)                  \" S5      \" S5      5      R/                  S5      r\R                   R#                  \S5      r \" SSSSS9rSr\
" \	\5      r\" SS9r\
" \\5      r\" / SQS/S S!S"S#S$S%S$S&S'S(9r U4S) jr!S* r"S+ r#S, r$S- r%S. r&S/ r'S0 r(S1 r)S2 r*S3 r+S4 r,S5 r-S6 r.STS8 jr/S9 r0S: r1S; r2S< r3S= r4S> r5S70 4S7S?S04S@0 4SA0 4/r6SB r7SC r8SD r9SE r:SUSF jr;SG r<SH r=SI r>SJ r?SK r@SL rASM rBSN rCSO rDSP rESQ rFSR rGSS rHSArIU=rJ$ s  snnn f )VCryptContextTest1   r   )	des_crypt	md5_crypt
bsdi_cryptsha512_cryptr.   皙?i1u  ia  iP  @  )schemesdefaultall__vary_roundsbsdi_crypt__max_roundsbsdi_crypt__default_roundssha512_crypt__max_roundssha512_crypt__min_roundsr3   a  [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
z[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

zsample1.cfg
z
zsample1b.cfg	[passlib]z
[mypolicy]utf-16zsample1c.cfgiIq  i  iy  iȯ  )bsdi_crypt__min_roundsr6   r7   r9   z[passlib]
bsdi_crypt__min_rounds = 29001
bsdi_crypt__max_rounds = 35001
bsdi_crypt__default_rounds = 31001
sha512_crypt__min_rounds = 45000
r0   r4   )r-   r.   phpassr/   sha256_cryptr-   rA         r       H   )r3   
deprecatedr4   r6   r7   bsdi_crypt__vary_roundssha256_crypt__max_roundssha256_crypt__min_roundssha256_crypt__default_roundsphpass__identphpass__default_roundsc                    > [         [        U ]  5         [        R                  " SS5        [        R                  " SS5        g )Nignorez The 'all' scheme is deprecated.*z4.*'scheme' keyword is deprecated as of Passlib 1.7.*)superr+   setUpwarningsfilterwarnings)self	__class__s    r'   rR   CryptContextTest.setUp   s3    +-*LM*`ar)   c                    [        5       nU R                  UR                  5       0 5        [        S0 U R                  D6nU R                  UR                  5       U R                  5        [        S0 U R                  D6nU R                  UR                  5       U R                  5        [        S0 U R
                  D6nU R                  UR                  5       U R
                  5        [        S0 U R                  D6nU R                  UR                  5       U R                  5        [        [        S5      /S9nU R                  UR                  5       S5        g)ztest class constructorrA   r:   )rA   N )	r   assertEqualto_dictsample_1_dictsample_1_resolved_dictsample_2_dictsample_3_dictr   r3   rU   ctxs     r'   test_01_constructor$CryptContextTest.test_01_constructor   s    n+ 0T//0(:(:; 9T889(:(:; 0T//0(:(:; 0T//0(:(:; An$5#67(9:r)   c                    [         R                  " U R                  5      nU R                  UR	                  5       U R
                  5        [         R                  " U R                  5      nU R                  UR	                  5       U R
                  5        [         R                  " U R                  R                  S5      5      nU R                  UR	                  5       U R
                  5        [         R                  " U R                  5      nU R                  UR	                  5       U R
                  5        [         R                  " U R                  SSS9nU R                  UR	                  5       U R
                  5        U R                  [        [         R                  S5        U R                  [        [         R                  U R                  SS9  g)ztest from_string() constructorutf-8mypolicyr=   sectionencodingNfakesectionrh   )r   from_stringsample_1_unicoderZ   r[   r\   sample_1_unnormalizedencodesample_1b_unicodesample_1c_bytesassertRaises	TypeErrorr   r`   s     r'   test_02_from_string$CryptContextTest.test_02_from_string   s]    &&t'<'<=(:(:; &&t'A'AB(:(:; &&t'<'<'C'CG'LM(:(:; &&t'='=>(:(:; &&t';';Z.68(:(:; 	)\%=%=tD 	.,*B*B// 	 	Hr)   c                 6   [         R                  R                  U R                  5      (       d  [	        SU R                  -  5      e[
        R                  " U R                  5      nU R                  UR                  5       U R                  5        [
        R                  " U R                  5      nU R                  UR                  5       U R                  5        [
        R                  " U R                  SSS9nU R                  UR                  5       U R                  5        U R                  [        [
        R                  [         R                  R                  [        S5      5        U R                  [         [
        R                  U R                  SS9  g)	ztest from_path() constructorzcan't find data file: %rrf   r=   rg   zsample1xxx.cfgrj   rk   N)ospathexistssample_1_pathRuntimeErrorr   	from_pathrZ   r[   r\   sample_1b_pathsample_1c_pathrr   EnvironmentErrorjoinherer   r`   s     r'   test_03_from_path"CryptContextTest.test_03_from_path   s1    ww~~d00119D<N<NNOO $$T%7%78(:(:; $$T%8%89(:(:; $$T%8%8*.68(:(:; 	*L,B,B'',,t-=>	@ 	.,*@*@,,m 	 	Er)   c                 D   [        S0 U R                  D6nUR                  " S0 U R                  D6nU R	                  UR                  5       U R                  5        U R	                  UR                  5       U R                  5        UR                  " S0 U R                  D6nU R	                  UR                  5       U R                  5        U R	                  UR                  5       U R                  5        UR                  " S0 U R                  D6nU R	                  UR                  5       U R                  5        UR                  5       nU R                  XQ5        U R	                  UR                  5       U R                  5        U R	                  UR                  5       U R                  5        UR                  " S0 U R                  D6  U R	                  UR                  5       U R                  5        U R	                  UR                  5       U R                  5        g)ztest copy() methodNrY   )r   r\   r    r^   rZ   r[   sample_12_dictr_   sample_123_dictassertIsNotr!   )rU   cc1cc2cc2bcc3cc4s         r'   test_04_copyCryptContextTest.test_04_copy  s   0T//0 hh,++,(:(:;(;(;< xx-$,,-(:(:;)<)<= hh,++,(<(<= hhj"(:(:;(:(:; 	

(T''((:(:;(;(;<r)   c                 d    [        S0 U R                  D6nU R                  [        U5      S5        g)ztest repr()z!^<CryptContext at 0x-?[0-9a-f]+>$NrY   )r   r\   assertRegexrepr)rU   r   s     r'   test_09_reprCryptContextTest.test_09_repr+  s*    0T//0c$GHr)   c                    [        5       nUR                  U R                  5        U R                  UR	                  5       U R                  5        UR                  U R
                  5        U R                  UR	                  5       U R                  5        UR                  U R
                  R                  S5      5        U R                  UR	                  5       U R                  5        U R                  [        UR                  S5        [        S0 U R                  D6nUR                  0 SS9  U R                  UR	                  5       U R                  5        [        5       nUR                  U R                  5        UR                  U R                  5        U R                  UR	                  5       U R                  5        g)z test load() / load_path() methodre   NT)r!   rY   )
r   loadr\   rZ   r[   rm   ro   rr   rs   r^   r`   s     r'   test_10_loadCryptContextTest.test_10_load4  sH    n 	##$(:(:; 	&&'(:(:; 	&&--g67(:(:; 	)SXXt4 0T//0D!(:(:; n##$##$(:(:;r)   c                    [        SS/SSS9nUR                  5       nU R                  [        UR                  SS9  U R                  UR                  5       U5        U R                  [        UR                  SS9  U R                  UR                  5       U5        U R                  [        UR                  S	S
9  U R                  UR                  5       U5        g)z$test load() errors restore old stater-   rA   i  r1   )rL   r5   T)too__many__key__parts)fake_context_optioni'  rK   N)r   	to_stringrr   rs   r!   rZ   KeyError
ValueError)rU   ccresults      r'   test_11_load_rollback&CryptContextTest.test_11_load_rollback_  s     ;7)-   	)RYYdK0
 	(BII4H0 	*bii%P0r)   c                    [        S0 U R                  D6nUR                  5         U R                  UR	                  5       U R                  5        [        S0 U R                  D6nUR                  " S0 U R
                  D6  U R                  UR	                  5       U R                  5        UR                  " S0 U R                  D6  U R                  UR	                  5       U R                  5        [        S0 U R                  D6nUR                  U R
                  5        U R                  UR	                  5       U R                  5        [        S0 U R                  D6nUR                  U R                  5        U R                  UR	                  5       U R                  5        U R                  [        UR                  0 0 5        U R                  [        UR                  0 S/S9  U R                  [        UR                  S5        g)ztest update() methodr-   r:   NrY   )r   r\   r!   rZ   r[   r^   r   r_   r   sample_2_unicoderr   rs   r`   s     r'   test_12_updateCryptContextTest.test_12_updatew  s    0T//0

(:(:; 0T//0

(T''((;(;< 	

(T''((<(<= 0T//0

4%%&(;(;< 0T//0

4(()(;(;< 	)SZZR8)SZZk]K 	)SZZ6r)   c                 >   S nU R                  [        [        SS9  U R                  [        [        SS9  U R                  [        [        SS9  U R                  [        [        SS9  U R                  [        [        SS9  U R                  [        [        S	S
9  U R                   " [        U40 SS0D6  [        S&0 SSS.D6nU R	                  UR                  S5      S5        [        SS9nU R	                  U" SS9U5        U R	                  U" SS9U5        U R	                  U" SS9U5        U R	                  U" S&0 SS0D6U5        U R	                  U" S&0 SS0D6U5        [        SS9nU R	                  U" SS9U5        U R	                  U" S&0 SS0D6U5        [        SS9nU R	                  U" SS9U5        U R	                  U" SS9U5        U R	                  U" S&0 SS0D6U5        U R	                  U" S&0 SS0D6U5        [        SS9nU R	                  U" SS9U5        U R	                  U" S&0 SS0D6U5        [        SS/SS 9nU R                  [        UR                  SS!9  U R                  [        [        S/S"S#9  U R                  [        [        S/S"S$9  g%)'ztest basic option parsingc                  4    [        S0 U D6R                  5       $ )NrY   r   r[   )r$   s    r'   parse/CryptContextTest.test_20_options.<locals>.parse  s    '$'//11r)   r1   )__x)default__scheme__)__option)default____option)__scheme__optioni0u  )!category__scheme__option__invalidzadmin.context__schemesr.   md5_crypt,des_cryptr-   )r3   zadmin.context__defaultadminr?   )context__default)default__context__defaultzcontext.defaultzdefault.context.defaultadmin__context__defaultzadmin.context.defaultr5   )default__all__vary_roundszall.vary_roundszdefault.all.vary_rounds)admin__all__vary_roundszadmin.all.vary_roundsr@   P)rM   )md5_crypt__identxx)r3   des_crypt__salt)r3   	all__saltNrY   )rr   rs   r   r   rZ   default_schemedictr    )rU   r   ra   r   s       r'   test_20_options CryptContextTest.test_20_options  s   	2 	)\c:)\SI 	)\C@)\SI 	)\CH 	)\>C 	 	E
 	(E 	D5kB	D E(=7BD E++G4kB k*{3V<<fEEvNA"3K!@A6JI";K!HI6R k:{CVLG"9+!FGP s+4f==vF9"3C!896BA";C!@A6J c2s;VD?"9#!>?H Hk2#F(CHHsC 	(L;-BF 	 	H(L;-<@ 	 	Br)   c                    [        SS9nU R                  UR                  5       S5        [        SS/S9nU R                  UR                  5       S5        [        SS9nU R                  UR                  5       S5        [        [        R                  [        R
                  /S9nU R                  UR                  5       S5        U R                  [        [         [        R                  /S9   " S S	[        R                  5      nU R                  [        [         U/S9   " S
 S[        R                  5      nU R                  [        [         X3/S9  U R                  [        [         S/S9  g)z%test 'schemes' context option parsingNr:   rY   r-   r.   )r-   r.   z des_crypt, md5_crypt, c                       \ rS rSrSrSrg)2CryptContextTest.test_21_schemes.<locals>.namelessi  NrY   __name__
__module____qualname____firstlineno__name__static_attributes__rY   r)   r'   namelessr     s    Dr)   r   c                       \ rS rSrSrSrg)1CryptContextTest.test_21_schemes.<locals>.dummy_1i  dummy_1rY   Nr   rY   r)   r'   r   r     s    Dr)   r   )admin__context__schemes)r   rZ   r3   r   r-   r.   rr   rs   uhStaticHandlerr   r   )rU   r   r   r   s       r'   test_21_schemes CryptContextTest.test_21_schemes  s2    $'r* ;"<='AB ";<'AB 4>>4>>"BC'AB 	)\B<L<L;MN	r'' 	*lXJG	b&& 	(L7:LM 	(L3>- 	 	Ar)   c                    SS jn[        S/S9nUR                  SS/S9  U R                  U" U5      S/5        [        S/SS/S9nU R                  U" U5      S/5        U R                  [        [         [
        R                  /SS/S9  [        S/ S	QS9nU R                  U" U5      SS/5        U R                  [        [         S/S/S
9  U R                  [        [         S/S/S
9  U R                  [        [         SS/SS/S9  U R                  [        [         SS/SSS9  U R                  [        [         SS/SSS9  U R                  [        [         SS/SSS9  U R                  [        [         SS/SSS9  [        SS/SS/ S9  U R                  [        [         SS9  [        S/SS/S/S9nU R                  U" U5      S/5        U R                  U" US5      S/5        U R                  U" US5      S/5        [        S/SS// S9nU R                  U" U5      S/5        U R                  U" US5      S/5        U R                  U" US5      / 5        g)z(test 'deprecated' context option parsingNc                     U R                  5        Vs/ s H'  nU R                  X!5      R                  (       d  M%  UPM)     sn$ s  snf r   r3   handlerrH   )ra   categoryr   s      r'   getdep3CryptContextTest.test_22_deprecated.<locals>.getdep  s=    %([[] ?]T{{42== ] ? ? ?s
   $AAr.   rH   r-   r:   )rH   r3   r   )r.   r-   rA   r3   rH   )r3   admin__context__deprecated)r3   r4   rH   )r3   r4   r   )r3   r   rH   )r3   r   r   )r3   rH   r   r   {   )rH   r3   r   userr   r   )	r   r!   rZ   rr   rs   r   r.   r   r   )rU   r   r   s      r'   test_22_deprecated#CryptContextTest.test_22_deprecated  s   	?
 k]3
		;4	5[M2 k][+<VWk]3 	)\t~~>N#."< 	 	> %:Dnok;%?@ 	(L;->I] 	 	L 	*l#.-&1] 	 	4 	*l#."<6A;5O 	 	Q 	*l#."<"-%0 	 	2 	*l#."<"-5@ 	 	B 	*l#."<2=%0 	 	2 	*l#."<2=5@ 	 	B 	#."<%02=57		9 	)\cB k]#."<6A] 	k]3F+k];G,{m< k]#."<57 	k]3F+k];G,b1r)   c                 &   U R                  [        SS9R                  5       [        SS95        [        SSS/S9nU R                  UR	                  5       S5        [        [
        R                  SS/S9nU R                  UR	                  5       S5        [        SS/S9nU R                  UR	                  5       S5        UR                  SS9  U R                  UR	                  5       S5        U R                  [        [        S/SS9  U R                  [        [        SS9  [        SSS/SS	9nU R                  UR	                  5       S5        U R                  UR	                  S
5      S5        U R                  UR	                  S5      S5        g)z%test 'default' context option parsingr.   r?   r-   )r4   r3   r:   r   )r3   r4      )r4   r3   r   r   r   N)rZ   r   r[   r   r   r   r.   r!   rr   r   rs   r`   s     r'   test_23_default CryptContextTest.test_23_defaulth  sz    	k:BBDk2	4 ;k8RS++-{; 4>>K;UV++-{; K#=>++-{;

k
*++-{; 	(L;-:E 	 	G 	)\1= ;$/#=3>@ 	++-{;++F3[A++G4kBr)   c                     S nU R                  U" S5      S5        U R                  U" S5      S5        U R                  U" S5      S5        U R                  U" S5      S5        U R                  U" S5      S5        g)z&test 'vary_rounds' hash option parsingc                 6    [        U S9R                  5       S   $ )Nr   r5   r   )vs    r'   r   3CryptContextTest.test_24_vary_rounds.<locals>.parse  s    3;;=>PQQr)   r1   z0.1z10%i  1000N)rZ   )rU   r   s     r'   test_24_vary_rounds$CryptContextTest.test_24_vary_rounds  sr    	R 	sS)us+ 	us+ 	td+v-r)   Nc                 6    U R                  [        X5      US9  g )N)msg)
assertTruer   )rU   r   baser   s       r'   assertHandlerDerivedFrom)CryptContextTest.assertHandlerDerivedFrom  s    ,W;Er)   c                    [        5       nU R                  UR                  5       S5        U R                  UR                  SS9S5        [        S0 U R                  D6nU R                  UR                  5       [	        U R
                  5      5        U R                  UR                  SSS9[	        U R                  5      5        [        UR                  SS9U R                  5       H  u  p#U R                  [        X#5      5        M!     [        S0 U R                  D6nU R                  UR                  5       S5        g)ztest schemes() methodrY   Tresolver   unconfiguredN)r   rZ   r3   r\   tuplesample_1_schemessample_1_handlerszipr   r   r^   )rU   ra   r   corrects       r'   test_30_schemes CryptContextTest.test_30_schemes  s    
 n+T2B7 0T//0d.C.C(DETEuTMcMcGde"3;;t;#<d>T>TUOFOO0AB  V 0T//0+r)   c                 H   [        5       nU R                  [        UR                  5        [        S0 U R                  D6nU R                  UR                  5       S5        U R                  UR                  SSS9[        R                  5        U R                  UR                  SS9[        R                  5        [        S0 U R                  D6nU R                  [        UR                  5        [        U R                  S9nU R                  UR                  5       S5        g)	ztest default_scheme() methodr.   Tr   r   r:   r-   NrY   )r   rr   r   r   r\   rZ   r   r.   r   r^   r   r`   s     r'   test_31_default_scheme'CryptContextTest.test_31_default_scheme  s    
 n(C$6$67 0T//0++-{;++Dt+Ldnn]%%c&8&8&8&FW 0T//0(C$6$67 4#8#89++-{;r)   c                    [        5       nU R                  [        UR                  5        U R                  [        UR                  S5        [        S0 U R                  D6nU R                  UR                  SS9[        R                  5        U R                  UR                  5       [        R                  5        U R                  UR                  SSS9[        R                  5        U R                  UR                  S5      [        R                  5        U R                  [        UR                  S5        [        SSS9nU R                  UR                  SS9[        R                  5        U R                  UR                  5       [        R                  5        U R                  UR                  SSS	9[        R                  5        U R                  UR                  SS
9[        R                  5        U R                  UR                  SSS	9[        R                  5        U R                  UR                  SS
9[        R                  5        [        (       ao  U R                  UR                  [        S5      SS	9[        R                  5        U R                  UR                  [        S5      SS	9[        R                  5        gg)ztest handler() methodr.   T)r   r-   mysql323sha256_crypt,md5_cryptr   staff)r   r   r   r   NrY   )r   rr   r   r   r\   rZ   r   r.   r   r-   rA   r   r   r`   s     r'   test_32_handler CryptContextTest.test_32_handler  s	    n(CKK0(CKK= 0T//0$7H%%ckkmT^^D 	[tDdnnU%%ckk+&>O 	(CKK< 3[Y$79J9JK%%ckkmT5F5FGgDI4K\K\]%%ckk7k&CTEVEVWgDI4>>Z%%ckk7k&CTEVEVW 3S[[!G*4[PRVRcRcdS[[!G*4[PRVR`R`a r)   c                    SS jn[        S/ SQSS/SSS	SS
/SSSS9
nU R                  UR                  R                  S5        U R                  U" US5      [	        SSS	S95        U R                  U" USS5      [	        SSS	S95        U R                  U" USS5      [	        SSS95        U R                  U" US5      [	        SSS95        U R                  U" USS5      [	        SSS95        U R                  U" USS5      [	        SSS95        U R                  U" US
5      [	        SS95        U R                  U" US
S5      [	        SS95        U R                  U" US
S5      [	        SSS95        g)z*test internal _get_record_options() methodNc                 >    U R                   R                  X5      S   $ )Nr   )_config_get_record_options_with_flag)ra   schemer   s      r'   options1CryptContextTest.test_33_options.<locals>.options  s    ;;<<VNqQQr)   T)r0   r-   r/   r0   r-   r1   皙?i N  r/   皙?g333333?r2   )
truncate_errorr3   rH   r5   rI   r8   r   r   admin__bsdi_crypt__vary_roundsadmin__sha512_crypt__max_rounds)r   )rH   vary_rounds
max_roundsr   r   )r  r  )rH   r  )r  )r  rH   r   )r   rZ   r  
categoriesr   )rU   r  r   s      r'   test_33_options CryptContextTest.test_33_options  s   	R
 B(+6"$'',+6)F&*+..3
 	//< 	n5t8
 	 	nf=t@
 	 	ng>A
 	 	k2D5
 	
 	k6:D=
 	
 	k7;T>
 	 	l3T6
 	 	lF;T>
 	 	lG<d?
 	r)   c                     [        S0 U R                  D6nU R                  UR                  5       U R                  5        U R                  UR                  SS9U R                  5        g)ztest to_dict() methodTr   NrY   )r   r\   rZ   r[   r]   r`   s     r'   test_34_to_dict CryptContextTest.test_34_to_dictC  sT     0T//0(:(:;T2D4O4OPr)   c                    [        S
0 U R                  D6nUR                  5       n[        (       d  U R	                  X R
                  5        [         R                  " U5      nU R	                  UR                  5       U R                  5        UR                  SS9nU R	                  XBR                  SS5      5        SSK	J
n  [        US/5      nUR                  5       nU R                  US5        g	)ztest to_string() methodzpassword-securityrk   r<   z[password-security]r   )UnsaltedHashr.   zM# NOTE: the 'unsalted_test_hash' handler\(s\) are not registered with PasslibNrY   )r   r\   r   r   rZ   rm   rl   r[   replace!passlib.tests.test_utils_handlersr"  r   )rU   ra   dumpctx2otherr"  ctx3s          r'   test_35_to_string"CryptContextTest.test_35_to_stringJ  s     0T//0}} tT#8#89 ''-););< &9:[9N OP 	C\;78~~  C 	Dr)   r  r   rY   c           	         [         R                  [         R                  [         R                  /n[	        USS9nU H  nUR                  SUR
                  S9nU R                  UR                  U5      UR
                  5        U R                  UR                  USSS9U5        U R                  UR                  USS9U5        U R                  UR                  SU5      5        U R                  UR                  SU5      5        M     UR                  S5      nU R                  UR                  U5      S	5        UR                  S
UR                  5       5      nU R                  UR                  U5      S	5        UR                  S
UR                  5       S	S9nU R                  UR                  U5      S	5        U R                  [        UR                  S
UR                  5       SS9  g)z-test basic hash/identify/verify functionality   r7   testr  Tr   r   notestr.   secretr-   N)r   r.   r-   r/   r   r   rZ   identifyr   r   verifyassertFalsegenhash	genconfigrr   r   )rU   handlersr   crypths        r'   test_40_basicCryptContextTest.test_40_basicq  s}   NNDNNDOOD(qA Euzz2AR[[^UZZ8R[[Dt[LeT))"++a+*FNOOBIIfa01RYYx34  GGFOQ5 JJx0Q5JJxJDQ5*bjj(BLLNS^_r)   c           	      v   [        SS/SSSS9nU R                  UR                  5       R                  S5      5        U R                  UR                  SS9R                  S	5      5        U R                  UR                  SS
S9R                  S5      5        U R                  UR                  SSS9R                  S	5      5        U R	                  UR                  SSSSS9S5        [
        (       a{  UR                  SS9nU R                  UR                  [        S
5      S9R                  S5      5        U R                  UR                  [        S5      S9R                  S	5      5        U R                  [        [        5       R                  5        U R                  [        [        5       R                  SS9  U R                  [        UR                  SS9  U R                  [        UR                  SSS9  U R                  [        UR                  SS9  U R                  [        UR                  SS9  g)ztest genconfig() methodr.   r@   rF   rG   r   )r3   rM   rN   admin__phpass__identz$1$r/  z$H$5r   )r  r   z$P$5r	  ........   )r  saltroundsidentz"$P$6........22zGEuacuPOqEpYPDeR0R/r?   r
  faker   N)r   r   r6  
startswithrZ   r   r    r   rr   r   rs   rU   r   c2s      r'   test_41_genconfig"CryptContextTest.test_41_genconfig  s   ;"9(+12/2 	11%89 	H5@@HI 	HwGRRSYZ[HwGRRSYZ[ 	LLuQcLJ0	 3*BOOBLL!G*L=HHPQOOBLL!G*L=HHPQ 	(LN$<$<=(LN$<$<[Q 	(BLL@)R\\!gN)R\\!< 	)R\\A>r)   c                    [        S/5      nUR                  S5      nU R                   H(  u  p4U R                  " [        UR
                  X240 UD6  M*     [        S/5      nU R                   H.  u  pTUc  M
  U R                  " [        UR
                  SU40 UD6  M0     [        S/5      nU R                  [        UR
                  SS5        U R                  [        [        5       R
                  SS5        U R                  [        UR
                  SUSS9  U R                  [        UR
                  SUS	S9  U R                  [        UR                  SUS	S
9  g)ztest genhash() methodr-   stubNr1  r  r   rC  r/  r   r
  )r   r   nonstring_vectorsrr   rs   r5  r   r6  )rU   r   r   r1  r$   configs         r'   test_42_genhash CryptContextTest.test_42_genhash  s0    ;-(wwv 22LFiVJTJ 3 ;-( 22LF| iXvNN 3 :,')RZZ> 	(LN$:$:HfM 	(BJJ$vN)RZZ4J 	)R\\8TANr)   c                 n   [        S0 U R                  D6nUR                  S5      nU R                  UR                  " S5      5        U R                  UR                  SU5      5        U R                  UR                  SU5      5        U R                  [        UR                  SS9  [        S/5      nU R                   H(  u  p4U R                  " [        UR                  U40 UD6  M*     U R                  [        [        5       R                  S5        U R                  [        UR                  SSS	9  g
)ztest hash() methodpasswordz$5$rounds=3000$	passwordxi  rL   r-   r1  r   r
  NrY   )r   sample_4_dictr   r   rD  r3  r4  rr   r   r    rK  rs   r   )rU   r   r   r1  r$   s        r'   test_43_hashCryptContextTest.test_43_hash  s     /D../wwz"(9:;		*d34;56 	*bgg7; 	 	= ;-( 22LFi&ADA 3 	(LN$7$7B 	)RWWhCr)   c           
         [        S0 U R                  D6nU R                  S/5         U R                  UR	                  SSSS9S5        SSS5        U R                  S/5         U R                  UR	                  SSSSS	9S
5        SSS5        U R                  S/5         U R                  UR	                  SSSS9S5        SSS5        U R                  S/5         U R                  UR	                  SSSS9S5        SSS5        U R                  [        UR                  SSS9  U R                  [        UR                  SSS9  g! , (       d  f       GN= f! , (       d  f       N= f! , (       d  f       N= f! , (       d  f       N= f)z;test hash() method -- legacy 'scheme' and settings keywords"passing settings to.*is deprecatedrP  r@   r>  )r  r@  z"$H$5........De04R5Egz0aq8Tf.1eVhY/Nr   )r  r@  rB  z"$P$5........De04R5Egz0aq8Tf.1eVhY/  naclrA  r@  z?$5$rounds=1999$nacl$nmfwJIxqj0csloAAvSER0B8LU0ERCAbhmMug4Twl609  z?$5$rounds=2001$nacl$8PdeoPL4aXQnJ0woHhqgIw/efyfCKC2WHneOpnvF.31r1  rC  r/  r   rY   )r   rS  assertWarningListrZ   r   rr   r   rs   )rU   use_16_legacyr   s      r'   test_43_hash_legacy$CryptContextTest.test_43_hash_legacy  sk   /D../  ##%I$JK
8%@4 L
 ##%I$JK
8%sK4 L ##%I$JK
4f=Q L ##%I$JK
4f=Q L 	(BGGXfE)RWWhqA; LK
 LK LK LKs/   "E$#E!"E+"E<
E
E(+
E9<
F
c                     / SQn[        USS9nU R                  UR                  S5      S5        U R                  [        UR                  SSS9  [        S/5      nU R
                   H(  u  p4U R                  " [        UR                  U40 UD6  M*     [        5       nU R                  UR                  S	5      S5        U R                  [        UR                  S	SS9  U R                  [        UR                  SS
S9  g)ztest identify() border casesr.   r-   r/   r,  r-  z$9$232323123$1287319827NT)requiredr-   r   r   r
  )	r   rZ   r2  rr   r   rK  rs   assertIsr   )rU   r7  r   r   r$   s        r'   test_44_identify!CryptContextTest.test_44_identify.  s    ;(qA 	%>?F*bkk3LW[\ ;-(00JDidCdC 1 ^bkk&)40(BKK$G 	)R[[$Cr)   c                    / SQn[        USS9n[        R                  R                  S5      nU R                  UR	                  SU5      5        U R                  UR	                  SU5      (       + 5        U R                  UR	                  SUSS95        U R                  UR	                  SUSS9(       + 5        U R                  [        UR                  SUSS9  U R                  [        UR                  S	S
5        [        S/5      nUR                  S	5      =p4U R                   H(  u  pVU R
                  " [        UR                  XS40 UD6  M*     U R                  UR	                  WS5      5        [        S/5      nU R                   H.  u  p6Uc  M
  U R
                  " [        UR                  SU40 UD6  M0     U R                  [        [        5       R                  SS5        U R                  [        UR                  SUSS9  U R                  [        UR                  SUSS9  U R                  [        UR                  SUSS9  g)ztest verify() scheme kwdra  r,  r-  r.  r0  r.   r/  r/   rJ  z$6$232323123$1287319827r-   Nr1  r   rC  r   r
  )r   r   r.   r   r3  rr   r   rK  rs   r4  r   )rU   r7  r   r9  refhashr1  r$   s          r'   test_45_verifyCryptContextTest.test_45_verifyH  s   ;(qANN' 			&!,-BIIh223 			&!K	@ABIIh+IFFG 	*bii<P 	*bii9RS ;-(ggfo% 22LFiFFF 3 	6401 ;-(--GAyiHaH4H . 	(LN$9$98VL 	(BIIxP)RYY'!L 	)RYY'ANr)   c                   ^ [        S0 U R                  D6nU R                  UR                  S5      5        U R	                  UR                  S5      5        U R                  UR                  S5      5        U R	                  UR                  S5      5        U R	                  UR                  S5      5        U R                  UR                  S5      5        / m " U4S jS[
        R                  5      n[        U/5      nUR                  S	5      =pEU R	                  UR                  U5      5        U R                  TUS
4/5        TS
S
2	 U R	                  UR                  USS95        U R                  TUS4/5        TS
S
2	 U R                  UR                  USS95        U R                  TUS4/5        TS
S
2	 [        S/5      nU R                   H(  u  pFU R                  " [        UR                  U40 UD6  M*     U R                  [        [        5       R                  S5        U R                  [        UR                  USS9  U R                  [        UR                  USS9  U R                  [        UR                  USS9  g
)ztest needs_update() method9XXD4trGYeGJAz"$1$J8HC2RCr$HcmM.7NxB2weSvlw2FgzU0zK$5$rounds=1999$jD81UCoo.zI.UETs$Y7qSTQ6mTiU9qZB4fRr43wRgQq4V.5AAf7F97Pzxey/zK$5$rounds=2000$228SSRje04cnNCaQ$YGV4RYu.5sNiBvorQDlO0WWQjyJVGKBcJXz3OtyQ2u8zK$5$rounds=3000$fS9iazEwTKi7QPW4$VasgBC8FqlOvD7x2HhABaMXCTh9jwHclPA9j5YQdns.zK$5$rounds=3001$QlFHHifXvpFX4PLs$/0ekt7lSs/lOikSerQ0M/1porEHxYq7W/2hdFpxA3fAc                   >   > \ rS rSrSrSr\SU 4S jj5       rS rSr	g)	4CryptContextTest.test_46_needs_update.<locals>.dummyi  dummy@Nc                 2   > TR                  X45        US:H  $ )Nnu)append)clsr   r1  check_states      r'   needs_updateACryptContextTest.test_46_needs_update.<locals>.dummy.needs_update  s    ""D>2~%r)   c                     SSK Jn  [        U[        5      (       a  UR	                  S5      n[        U" U5      R                  5       5      $ )Nr   )md5re   )hashlibrx  
isinstancer   ro   r   	hexdigest)rU   r1  rx  s      r'   _calc_checksumCCryptContextTest.test_46_needs_update.<locals>.dummy._calc_checksum  s8    'fg..#]]73F$S[%:%:%<==r)   rY   r   )
r   r   r   r   r   _hash_prefixclassmethodru  r|  r   )rt  s   r'   rn  rm    s$    DL& &>r)   rn  r.  Nbob)r1  rq  r-   r   rC  r/  r   r
  rY   )r   rS  r   ru  r4  r   r   r   rZ   rK  rr   rs   r   )rU   r   rn  ra   r   rg  r$   rt  s          @r'   test_46_needs_update%CryptContextTest.test_46_needs_update{  s7   /D../ 	89)MNO 	(uvw)vwx 	)vwx(uvw
 	>B$$ 	>  E7#F++))$/0T{m4N 	))$u)=>U|n5N 	((d(;<T{m4N ;-(00JDi$G$G 1 	(LN$?$?H 	(BOOWVL)R__gaH 	)R__gJr)   c                 "   [        S0 U R                  D6nUR                  S5      R                  S5      nUR                  S5      R                  S5      nUR	                  SU5      u  pEU R                  U5        U R                  US5        UR	                  SU5      u  pEU R                  U5        U R                  US5        UR	                  SU5      u  pEU R                  U5        U R                  UR                  U5      S5        UR	                  SU5      u  pEU R                  U5        U R                  US5        [        S/5      nUR                  S5      =pgU R                   H(  u  pU R                  " [        UR                  X40 U	D6  M*     U R                  UR	                  WS5      S5        [        S/5      nU R                   H.  u  piUc  M
  U R                  " [        UR                  SU40 U	D6  M0     U R                  [        [        5       R                  SS	5        U R                  [        UR                  SUS
S9  U R                  [        UR                  SUSS9  U R                  [        UR                  SUSS9  g)ztest verify_and_update()r-   rP  rA   	wrongpassNrJ  FNr1  r   rC  r/  r   r
  rY   )r   rS  r   r   verify_and_updater4  rc  r   r2  rK  rr   rs   rZ   r   )
rU   r   h1h2oknew_hashr   rg  r1  r$   s
             r'   test_47_verify_and_update*CryptContextTest.test_47_verify_and_update  sM   /D../ ZZ$))*5ZZ',,Z8 ++K<h% ++K<h% ++J;H-~> ++J;h% ;-(( 22LFi)=)=vTtT 3 	--fd;]K ;-(00JD|i)=)=xVQUV 1 	(LN$D$DhPVW 	(B$8$8(GTZ[)R%9%98WUVW 	)R%9%98WWXYr)   c           	         SSK JnJnJn  UR	                  S5      nUR	                  SSS9nUR	                  SSS9n[        X/5      nU R                  UR                  [        5       5        U R                  UR                  UR	                  S5      5      S5        U R                  UR                  SU5      5        U R                  UR                  SU5      S5        U R                  S	/5         U R                  [        UR                  SSS9  S
S
S
5        U R                  [        UR                  SUSS9  U R                  [        UR                  SUSS9  [        X/5      nU R                  UR                  [        S/5      5        U R                  UR                  UR	                  S5      5      S5        U R                  UR                  SU5      5        U R                  UR                  SU5      S5        U R                  UR                  UR	                  SSS95      S5        U R                  UR                  SUSS95        U R                  UR                  SUSS9S5        U R                  S	/5         U R                  [        UR                  SSS9  S
S
S
5        U R                  [        UR                  SUSS9  U R                  [        UR                  SUSS9  [        X1/SS9n	U R                  U	R                  [        S/5      5        U R                  [        U	R                  S5        U R                  [        U	R                  SU5        U R                  [        U	R                  SU5        U R                  U	R	                  SSS9U5        U R                  U	R                  SUSS95        U R                  U	R                  SUSS9S5        U R                  U	R                  SUSS9S5        U R                  U	R                  SUSS9SU45        g
! , (       d  f       GN= f! , (       d  f       GN= f)zLhash(), verify(), and verify_and_update() -- discard unused context keywordsr   )r-   r.   postgres_md5rJ  root)r   r   r-   )TNrW  Nr   )badkwdautor   r  T)passlib.hashr-   r.   r  r   r   rZ   context_kwdssetr   r2  r3  r  r\  rr   rs   )
rU   r-   r.   r  des_hashpg_root_hashpg_admin_hashr   r   r   s
             r'   test_48_context_kwds%CryptContextTest.test_48_context_kwds  s   
 	DC>>&)#((f(=$))&w)?
 I12))351 		**388F+;<kJ

6845..vx@,O ##%I$JKi6G L)SZZO)S%:%:FHSYZ
 I45))3x=9 		**388F+;<kJ

6845..vx@,O 		**388F8+HI;W

68&
AB..vxf.M|\ ##%I$JKi6&I L)SZZ&Q)S%:%:FHU[\
 L4H))3x=9 	)SXXv6)SZZF)S%:%:FLQ 	&v6E

6<f
EF..v|&.QS_` 	..v|'.RTab 	..vxf.M-	/_ LK, LKs   1!P*!P<*
P9<
Qc                 6	   [        S/SSSS9nSnUR                  SS5      nU R                  UR                  S5        U R                  UR                  S5        U R                  UR
                  S5        U R                  [        /S-  5         UR                  S	SS	S
9nSSS5        U R                  WR                  SS9SU-   5        U R                  / 5         U R                  UR                  SSS9SU-   5        SSS5        U R                  UR                  SSS9SU-   5        U R                  UR                  SSS9SU-   5        U R                  [        /S-  5         UR                  [        S5      S	-   S[        S5      S	-   S9nSSS5        U R                  UR                  SS9SU-   5        U R                  / 5         U R                  UR                  SSS9SU-   5        SSS5        U R                  UR                  SSS9SU-   5        U R                  UR                  SSS9SU-   5        U R                  UR                  SS9SU-   5        [        R                  R
                  nUR                  SUS-  S9nU R                  UR                  SS9SXR4-  5        UR                  SSS9nU R                  UR                  SS9SU-   5        U R                  [        UR                  SS 9  UR                  SS 9  UR                  SS 9  U R                  [        UR                  SS 9  [        S/S!9nU R                  [        UR                  SSS"9  U R                  [        [         S#S$9  U R                  [        [         S#S%9  U R                  [        [         S#S&9  U R                  [        [         S#S 9  [        R                  R!                  5       nU R                  ["        [         SUS$9  U R                  ["        [         SUS%9  U R                  ["        [         SUS&9  U R                  ["        [         SUS 9  g! , (       d  f       GN= f! , (       d  f       GNl= f! , (       d  f       GN= f! , (       d  f       GN= f)'ztest rounds limitsrA   rE   rD   i	  r3   rK   rJ   rL   z+...........................................N   i  )rK   rJ   rL   rY  r@  z$5$rounds=1000$nacl$rX  rZ  z$5$rounds=1999$nacl$z$5$rounds=2000$nacl$r[  z$5$rounds=2001$nacl$g    eA)rJ   rK   rL   z$5$rounds=999999999$nacl$i  z$5$rounds=3001$nacl$z$5$rounds=3000$nacl$i  z$5$rounds=2999$nacl$z$5$rounds=2500$nacl$r   )rL   rJ   z$5$rounds=%d$nacl$%srR  r:   )rK   rJ   r   r   )rJ   r   )r   _get_recordrZ   min_desired_roundsmax_desired_roundsdefault_roundsr\  r   r    r6  intr   rA   rr   r   datetimenowrs   )rU   r   STUBcustom_handlerrF  dfbads          r'   test_50_rounds_limits&CryptContextTest.test_50_rounds_limitsQ  sx   >"237377; = =::DA::DA66= ##%7$8$:;#PT9<  >B < 	624JT4QR ##B'Dv68NQU8UW (
 	LL6L24JT4Q	S 	LL6L24JT4Q	S ##%7$8$:;#c(3,Y]9<S#  GB < 	624ORV4VW ##B'Dv68NQU8UW (
 	LL6L24JT4Q	S 	LL6L24JT4Q	S 	624JT4QR --WW$QSUVQVWW624JbZ4WX WW$QUWV624JT4QR
 	*bggDQ
T2
T2*bggDQ >"23 	*bgg37 	 	9 	*lSQ*lSQ*lSI*lQTU ##%)\>\_`)\>\_`)\>TWX)\>`cdw <; ('" <; ('s0   Q$Q%'*Q7$R	
Q"%
Q47
R	
Rc                    [        S/SSSS9nU R                  [        UR                  SS9  U R                  [        UR                  SS9  U R                  [        UR                  S	S9  UR                  S
S9nU R	                  UR                  SS5      R                  S
5        U R                  USSS5        UR                  SS9nU R	                  UR                  SS5      R                  S
5        U R                  USSS5        UR                  SS9nU R	                  UR                  SS5      R                  S5        U R                  USSS5        UR                  SS9nU R	                  UR                  SS5      R                  S5        U R                  USSS5        UR                  SS9nU R	                  UR                  SS5      R                  S5        U R                  USSS5        UR                  SS9nU R	                  UR                  SS5      R                  S5        U R                  USSS5        g)ztest linear vary roundsrA   i  i  rE   r  r   -1%101%r   N0%r   rX  r[  d   z0.1%gMbP?i  i  100%      ?r   rr   r   r    rZ   r  r  assert_rounds_rangerE  s      r'   test_51_linear_vary_rounds+CryptContextTest.test_51_linear_vary_rounds  s   >"237377; 	*bggC*bggF*bggG WWaW(=II1M  ^T4@WWdW+=II1M  ^T4@ WWaW(=II1M  ^T4@WWcW*=II3O  ^T4@ WWfW-=II5Q  ^T4@WWfW-=II3O  ^T4@r)   c                    [        S/SSSS9nU R                  [        UR                  SS9  U R                  [        UR                  SS9  U R                  [        UR                  S	S9  UR                  S
S9nU R	                  UR                  SS5      R                  S
5        U R                  USSS5        UR                  SS9nU R	                  UR                  SS5      R                  S
5        U R                  USSS5        UR                  SS9nU R	                  UR                  SS5      R                  S5        U R                  USSS5        UR                  SS9nU R	                  UR                  SS5      R                  S5        U R                  USSS5        UR                  SS9nU R	                  UR                  SS5      R                  S5        U R                  USSS5        UR                  SS9nU R	                  UR                  SS5      R                  S5        U R                  USSS5        UR                  SS9nU R	                  UR                  SS5      R                  S5        U R                  USSS5        UR                  SS9nU R	                  UR                  SS5      R                  S5        U R                  USSS5        g)ztest log2 vary roundsbcrypt   rC      )r3   bcrypt__min_roundsbcrypt__max_roundsbcrypt__default_roundsr  r   r  r  r   Nr  r         r  z1%g{Gz?z49%g\(\?z50%g      ?r  r  r  rE  s      r'   test_52_log2_vary_rounds)CryptContextTest.test_52_log2_vary_rounds  s   8*-/-/13 	*bggC*bggF*bggG WWaW($7CCQG  Xr26WWdW+$7CCQG  Xr26 WWaW($7CCQG  Xr26WWcW*$7CCSI  Xr26 WWdW+$7CCTJ  Xr26WWeW,$7CCTJ  Xr26WWeW,$7CCSI  Xr26WWfW-$7CCSI  Xr26r)   c                 |   UR                  U5      nUR                  SS UR                  -  n[        5       n[	        S5       H>  nUR                  X&S9n	UR                  U	5      R                  n
UR                  U
5        M@     U R                  [        U5      US5        U R                  [        U5      US5        g)z2helper to check vary_rounds covers specified ranger   r   i,  r  z"vary_rounds had wrong lower limit:z"vary_rounds had wrong upper limit:N)r   default_salt_charsmax_salt_sizer  r   r6  rl   rA  addrZ   minmax)rU   contextr  lowerupperr   r@  seenir9  rs              r'   r  $CryptContextTest.assert_rounds_range  s     //&)))!A.1F1FFuA!!&!4A##A&--AHHQK  	TE+OPTE+OPr)   c                 z   [         R                  " SS[        S9  [        S/S9nU R	                  UR
                  S5        U R	                  UR                  SS9R
                  S5        U R	                  UR                  S	S9R
                  S5        U R	                  UR                  S
S9R
                  S5        g)zharden_verify -- parsingrP   z.*harden_verify.*r
  rA   r:   N )harden_verifytruefalse)rS   rT   DeprecationWarningr   rZ   r  usingr`   s     r'   test_harden_verify_parsing+CryptContextTest.test_harden_verify_parsing-  s    *=);	= N#34**D14BBDI8FFM9GGNr)   c                     SnSn[         R                  5       nXl        [        U/S9nUR	                  5         [        UR                  5      u  pVU R                  XQX-  S9  g)z
dummy_verify() method
r  r  r:   )deltaN)	DelayHashr  delayr   dummy_verifyr   assertAlmostEqual)rU   expectedaccuracyr   ra   elapsed_s          r'   test_dummy_verify"CryptContextTest.test_dummy_verify9  s_    
 //# G9-s//0
w8KLr)   c                    SS jn[        SSS9nU R                  U" US5      / SQ5        U R                  U" US5      / SQ5        UR                  SS	9  U R                  U" US5      / S
Q5        U R                  U" US5      / S
Q5        UR                  SS9  U R                  U" US5      / S
Q5        U R                  U" US5      / SQ5        [        S/SS9nU R                  U" US5      S/5        U R                  U" US5      S/5        U R                  [        [         SSS9  U R                  [        [         SSS9  g)z+test deprecated='auto' is handled correctlyNc                 ~    U R                  5        Vs/ s H  o R                  X!5      R                  PM     sn$ s  snf r   r   )ra   r   r  s      r'   getstate8CryptContextTest.test_61_autodeprecate.<locals>.getstateP  s-    KN;;=Y=KK1<<=YYYs   $:z sha256_crypt,md5_crypt,des_cryptr  r   )FTTr   r.   r?   )TFTr-   r   )TTFrA   Fr  zauto,md5_cryptzmd5_crypt,autor   )r   rZ   r!   rr   r   )rU   r  ra   s      r'   test_61_autodeprecate&CryptContextTest.test_61_autodeprecateM  sF   	Z =&Q#$/1DE#w/1DE 	

;
'#$/1DE#w/1DE 	

;
7#$/1DE#w/1DE N+?#$/%9#w/%9 	*l4L%5 	 	7*l4L%5 	 	7r)   c                 r   SSK Jn  SSKJnJn  [        S/5      n[        SS/5      nUR                  S5      nUR                  S5      nU R                  [        SUR                  5        U R                  [        SUR                  U5        U R                  [        SUR                  U5        UR                  5       nU R                  XR                  5        UR                  U5      n	U R                  XR                  U-   5        UR                  U5      n
U R                  XR                  U-   5        U R                  UR                  U	5      U	5        U R                  UR                  U5      5        U R                  XR                  U5        U R                  XR                  U5        U R                  XR                  U	5        U R                  UR                  U5      5        U R                  XR                  U5        U R                  UR                  U5      5        U R                  UR                  U	5      5        U R                  XR                   S5        U R                  ["        UR                   S	5        U R                  UR!                  U5      U5        U R                  XR                   U5        U R                  XR                   U5        U R                  XR                   U	5        U R                  XR                   S5        U R                  ["        UR                   S	5        U R                  UR!                  U5      U5        U R                  XR                   U5        U R                  [$        S
UR                   U5        U R                  UR!                  U	5      U5        g	)zdisabled hash supportr   )UnknownHashError)r.   unix_disabledr-   r  foozno disabled hasher presentr  Nzcannot restore original hash)passlib.excr  r  r.   r  r   r   assertRaisesRegexr{   disablerZ   default_markerr   
is_enabledrr   r4  enablers   r   )rU   r  r.   r  ra   r&  h_refh_otherh_dis	h_dis_refh_dis_others              r'   test_disabled_hashes%CryptContextTest.test_disabled_hashesm  s   
 	19K=)[/:;..' 	|-I"{{	,|-I"{{E	3|-I"{{G	5  < <=LL'	$@$@5$HIll7+&B&BW&LM 	i0)< 	u-.*NNGD*NNEB*NNIF 	./*NNGD/034 	*JJ;)SZZ6E*E2*JJ@*JJ>*JJ	B 	*JJ;)T[[$7U+U3*KKAz+I#{{E	3Y/7r)   r   F)Kr   r   r   r   descriptionPrefixr   r   r   r   r\   r(   r]   r   rn   rm   rw   rx   r   r   rz   r#  rp   r}   ro   rq   r~   r   r^   r   r   r_   r   rS  rR   rb   rt   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r  r  r  r)  rK  r:  rG  rM  rT  r^  rd  rh  r  r  r  r  r  r  r  r  r  r  r  r   __classcell__).0r   r   rV   s   000@r'   r+   r+   1   s   & P=MN=MT*40=MN"!&%*#(#(M )3DF  
 
  
 
" GGLL}5M )004!F)DWW\\$7N '..q~/0@@Fx@P WW\\$7N  !&!&%*!&M !>N
 M
 ".-@O
 #"% !#%'"##'#''+!"M$b;6H<E6=:I)<V10 7JJBX"AHZ2x#CJ.(F,(<0"bHM^QDB 
r
	+&'	
B	R	
`6.?b"OHD8/BbD41OfEKN8ZtF/jtel$AL-7^Q"
OM(7@H8 H8]1 Os   F9r+   c                   R    \ rS rSrSrSr\R                  rSr	Sr
\" S5      rS rSrg	)
r  i  z-dummy hasher which delays by specified amount
delay_hash(   r   z$x$c                     [         R                  " U R                  5        [        U[        5      (       a  UR                  S5      n[        [        R                  " SU-   5      R                  5       5      $ )Nre   s   prefix)
timesleepr  rz  r   ro   r   ry  sha1r{  )rU   r1  s     r'   r|  DelayHash._calc_checksum  sO    

4::fg&&]]7+FW\\)f*<=GGIJJr)   rY   N)r   r   r   r   __doc__r   r   LOWER_HEX_CHARSchecksum_charschecksum_sizer  r   r~  r|  r   rY   r)   r'   r  r    s.    7D''NMEU8LKr)   r  c                       \ rS rSrS rSrg)dummy_2i  rY   Nr   rY   r)   r'   r  r    s    Dr)   r  c                   *    \ rS rSrSrS rS rS rSrg)LazyCryptContextTesti  r	   c                 F    [        S5        U R                  [         S5        g )Nr  )unload_handler_name
addCleanup)rU   s    r'   rR   LazyCryptContextTest.setUp  s    I&+Y7r)   c                 |   U R                  [        S5      5        [        SS5        [        [	        SS/5      S/S9nU R                  [        SS5      5        U R                  UR                  5       S5        U R                  UR                  S5      R                  5        U R                  [        SS5      5        g)ztest plain kwdsr  passlib.tests.test_contextr-   r   Tr  r-   N)
r4  has_crypt_handlerr   r	   iterrZ   r3   r   r   rH   )rU   r   s     r'   test_kwd_constructor)LazyCryptContextTest.test_kwd_constructor  s    *956#I/KLdI{#;<+W*9d;<'?@

;/::;))T:;r)   c                 v  ^  T R                  [        S5      5        [        SS5        SU 4S jjn[        USS9nT R                  [        SS5      5        T R	                  UR                  5       S5        T R                  UR                  S5      R                  5        T R                  [        SS5      5        g )	Nr  r  c                 R   > TR                  U 5        [        [        SS/5      S/S9$ )Nr  r-   r   )r   r   r  )flagrU   s    r'   onload>LazyCryptContextTest.test_callable_constructor.<locals>.onload  s(    OOD!i%= >K=YYr)   T)r  r  r  r-   r  )	r4  r  r   r	   rZ   r3   r   r   rH   )rU   r  r   s   `  r'   test_callable_constructor.LazyCryptContextTest.test_callable_constructor  s    *956#I/KL	Z V$7*9d;<'?@

;/::;))T:;r)   rY   N)	r   r   r   r   r  rR   r  r  r   rY   r)   r'   r  r    s    *8
<<r)   r  )Ar  
__future__r   passlib.utils.compatr   configparserr   ConfigParserr  	functoolsr   logging	getLoggerr   logrw   rS   passlibr   passlib.contextr   r	   r  r
   r   passlib.utilsr   r   r   r   r   r   r   r   passlib.utils.handlersutilsr7  r   passlib.tests.utilsr   r   r   r   r   r   passlib.registryr   r   r  r   r  r   rx   abspathdirname__file__r   r(   r+   ry  r  r   r  r  r  rY   r)   r'   <module>r3     s    
 & $++   g''1 	   : @ * M M # #N N  
wwrwwx01D8x D8T4 K   K"b %<8 %<r)   