a fŸWc$ã@s¾dZddlmZddlmZddlZddlZddlmZm Z m Z ddl m Z m Z mZmZmZddlmmZddlmZeeƒZGdd „d ejƒZGd d „d ejƒZd ZGd d„deƒZdS)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@seZdZdZdS)Údummy_0N©Ú__name__Ú __module__Ú __qualname__Úname©rrú?/usr/lib/python3.9/site-packages/passlib/tests/test_registry.pyr sr c@seZdZdZdS)Ú alt_dummy_0r NrrrrrrsrécsPeZdZdZ‡fdd„Zdd„Zdd„Zdd „Zd d „Zd d „Z dd„Z ‡Z S)Ú RegistryTestzpasslib.registrycs>tt|ƒ ¡ttjƒ‰ttjƒ‰‡‡fdd„}| |¡dS)Ncs0tj ¡tj ˆ¡tj ¡tj ˆ¡dS)N)rÚ _locationsÚclearÚupdateÚ _handlersr©ÚhandlersZ locationsrrÚrestore0s   z#RegistryTest.setUp..restore)ÚsuperrÚsetUpÚdictrrrZ addCleanup)Úselfr©Ú __class__rrr *s   zRegistryTest.setUpcCs¶ttƒttƒ| tttd¡ttddƒ}tƒ}|t_| tj|¡|durdt`|  t tdƒ¡n|t_| tj|¡Gdd„dt j ƒ}|t_ | tdƒ|¡| tttd|¡dS)ztest passlib.hash proxy objectZfooeyÚ __loader__Nc@seZdZdZdS)z-RegistryTest.test_hash_proxy..dummy_1Údummy_1Nrrrrrr&Psr&Zdummy_1x)ÚdirrÚreprÚ assertRaisesÚAttributeErrorÚgetattrÚobjectr%ÚassertIsÚ assertFalseÚhasattrÚuhÚ StaticHandlerr&r Ú ValueErrorÚsetattr)r"ÚoldÚtestr&rrrÚtest_hash_proxy7s  zRegistryTest.test_hash_proxycCs†tj}| d|v¡| ttdƒ¡| ttdd¡| ttdt d¡| ttdt d¡tdt ƒ| dt ƒv¡| dt ddv¡|  tj t ¡| dt ddv¡t dƒtdt dƒ|  tj t¡t dƒtdt ƒ| ttd¡td t ƒ| ttd ¡t d ƒtj d d ¡td d ƒt ¡&t d dt¡td ƒ}Wd ƒn1s^0Yddlm}|  ||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_xrz passlib.tests._test_bad_registerNZ dummy_badÚignoreZ xxxxxxxxxxr)Ú_test_bad_register)rrÚ assertTruer.r/rr)r2rrr r-r Úunload_handler_namerÚ TypeErrorr ÚsysÚmodulesÚpopÚwarningsÚcatch_warningsÚfilterwarningsÚDeprecationWarningZ passlib.testsr9Z alt_dummy_bad)r"ÚpathsÚhZtbrrrrÚ test_register_crypt_handler_pathXsBÿÿÿ     ( z-RegistryTest.test_register_crypt_handler_pathc CsP| tti¡| tttdtjftddƒ¡| tttdtjftddƒ¡| tttdtjftddƒ¡| tttdtjftddƒ¡| tttdtjftddƒ¡Gdd „d tjƒ}Gd d „d tjƒ}| d t ƒv¡t|ƒt|ƒ|  t d ƒ|¡| t t|¡|  t d ƒ|¡t|d d |  t d ƒ|¡| d t ƒv¡dS)ztest register_crypt_handler()ÚxN)rZAB_CDzab-cdZab__cdÚdefaultc@seZdZdZdS)z9RegistryTest.test_register_crypt_handler..dummy_1r&Nrrrrrr&“sr&c@seZdZdZdS)z:RegistryTest.test_register_crypt_handler..dummy_1br&NrrrrrÚdummy_1b–srIT)Úforce) r)r<rr2Útyper0r1r!r:r r-r ÚKeyError)r"r&rIrrrÚtest_register_crypt_handlerˆs"      z(RegistryTest.test_register_crypt_handlercCsîGdd„dtjƒ}| ttd¡| tddƒd¡t|ƒ| tdƒ|¡t ¡Ht  ddt ¡| tdƒ|¡t dt ƒ| tdƒt ¡Wdƒn1s 0Yd d lm}d |jd <d D]$}| tt|¡| t|dƒd¡qÄdS)ztest get_crypt_handler()c@seZdZdZdS)z4RegistryTest.test_get_crypt_handler..dummy_1r&Nrrrrrr&ªsr&Nr8zMhandler names should be lower-case, and use underscores instead of hyphens:.*zDUMMY-1r zDUMMY-0r)rÚdummyÚ_fake)rOÚ __package__)r0r1r)rLr r-rr@rArBÚ UserWarningrrr ÚpasslibrÚ__dict__)r"r&rrrrrÚtest_get_crypt_handler§s  .  z#RegistryTest.test_get_crypt_handlercCsDddlm}dtjd<|ƒD]}| | d¡d|¡qtdƒdS)ztest list_crypt_handlers()r©r rNrOÚ_z%r: N)Úpasslib.registryr rrSr.Ú startswithr;)r"r rrrrÚtest_list_crypt_handlersÆs    z%RegistryTest.test_list_crypt_handlersc CsŠddlm}ddlm}m}|ƒD]b}| d¡rD|dd…|ƒvrDq"|dvrNq"z| ||ƒ¡Wq"tjy‚||vr|Yq"‚Yq"0q"dS)z-verify we have tests for all builtin handlersrrU)Úget_handler_caseÚconditionally_available_hashesZldap_éN)Zroundup_plaintext) rWr Zpasslib.tests.test_handlersrZr[rXr:rZMissingBackendError)r"r rZr[rrrrÚ test_handlersÐs  zRegistryTest.test_handlers) rrrZdescriptionPrefixr r6rFrMrTrYr]Ú __classcell__rrr#rr&s !0 r)Ú__doc__Z __future__rZloggingrr@r=rRrrrrWrrr r r r;Zpasslib.utils.handlersZutilsrr0Zpasslib.tests.utilsr rÚlogr1r rr7rrrrrÚs