%PDF- %PDF-
Mini Shell

Mini Shell

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

�

Ϫ�f[;��4�dZ	ddlZeZ	ddlZeZddlZddlmZddl	m
Z
ddlmZm
Z
ddlmZdZd�Ze�ZGd	�d
�ZGd�dee�ZGd
�dee�ZGd�d�ZGd�dee�ZGd�dee�Zy#e$rdZY�wxYw#e$rdZY��wxYw)z&
Tests for L{twisted.python.fakepwd}.
�N)�getitem)�_PYPY)�ShadowDatabase�UserDatabase)�TestCasei�c�x�t}t�		tj|�|dz}�|S#t$rY|SwxYw)a�
    By convention, UIDs less than 1000 are reserved for the system.  A system
    which allocated every single one of those UIDs would likely have practical
    problems with allocating new ones, so let's assume that we'll be able to
    find one.  (If we don't, this will wrap around to negative values and
    I{eventually} find something.)

    @return: a user ID which does not exist on the local system.  Or, on
        systems without a L{pwd} module, return C{SYSTEM_UID_MAX}.
    �)�SYSTEM_UID_MAX�pwd�getpwuid�KeyError)�guesss �B/usr/lib/python3/dist-packages/twisted/python/test/test_fakepwd.py�findInvalidUIDr sT��
�E�
���
����U�#���
��
��L��	�
���L�	
�s�,�	9�9c�:�eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
y	)
�UserDatabaseTestsMixina^
    L{UserDatabaseTestsMixin} defines tests which apply to any user database
    implementation.  Subclasses should mix it in, implement C{setUp} to create
    C{self.database} bound to a user database instance, and implement
    C{getExistingUserInfo} to return information about a user (such information
    should be unique per test method).
    c��td�D]�}|j�\}}}}}}}|jj|�}	|j	|	j
|�|j	|	j|�|j	|	j|�|j	|	j|�|j	|	j|�|j	|	j|�|j	|	j|���y)zc
        I{getpwuid} accepts a uid and returns the user record associated with
        it.
        �N)�range�getExistingUserInfo�databaser�assertEqual�pw_name�	pw_passwd�pw_uid�pw_gid�pw_gecos�pw_dir�pw_shell�
�self�i�username�password�uid�gid�gecos�dir�shell�entrys
          r�
test_getpwuidz$UserDatabaseTestsMixin.test_getpwuidCs���
�q��	4�A�>B�>V�>V�>X�;�H�h��S�%��e��M�M�*�*�3�/�E����U�]�]�H�5����U�_�_�h�7����U�\�\�3�/����U�\�\�3�/����U�^�^�U�3����U�\�\�3�/����U�^�^�U�3�	4�c�b�|jt|jjt�y)zu
        I{getpwuid} raises L{KeyError} when passed a uid which does not exist
        in the user database.
        N)�assertRaisesr
rr�INVALID_UID�r!s r�test_noSuchUIDz%UserDatabaseTestsMixin.test_noSuchUIDVs ��
	
���(�D�M�M�$:�$:�K�Hr,c��td�D]�}|j�\}}}}}}}|jj|�}	|j	|	j
|�|j	|	j|�|j	|	j|�|j	|	j|�|j	|	j|�|j	|	j|�|j	|	j|���y)zh
        I{getpwnam} accepts a username and returns the user record associated
        with it.
        rN)rrr�getpwnamrrrrrrrrr s
          r�
test_getpwnamz$UserDatabaseTestsMixin.test_getpwnam]s���
�q��	4�A�>B�>V�>V�>X�;�H�h��S�%��e��M�M�*�*�8�4�E����U�]�]�H�5����U�_�_�h�7����U�\�\�3�/����U�\�\�3�/����U�^�^�U�3����U�\�\�3�/����U�^�^�U�3�	4r,c�v�t}trt}|j||jj
d�y)zN
        L{getpwnam} rejects a non-L{str} username with an exception.
        �
i-am-bytesN)�	TypeErrorr�	Exceptionr.rr3)r!�exc_types  r�test_getpwnamRejectsBytesz0UserDatabaseTestsMixin.test_getpwnamRejectsBytesps/�����!�H����(�D�M�M�$:�$:�M�Jr,c�Z�|jt|jjd�y)zz
        I{getpwnam} raises L{KeyError} when passed a username which does not
        exist in the user database.
        z.nosuchuserexiststhenameistoolongandhasinittooN)r.r
