a
    Oʞh$                     @   s   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	m
Z
 ddlmZmZmZmZmZ ddlm  mZ ddlmZ eeZG dd	 d	ejZG d
d dejZdZG dd deZdS )z>tests for passlib.hash -- (c) Assurance Technologies 2003-2009    )with_statement)	getLoggerN)hashregistryexc)register_crypt_handlerregister_crypt_handler_pathget_crypt_handlerlist_crypt_handlers_unload_handler_name)TestCasec                   @   s   e Zd Zd ZdS )dummy_0N__name__
__module____qualname__name r   r   V/wd/webapps/venvs/v2025_4um/lib/python3.9/site-packages/passlib/tests/test_registry.pyr      s   r   c                   @   s   e Zd ZdZdS )alt_dummy_0r   Nr   r   r   r   r   r      s   r      c                       sP   e Zd ZdZ fddZdd Zdd Zdd	 Zd
d Zdd Z	dd Z
  ZS )RegistryTestzpasslib.registryc                    s>   t t|   ttjttj  fdd}| | d S )Nc                      s0   t j  t j t j  t j  d S )N)r   
_locationsclearupdate	_handlersr   handlers	locationsr   r   restore0   s    

z#RegistryTest.setUp.<locals>.restore)superr   setUpdictr   r   r   Z
addCleanup)selfr   	__class__r   r   r!   *   s
    

zRegistryTest.setUpc                 C   s   t t tt | tttd ttdd}t }|t_| tj| |du rdt`| 	t
td n|t_| tj| G dd dtj}|t_| td| | tttd| dS )ztest passlib.hash proxy objectZfooey
__loader__Nc                   @   s   e Zd ZdZdS )z-RegistryTest.test_hash_proxy.<locals>.dummy_1dummy_1Nr   r   r   r   r   r'   P   s   r'   Zdummy_1x)dirr   reprassertRaisesAttributeErrorgetattrobjectr&   assertIsassertFalsehasattruhStaticHandlerr'   r	   
ValueErrorsetattr)r#   oldtestr'   r   r   r   test_hash_proxy7   s     zRegistryTest.test_hash_proxyc                 C   s  t j}| d|v | ttd | ttdd | ttdt	d  | ttdt	d  tdt	 | dt
 v  | dt
ddv | tjt | dt
ddv  td tdt	d  | tjt td tdt	 | ttd td	t	 | ttd	 td	 tjd
d tdd
 t & tddt td}W d   n1 s^0    Y  ddlm} | ||j dS )z"test register_crypt_handler_path()r   z.test_registryz:dummy_0:xxxz:dummy_0.xxxT)Zloaded_onlyz:alt_dummy_0dummy_xr   z passlib.tests._test_bad_registerNZ	dummy_badignoreZ
xxxxxxxxxxr   )_test_bad_register)r   r   
assertTruer/   r0   r   r*   r3   r   r   r
   r.   r   unload_handler_namer   	TypeErrorr	   sysmodulespopwarningscatch_warningsfilterwarningsDeprecationWarningZpasslib.testsr:   Zalt_dummy_bad)r#   pathshZtbrr   r   r    test_register_crypt_handler_pathX   sB    




(z-RegistryTest.test_register_crypt_handler_pathc              
   C   sP  |  tti  |  tttdtjftdd |  tttdtjftdd |  tttdtjftdd |  tttdtjftdd |  tttdtjftdd G dd	 d	tj}G d
d dtj}| d	t	 v t| t| | 
td	| |  tt| | 
td	| t|dd | 
td	| | d	t	 v  dS )ztest register_crypt_handler()xN)r   ZAB_CDzab-cdZab__cddefaultc                   @   s   e Zd ZdZdS )z9RegistryTest.test_register_crypt_handler.<locals>.dummy_1r'   Nr   r   r   r   r   r'      s   r'   c                   @   s   e Zd ZdZdS )z:RegistryTest.test_register_crypt_handler.<locals>.dummy_1br'   Nr   r   r   r   r   dummy_1b   s   rJ   T)force)r*   r=   r   r3   typer1   r2   r"   r;   r
   r.   r	   KeyError)r#   r'   rJ   r   r   r   test_register_crypt_handler   s"         z(RegistryTest.test_register_crypt_handlerc                 C   s   G dd dt j}| ttd | tddd t| | td| t H t	ddt
 | td| tdt | tdt W d   n1 s0    Y  d	d
lm} d|jd< dD ]$}| tt| | t|dd qdS )ztest get_crypt_handler()c                   @   s   e Zd ZdZdS )z4RegistryTest.test_get_crypt_handler.<locals>.dummy_1r'   Nr   r   r   r   r   r'      s   r'   Nr9   zMhandler names should be lower-case, and use underscores instead of hyphens:.*zDUMMY-1r   zDUMMY-0r   )r   dummy_fake)rP   __package__)r1   r2   r*   rM   r	   r.   r   rA   rB   rC   UserWarningr   r   r   passlibr   __dict__)r#   r'   r   r   r   r   r   test_get_crypt_handler   s    

.
z#RegistryTest.test_get_crypt_handlerc                 C   sD   ddl m} dtjd< | D ]}| |dd|  qtd dS )ztest list_crypt_handlers()r   r
   rO   rP   _z%r: N)passlib.registryr
   r   rT   r/   
startswithr<   )r#   r
   r   r   r   r   test_list_crypt_handlers   s
    

z%RegistryTest.test_list_crypt_handlersc              	   C   s   ddl m} ddlm}m} | D ]b}|drD|dd | v rDq"|dv rNq"z| || W q" tjy   ||v r|Y q" Y q"0 q"dS )z-verify we have tests for all builtin handlersr   rV   )get_handler_caseconditionally_available_hashesZldap_   N)Zroundup_plaintext)	rX   r
   Zpasslib.tests.test_handlersr[   r\   rY   r;   r   ZMissingBackendError)r#   r
   r[   r\   r   r   r   r   test_handlers   s    
zRegistryTest.test_handlers)r   r   r   ZdescriptionPrefixr!   r7   rG   rN   rU   rZ   r^   __classcell__r   r   r$   r   r   &   s   !0
r   )__doc__
__future__r   loggingr   rA   r>   rS   r   r   r   rX   r   r   r	   r
   r   r<   Zpasslib.utils.handlersutilsr   r1   Zpasslib.tests.utilsr   r   logr2   r   r   r8   r   r   r   r   r   <module>   s   	