
    K}bgr                        d Z ddlmZ ddlmZ ddlZddlZddlmZm	Z	 ddl
mZ ddlmZ ddlmZ dd	lmZmZmZmZ dd
lmZ ddlmZ ddlmZ  ee          ZddZej                            d          pdZddZ d Z!d Z" e"            \  Z#Z$ ej%        e#d          Z& G d de          Z' G d de          Z(dS )z@tests for passlib.apache -- (c) Assurance Technologies 2008-2011    )with_statement)	getLoggerN)apacheregistry)MissingBackendError)irange)unittest)TestCaseget_fileset_fileensure_mtime_changed)u)to_bytes)to_unicode_for_identify
   c                     t           j                            |           }t           j                            |           |z
  }t          j        | ||f           dS )z)backdate file's mtime by specified amountN)ospathgetatimegetmtimeutime)r   offsetatimemtimes       l/home/e360mart.nyusoft.in/public_html/e360mart_env/lib/python3.11/site-packages/passlib/tests/test_apache.pybackdate_file_mtimer      sO     GT""EGT""6)EHTE5>"""""    PASSLIB_TEST_HTPASSWD_PATHhtpasswdc                 8   ||                     d          }t          j        t          g| z   t          j        t          j        |rt          j        nd          }|                    |          \  }}|                                }t          |pd          }||fS )z$
    helper to run htpasswd cmd
    Nutf-8)stdoutstderrstdin )	encode
subprocessPopenhtpasswd_pathPIPESTDOUTcommunicatewaitr   )argsr$   procouterrrcs         r   _call_htpasswdr3   +   s     W%%]Od2:?#-#4u<^JOOZ^` ` `D&&HC	B
!#)
,
,C7Nr   c                 4    t          d| |g|          \  }}| S )z%
    wrapper for htpasswd verify
    z-vi)r3   )r   userpasswordr0   r2   s        r   _call_htpasswd_verifyr7   9   s%     eT40(;;GC6Mr   c                      	 t          g           \  } }n# t          $ r Y dS w xY w|st                              d           d| v }d|fS )z0
    helper to check if htpasswd is present
    )FFz htpasswd test returned with rc=0z -B T)r3   OSErrorlogwarning)r0   r2   have_bcrypts      r   _detect_htpasswdr=   A   so     $$RR    ||
  86777C-Ks    
##z requires `htpasswd` cmdline toolc                      e Zd ZdZdZdZdZdZdZdZ	dZ
d	Zd
 Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zed             Ze e j!         e"j#        d          d          d                         Z$d S )!HtpasswdFileTestztest HtpasswdFile classHtpasswdFilest   user2:2CHkkwa2AtqGs
user3:{SHA}3ipNV1GrBtxPmHFC21fCbVCSXIo=
user4:pass4
user1:$apr1$t4tc7jTh$GPIWVUo8sQKJlUdV8V5vu0
s4   user3:{SHA}3ipNV1GrBtxPmHFC21fCbVCSXIo=
user4:pass4
sy   user2:pass2x
user3:{SHA}3ipNV1GrBtxPmHFC21fCbVCSXIo=
user4:pass4
user1:$apr1$t4tc7jTh$GPIWVUo8sQKJlUdV8V5vu0
user5:pass5
s   useræ:2CHkkwa2AtqGs
s   user:2CHkkwa2AtqGs
s   user1: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.
c                 b   |                                  }t          || j                   t          j        |          }|                     |                                | j                   |                     |j        |           |                     |j	                   |dz   |_        |                     |j        |dz              | 
                    |j	                   t          j        |d          }|                     |                                d           |                     |j        |           | 
                    |j	                   |                     d          5  t          j        |d          }ddd           n# 1 swxY w Y   |                     |                                d           |                     |j        |           | 
                    |j	                   t          j        |           |                     t          t          j        |           dS )	test constructor autoloadxTnewr   z ``autoload=False`` is deprecatedF)autoloadN)mktempr   	sample_01r   r@   assertEqual	to_stringr   