rr3r0s r�test_noSuchNamez&UserDatabaseTestsMixin.test_noSuchName{s'��
	
�����M�M�"�"�
�	
r,c�2�|j}|j�\}}}}}}}|j|�|j|�|j	�dfD]<}	|jt
|	�t�|jt
|	�d��>y)zm
        The user record returned by I{getpwuid}, I{getpwnam}, and I{getpwall}
        has a length.
        r�N)	rrrr3�getpwall�assertIsInstance�len�intr�
r!�dbr#r$r%r&r'r(r)r*s
          r�test_recordLengthz(UserDatabaseTestsMixin.test_recordLength�s���
�]�]��:>�:R�:R�:T�7��(�C��e�S�%��k�k�#�&����H�(=�r�{�{�}�Q�?O�P�	,�E��!�!�#�e�*�c�2����S��Z��+�	,r,c	�v�|j}|j�\}}}}}}}|j|�|j|�|j	�dfD]�}	|j|	d|�|j|	d|�|j|	d|�|j|	d|�|j|	d|�|j|	d|�|j|	d|�|jt
|	�t
t|	���|jtt|	d���y	)
a:
        The user record returned by I{getpwuid}, I{getpwnam}, and I{getpwall}
        is indexable, with successive indexes starting from 0 corresponding to
        the values of the C{pw_name}, C{pw_passwd}, C{pw_uid}, C{pw_gid},
        C{pw_gecos}, C{pw_dir}, and C{pw_shell} attributes, respectively.
        rr	r����r>N)rrrr3r?rrA�listr.�
IndexErrorrrCs
          r�test_recordIndexablez+UserDatabaseTestsMixin.test_recordIndexable�s���]�]��:>�:R�:R�:T�7��(�C��e�S�%��k�k�#�&����H�(=�r�{�{�}�Q�?O�P�
	=�E����U�1�X�x�0����U�1�X�x�0����U�1�X�s�+����U�1�X�s�+����U�1�X�u�-����U�1�X�s�+����U�1�X�u�-����S��Z��T�%�[�)9�:����j�'�5�!�<�
	=r,N)�__name__�
__module__�__qualname__�__doc__r+r1r4r:r<rErM�r,rrr:s,���4�&I�4�&	K�
�2	,�=r,rc�"�eZdZdZd�Zd�Zd�Zy)�UserDatabaseTestsz$
    Tests for L{UserDatabase}.
    c�>�t�|_tdz|_y)zC
        Create a L{UserDatabase} with no user data in it.
        r	N)rrr
�_counterr0s r�setUpzUserDatabaseTests.setUp�s��%���
�&��*��
r,c	��|xjdz
c_dt|j�z}d|z}d|z}|j}|jdz}d|z}d|z}d|z}|jj|||||||�|||||||fS)	�P
        Add a new user to C{self.database} and return its information.
        r	�_r#r$i�r'r(r)�rV�strr�addUser)	r!�suffixr#r$r%r&r'r(r)s	         rrz%UserDatabaseTests.getExistingUserInfo�s���	
�
�
���
��s�4�=�=�)�)����&����&���m�m���m�m�d�"���&� ���f�n���&� ���
�
���h��#�s�E�3��N��(�C��e�S�%�@�@r,c	�b�d}d}d}d}d}d}d}|j}|j|||||||�|j|�g|j|�g|j	�fD]�\}	|j|	j|�|j|	j|�|j|	j|�|j|	j|�|j|	j|�|j|	j|�|j|	j|���y)	�
        L{UserDatabase.addUser} accepts seven arguments, one for each field of
        a L{pwd.struct_passwd}, and makes the new record available via
        L{UserDatabase.getpwuid}, L{UserDatabase.getpwnam}, and
        L{UserDatabase.getpwall}.
        �alice�secr3t�{i�zAlice,,,z/users/alicez/usr/bin/fooshN)
rr]rr3r?rrrrrrrr)
r!r#r$r%r&r'�homer)rDr*s
          r�test_addUserzUserDatabaseTests.test_addUser�s
