%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /lib/python3/dist-packages/certbot/tests/__pycache__/
Upload File :
Create Path :
Current File : //lib/python3/dist-packages/certbot/tests/__pycache__/util.cpython-312.pyc

�

M/�e�F�	�d�dZddlZddlmZddlZddlmZddlZddl	Z	ddl
Z
ddl
mZddlZddl
Z
ddlZddlmZddlmZddlmZdd	lmZdd
lmZddlmZddlmZdd
lmZddlZddlmZddlmZddlmZddlmZddl Z!ddl"m#Z#ddl$m%Z%ddl$m&Z&ddl'm(Z(ddl'm)Z)ddl'm*Z*ddl+m,Z-ddl.m/Z/ddl.m0Z0ddl1m&Z2ddl3m4Z4e
jjdk\rddl6m7Z8nddl8Z8Gd�de4jr�Z:de;d e;fd!�Z<de;d e=fd"�Z>d#e;d$e?d%e?d e?fd&�Z@de;d e#j�fd'�ZBde;d e#j�fd(�ZDde;d e!j�fd)�ZFde;d e!j�fd*�ZHde;d e#j�fd+�ZJdId,e;d-e;d.eKd e;fd/�ZLd ej�fd0�ZN	dJd1eed ej�fd2�ZOGd3�d4�ZPd ePfd5�ZQd1ed ePfd6�ZRd7ed8ed dfd9�ZSGd:�d;ej��ZUGd<�d=eU�ZVd>ej�d?ej�d@e;d dfdA�ZXdBegefdCe;d dfdD�ZYdEe;d eedFefgedFefffdG�ZZd@e;d e;fdH�Z[y)KzTest utilities.�N)�	ExitStack)�reload)�synchronize)�Any)�Callable)�cast)�IO)�Iterable)�List)�Optional)�Union)�mock)�default_backend)�
serialization)�
RSAPrivateKey)�crypto)�
configuration)�util)�	constants)�lock)�storage)�obj)�
filesystem)�os)�common)��	c���eZdZdZdeefd�Zdedededededd	fd
�Z	ddededee	e
eefdd	fd
�Zde
efd�Zddeede
dd	fd�Zdd�Zdd�Zededdd	fd��Zdd�Zdefd�Zy	)�DummyInstallerz(Dummy installer plugin for test purpose.�returnc��gS�N���selfs �4/usr/lib/python3/dist-packages/certbot/tests/util.py�
get_all_nameszDummyInstaller.get_all_names1����	��domain�	cert_path�key_path�
chain_path�fullchain_pathNc��yr"r#)r%r*r+r,r-r.s      r&�deploy_certzDummyInstaller.deploy_cert4���r)�enhancement�optionsc��yr"r#)r%r*r2r3s    r&�enhancezDummyInstaller.enhance8r1r)c��gSr"r#r$s r&�supported_enhancementsz%DummyInstaller.supported_enhancements<r(r)�title�	temporaryc��yr"r#)r%r8r9s   r&�savezDummyInstaller.save?���r)c��yr"r#r$s r&�config_testzDummyInstaller.config_testBr<r)c��yr"r#r$s r&�restartzDummyInstaller.restartEr<r)�add).Nc��yr"r#)�clsrAs  r&�add_parser_argumentsz#DummyInstaller.add_parser_argumentsHr1r)c��yr"r#r$s r&�preparezDummyInstaller.prepareLr<r)c��y)N�r#r$s r&�	more_infozDummyInstaller.more_infoOs��r)r")NF�r N)�__name__�
__module__�__qualname__�__doc__r
�strr'r0rr
rr5r7�boolr;r>r@�classmethodrrDrFrIr#r)r&rr/s���2��x��}��
�#�
�#�
��
�RU�
�$'�
�,0�
�
<@�
�c�
��
�!�%��S�	�3��"7�8�
�DH�
���S�	��
�(�3�-�
�4�
�D�
�
�
��
�x�	�':�
�t�
��
�
��3�r)r�namesr c��t�}tj|j�t	j
t�jdg|���}|jt	j|��}t|�S)zPath to a test vector.�testdata)r�atexit�register�close�importlib_resources�files�__package__�joinpath�
enter_context�as_filerO)rR�
_file_manager�
vector_ref�paths    r&�vector_pathraSsd���K�M�
�O�O�M�'�'�(�@�$�*�*�;�7�@�@��T�e�T�J��&�&�':�'B�'B�:�'N�O�D��t�9�r)c��tjt�jdg|���}|j	�}	|j�j
dd�j�S#t$r|cYSwxYw)zLoad contents of a test vector.rTz
�
)	rXrYrZr[�
read_bytes�decode�replace�encode�
ValueError)rRr_�datas   r&�load_vectorrj\sp��@�$�*�*�;�7�@�@��T�e�T�J�� � �"�D���{�{�}�$�$�V�T�2�9�9�;�;�������s�-A*�*A8�7A8�filename�
loader_pem�
loader_derc��tjj|�\}}|j�dk(r|S|j�dk(r|St	d��)Nz.pemz.derz1Loader could not be recognized based on extension)rr`�splitext�lowerrh)rkrlrm�_�exts     r&�
_guess_loaderrsisN��
�W�W�
�
�h�
'�F�A�s�
�y�y�{�f����	�����	���
�H�
I�Ir)c��t|dtjtj�}tj|t|��S)zLoad certificate.���)rsr�FILETYPE_PEM�
FILETYPE_ASN1�load_certificaterj�rR�loaders  r&�	load_certr{rs;��
�
�b�	�6�&�&��(<�(<�>�F��"�"�6�;��+>�?�?r)c��t|dtjtj�}tj|t|��S)zLoad certificate request.ru)rsrrvrw�load_certificate_requestrjrys  r&�load_csrr~ys;��
�
�b�	�6�&�&��(<�(<�>�F��*�*�6�;��3F�G�Gr)c�8�tjt|��S)z(Load ComparableX509 certificate request.)�jose�ComparableX509r~)rRs r&�load_comparable_csrr��s�����x��/�0�0r)c�6�t|dtjtj�}|tjk(rtj
}ntj}tjtt|t|�dt�����S)zLoad RSA private key.ruN)�password�backend)
rsrrvrwr�load_pem_private_key�load_der_private_keyr��ComparableRSAKeyrrrjr)rRrz�	loader_fns   r&�load_rsa_private_keyr��sx��
�5��9�f�&9�&9�6�;O�;O�
P�F�
��$�$�$�!�6�6�	�!�6�6�	�� � ��]�
�{�E�*�T�?�CT�
U�	W�X�Xr)c��t|dtjtj�}tj|t|��S)zLoad pyOpenSSL private key.ru)rsrrvrw�load_privatekeyrjrys  r&�load_pyopenssl_private_keyr��s;��
�
�b�	�6�&�&��(<�(<�>�F��!�!�&�+�u�*=�>�>r)�
config_dir�testfile�ecc
����|dtd�}tjj�tj
�}tjj�tj|�}tjj�tj|�}|||fD]7}tjj|�r�#tj|��9tdj|rdnd��}tj|�D]T}	tjtjj||	�tjj||	���Vt j"D]r}	tj$tjj|dj|	��tjj|dj|	����ttjj�||�}
t't|��5}t'|
d�5}|j)�fd	�|D��ddd�ddd�|
S#1swY�xYw#1swY|
SxYw)
a�Creates a lineage defined by testfile.

    This creates the archive, live, and renewal directories if
    necessary and creates a simple lineage.

    :param str config_dir: path to the configuration directory
    :param str testfile: configuration file to base the lineage on
    :param bool ec: True if we generate the lineage with an ECDSA key

    :returns: path to the renewal conf file for the created lineage
    :rtype: str

    Nz.confzsample-archive{}z-ecrHz{0}1.pemz{0}.pem�wc3�B�K�|]}|jd�����y�w)�MAGICDIRN)rf)�.0�liner�s  �r&�	<genexpr>zmake_lineage.<locals>.<genexpr>�s#�����F�9=����Z��4�F�s�)�lenrr`�joinr�RENEWAL_CONFIGS_DIR�ARCHIVE_DIR�LIVE_DIR�existsr�makedirsra�format�listdir�shutil�copyfiler�ALL_FOUR�symlink�open�
