o
    5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   o/var/www/html/construction_image-detection-poc/venv/lib/python3.10/site-packages/passlib/tests/test_registry.pyr          r   c                   @      e Zd ZdZdS )alt_dummy_0r   Nr   r   r   r   r   r      r   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   
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 r2t`| 	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 objectfooey
__loader__Nc                   @   r   )z-RegistryTest.test_hash_proxy.<locals>.dummy_1dummy_1Nr   r   r   r   r   r+   P   r   r+   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 sw   Y  ddlm} | ||j dS )z"test register_crypt_handler_path()r   z.test_registryz:dummy_0:xxxz:dummy_0.xxxT)loaded_onlyz:alt_dummy_0dummy_xr   z passlib.tests._test_bad_registerN	dummy_badignore
xxxxxxxxxxr   )_test_bad_register)r   r   
assertTruer4   r5   r   r/   r8   r   r   r
   r3   r   unload_handler_namer   	TypeErrorr	   sysmodulespopwarningscatch_warningsfilterwarningsDeprecationWarningpasslib.testsrB   alt_dummy_bad)r&   pathshtbrr   r   r    test_register_crypt_handler_pathX   sD   





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   AB_CDzab-cdab__cddefaultc                   @   r   )z9RegistryTest.test_register_crypt_handler.<locals>.dummy_1r+   Nr   r   r   r   r   r+      r   r+   c                   @   r   )z:RegistryTest.test_register_crypt_handler.<locals>.dummy_1br+   Nr   r   r   r   r   dummy_1b   r   rW   T)force)r/   rE   r   r8   typer6   r7   r$   rC   r
   r3   r	   KeyError)r&   r+   rW   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 $ t	ddt
 | td| tdt | tdt W d   n1 sPw   Y  d	d
lm} d|jd< dD ]}| tt| | t|dd qbdS )ztest get_crypt_handler()c                   @   r   )z4RegistryTest.test_get_crypt_handler.<locals>.dummy_1r+   Nr   r   r   r   r   r+      r   r+   Nr@   zMhandler names should be lower-case, and use underscores instead of hyphens:.*zDUMMY-1r   zDUMMY-0r   )r   dummy_fake)r]   __package__)r6   r7   r/   rZ   r	   r3   r   rI   rJ   rK   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
   r\   r]   _z%r: N)passlib.registryr
   r   ra   r4   
startswithrD   )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 ].}|dr"|dd | v r"q|dv r'qz	| || W q tjy?   ||v r>Y q w dS )z-verify we have tests for all builtin handlersr   rc   )get_handler_caseconditionally_available_hashesldap_   N)roundup_plaintext)	re   r
   passlib.tests.test_handlersrh   ri   rf   rC   r   MissingBackendError)r&   r
   rh   ri   r   r   r   r   test_handlers   s   
zRegistryTest.test_handlers)r   r   r   descriptionPrefixr#   r<   rR   r[   rb   rg   ro   __classcell__r   r   r'   r   r   &   s    !0
r   )__doc__
__future__r   loggingr   rI   rF   r`   r   r   r   re   r   r   r	   r
   r   rD   passlib.utils.handlersutilsr   r6   passlib.tests.utilsr   r   logr7   r   r   r>   r   r   r   r   r   <module>   s    	