�������������� ��
�]�]��
�
�
�8�X�s�C���e�D����S�)�*�R�[�[��-B�,C�R�[�[�]�S�	4�G�U����U�]�]�H�5����U�_�_�h�7����U�\�\�3�/����U�\�\�3�/����U�^�^�U�3����U�\�\�4�0����U�^�^�U�3�	4r,N�rNrOrPrQrWrrerRr,rrTrT�s���+�A�"4r,rTc�*�eZdZdZe�dZneZd�Zd�Zy)�PwdModuleTestsz�
    L{PwdModuleTests} runs the tests defined by L{UserDatabaseTestsMixin}
    against the built-in C{pwd} module.  This serves to verify that
    L{UserDatabase} is really a fake of that API.
    Nz2Cannot verify UserDatabase against pwd without pwdc�r�t|jj��|_t	�|_y�N)�iterrr?�_users�set�_uidsr0s rrWzPwdModuleTests.setUp�s$���4�=�=�1�1�3�4����U��
r,c��	t|j�}|j}||jvr|jj	|�|S�M)z�
        Read and return the next record from C{self._users}, filtering out
        any records with previously seen uid values (as these cannot be
        found with C{getpwuid} and only cause trouble).
        )�nextrlrrn�add)r!r*r%s   rrz"PwdModuleTests.getExistingUserInfo�sD�������%�E��,�,�C��$�*�*�$��
�
���s�#���r,)	rNrOrPrQr�skiprrWrrRr,rrhrh�s"����{�C�����r,rhc�.�eZdZdZd�Zd�Zd�Zd�Zd�Zy)�ShadowDatabaseTestsMixinan
    L{ShadowDatabaseTestsMixin} defines tests which apply to any shadow user
    database implementation.  Subclasses should mix it in, implement C{setUp} to
    create C{self.database} bound to a shadow user database instance, and
    implement C{getExistingUserInfo} to return information about a user (such
    information should be unique per test method).
    c
��td�D�]4}|j�\	}}}}}}}}	}
|jj|�}|j	|j
|�|j	|j|�|j	|j|�|j	|j|�|j	|j|�|j	|j|�|j	|j|�|j	|j|	�|j	|j|
���7y)zh
        L{getspnam} accepts a username and returns the user record associated
        with it.
        rN)rrr�getspnamr�sp_nam�sp_pwd�	sp_lstchg�sp_min�sp_max�sp_warn�sp_inact�	sp_expire�sp_flag)r!r"r#r$�
lastChange�min�max�warn�inact�expire�flagr*s            r�
test_getspnamz&ShadowDatabaseTestsMixin.test_getspnams��
�q��	2�A��(�(�*�

�����������M�M�*�*�8�4�E����U�\�\�8�4����U�\�\�8�4����U�_�_�j�9����U�\�\�3�/����U�\�\�3�/����U�]�]�D�1����U�^�^�U�3����U�_�_�f�5����U�]�]�D�1�/	2r,c�Z�|jt|jjd�y)zz
        I{getspnam} raises L{KeyError} when passed a username which does not
        exist in the user database.
        raN)r.r
rrvr0s rr<z(ShadowDatabaseTestsMixin.test_noSuchName3s ��
	
���(�D�M�M�$:�$:�G�Dr,c�Z�|jt|jjd�y)zm
        I{getspnam} raises L{TypeError} when passed a L{bytes}, just like
        L{spwd.getspnam}.
        r6N)r.r7rrvr0s r�test_getspnamBytesz+ShadowDatabaseTestsMixin.test_getspnamBytes:s ��
	
���)�T�]�]�%;�%;�]�Kr,c��|j}|j�d}|j|�|j�dfD]<}|j	t|�t�|jt|�d��>y)zf
        The shadow user record returned by I{getspnam} and I{getspall} has a
        length.
        r�	N)rrrv�getspallr@rArBr)r!rDr#r*s    rrEz*ShadowDatabaseTestsMixin.test_recordLengthAsp��
�]�]���+�+�-�a�0���k�k�(�+�R�[�[�]�1�-=�>�	,�E��!�!�#�e�*�c�2����S��Z��+�	,r,c	��|j}|j�\	}}}}}}}}	}
|j|�|j�dfD�]	}|j	|d|�|j	|d|�|j	|d|�|j	|d|�|j	|d|�|j	|d|�|j	|d|�|j	|d|	�|j	|d	|
�|j	t|�tt
|���|jtt|d
���y)aS
        The shadow user record returned by I{getpwnam} and I{getspall} is
        indexable, with successive indexes starting from 0 corresponding to the
        values of the C{sp_nam}, C{sp_pwd}, C{sp_lstchg}, C{sp_min}, C{sp_max},
        C{sp_warn}, C{sp_inact}, C{sp_expire}, and C{sp_flag} attributes,
        respectively.
        rr	rrGrHrIrJr>�r�N)
