%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /lib/python3/dist-packages/twisted/cred/test/__pycache__/
Upload File :
Create Path :
Current File : //lib/python3/dist-packages/twisted/cred/test/__pycache__/test_cred.cpython-312.pyc

�

Ϫ�f�7��`�dZddlmZmZddlmZmZddlmZm	Z	m
Z
mZddlm
Z
ddlmZddlmZddlmZ	dd	lmZeZeddd
d�ZGd�de�ZGd�d�Zee�Gd�dej4��Zej8eee�Gd�de	j:�Zeee�Gd�d��Zeej@�Gd�d��Z!Gd�dejD�Z#Gd�dejD�Z$Gd�dejD�Z%Gd �d!�Z&Gd"�d#�Z'Gd$�d%e'�Z(Gd&�d'e'�Z)Gd(�d)e'e&ejD�Z*Gd*�d+e(e&ejD�Z+Gd,�d-e)e&ejD�Z,Gd.�d/ejD�Z-y
#e$rd
ZY��lwxYw)0z6
Tests for L{twisted.cred}, now with 30% more starch.
�)�hexlify�	unhexlify)�	Interface�implementer)�checkers�credentials�error�portal)�defer)�
components)�Version)�unittest)�cryptN�Twisted��c��eZdZdZy)�	ITestablez2
    An interface for a theoretical protocol.
    N��__name__�
__module__�__qualname__�__doc__���=/usr/lib/python3/dist-packages/twisted/cred/test/test_cred.pyrrs���	rrc�"�eZdZdZd�Zd�Zd�Zy)�
TestAvatarz
    A test avatar.
    c�.�||_d|_d|_y)NF)�name�loggedIn�	loggedOut)�selfr s  r�__init__zTestAvatar.__init__,s����	���
���rc�.�|jrJ�d|_y�NT)r!�r#s r�loginzTestAvatar.login1s���=�=� � ���
rc��d|_yr&)r"r's r�logoutzTestAvatar.logout5s	����rN)rrrrr$r(r*rrrrr's����
�rrc��eZdZdZy)�Testablez-
    A theoretical protocol for testing.
    Nrrrrr,r,9s���	rr,c��eZdZy)�IDerivedCredentialsN�rrrrrrr.r.Es��rr.c��eZdZd�Zd�Zy)�DerivedCredentialsc� �||_||_y�N)�username�password)r#r4r5s   rr$zDerivedCredentials.__init__Ks�� ��
� ��
rc� �||jk(Sr3)r5�r#r5s  r�
checkPasswordz DerivedCredentials.checkPasswordOs���4�=�=�(�(rN)rrrr$r8rrrr1r1Is��!�)rr1c��eZdZdZd�Zd�Zy)�	TestRealmz
    A basic test realm.
    c��i|_yr3)�avatarsr's rr$zTestRealm.__init__Ys	����rc���||jvr|j|}nt|�}||j|<|j�|d|d|�|jfS)Nr)r<rr(r*)r#�avatarId�mind�
interfaces�avatars     r�
requestAvatarzTestRealm.requestAvatar\s]���t�|�|�#��\�\�(�+�F���)�F�%+�D�L�L��"������1�
�}�z�!�}�V�4�f�m�m�D�DrN)rrrrr$rBrrrr:r:Ss����Err:c�4�eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z	y)	�	CredTestsz^
    Tests for the meat of L{twisted.cred} -- realms, portals, avatars, and
    checkers.
    c��t�|_tj|j�|_t	j
�|_|jjdd�|jj|j�y)N�bob�hello)	r:�realmr
�Portalr�'InMemoryUsernamePasswordDatabaseDontUse�checker�addUser�registerCheckerr's r�setUpzCredTests.setUplsY���[��
��m�m�D�J�J�/����G�G�I��������V�X�.����#�#�D�L�L�1rc��tjtjg}|jj	�}|jt
|�t
|��y)z�
        The checkers in a portal can check only certain types of credentials.
        Since this portal has
        L{checkers.InMemoryUsernamePasswordDatabaseDontUse} registered, it
        N)r�IUsernamePassword�IUsernameHashedPasswordr
�listCredentialsInterfaces�assertEqual�sorted)r#�expected�gots   r�test_listCheckerszCredTests.test_listCheckersssE�� �1�1�;�3V�3V�W���k�k�3�3�5��������f�X�&6�7rc��|j|jjtjdd�|t
��}|\}}}|j
|t
�|j|j|�|�d|���|j|jj�|j|jj�|�|j|jj�y)z�
        Calling C{login} on a portal with correct credentials and an interface
        that the portal's realm supports works.
        rFrG� does not implement N)�successResultOfr
r(r�UsernamePasswordrrS�
assertTrue�
providedBy�originalr!r"�r#r(�iface�implr*s     r�test_basicLoginzCredTests.test_basicLogin}s���
�$�$��K�K����,�,�V�X�>��i�
�
��
$���t�V�	
����	�*�����(�(��.�4�&�8L�U�G�0T�U�	
����
�
�.�.�/����D�M�M�3�3�3�4�������
�
�/�/�0rc���|j|jjtdd�|t��}|\}}}|j|t�|j
|j|�|�d|���|j
|jj�|j
|jj�|�|j
|jj�y)z~
        Logging in with correct derived credentials and an interface
        that the portal's realm supports works.
        rFrGrYN)rZr
r(r1rrSr\r]r^r!r"r_s     r�test_derivedInterfacezCredTests.test_derivedInterface�s���
�$�$��K�K���0���B�D�)�T�
��$���t�V�	
����	�*�����(�(��.�4�&�8L�U�G�0T�U�	
����
�
�.�.�/����D�M�M�3�3�3�4�������
�
�/�/�0rc��|j|jjtjdd�|t
��}|j
|�|jtj|j�y)z�
        Calling C{login} with incorrect credentials (in this case a wrong
        password) causes L{error.UnauthorizedLogin} to be raised.
        rFsh3lloN��failureResultOfr
r(rr[rr\rSr	�UnauthorizedLogin�type�r#r(s  r�test_failedLoginPasswordz"CredTests.test_failedLoginPassword��b��
�$�$��K�K����,�,�V�X�>��i�
�
��
	
���������0�0�%�*�*�=rc��|j|jjtjdd�|t
��}|j
|�|jtj|j�y)z�
        Calling C{login} with incorrect credentials (in this case no known
        user) causes L{error.UnauthorizedLogin} to be raised.
        sjayrGNrfrjs  r�test_failedLoginNamezCredTests.test_failedLoginName�rlrN)
rrrrrNrWrbrdrkrnrrrrDrDfs%���
2�8�1�,1�(>�>rrDc�8�eZdZgd�Zd�Zd�Zd�Zd�Zd�Zd�Z	y)	�OnDiskDatabaseTests�)�user1spass1)�user2spass2)�user3spass3c���|j�|_t|jd�5}|jD]\}}|j	|dz|zdz��!	ddd�y#1swYyxYw)N�wb�:�
)�mktemp�dbfile�open�users�write)r#�f�u�ps    rrNzOnDiskDatabaseTests.setUp�sd���k�k�m���
�$�+�+�t�
$�	.���
�
�
.���1�����D��1��u�,�-�
.�	.�	.�	.�s�/A%�%A.c��tjd�|_|jtj
|jjd�y)zg
        A missing db file will cause a permanent rejection of authorization
        attempts.
        ztest_thisbetternoteverexist.db�userN)r�FilePasswordDB�db�assertRaisesr	rh�getUserr's r�test_getUserNonexistentDatabasez3OnDiskDatabaseTests.test_getUserNonexistentDatabase�s7��
�)�)�*J�K������%�1�1�4�7�7�?�?�F�Krc�@�tj|j�|_|jD]k\}}|jt|jj|j��|j|jj|�||f��myr3)
rr�rzr�r|r��KeyErrorr��upperrS�r#rr�s   r�testUserLookupz"OnDiskDatabaseTests.testUserLookup�sp���)�)�$�+�+�6����J�J�	9�D�A�q����h����������C����T�W�W�_�_�Q�/�!�Q��8�	9rc���tj|jd��|_|jD]@\}}|j|jj
|j��||f��By)NF)�
caseSensitive)rr�rzr�r|rSr�r�r�s   r�testCaseInSensitivityz)OnDiskDatabaseTests.testCaseInSensitivity�sZ���)�)�$�+�+�U�K����J�J�	A�D�A�q����T�W�W�_�_�Q�W�W�Y�7�!�Q��@�	Arc	���tj|j�|_|jD��cgc]\}}tj||���}}}tj|D�cgc],}tj|jj|���.c}�}|j|j|jD��cgc]\}}|��	c}}�|Scc}}wcc}wcc}}wr3)
rr�rzr�r|rr[r�
gatherResults�
maybeDeferred�requestAvatarId�addCallbackrS)r#rr��creds�c�ds      r�testRequestAvatarIdz'OnDiskDatabaseTests.testRequestAvatarId�s����)�)�$�+�+�6���@D�
�
�K���1��-�-�a��3�K��K����FK�L��U�
 �
 ����!8�!8�!�
<�L�
��	
�
�
�d�&�&�t�z�z�(B�t�q�!��(B�C����L��L��(Bs� C�*1C#�C(c	���tj|j�|_|j	ddt
�}|jD��cgc]\}}|||���}}}tj|D�cgc],}tj|jj|���.c}�}|j|j|jD��cgc]\}}|��	c}}�|Scc}}wcc}wcc}}w)N�twisted.cred.credentials�UsernameHashedPassword)
rr�rzr��getDeprecatedModuleAttribute�_uhpVersionr|rr�r�r�r�rS)r#r�rr�r�r�r�s       r�testRequestAvatarId_hashedz.OnDiskDatabaseTests.testRequestAvatarId_hashed�s����)�)�$�+�+�6���!%�!B�!B�&�(@�+�"
��;?�*�*�E�$�!�Q�'��1�-�E��E����FK�L��U�
 �
 ����!8�!8�!�
<�L�
��	
�
�
�d�&�&�t�z�z�(B�t�q�!��(B�C����F��L��(Bs�C'�41C-�C2N)
rrrr|rNr�r�r�r�r�rrrrprp�s)��
�E�.�L�9�A�
�
rrpc�Z�eZdZgd�Zd�Zdedededefd�Zd�Zd	�Zd
�Z	d�Z
d�Ze�dZ
y
y
)�!HashedPasswordOnDiskDatabaseTestsrqc���|j�}tj||j��|_t|d�5}|jD]3\}}|j|dz|j|||dd�zdz��5	ddd�t�}tj|�|_|jj|j�y#1swY�SxYw)N)�hashrvrwrrx)
ryrr�r�r�r{r|r}r:r
rI�portrM)r#rzr~rr��rs      rrNz'HashedPasswordOnDiskDatabaseTests.setUps���������)�)�&�t�y�y�A���
�&�$�
�	C�1��
�
�
C���1�����D��4�9�9�Q��1�R�a�5�#9�9�E�A�B�
C�	C�
�K���M�M�!�$��	��	�	�!�!�$�'�'�*�
	C�	C�s
�AC�C"rr��s�returnc�x�t|jd�|jd��}|jd�S)N�ascii)r�decode�encode)r#rr�r��hashed_passwords     rr�z&HashedPasswordOnDiskDatabaseTests.hashs1������� 1�1�8�8�G�3D�E���%�%�g�.�.rc	�v�|jD��cgc]\}}tj||���}}}tj|D�cgc]}|j
j
|���c}�}|j|j|jD��cgc]\}}|��	c}}�|Scc}}wcc}wcc}}wr3)	r|rr[rr�r�r�r�rS�r#rr��	goodCredsr�r�s      r�testGoodCredentialsz5HashedPasswordOnDiskDatabaseTests.testGoodCredentialss���DH�J�J�O�D�A�q�[�1�1�!�Q�7�O�	�O����Y� O�����!8�!8��!;� O�P��	�
�
�d�&�&�t�z�z�(B�t�q�!��(B�C����P�� O��(Bs� B*�"B0�B5c
��|jD��cgc]\}}tj||���}}}tj|D�cgc]#}|j
j
|dt���%c}�}|jd��|j|j|jD��cgc]\}}|��	c}}�|Scc}}wcc}wcc}}w)Nc�h�|D���cgc]\}}}|jj��c}}}Scc}}}wr3)r^r )�x�i�a�ls    r�<lambda>zMHashedPasswordOnDiskDatabaseTests.testGoodCredentials_login.<locals>.<lambda>s%��� B� B�W�Q��1������ B��� Bs�!-)
r|rr[rr�r�r(rr�rSr�s      r�testGoodCredentials_loginz;HashedPasswordOnDiskDatabaseTests.testGoodCredentials_logins���DH�J�J�O�D�A�q�[�1�1�!�Q�7�O�	�O����:C�D�Q�T�Y�Y�_�_�Q��i�
0�D�
��	
�
�
�B�C�	�
�
�d�&�&�t�z�z�(B�t�q�!��(B�C����
P��D��)Cs� C�(C�,C
c
�\�|jD��cgc]\}}tj|d���}}}tj|D�cgc]#}|j
j
|dt���%c}d��}|j|jtj�|Scc}}wcc}w)Nswrong passwordT��
consumeErrors)r|rr[r�DeferredListr�r(rr��_assertFailuresr	rh)r#rr��badCredsr�r�s      r�testBadCredentialsz4HashedPasswordOnDiskDatabaseTests.testBadCredentialss���KO�:�:�
�CG�1�a�K�(�(��,=�>�
��
�
���:B�C�Q�T�Y�Y�_�_�Q��i�
0�C�SW�
��	
�
�
�d�*�*�E�,C�,C�D����
��
Ds� B#�(B)c��|jddt�}|jD��cgc]"\}}|||jd||dd����$}}}t	j
|D�cgc]#}|jj|dt���%c}d��}|j|jtj�|Scc}}wcc}w)Nr�r�rTr�)
r�r�r|r�rr�r�r(rr�r�r	�UnhandledCredentials)r#r�rr��hashedCredsr�r�s       r�testHashedCredentialsz7HashedPasswordOnDiskDatabaseTests.testHashedCredentials(s���!%�!B�!B�&�(@�+�"
��NR�Z�Z�
�EI�Q��"�1�d�i�i��a��2�A��&?�@�
��
�
���:E�F�Q�T�Y�Y�_�_�Q��i�
0�F��
��	
�
�
�d�*�*�E�,F�,F�G����
��
Gs�'C�$(Cc�v�|D]4\}}|j|tj�|j|��6yr3)rSr�FAILURE�trap)r#�failures�expectedFailures�flag�failures     rr�z1HashedPasswordOnDiskDatabaseTests._assertFailures6s=��%�	,�M�D�'����T�5�=�=�1��G�L�L�*�+�	,�rNzcrypt module not available)rrrr|rN�bytesr�r�r�r�r�r�r�skiprrrr�r��sY��
�E�	+�/�e�/��/�%�/�E�/������
�}�+��rr�c�X�eZdZdZej
d��Zej
d��Zy)�
CheckersMixina�
    L{unittest.TestCase} mixin for testing that some checkers accept
    and deny specified credentials.

    Subclasses must provide
      - C{getCheckers} which returns a sequence of
        L{checkers.ICredentialChecker}
      - C{getGoodCredentials} which returns a list of 2-tuples of
        credential to check and avaterId to expect.
      - C{getBadCredentials} which returns a list of credentials
        which are expected to be unauthorized.
    c#�K�|j�D]?}|j�D]*\}}|j|���}|j||��,�Ay�w)zt
        The given credentials are accepted by all the checkers, and give
        the expected C{avatarID}s
        N)�getCheckers�getGoodCredentialsr�rS)r#�chk�credr>r�s     r�
test_positivezCheckersMixin.test_positiveNs_�����#�#�%�	.�C�"&�"9�"9�";�
.���h��-�-�d�3�3��� � ��H�-�
.�	.�s�AAc#��K�|j�D]J}|j�D]5}|j|�}|j|tj
����7�Ly�w)zI
        The given credentials are rejected by all the checkers.
        N)r��getBadCredentialsr��
assertFailurer	rh)r#r�r�r�s    r�
test_negativezCheckersMixin.test_negativeYse����
�#�#�%�	E�C��.�.�0�
E���'�'��-���(�(��E�,C�,C�D�D�
E�	E�s�AA!N)rrrrr�inlineCallbacksr�r�rrrr�r�@s=������.��.����E��Err�c�\�eZdZejZdZededefd��Z	gd�Z
d�Zd�Zd�Z
y)	�HashlessFilePasswordDBMixinNr�r�c��|Sr3r�r�s r�networkHashz'HashlessFilePasswordDBMixin.networkHashhs���r))rr�	password1)rss	password2)rt�	password3c#�~K�|jD]*\}}|j||j|��|f���,y�wr3)�_validCredentials�	credClassr�r�s   rr�z.HashlessFilePasswordDBMixin.getGoodCredentialsrs@�����*�*�	<�D�A�q��.�.��D�$4�$4�Q�$7�8�!�;�;�	<�s�;=c#�fK�dD](\}}|j||j|�����*y�w)N))rrr�)rsr�)sbloofsblarf)r�r�r�s   rr�z-HashlessFilePasswordDBMixin.getBadCredentialsvs9����
�	9�D�A�q�
�.�.��D�$4�$4�Q�$7�8�8�	9�s�/1c
#��K��jxsd�}�jxr�fd�}dD�]w}�j�}t|d�5}�jD]%\}}|j	|dz||�zdz��'	ddd�tj|||�����j�}t|d�5}�jD]%\}}|j	||�dz|zdz��'	ddd�tj|d	d
d||�����j�}t|d�5}�jD]6\}}|j	d|j�zd
z||�zdz��8	ddd�tj|dddd||������zy#1swY��(xYw#1swY��xYw#1swY�DxYw�w)Nc��|Sr3rr�s rr�z9HashlessFilePasswordDBMixin.getCheckers.<locals>.<lambda>s��q�rc�&���j|�Sr3)�diskHash)r4r5�storedr#s   �rr�z9HashlessFilePasswordDBMixin.getCheckers.<locals>.<lambda>�s���t�}�}�X�/F�r)TFrvrwrx)�cacher�s dingle dongle � �rszip,zap,s,zup,�,r�F)r�ryr{r�r}rr��title)r#r��	hashCheckr��fn�fObjrr�s`       rr�z'HashlessFilePasswordDBMixin.getCheckers~s�������=�=�1�[���M�M�
�F�	�!�	�E�����B��b�$��
?�4� �2�2�?�D�A�q��J�J�q�4�x�(�1�+�5��=�>�?�
?��)�)�"�E�	�J�J�����B��b�$��
M�4� �2�2�M�D�A�q��J�J�x��{�-?�?�!�C�e�K�L�M�
M��)�)�"�d�A�q��I�V�V�����B��b�$��
�4� �2�2��D�A�q��J�J�#�a�g�g�i�/�(�:�X�a�[�H�5�P���
�
�)�)��D�!�Q��U���
�'	�
?�
?��
M�
M��
�
�sP�AG�
5F&�>G�>5F3�4AG�5AF?�<*G�&F0	�+G�3F<	�8G�?G	�G)rrrrr[r�r��staticmethodr�r�r�r�r�r�rrrr�r�dsI���,�,�I��H���u��������<�9�rr�c��eZdZed��Zy)� LocallyHashedFilePasswordDBMixinc��t|�Sr3�rr�s rr�z)LocallyHashedFilePasswordDBMixin.diskHash�����q�z�rN)rrrr�r�rrrr�r��s�����rr�c�P�eZdZededefd��ZGd�dej�Zy)� NetworkHashedFilePasswordDBMixinr�r�c��t|�Sr3r�r�s rr�z,NetworkHashedFilePasswordDBMixin.networkHash�r�rc��eZdZd�Zy)�*NetworkHashedFilePasswordDBMixin.credClassc�2�t|j�|k(Sr3)rr5r7s  rr8z8NetworkHashedFilePasswordDBMixin.credClass.checkPassword�s���T�]�]�+�x�7�7rN)rrrr8rrrr�r��s��	8rr�N)	rrrr�r�r�rr[r�rrrr�r��s4����u������8�K�0�0�8rr�c��eZdZy)�"HashlessFilePasswordDBCheckerTestsNr/rrrr�r�����	rr�c��eZdZy)�'LocallyHashedFilePasswordDBCheckerTestsNr/rrrrr�rrrc��eZdZy)�'NetworkHashedFilePasswordDBCheckerTestsNr/rrrrr�rrrc��eZdZdZd�Zy)�UsernameHashedPasswordTestszo
    UsernameHashedPassword is a deprecated class that is functionally
    equivalent to UsernamePassword.
    c�4�|jddtd�y)zB
        Tests that UsernameHashedPassword is deprecated.
        r�r�z6Use twisted.cred.credentials.UsernamePassword instead.N)r�r�r's r�test_deprecationz,UsernameHashedPasswordTests.test_deprecation�s��	
�)�)�&�$��D�		
rN)rrrrrrrrrr�s���
	
rr).r�binasciirr�zope.interfacerr�twisted.credrrr	r
�twisted.internetr�twisted.pythonr�twisted.python.versionsr
�
twisted.trialrr�_crypt�ImportErrorr�rr�Adapterr,�registerAdapterrPr.r1�IRealmr:�TestCaserDrpr�r�r�r�r�r�rrrrrr�<module>rs����
(�1�=�=�"�%�+�"��%�
�E��i��Q��*��	�	�	���$
�Y��	�z�!�!�	��	��
���8�Z��;�	�+�7�7�	�
�
 �)�,�)�)�-�)�
�V�]�]��E�E��E�$Y>��!�!�Y>�x4�(�+�+�4�nD,��(9�(9�D,�N!E�!E�H5�5�p�'B��8�'B�8�	����0A�0A�	�	�$�m�X�5F�5F�	�	�$�m�X�5F�5F�	�
�(�"3�"3�
��S
���E��s�F"�"F-�,F-

Zerion Mini Shell 1.0