assertTruer   assertFalseassertWarningListr   removeassertRaisesIOErrorselfr   hts      r   test_00_constructor_autoloadz-HtpasswdFileTest.test_00_constructor_autoload}   s    {{}}t~&&& &&888$'''!!! *$*---"""  4000---$'''""" ##$FGG 	; 	;$TE:::B	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	;---$'''""" 		$'6#6=====s   *FFFc                 Z   |                                  }t          || j                   t          j                            |          }|                     |                                | j                   |                     |j        d            | 	                    |j
                   d S N)rG   r   rH   r   r@   	from_pathrI   rJ   r   rL   r   rQ   s      r   test_00_from_pathz"HtpasswdFileTest.test_00_from_path   s    {{}}t~&&& **400888$'''"""""r   c                    t           j                            | j                  }|                     |                    d                     |                     |                    d                     |                     |                    d                     |                     |                                | j	                   | 
                    t          |j        d           dS )test delete()user1user2user5user:N)r   r@   from_stringrH   rK   deleterL   rI   rJ   	sample_02rO   
ValueErrorrR   rS   s     r   test_01_deletezHtpasswdFileTest.test_01_delete   s     ,,T^<<		'**+++		'**+++7++,,,888 	*bi99999r   c                    |                                  }d}t          ||           t          j        |          }|                    d           |                     t          |          |           t          j        |d          }|                    d           |                     t          |          d           d S )Ns   user1:pass1
user2:pass2
r[   T)autosaves   user2:pass2
)rG   r   r   r@   r`   rI   r   rR   r   samplerS   s       r   test_01_delete_autosavez(HtpasswdFileTest.test_01_delete_autosave   s    {{}}.v &&
		'$000 555
		'$)9:::::r   c                    t           j                            | j        d          }|                     |                    dd                     |                     |                    dd                     |                     |                                | j	                   | 
                    d          5  t           j                            | j        d          }d	d	d	           n# 1 swxY w Y   |                     |                    dd                     |                     |                    dd                     |                     |                                | j	                   |                     t          |j        d
d           | 
                    d          5  |                    dd           d	d	d	           n# 1 swxY w Y   |                     |                    dd                     d	S )ztest set_password()	plaintextdefault_schemer\   pass2xr]   pass5z``default`` is deprecated)defaultNr^   passupdate\(\) is deprecatedtest)r   r@   r_   rH   rK   set_passwordrL   rI   rJ   	sample_03rM   rO   rb   updatecheck_passwordrc   s     r   test_02_set_passwordz%HtpasswdFileTest.test_02_set_password   sJ    ,,N; - 8 8::;;;'::;;;888 ##$?@@ 	V 	V$000UUB	V 	V 	V 	V 	V 	V 	V 	V 	V 	V 	V 	V 	V 	V 	V::;;;'::;;;888 	*bowGGG ##$>?? 	' 	'IIgv&&&	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	'))'6::;;;;;s$   ;'C..C25C2/GGGc                    |                                  }d}t          ||           t          j        |          }|                    dd           |                     t          |          |           t          j        |dd          }|                    dd           |                     t          |          d           d S )N   user1:pass1
r[   pass2rk   T)rm   rf   s   user1:pass2
)rG   r   r   r@   rt   rI   r   rg   s       r   test_02_set_password_autosavez.HtpasswdFileTest.test_02_set_password_autosave   s    {{}}!v &&
)))$000 kDQQQ
)))$)9:::::r   c                 8   d }|                       |d          d           |                       |d          d           |                     t          |d           |                       |d          t          j        d                    |                       |d          t          j        d                    |                       |d          t          j        d                    |                       |d          t          j        d                    dS )	z%test set_password() -- default_schemec                     t          j        |           }|                    dd           |j                            |                    d                    S )Nrl   r[   pass1)r   r@   rt   contextidentifyget_hash)schemerS   s     r   checkzCHtpasswdFileTest.test_02_set_password_default_scheme.<locals>.check   sK    $F;;;BOOGW---:&&r{{7';';<<<r   sha256_crypt	des_cryptxxxportableportable_apache_22host_apache_22N)rI   rO   KeyErrorr   htpasswd_defaults)rR   r   s     r   #test_02_set_password_default_schemez4HtpasswdFileTest.test_02_set_password_default_scheme   s   	= 	= 	= 	~..???{++[999 	(E5111 	z**F,DZ,PQQQ344f6NOc6deee/00&2JK[2\]]] 	tf&>?S&TUUUUUr   c                 >   t           j                            | j                  }|                    dd           |                    d           |                    dd           |                     t          |                                          g d           dS )test users()r]   ro   user3pass3r[   r\   r   user4r]   N)	r   r@   r_   rH   rt   r`   rI   sortedusersrc   s     r   test_03_userszHtpasswdFileTest.test_03_users   s     ,,T^<<
)))
		'
)))

++-Z-Z-Z[[[[[r   c                 b   t           j                            | j                  }|                     t
          |j        dd           |                     |                    dd          du            t          dd          D ]}t          |          }	 |                     |                    d|z   d|z                        |                     |                    d|z   d          du            p# t          $ r
 |d	k    rY  w xY w|                     t          |j        d
d           |                     dgdz            5  |                     |                    dd                     |                     |                    dd                     ddd           dS # 1 swxY w Y   dS )test check_password()   pass9user9N   r5   rq   F5r^   verify\(\) is deprecated   r[   r   r{   )r   r@   r_   	sample_05rO   	TypeErrorrw   rK   r   strr   rb   rM   verifyrL   rR   rS   is      r   test_04_check_passwordz'HtpasswdFileTest.test_04_check_password  s    ,,T^<<)R%67CCC))''::dBCCC 1 		 		AAA 1 1&(F1H E EFFF 1 1&(G D D MNNNN&   88H	 	*b&7&III ##%?$@$BCC 	: 	:OOBIIgw77888RYYw88999	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	:s&   AC22DDAF$$F(+F(c                 Z   |                                  }t          |d           t          |d           t          j        |d          }|                     |                                d           |                    dd           |                                 |                     |                                d           t          || j	                   |                                 |                     |                                | j	                   |                    d	d
           |
                                 |                     |                                | j	                   t          j                    }|                     t          |j
                   |                     t          |j                   t          || j                   t          j                    }|
                    |           |                     |                    dd                     dS )test load()r%      rk   rl   r   r[   r   rz   r]   ro   N)rG   r   r   r   r@   rI   rJ   rt   load_if_changedrH   loadrO   RuntimeError
sample_duprK   rw   rR   r   hahbhcs        r   test_05_loadzHtpasswdFileTest.test_05_load  s    {{}}rD!$$$ kBBB--- 	)))
)9::: 	t~&&&
888 	)))
			888  "",000,(:;;; 	t''' ""
))''::;;;;;r   c                 R   |                                  }t          || j                   t          j        |          }|                    d           |                    d           |                                 |                     t          |          | j	                   t          j        d          }|
                    dd           |                     t          |j                   |                    |           |                     t          |          d           dS )test save()r[   r\   rk   rl   r   rz   N)rG   r   rH   r   r@   r`   saverI   r   ra   rt   rO   r   rR   r   rS   r   s       r   test_06_savezHtpasswdFileTest.test_06_saveA  s     {{}}t~&&& && 			'
		'
			$888  <<<
))),000 	$)9:::::r   c                    |                      t          t          j        d           t          j                            | j        dd          }|                     |                                t          d          g           | 	                    d          5  t          j                            | j        d          }ddd           n# 1 swxY w Y   |                     |                                d	g           t          j                            | j
        d
d          }|                     |                                t          d          g           dS )ztest 'encoding' kwdutf-16encodingr!   Tr   return_unicode   useræz``encoding=None`` is deprecatedNs   userælatin-1)rO   rb   r   r@   r_   sample_04_utf8rI   r   r   rM   sample_04_latin1rc   s     r   test_07_encodingsz"HtpasswdFileTest.test_07_encodingsW  s    	*f&9HMMM  ,,T-@7<@ - B Bq%8999 ##$EFF 	U 	U$001Dt0TTB	U 	U 	U 	U 	U 	U 	U 	U 	U 	U 	U 	U 	U 	U 	U%8999  ,,T-B7@QU - W Wq%899999s   'CCCc                    t           j                            | j                  }|                     |                    d          d           |                     |                    d          d           |                     |                    d          d           |                     d          5  |                     |                    d          d           ddd           dS # 1 swxY w Y   dS )test get_hash()r   s!   {SHA}3ipNV1GrBtxPmHFC21fCbVCSXIo=r   s   pass4r]   Nfind\(\) is deprecated)r   r@   r_   rH   rI   r   rM   findrc   s     r   test_08_get_hashz!HtpasswdFileTest.test_08_get_hashk  s    ,,T^<<W--/STTTW--x888W--t444##$<== 	9 	9RWWW--x888	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9s   5*C,,C03C0c                    t           j                            | j                  }|                     |                                | j                   t          j                    }|                     |                                d           dS )ztest to_stringr   N)r   r@   r_   rH   rI   rJ   rc   s     r   test_09_to_stringz"HtpasswdFileTest.test_09_to_stringu  p      ,,T^<<888  ""-----r   c                 T    t          j        dddd          }t          |           d S )NfakepathTr   )rf   rE   r   )r   r@   reprrc   s     r   test_10_reprzHtpasswdFileTest.test_10_repr  s*     dyYYYRr   c                     |                      t          t          j        j        d           |                      t          t          j        j        d           d S )Ns   realm:user1:pass1
s   pass1
)rO   rb   r   r@   r_   rR   s    r   test_11_malformedz"HtpasswdFileTest.test_11_malformed  sV    *f&9&E"	$ 	$ 	$*f&9&E	 	 	 	 	r   c                 `    |                      t          t          j        j        dd            d S )Nr   )r   )rO   r   r   r@   r_   r   s    r   test_12_from_stringz$HtpasswdFileTest.test_12_from_string  s8    )V%8%DD 	 	* 	* 	* 	* 	*r   c                 
   t          d          }t          j                            |          }|                     t          |                                          g d           |                    dd           |                     t          |                                          g d           |                    dd           |                     t          |                                          g d           |                    d           |                     t          |                                          g d	           t          d
          }|                     |	                                |           dS )zwhitespace & comment handlingz`
user2:pass2
user4:pass4
user7:pass7
 	 
user1:pass1
 # legacy users
#user6:pass6
user5:pass5

)r[   r\   r   r]   user7r   althash4user6althash6)r[   r\   r   r]   r   r   r   )r[   r\   r   r]   r   zd
user2:pass2
user4:althash4
 	 
user1:pass1
 # legacy users
#user6:pass6
user5:pass5
user6:althash6
N)
r   r   r@   r_   rI   r   r   set_hashr`   rJ   )rR   sourcerS   targets       r   test_13_whitespacez#HtpasswdFileTest.test_13_whitespace  s`   
 

 

  ,,V44

++-Z-Z-Z[[[ 	GZ(((

++-Z-Z-Z[[[ 	GZ(((

++-c-c-cddd 			'

++-Z-Z-Z[[[ 

 

 	00000r   c                    |                                  }t          j        |d          fd}                    d |dd                     t          j        d         }                    d |d|                     t          j        d	         }                    d
 |d|                                         dd                                            |                     t          |dd                     |                     t          |dd                     |                     t          |d
d                     |                     t          |dd                     |                     t          |dd                     |                     t          |dd                     |                     t          |d
d                     dS )z;
        verify "htpasswd" command can read output
        Tr   rE   c                 ^    j                             |                              |           S rV   r   handlerhashpwdr   rS   s     r   hash_schemez>HtpasswdFileTest.test_htpasswd_cmd_verify.<locals>.hash_scheme  '    :%%f--223777r   r[   r6   apr_md5_cryptr   r\   hostr   r   z$xxx$foo$bar$bazwrongN)	rG   r   r@   r   r   r   rL   r7   rK   )rR   r   r   host_no_bcrypt	host_bestrS   s        @r   test_htpasswd_cmd_verifyz)HtpasswdFileTest.test_htpasswd_cmd_verify  s   
 {{}} d555	8 	8 	8 	8 	8 	G[[ODDEEE  12BC
G[[^DDEEE ,V4	
G[[Y??@@@ 	G/000 				.tWgFFGGG.tWgFFGGG.tWgFFGGG.tWgFFGGG-dGZHHIII-dGZHHIII-dGZHHIIIIIr   bcryptzbcrypt support requiredc                    |                                  }t          j        |d          fd}                    d |dd                                                      |                     t          |dd                     t          r&|                     t          |dd                     dS |                     t          |dd                     dS )	z
        verify "htpasswd" command can read bcrypt format

        this tests for regression of issue 95, where we output "$2b$" instead of "$2y$";
        fixed in v1.7.2.
        Tr   c                 ^    j                             |                              |           S rV   r   r   s     r   r   zEHtpasswdFileTest.test_htpasswd_cmd_verify_bcrypt.<locals>.hash_scheme  r   r   r[   r6   r   r   N)	rG   r   r@   r   r   rL   r7   HAVE_HTPASSWD_BCRYPTrK   )rR   r   r   rS   s      @r   test_htpasswd_cmd_verify_bcryptz0HtpasswdFileTest.test_htpasswd_cmd_verify_bcrypt  s     {{}} d555	8 	8 	8 	8 	8
G[[X>>???
			.tWgFFGGG 	OOO1$LLMMMMM 24*MMNNNNNr   N)%__name__
__module____qualname____doc__descriptionPrefixrH   ra   ru   r   r   r   r   rT   rX   rd   ri   rx   r|   r   r   r   r   r   r   r   r   r   r   r   r   requires_htpasswd_cmdr   r	   
skipUnlessr   has_backendr    r   r   r?   r?   Z   s       !!&BI JI"I 5N2.JFI> > >D# # #	: 	: 	:; ; ;< < <.; ; ;V V V.\ \ \: : :4!< !< !<J; ; ;,: : :(9 9 9	. 	. 	.    * * *
-1 -1 -1^ "J "J "JH X--h779RSSO O TS O O Or   r?   c                   x    e Zd ZdZdZdZdZdZdZdZ	d Z
d	 Zd
 Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd ZdS )HtdigestFileTestztest HtdigestFile classHtdigestFiles   user2:realm:549d2a5f4659ab39a80dac99e159ab19
user3:realm:a500bb8c02f6a9170ae46af10c898744
user4:realm:ab7b5d5f28ccc7666315f508c7358519
user1:realm:2a6cf53e7d8f8cf39d946dc880b14128
sZ   user3:realm:a500bb8c02f6a9170ae46af10c898744
user4:realm:ab7b5d5f28ccc7666315f508c7358519
s   user2:realm:5ba6d8328943c23c64b50f8b29566059
user3:realm:a500bb8c02f6a9170ae46af10c898744
user4:realm:ab7b5d5f28ccc7666315f508c7358519
user1:realm:2a6cf53e7d8f8cf39d946dc880b14128
user5:realm:03c55fdc6bf71552356ad401bdb9af19
s0   useræ:realmæ:549d2a5f4659ab39a80dac99e159ab19
s.   user:realm:549d2a5f4659ab39a80dac99e159ab19
c                    |                                  }t          || j                   t          j        |          }|                     |                                | j                   t          j        |d          }|                     |                                d           t          j        |           | 	                    t          t          j        |           dS )rB   TrD   r   N)rG   r   rH   r   r   rI   rJ   r   rN   rO   rP   rQ   s      r   rT   z-HtdigestFileTest.test_00_constructor_autoload  s     {{}}t~&&& &&888  4000--- 		$'6#6=====r   c                 x   t           j                            | j                  }|                     |                    dd                     |                     |                    dd                     |                     |                    dd                     |                     |                    dd                     |                     |                                | j	                   | 
                    t          |j        dd           | 
                    t          |j        dd	           d
S )rZ   r[   realmr\   r]   r   realm5r^   r5   realm:N)r   r   r_   rH   rK   r`   rL   rI   rJ   ra   rO   rb   rc   s     r   rd   zHtdigestFileTest.test_01_delete+  s     ,,T^<<		'733444		'7334447G445557H55666888 	*bi'BBB 	*biBBBBBr   c                 v   |                                  }t          || j                   t          j        |          }|                     |                    dd                     |                     |                    dd                     |                     |                    dd                     |                     t          |          | j                   d|_
        |                     |                    dd                     |                     t          |          | j                   d S )Nr[   r   r   r  r]   Tr\   )rG   r   rH   r   r   rK   r`   rL   rI   r   rf   ra   rQ   s      r   ri   z(HtdigestFileTest.test_01_delete_autosave:  s    {{}}t~&&& &&		'7334447H556667G44555$888		'733444$88888r   c                    t           j                            | j                  }|                     |                    ddd                     |                     |                    ddd                     |                     |                                | j	                   | 
                    t          |j        dd           d|_        |                    dd           |                    ddd           | 
                    t          |j        ddd	           | 
                    t          |j        d
dd	           | 
                    t          |j        ddd	           | 
                    t          |j        ddd	           |                     d          5  |                    ddd           ddd           n# 1 swxY w Y   |                     |                    dd                     dS )ztest update()r\   r   rn   r]   ro   r   realm2r^   rq      uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuur5   r     rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr   rs   N)r   r   r_   rH   rK   rt   rL   rI   rJ   ru   rO   r   default_realmrw   rb   rM   rv   rc   s     r   rx   z%HtdigestFileTest.test_02_set_passwordH  s    ,,T^<<(CCDDD'7CCDDD888 	)R_gwGGG#
)))
'8W555 	*bowPPP*bowPPP 	*bovxPPP*bovwOOO ##$>?? 	1 	1IIgx000	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1))'6::;;;;;s   GGGc                    t           j                            | j                  }|                    ddd           |                    dd           |                    ddd           |                     t          |                    d                    g d           | 	                    t          |j        d           dS )	r   r]   r   ro   r   r   r   r   N)r   r   r_   rH   rt   r`   rI   r   r   rO   r   rc   s     r   r   zHtdigestFileTest.test_03_usersd  s     ,,T^<<
'222
		'7###
'222 1 1224a4a4abbb)RXq11111r   c           	      x   t           j                            | j                  }|                     t
          |j        ddd           |                     t
          |j        ddd           |                     |                    ddd          d           t          dd          D ]o}t          |          }| 
                    |                    d|z   dd|z                        |                     |                    d|z   dd          d	           p|                     t
          |j        dd           d|_        | 
                    |                    d
d                     |                     |                    dd          d           |                     dgdz            5  | 
                    |                    d
dd                     |                     |                    d
dd                     ddd           n# 1 swxY w Y   |                     t          |j        ddd           dS )r   r   r   ro   r5   r]   Nr   rq   Fr[   r   r   r   r{   r^   )r   r   r_   rH   rO   r   rw   assertIsr   r   rK   r  rM   r   rL   rb   r   s      r   r   z'HtdigestFileTest.test_04_check_passwordn  sZ    ,,T^<<)R%67GLLL)R%67KKKb''AA4HHH! 	P 	PAAAOOB--fQhJJKKKMM"++F1HgwGGOOOO 	)R%6III"))'7;;<<<b''994@@@ ##%?$@$BCC 	C 	COOBIIgw@@AAARYYwAABBB	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	C
 	*b&7'6RRRRRs   +AHHHc                 L   |                                  }t          |d           t          |d           t          j        |          }|                     |                                d           |                    ddd           |                                 |                     |                                d           t          || j	                   |                                 |                     |                                | j	                   |                    ddd	           |
                                 |                     |                                | j	                   t          j                    }|                     t          |j
                   |                     t          |j                   t          j                    }|
                    |           |                     |                                | j	                   t          |           t          |d           |                     d
          5  |
                    d           ddd           n# 1 swxY w Y   |                     |                                d           dS )r   r%   r   r   r[   r   r   s-   user1:realm:2a6cf53e7d8f8cf39d946dc880b14128
r]   ro   z!load\(force=False\) is deprecatedF)forceN)rG   r   r   r   r   rI   rJ   rt   r   rH   r   rO   r   r   rM   r   s        r   r   zHtdigestFileTest.test_05_load  su    {{}}rD!$$$ &&--- 	'222
)Z[[[ 	t~&&&
888 	'222
			888  "",000,(:;;;  ""
888 	T"""r##$HII 	! 	!GG%G   	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	!-----s   I11I58I5c                 x   |                                  }t          || j                   t          j        |          }|                    dd           |                    dd           |                                 |                     t          |          | j	                   t          j                    }|
                    ddd           |                     t          |j                   |                    |           |                     t          |          |                                           dS )r   r[   r   r\   r   N)rG   r   rH   r   r   r`   r   rI   r   ra   rt   rO   r   rJ   r   s       r   r   zHtdigestFileTest.test_06_save  s    {{}}t~&&& && 			'7###
		'7###
			$888  ""
'222,000 	$88888r   c                    t           j                            | j                  }|                     |                    d          d           |                     |                                dg           |                     |                    d          d           |                     |                                g            |                     |                                d           dS )ztest realms() & delete_realm()rC   r   r      r   N)r   r   r_   rH   rI   delete_realmrealmsrJ   rc   s     r   test_07_realmszHtdigestFileTest.test_07_realms  s     ,,T^<<--q111wi000111555b)))-----r   c                    t           j                            | j                  }|                     |                    dd          d           |                     |                    dd          d           |                     |                    dd          d           |                     d          5  |                     |                    dd          d           ddd           dS # 1 swxY w Y   dS )	r   r   r    a500bb8c02f6a9170ae46af10c898744r    ab7b5d5f28ccc7666315f508c7358519r]   Nr   )r   r   r_   rH   rI   r   rM   r   rc   s     r   r   z!HtdigestFileTest.test_08_get_hash  s:    ,,T^<<Wg668Z[[[Wg668Z[[[Wg66===##$<== 	\ 	\RWWWg668Z[[[	\ 	\ 	\ 	\ 	\ 	\ 	\ 	\ 	\ 	\ 	\ 	\ 	\ 	\ 	\ 	\ 	\ 	\s   8+C00C47C4c                    |                      t          t          j        d           t          j                            | j        dd          }|                     |                                t          d          g           |                     |	                    t          d                    t          d          g           t          j                            | j
        dd          }|                     |                                t          d          g           |                     |	                    t          d                    t          d          g           d	S )
ztest encoding parameterr   r   r!   Tr   u   realmær   r   N)rO   rb   r   r   r_   r   rI   r  r   r   r   rc   s     r   test_09_encodingsz"HtdigestFileTest.test_09_encodings  s&    	*f&9HMMM  ,,T-@7cg,hh-(8(8&:;;;!M"2"233q5HIII  ,,T-BYgk,ll-(8(8&:;;;!M"2"233q5HIIIIIr   c                    t           j                            | j                  }|                     |                                | j                   t          j                    }|                     |                                d           dS )ztest to_string()r   N)r   r   r_   rH   rI   rJ   rc   s     r   test_10_to_stringz"HtdigestFileTest.test_10_to_string  r   r   c                     |                      t          t          j        j        d           |                      t          t          j        j        d           d S )Ns   realm:user1:pass1:other
rz   )rO   rb   r   r   r_   r   s    r   r   z"HtdigestFileTest.test_11_malformed  sV    *f&9&E(	* 	* 	**f&9&E	 	 	 	 	r   N)r   r   r   r   r   rH   ra   ru   r   r   rT   rd   ri   rx   r   r   r   r   r  r   r  r  r   r   r   r   r   r      s       !!&CICICI VNO> > >$C C C9 9 9< < <82 2 2S S S2'. '. '.R9 9 9,	. 	. 	.\ \ \J J J	. 	. 	.    r   r   )r   rV   ))r   
__future__r   loggingr   r   r'   passlibr   r   passlib.excr   passlib.utils.compatr   passlib.tests.backportsr	   passlib.tests.utilsr
   r   r   r   r   passlib.utilsr   passlib.utils.handlersr   r   r:   r   environgetr)   r3   r7   r=   HAVE_HTPASSWDr   r   r   r?   r   r   r   r   <module>r(     s   F F & % % % % %       				     % $ $ $ $ $ $ $ + + + + + + ' ' ' ' ' ' , , , , , , R R R R R R R R R R R R " " " " " " " " " " " " : : : : : :i# # # # 
;<<J
       " '7&6&8&8 ##++M;]^^ ]O ]O ]O ]O ]Ox ]O ]O ]OLy y y y yx y y y y yr   