관리-도구
편집 파일: test_context_deprecated.cpython-39.pyc
a ����f�Wcbr����������������������@���s��d�Z�ddlmZ�ddlmZ�ddlZddlZzddlmZ�W�n�e yR���dZY�n0�ddl mZ�ddlm Z mZmZ�ddlmZmZ�ddlm��mZ�dd lmZmZ�dd lmZmZmZ�ee �Z!G�dd��de�Z"G�d d��de�Z#G�dd��dej$�Z%G�dd��de�Z&dS�)a��tests for passlib.context this file is a clone of the 1.5 test_context.py, containing the tests using the legacy CryptPolicy api. it's being preserved here to ensure the old api doesn't break (until Passlib 1.8, when this and the legacy api will be removed). �����)�with_statement)� getLoggerN)�resource_filename)�hash)�CryptContext�CryptPolicy�LazyCryptContext)�to_bytes� to_unicode)�TestCase�set_file)�register_crypt_handler_path�_has_crypt_handler�_unload_handler_namec���������������� ���@���s ��e�Zd�ZdZdZdZej�ej� ej� e�d��Zej� e�sLerLedd�Ze�d�sZJ��eg�d�dd d ddd d�Zddd d ddd d�Zeejejejejgdd d ddd d�ZdZeddddd�Zeg�d�dd dddddd�Zedd�Zeg�d�dd dddddd�ZdZedgd ddd d�Zed�Z e�!��Z"e"j#dgdd gd!��e�!��Z$e$�#dd"d#���e�!��Z%e%�#dgdd gd!���d$d%��Z&d&d'��Z'd(d)��Z(d*d+��Z)d,d-��Z*d.d/��Z+d0d1��Z,d2d3��Z-d4d5��Z.d6d7��Z/d8d9��Z0d:d;��Z1d<d=��Z2d>d?��Z3d@dA��Z4dBdC��Z5dDdE��Z6dFdG��Z7dHS�)I�CryptPolicyTestztest CryptPolicy objectr���z�[passlib] schemes = des_crypt, md5_crypt, bsdi_crypt, sha512_crypt default = md5_crypt all.vary_rounds = 10%% bsdi_crypt.max_rounds = 30000 bsdi_crypt.default_rounds = 25000 sha512_crypt.max_rounds = 50000 sha512_crypt.min_rounds = 40000 zsample_config_1s.cfgz passlib.testsz[passlib] schemes�� des_crypt� md5_crypt� bsdi_crypt�sha512_cryptr���皙�����?�0u��i�a���P����@���)�schemes�default�all__vary_rounds�bsdi_crypt__max_rounds�bsdi_crypt__default_rounds�sha512_crypt__max_rounds�sha512_crypt__min_roundsz.des_crypt, md5_crypt, bsdi_crypt, sha512_crypt)r���r���zall.vary_roundszbsdi_crypt.max_roundszbsdi_crypt.default_roundszsha512_crypt.max_roundszsha512_crypt.min_roundsz�[passlib] bsdi_crypt.min_rounds = 29000 bsdi_crypt.max_rounds = 35000 bsdi_crypt.default_rounds = 31000 sha512_crypt.min_rounds = 45000 �Hq��鸈���y���ȯ��)�bsdi_crypt__min_roundsr���r���r ���)r���r���r���r%���r���r���r���r ���r����r���z� [passlib] schemes = sha512_crypt all.vary_rounds = 10%% default.sha512_crypt.max_rounds = 20000 admin.all.vary_rounds = 5%% admin.sha512_crypt.max_rounds = 40000 � N��皙�����?)r���r���r���Zadmin__all__vary_roundsZadmin__sha512_crypt__max_roundszJdeprecated = des_crypt admin__context__deprecated = des_crypt, bsdi_crypt r���r���)� deprecatedZadmin__context__deprecatedzdes_crypt, bsdi_crypt)r)���zadmin.context.deprecatedc�����������������C���s>���t��|���t�dd��t�dd��t�dd��t�dd��d�S�)N�ignorez)The CryptPolicy class has been deprecated�,the method.*hash_needs_update.*is deprecatedz The 'all' scheme is deprecated.*zbsdi_crypt rounds should be odd�r����setUp�warnings�filterwarnings��self��r2����I/usr/lib/python3.9/site-packages/passlib/tests/test_context_deprecated.pyr-�������s���� ��zCryptPolicyTest.setUpc�����������������C���s��t�f�i�|�j��}|��|���|�j��t�|�j�}|��|���|�j��|��tt�i�i���|�jtt�i�dd��|�jtt�g�d�dd��G�dd��dtj�}|�jtt�|gd��|�jtt�tjgd��G�d d ��d tj�}|�jt t�||gd��|�jt t�dgdgd ��|�jt t�dgdd��dS�)ztest CryptPolicy() constructor����)Zdummyr���r���)r���Z bad__key__bsdi_crypt__max_roundsc�������������������@���s���e�Zd�ZdZdS�)z5CryptPolicyTest.test_00_constructor.<locals>.namelessN��__name__� __module__�__qualname__�namer2���r2���r2���r3����nameless����s���r:����r���c�������������������@���s���e�Zd�ZdZdS�)z4CryptPolicyTest.test_00_constructor.<locals>.dummy_1�dummy_1Nr5���r2���r2���r2���r3���r<�������s���r<���r���r����r���r)����r���r���N) r����sample_config_1pd�assertEqual�to_dict�assertRaises� TypeError�uh� StaticHandler� ValueError�KeyError)r1����policyr:���r<���r2���r2���r3����test_00_constructor����s.���� ���z#CryptPolicyTest.test_00_constructorc�����������������C���s:���|�j�}t�|�}|��|���|�j��|��ttj|d���dS�)z(test CryptPolicy.from_path() constructorZxxxN)�sample_config_1s_pathr���� from_pathr@���rA���r?���rB����EnvironmentError)r1����pathrH���r2���r2���r3����test_01_from_path_simple��s���� z(CryptPolicyTest.test_01_from_path_simplec�����������������C���s����|�����}t||�j��t�|�}|��|���|�j��t||�j�dd���t�|�}|��|���|�j��t |�jddd�}t||��tj|dd�}|��|���|�j��dS�)z7test CryptPolicy.from_path() constructor with encodings� � �utf-16�utf-8�Zsource_encoding��encodingN) Zmktempr����sample_config_1sr���rK���r@���rA���r?����replacer ���)r1���rM���rH����uc2r2���r2���r3����test_01_from_path��s���� z!CryptPolicyTest.test_01_from_pathc�����������������C���s����t��|�j�}|��|���|�j��t��|�j�dd��}|��|���|�j��t|�j�}t��|�}|��|���|�j��t|�jddd�}t�j|dd�}|��|���|�j��t��|�j �}|��|���|�j ��dS�)z*test CryptPolicy.from_string() constructorrO���rP���rQ���rR���rS���rT���N)r����from_stringrV���r@���rA���r?���rW���r ���r ����sample_config_4s�sample_config_4pd)r1���rH����datarX���r2���r2���r3����test_02_from_string"��s����� z#CryptPolicyTest.test_02_from_stringc�����������������C���s����t��|�j�}|��|���|�j��t��|�j�}|��|���|�j��t��|�j����}|��|���|�j��t��|�}|��||��|�� t t�jd��|�� t t�jg���dS�)z*test CryptPolicy.from_source() constructorr4���N)r���Zfrom_sourcerJ���r@���rA���r?���rV����copy�assertIsrB���rC���)r1���rH����p2r2���r2���r3����test_03_from_source;��s���� z#CryptPolicyTest.test_03_from_sourcec�����������������C���s\���|���ttjg���t�|�jg�}|��|���|�j��t�|�j|�j |�j g�}|��|���|�j��dS�)z+test CryptPolicy.from_sources() constructorN)rB���rF���r���Zfrom_sourcesrV���r@���rA���r?���rJ����sample_config_2s�sample_config_3pd�sample_config_123pd)r1���rH���r2���r2���r3����test_04_from_sourcesQ��s������z$CryptPolicyTest.test_04_from_sourcesc�����������������C���sz���t�f�i�|�j��}|jf�i�|�j��}|��|���|�j��|jf�i�|�j��}|��|���|�j��|�|�j�}|��|���|�j��dS�)z&test CryptPolicy.replace() constructorN) r���r?���rW����sample_config_2pdr@���rA����sample_config_12pdrd���re���)r1����p1ra���Zp2b�p3r2���r2���r3����test_05_replaced��s����zCryptPolicyTest.test_05_replacec�����������������C���sB���|�j�ttdgdd��|�j�ttdgdd��|�j�ttdgdgd��dS�)z!test CryptPolicy() forbidden kwdsr����xx)r���Zdes_crypt__salt)r���Z all__saltr���)r���Zuser__context__schemesN)rB���rG���r���r0���r2���r2���r3����test_06_forbiddenu��s�������z!CryptPolicyTest.test_06_forbiddenc�����������������C���sB���t�f�i�|�j��}|��|�����t�f�i�|�j��}|��|������dS�)ztest has_schemes() methodN)r���r?���� assertTrueZhas_schemesrd���)r1���ri���rj���r2���r2���r3����test_10_has_schemes���s����z#CryptPolicyTest.test_10_has_schemesc�����������������C���sV���t�f�i�|�j��}|�jd�}|��t|����|��t�f�i�|�j��}|��t|����g���dS�)ztest iter_handlers() methodr���N)r���r?����sample_config_1prdr@����list� iter_handlersrd���)r1���ri����srj���r2���r2���r3����test_11_iter_handlers���s ���� z%CryptPolicyTest.test_11_iter_handlersc�����������������C���s`���t�f�i�|�j��}|��|�d�tj��|��|�d�d��|�jt|jddd��|��|���tj��dS�)ztest get_handler() methodr����sha256_cryptNT��required) r���r?���r`����get_handlerr���r���rB���rG���r���)r1���ri���r2���r2���r3����test_12_get_handler���s ����z#CryptPolicyTest.test_12_get_handlerc�������������� ���C���s����t�f�i�|�j��}|��|�d�tddddd���|��|�d�tddd d ���t��|�j�}|��|�d�tddd���|��|�dd �tddd���|��|�dd�tddd���dS�)ztest get_options() methodr���r���r!���r"���r#���)�vary_rounds� min_rounds� max_roundsZdefault_roundsr���r$���r���)rz���r{���r|���r'���)rz���r|����user�adminr(���r���N)r���rh���r@���Zget_options�dictrZ���r[���)r1���Zp12Zp4r2���r2���r3����test_13_get_options���s2���������z#CryptPolicyTest.test_13_get_optionsc�����������������C���s*��t�f�i�|�j��}t�f�i�|�j��}|��|�d���|��|�tj���|��|�d���|��|�d���|��|�tj���|��|�d���|��|�dd���|��|�dd���|��|�dd���|��|�dd���t�ddgdgdgd�}|��|�d���|��|�d���|��|�dd���|��|�dd���dS�) z#test handler_is_deprecated() methodr���r���r}���r���r~���r���)r���r)���Zuser__context__deprecatedN)r���r?����sample_config_5pd�assertFalse�handler_is_deprecatedr���r���rn���)r1����pa�pbZpcr2���r2���r3����test_14_handler_is_deprecated���s*�����z-CryptPolicyTest.test_14_handler_is_deprecatedc�����������������C���sh���t�jdtd��t��}|��|���d��|��|�d�d��|jdd�}|��|���d��|��|�d�d��dS�)z!test get_min_verify_time() methodr*���)�categoryr���r~���r���)Zmin_verify_timeN)r.���r/����DeprecationWarningr���r@���Zget_min_verify_timerW���)r1���r����r����r2���r2���r3����test_15_min_verify_time���s����z'CryptPolicyTest.test_15_min_verify_timec�����������������C���s^���t�f�i�|�j��}|��t|����|�j��|��t|jdd��|�j��|��t|jdd��|�j��dS�)ztest iter_config() methodT��resolve)ZiniN)r���r����r@���r���Ziter_config�sample_config_5prd�sample_config_5pid�r1���Zp5r2���r2���r3����test_20_iter_config��s����z#CryptPolicyTest.test_20_iter_configc�����������������C���s<���t�f�i�|�j��}|��|���|�j��|��|jdd�|�j��dS�)ztest to_dict() methodTr����N)r���r����r@���rA���r����r����r2���r2���r3����test_21_to_dict ��s����zCryptPolicyTest.test_21_to_dictc�����������������C���sP���t�f�i�|�j��}|���}t��|�}|��|���|�j��|jdd�}|��|t��dS�)ztest to_string() methodzlatin-1rT���N)r���r����Z to_stringrZ���r@���rA���ZassertIsInstance�bytes)r1���r����rs���r����r2���r2���r3����test_22_to_string��s���� z!CryptPolicyTest.test_22_to_stringN)8r6���r7���r8����__doc__�descriptionPrefixrV����osrM����abspath�join�dirname�__file__rJ����existsr���� startswithr���r?���Zsample_config_1pidr���r���r���r���r���rp���rc���rg���rh���rd���re���r[���r\���Zsample_config_5sr_���r�����updater����r����r-���rI���rN���rY���r^���rb���rf���rk���rm���ro���rt���ry���r����r����r����r����r����r����r2���r2���r2���r3���r���%���s���� ������ ��� � ��� ( 'r���c���������������� ���@���sh���e�Zd�ZdZdZdd��Zdd��Zdd��Zd d ��Ze g�d�dgd ddddddddd�Z dd��Zdd��ZdS�)�CryptContextTestztest CryptContext classr���c�����������������C���s>���t��|���t�dd��t�dd��t�dd��t�dd��d�S�)Nr*���z3CryptContext\(\)\.replace\(\) has been deprecated.*z9The CryptContext ``policy`` keyword has been deprecated.*�=.*(CryptPolicy|context\.policy).*(has|have) been deprecated.*r+���r,���r0���r2���r2���r3���r-���$��s���� ���zCryptContextTest.setUpc�����������������C���s��t�tjtjtjg�}|j���\}}}|��|tj��|��|tj��|��|tj��t�g�d��}|j���\}}}|��|tj��|��|tj��|��|tj��|j}t�|d�}|��|� ��|� ����t�|dd�}|�� |� ��|� ����|��|� ��tg�d�dd���|��t t|dd��|�jt t�dd��dS�) ztest constructor�r���r���r���)rH���r���)rH���r���r>���rH���N�x)r���r���r���r���r���rH���rr���r`���r@���rA���ZassertNotEqualr���rB���rC����setattr)r1����cc�c�b�arH���r2���r2���r3���rI���1��s(���� �z$CryptContextTest.test_00_constructorc�����������������C���sd���t�g�d��}|��|j���tj��|���}|��||��|jdd�}|��||��|��|j���tj��dS�)ztest replace()r����r���r&���N) r���r`���rH���rx���r���r���rW���ZassertIsNotr���)r1���r�����cc2Zcc3r2���r2���r3����test_01_replaceN��s����z CryptContextTest.test_01_replacec�����������������C���s����t���}|�jt|jddd��|��t|jd��|��t|jdd��t�dg�}tg�d�}||_|�jt|jddd��|��t|jd��|��t|jdd��dS�)ztest no handlersr���Trv���Zsecretr���r;���N)r���rB���rG���Zidentifyr���Zverifyr���rH���)r1���r�����pr2���r2���r3����test_02_no_handlers_��s���� z$CryptContextTest.test_02_no_handlers)r���r���Zphpassr���ru���r���ru�����������r���i���i����H����)r���r)���r���r���r���Zbsdi_crypt__vary_roundsZsha256_crypt__max_roundsZsha256_crypt__min_roundsZsha256_crypt__default_roundsZ phpass__identZphpass__default_roundsc�����������������C���st���t�f�i�|�j��}|��|�d���|��|�d���|��|�d���|��|�d���|��|�d���|��|�d���dS�)ztest hash_needs_update() methodZ 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/2hdFpxA3fAN)r����sample_policy_1rn����hash_needs_updater�����r1���r����r2���r2���r3����test_12_hash_needs_update���s����z*CryptContextTest.test_12_hash_needs_updatec�����������������C���sv���t��dd��tdg�}di�fdddifdi�fdi�ffD�] \}}|�jt|j|fi�|���q6tdg�}|��t|jd��dS�) z'test non-string hash values cause errorr*���z0.*needs_update.*'scheme' keyword is deprecated.*r���N�schemer4���r2���Zmysql323)r.���r/���r���rB���rC���r����)r1���r����r����kwdsr����r2���r2���r3����test_30_nonstring_hash���s���� � z'CryptContextTest.test_30_nonstring_hashN) r6���r7���r8���r����r����r-���rI���r����r����r���r����r����r����r2���r2���r2���r3���r���� ��s*��� �r����c�������������������@���s���e�Zd�Zd�ZdS�)�dummy_2Nr5���r2���r2���r2���r3���r�������s���r����c�������������������@���s(���e�Zd�ZdZdd��Zdd��Zdd��ZdS�) �LazyCryptContextTestr���c�����������������C���s:���t��|���td��|��td��t�dd��t�dd��d�S�)Nr����r*���z1CryptContext\(\)\.replace\(\) has been deprecatedr����)r���r-����unload_handler_nameZ addCleanupr.���r/���r0���r2���r2���r3���r-������s���� �zLazyCryptContextTest.setUpc�����������������C���sz���|���td���tdd��ttddg�dgd�}|���tdd���|��|j�d���|��|j� ��ddg��|��tdd���dS�)ztest plain kwdsr�����passlib.tests.test_contextr���)r)���TN) r�����has_crypt_handlerr ���r����iterrn���rH���r����r@���r���r����r2���r2���r3����test_kwd_constructor���s���� z)LazyCryptContextTest.test_kwd_constructorc��������������������s~�������td���tdd��d ��fdd� }t|dd�}����tdd������|j�d������|j���ddg�����tdd���d S�)z0test create_policy() hook, returning CryptPolicyr����r����Fc��������������������s �������|���ttddg�dgd�S�)Nr����r���r=���)rn���r���r����)�flagr0���r2���r3���� create_policy���s���� zELazyCryptContextTest.test_callable_constructor.<locals>.create_policyT)r����r����r���N)F) r����r����r ���r���rn���rH���r����r@���r���)r1���r����r����r2���r0���r3����test_callable_constructor���s���� z.LazyCryptContextTest.test_callable_constructorN)r6���r7���r8���r����r-���r����r����r2���r2���r2���r3���r�������s���r����)'r����Z __future__r���Zloggingr���r����r.���Z pkg_resourcesr����ImportErrorZpasslibr���Zpasslib.contextr���r���r���Z passlib.utilsr ���r ���Zpasslib.utils.handlersZutils�handlersrD���Zpasslib.tests.utilsr���r���Zpasslib.registryr ���r���r����r���r����r6����logr���r����rE���r����r����r2���r2���r2���r3����<module>���s.��� ���~