writelines)
r�r�r��lineage_name�conf_dir�archive_dir�live_dir�	directory�sample_archive�kind�	conf_path�src�dsts
`            r&�make_lineager��s�����N�c�'�l�]�+�L��w�w�|�|��I�1�1�3�H��'�'�,�,��I�)�)�<�9�K��w�w�|�|��I�&�&��6�H�"�8�X�7�+�	��w�w�~�~�i�(����	�*�+�!�!3�!:�!:�B�5�B�!O�P�N��
�
�>�*�9����������^�T�:������[�$�7�	9�9�� � �C��
�
�
�2�7�7�<�<��Z�->�->�t�-D�E��7�7�<�<��)�*:�*:�4�*@�A�	C�C������Z��8�<�I�	
�k�(�#�	$�F��
�)�S�
!�	F�S��N�N�F�AD�F�
F�	F�F�
��		F�	F��F�
��s$� 
I&�-I�I&�I#	�I&�&I0c�h�ttjtjdt���S)aDPatch certbot.display.util to use a special mock display utility.

    The mock display utility works like a regular mock object, except it also
    also asserts that methods are called with valid arguments.

    The mock created by this patch mocks out Certbot internals. That is, the
    mock object will be called by the certbot.display.util functions and the
    mock returned by that call will be used as the display utility. This was
    done to simplify the transition from zope.component and mocking
    certbot.display.util functions directly in test code should be preferred
    over using this function in the future.

    See https://github.com/certbot/certbot/issues/8948

    :returns: patch on the function used internally by certbot.display.util to
        get a display utility instance
    :rtype: mock.MagicMock

    �)certbot._internal.display.obj.get_display)�new_callable)rr�	MagicMock�patch�_create_display_util_mockr#r)r&�patch_display_utilr��s+��(�����
�
�+V�8Q�!S�T�Tr)�stdoutc	��|r|ntj�}ttjtj
dt
|����S)aPatch certbot.display.util to use a special mock display utility.

    The mock display utility works like a regular mock object, except it also
    asserts that methods are called with valid arguments.

    The mock created by this patch mocks out Certbot internals. That is, the
    mock object will be called by the certbot.display.util functions and the
    mock returned by that call will be used as the display utility. This was
    done to simplify the transition from zope.component and mocking
    certbot.display.util functions directly in test code should be preferred
    over using this function in the future.

    See https://github.com/certbot/certbot/issues/8948

    The `message` argument passed to the display utility methods is passed to
    stdout's write method.

    :param object stdout: object to write standard output to; it is
        expected to have a `write` method
    :returns: patch on the function used internally by certbot.display.util to
        get a display utility instance
    :rtype: mock.MagicMock

    r�)�new)�io�StringIOrrr�r��%_create_display_util_mock_with_stdout)r�s r&�patch_display_util_with_stdoutr��s@��4�V�2�;�;�=�F������
�
�+V�/T�U[�/\�!^�_�_r)c	��eZdZdZddej
jfdedee	de
fde
ddfd	�Zdd
�Zde
de
dejfd
�Zdede
fd�Zdede
ddfd�Zy)�
FreezableMocka�Mock object with the ability to freeze attributes.

    This class works like a regular mock.MagicMock object, except
    attributes and behavior set before the object is frozen cannot
    be changed during tests.

    If a func argument is provided to the constructor, this function
    is called first when an instance of FreezableMock is called,
    followed by the usual behavior defined by MagicMock. The return
    value of func is ignored.

    FN�frozen�func.�return_valuer c���|r
t�ndh|_||_tj�|_|tjjk7r||_||_	y)N�freeze)
�set�_frozen_set�_funcrr��_mock�sentinel�DEFAULTr��_frozen)r%r�r�r�s    r&�__init__zFreezableMock.__init__sH��$*�3�5�������
��^�^�%��
��4�=�=�0�0�0� ,�D����r)c��d|_y)z)Freeze object preventing further changes.TN)r�r$s r&r�zFreezableMock.freezes	����r)�args�kwargsc�b�|j�|j|i|��|j|i|��Sr")r�r�)r%r�r�s   r&�__call__zFreezableMock.__call__s5���:�:�!��D�J�J��'��'��t�z�z�4�*�6�*�*r)�namec�2�|dk(r	tj||�S|dvr ttj|d�|�S|dk(s||jvrtj||�Sttj|d�|�S#t$rYywxYw)Nr�F�r��side_effectr�r�)�object�__getattribute__�AttributeError�getattrr�)r%r�s  r&r�zFreezableMock.__getattribute__s����9��
��.�.�t�T�:�:��5�
5��6�2�2�4��A�4�H�H�
�]�
"�d�d�.>�.>�&>��*�*�4��6�6��6�2�2�4��A�4�H�H��"�
��
�s�B
�
	B�B�valuec�$�|jr3||jvrtd|z��t|j||�S|dk7r|jj|�|dvrt|j||�Stj|||�S)a� Before it is frozen, attributes are set on the FreezableMock
        instance and added to the _frozen_set. Attributes in the _frozen_set
        cannot be changed after the FreezableMock is frozen. In this case,
        they are set on the underlying _mock.

        In cases of return_value and side_effect, these attributes are always
        passed through to the instance's _mock and added to the _frozen_set
        before the object is frozen.

        zCannot change frozen attribute r�r�)r�r�r��setattrr�rAr��__setattr__)r%r�r�s   r&r�zFreezableMock.__setattr__*s����<�<��t�'�'�'�$�%F��%M�N�N��4�:�:�t�U�3�3��=� ���� � ��&��2�2��4�:�:�t�U�3�3��!�!�$��e�4�4r)rJ)rKrLrMrNrr�r�rPrrrr�r�r�r�rOr�r�r#r)r&r�r��s����',�RV�%)�]�]�%:�%:��t��8�H�S�#�X�<N�3O��"��?C���+�c�+�S�+�T�^�^�+�
I�S�I�S�I�5��5�C�5�D�5r)r�c	�d�t�}ttj�D�cgc]8}t	ttj|��r|j
d�s|��:}}|D]&}|dk7s�	tdt��}t|||��(|j�td|��Scc}w)N�__�notificationT�r�r��r�r�)
r��dir�display_obj�FileDisplay�callabler��
startswith�_assert_valid_callr�r�)�displayr��method_list�method�frozen_mocks     r&r�r�Cs����o�G�$'��(?�(?�$@�2�D��w�{�'>�'>��E�F��?�?�4�0��2�K�2��2���^�#�'�t�:L�M�K��G�V�[�1�2��N�N����7�;�;��2s�=B-c	�����dtdtdtddf�fd��dtdtddf�fd�}t�}ttj
�D�cgc]8}t
ttj
|��r|jd	�s|��:}}|D]/}|d
k(rtd���}n
td|��}t|||��1|j�td|�
�Scc}w)N�message�unused_args�
unused_kwargsr c�.��|r�j|�yy)z$Write to message to stdout.
        N)�write)r�r�r�r�s   �r&�
_write_msgz9_create_display_util_mock_with_stdout.<locals>._write_msgRs�����L�L��!�r)r�r�c�.��t||��|i|��y)z<
        Mock function for display utility methods.
        N)r�)r�r�r�s  �r&�mock_methodz:_create_display_util_mock_with_stdout.<locals>.mock_methodXs���	�4��(��D�#�F�#r)r�r�Tr�r�)rOrr�r�r�r�r�r�r�r�r�)r�r�r�r�r�r�r�r�s`      @r&r�r�Qs����"�C�"�s�"�S�"�T�"�$�3�$�#�$�$�$��o�G�$'��(?�(?�$@�2�D��w�{�'>�'>��E�F��?�?�4�0��2�K�2��.���^�#�'�t�-7�9�K�(�t�-8�:�K�����-�.��N�N����7�;�;��2s�=C&r�r�c��|r|dn|dg}|jdd�|jdd�|jdd�d�}tj|i|��y)Nrr��default�cli_flag�force_interactiveF)r�r�r�)�get�display_util�assert_valid_call)r�r��assert_args�
assert_kwargss    r&r�r�ps`��"�4��7��y�(9�:�K��:�:�i��.��J�J�z�4�0�#�Z�Z�(;�U�C��M��"�"�K�A�=�Ar)c� �eZdZdZdd�Zdd�Zy)�TempDirTestCasezBBase test class which sets up and tears down a temporary directoryNc�6�tj�|_y)zExecute before testN)�tempfile�mkdtemp�tempdirr$s r&�setUpzTempDirTestCase.setUps���'�'�)��r)c���tj�gtj�_t	j
�t
j|j�y)zExecute after testN)	�logging�shutdown�	getLogger�handlersr�_release_locksr��rmtreerr$s r&�tearDownzTempDirTestCase.tearDown�s?��	����(*�����$������
�
�d�l�l�#r)rJ)rKrLrMrNrrr#r)r&rr|s��L�*�$r)rc�$��eZdZdZd�fd�Z�xZS)�ConfigTestCasez2Test class which sets up a NamespaceConfig object.c	���t�|��tjt	j
dit
jtj����|_
|jji�d|jj_
tjj!|j"d�|jj_tjj!|j"d�|jj_tjj!|j"d�|jj_tjd|jj_tjd|jj_tjd|jj_d|jj_y)	N�certonly�config�work�logs�auth_cert_path�auth_chain_pathzhttps://example.comr#)�superrr�NamespaceConfigrr��copy�deepcopyr�CLI_DEFAULTSr�set_argument_sources�	namespace�verbrr`r�rr��work_dir�logs_dirr+r.r-�server)r%�	__class__s �r&rzConfigTestCase.setUp�s=���
��
��#�3�3��N�N�C�T�]�]�9�+A�+A�B�C�
���	
���(�(��,�%/������"�+-�7�7�<�<����h�+O������(�)+�����d�l�l�F�)K������&�)+�����d�l�l�F�)K������&�*3�*@�*@�AQ�*R������'�/8�/E�/E�FW�/X������,�+4�+A�+A�BS�+T������(�'<������$r)rJ)rKrLrMrNr�
__classcell__)r$s@r&rr�s���<�=�=r)r�event_in�	event_outr`c�8�tjj|�rtj|�}ntj
|�}	|j
�|jd��sJd��	|j�y#|j�wxYw)a�
    Acquire a file lock on given path, then wait to release it. This worker is coordinated
    using events to signal when the lock should be acquired and released.
    :param multiprocessing.Event event_in: event object to signal when to release the lock
    :param multiprocessing.Event event_out: event object to signal when the lock is acquired
    :param path: the path to lock
    ���timeoutz*Timeout while waiting to release the lock.N)	rr`�isdirr�lock_dir�LockFiler��wait�release)r&r'r`�my_locks    r&�_handle_lockr2�sm��
�w�w�}�}�T���-�-��%���-�-��%����
�
���}�}�R�}�(�V�*V�V�(����������s�)B�B�callback�path_to_lockc�t�tt�tj�}tj�}tjt
|||f��}|j
�|jd��sJd��|�|j�|jd��|jdk(sJ�y)z�
    Grab a lock on path_to_lock from a foreign process then execute the callback.
    :param callable callback: object to call after acquiring the lock
    :param str path_to_lock: path to file or directory to lock
    )�targetr��
r*z*Timeout while waiting to acquire the lock.rN)�
reload_moduler�multiprocessing�Event�Processr2�startr/r�r��exitcode)r3r4�
emit_event�
receive_event�processs     r&�
lock_and_callrA�s����$�� �&�&�(�J�#�)�)�+�M��%�%�\�,6�
�|�+T�V�G��M�M�O����b��)�W�+W�W�)��J��N�N���L�L��L�����q� � � r)�reason.c�P��dtdtfdtdtff�fd�}|S)zFDecorator to skip permanently a test on Windows. A reason is required.�function.r c�^��tjtjdk(��|�S)zWrapped version�win32)�unittest�skipIf�sys�platform)rDrBs �r&�wrapperz skip_on_windows.<locals>.wrapper�s$���?�x���s�|�|�w�6��?��I�Ir))rr)rBrKs` r&�skip_on_windowsrL�s2���J�(�3��8�,�J��#�s�(�1C�J��Nr)c�f�tjjtj�|�S)z�
    Return the given path joined to the tempdir path for the current platform
    Eg.: 'cert' => /tmp/cert (Linux) or 'C:\Users\currentuser\AppData\Temp\cert' (Windows)
    )rr`r�r�
gettempdir)r`s r&�	temp_joinrO�s"��
�7�7�<�<��+�+�-�t�4�4r))Tr")\rNrU�
contextlibrr�	importlibrr8r�r	r9rr�rIr�typingrrrr	r
rrr
rGr�cryptography.hazmat.backendsr�cryptography.hazmat.primitivesr�-cryptography.hazmat.primitives.asymmetric.rsar�josepyr��OpenSSLr�certbotrr�certbot._internalrrr�certbot._internal.displayrr��certbot.compatrr�certbot.displayr��certbot.pluginsr�version_info�importlib.resources�	resourcesrX�	InstallerrrOra�bytesrj�intrs�X509r{�X509Reqr~r�r�r�r��PKeyr�rPr�r�r�r�r�r�r�r��TestCaserrr:r2rArLrOr#r)r&�<module>rhs����
� ��-�	���'�
�
������������8�8�G���!��'�"�%�8�%��0�"����v��5��!�V�%�%�!�H�����
��
��
�J�C�J�S�J�c�J�c�J�@�c�@�f�k�k�@�H�S�H�V�^�^�H�1��1��(;�(;�1�

X��
X��)>�)>�
X�?�s�?�v�{�{�?�*�S�*�C�*�T�*�S�*�ZT�D�N�N�T�2 $�_����_�(,���_�@B5�B5�J<�=�<�<�"�<��<�>	B�c�	B�S�	B�T�	B�$�h�'�'�$�,=�_�=�&�;�,�,���9J�9J��RU��Z^��&!�H�R��W�-�!�S�!�T�!�6�C��H�h�s�C�x�.@�-A�8�C�QT�H�CU�-U�$V��5�C�5�C�5r)

Zerion Mini Shell 1.0