rrrvr�rrArKr.rLr)r!rDr#r$r�r�r�r�r�r�r�r*s            rrMz-ShadowDatabaseTestsMixin.test_recordIndexableLsH���]�]��
�$�$�&�
	
�����������k�k�(�+�R�[�[�]�1�-=�>�	=�E����U�1�X�x�0����U�1�X�x�0����U�1�X�z�2����U�1�X�s�+����U�1�X�s�+����U�1�X�t�,����U�1�X�u�-����U�1�X�v�.����U�1�X�t�,����S��Z��T�%�[�)9�:����j�'�5�!�<�	=r,N)	rNrOrPrQr�r<r�rErMrRr,rrtrts"���2�<E�L�	,� =r,rtc�"�eZdZdZd�Zd�Zd�Zy)�ShadowDatabaseTestsz&
    Tests for L{ShadowDatabase}.
    c�0�t�|_d|_y)zE
        Create a L{ShadowDatabase} with no user data in it.
        rN)rrrVr0s rrWzShadowDatabaseTests.setUpts��'�(��
���
r,c��|xjdz
c_dt|j�z}d|z}d|z}|jdz}|jdz}|jdz}|jdz}|jdz}|jd	z}	|jd
z}
|jj||||||||	|
�	||||||||	|
f	S)rYr	rZr#r$rrGrHrIrJr>r[)r!r^r#r$r�r�r�r�r�r�r�s           rrz'ShadowDatabaseTests.getExistingUserInfo{s���	
�
�
���
��s�4�=�=�)�)����&����&���]�]�Q�&�
��m�m�a����m�m�a����}�}�q� ���
�
��!������"���}�}�q� ���
�
����h�
�C��d�E�6�4�	
��(�J��S�$��v�t�T�Tr,c��d}d}d}d}d}d}d}d}d}	|j}
|
j|||||||||	�	|
j|�g|
j�fD�]\}|j	|j
|�|j	|j|�|j	|j|�|j	|j|�|j	|j|�|j	|j|�|j	|j|�|j	|j|�|j	|j|	���y	)
r`rarb��*�i�rGi�N)rr]rvr�rrwrxryrzr{r|r}r~r)r!r#r$r�r�r�r�r�r�r�rDr*s            rrez ShadowDatabaseTests.test_addUser�s3�������
�������������
�]�]��
�
�
�8�X�z�3��T�5�&�RV�W����X�.�/�����?�		2�G�U����U�\�\�8�4����U�\�\�8�4����U�_�_�j�9����U�\�\�3�/����U�\�\�3�/����U�]�]�D�1����U�^�^�U�3����U�_�_�f�5����U�]�]�D�1�		2r,NrfrRr,rr�r�os����U�*2r,r�c�X�eZdZdZe�dZnej�dk7rdZneZd�Z	d�Z
y)�SPwdModuleTestsz�
    L{SPwdModuleTests} runs the tests defined by L{ShadowDatabaseTestsMixin}
    against the built-in C{spwd} module.  This serves to verify that
    L{ShadowDatabase} is really a fake of that API.
    Nz6Cannot verify ShadowDatabase against spwd without spwdrz1Cannot access shadow user database except as rootc�T�t|jj��|_yrj)rkrr�rlr0s rrWzSPwdModuleTests.setUp�s���4�=�=�1�1�3�4��r,c�,�t|j�S)zF
        Read and return the next record from C{self._users}.
        )rprlr0s rrz#SPwdModuleTests.getExistingUserInfo�s���D�K�K� � r,)rNrOrPrQ�spwdrr�os�getuidrrWrrRr,rr�r��s7����|�G��	������	�B����5�!r,r�)rQr�_pwd�ImportErrorr��_spwdr��operatorr�twisted.python.compatr�twisted.python.fakepwdrr�twisted.trial.unittestrr
rr/rrTrhrtr�r�rRr,r�<module>r�s�������C����D�	��'�?�+����.���x=�x=�v64��"8�64�r�X�5��<`=�`=�F>2�(�$<�>2�B!�h� 8�!��M
��
�C������D��s"�B�B
�B
�	B
�
B�B

Zerion Mini Shell 1.0