AnonSec Shell
Server IP : 209.38.156.173  /  Your IP : 216.73.216.122   [ Reverse IP ]
Web Server : Apache/2.4.52 (Ubuntu)
System : Linux lakekumayuhotel 5.15.0-136-generic #147-Ubuntu SMP Sat Mar 15 15:53:30 UTC 2025 x86_64
User : root ( 0)
PHP Version : 8.1.2-1ubuntu2.22
Disable Function : NONE
Domains : 2 Domains
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : ON
Directory :  /lib/python3/dist-packages/certbot/tests/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ HOME ]     [ BACKUP SHELL ]     [ JUMPING ]     [ MASS DEFACE ]     [ SCAN ROOT ]     [ SYMLINK ]     

Current File : /lib/python3/dist-packages/certbot/tests/__pycache__/util.cpython-310.pyc
o

6��a�H�@sVdZddlmZddlZddlZddlmZddlmZddl	Z	ddl
Z
ddlZddlm
Z
ddlmZddlmZddlZddlZdd	lmZdd
lmZddlZddlZddlZddlmZddlmZdd
lmZddlmZddlm Z ddl!m"Z#ddl$m%Z%ddl$m&Z&ddl'mZ(ddl)m*Z*zddl+Z+e�,de-�Wne.y�ddlm+Z+YnwGdd�de*j/�Z0dd�Z1dd�Z2dd�Z3dd�Z4d d!�Z5d"d#�Z6d$d%�Z7d&d'�Z8dHd)d*�Z9dId,d-�Z:	+	dJd.d/�Z;d0d1�Z<dKd2d3�Z=Gd4d5�d5�Z>d6d7�Z?d8d9�Z@d:d;�ZAGd<d=�d=ejB�ZCGd>d?�d?eC�ZDd@dA�ZEdBdC�ZFdDdE�ZGdFdG�ZHdS)LzTest utilities.�)�reloadN)�Event)�Process)�Iterable)�List)�Optional)�default_backend)�
serialization)�
configuration)�util)�	constants)�lock)�storage)�obj)�
filesystem)�os)�commonz�The external mock module is being used for backwards compatibility since it is available, however, future versions of Certbot's tests will use unittest.mock. Be sure to update your code accordingly.)�mockc@s�eZdZdZdeefdd�Zdedededed	edd
fdd�Zd"ded
edee	edd
fdd�Z
de	efdd�Zd#deededd
fdd�Z
d$dd�Zd$dd�Zedd��Zd$dd�Zdefd d!�Zd
S)%�DummyInstallerz(Dummy installer plugin for test purpose.�returncC�dS�N���selfrr�4/usr/lib/python3/dist-packages/certbot/tests/util.py�
get_all_names2�zDummyInstaller.get_all_names�domain�	cert_path�key_path�
chain_path�fullchain_pathNcCrrr)rrrr r!r"rrr�deploy_cert5�zDummyInstaller.deploy_cert�enhancement�optionscCrrr)rrr%r&rrr�enhance9rzDummyInstaller.enhancecCrrrrrrr�supported_enhancements<rz%DummyInstaller.supported_enhancementsF�title�	temporarycCrrr)rr)r*rrr�save?rzDummyInstaller.savecCrrrrrrr�config_testBrzDummyInstaller.config_testcCrrrrrrr�restartErzDummyInstaller.restartcCrrr)�cls�addrrr�add_parser_argumentsHr$z#DummyInstaller.add_parser_argumentscCrrrrrrr�prepareLrzDummyInstaller.preparecCrrrrrrr�	more_infoOrzDummyInstaller.more_infor)NF)rN)�__name__�
__module__�__qualname__�__doc__r�strrr#rrr'r(�boolr+r,r-�classmethodr0r1r2rrrrr0s"�
�$



rcGst�ttjjdg|�R��S)zPath to a test vector.�testdata)�
pkg_resources�resource_filenamer3r�path�join��namesrrr�vector_pathSs�rAcGsJt�ttjjdg|�R��}z|���dd���WSt	y$|YSw)zLoad contents of a test vector.r:z
�
)
r;�resource_stringr3rr=r>�decode�replace�encode�
ValueError)r@�datarrr�load_vectorYs��rIcCs8tj�|�\}}|��dkr|S|��dkr|Std��)Nz.pemz.derz1Loader could not be recognized based on extension)rr=�splitext�lowerrG)�filename�
loader_pem�
loader_der�_�extrrr�
_guess_loadergsrQcG�*t|dtjjtjj�}tj�|t|��S)zLoad certificate.���)rQ�OpenSSL�crypto�FILETYPE_PEM�
FILETYPE_ASN1�load_certificaterI�r@�loaderrrr�	load_certp��r[cGrR)zLoad certificate request.rS)rQrTrUrVrW�load_certificate_requestrIrYrrr�load_csrwr\r^cGst�t|��S)z(Load ComparableX509 certificate request.)�jose�ComparableX509r^r?rrr�load_comparable_csr~�racGs.t|dtjtj�}t�|t|�dt�d��S)zLoad RSA private key.rSN)�password�backend)rQr	�load_pem_private_key�load_der_private_keyr_�ComparableRSAKeyrIrrYrrr�load_rsa_private_key�s��rhcGrR)zLoad pyOpenSSL private key.rS)rQrTrUrVrW�load_privatekeyrIrYrrr�load_pyopenssl_private_key�r\rjFc

s~|dtd��}tj��tj�}tj��tj|�}tj��tj|�}|||fD]
}tj�|�s5t	�
|�q(td�|r=dnd��}t�
|�D]}	t�tj�||	�tj�||	��qFtjD]}	t�tj�|d�|	��tj�|d�|	���q\tj��||�}
tt|���2}t|
d��}|��fd	d
�|D��Wd�n1s�wYWd�|
SWd�|
S1s�wY|
S)apCreates 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

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

    Nz.confzsample-archive{}z-ec�z{0}1.pemz{0}.pem�wc3s�|]	}|�d��VqdS)�MAGICDIRN)rE)�.0�line��
config_dirrr�	<genexpr>�s�
�zmake_lineage.<locals>.<genexpr>)�lenrr=r>r�RENEWAL_CONFIGS_DIR�ARCHIVE_DIR�LIVE_DIR�existsr�makedirsrA�format�listdir�shutil�copyfiler�ALL_FOUR�symlink�open�
writelines)
rq�testfile�ec�lineage_name�conf_dir�archive_dir�live_dir�	directory�sample_archive�kind�	conf_path�src�dstrrpr�make_lineage�sJ
���
��
�
��
��
��r��zope.component.getUtilitycCst�d�tj|td�S)z�Deprecated, patch certbot.display.util directly or use patch_display_util instead.

    :param str target: path to patch

    :returns: mock zope.component.getUtility
    :rtype: mock.MagicMock

    z�Decorator certbot.tests.util.patch_get_utility is deprecated. You should now patch certbot.display.util yourself directly or use certbot.tests.util.patch_display_util as a temporary workaround.��new_callable)�warnings�warnr�patch�_create_display_util_mock)�targetrrr�patch_get_utility�s
	r�cCs0t�d�|r	|nt��}t|�}tj||d�S)aEDeprecated, patch certbot.display.util directly
    or use patch_display_util_with_stdout instead.

    :param str target: path to patch
    :param object stdout: object to write standard output to; it is
        expected to have a `write` method

    :returns: mock zope.component.getUtility
    :rtype: mock.MagicMock

    z�Decorator certbot.tests.util.patch_get_utility_with_stdout is deprecated. You should now patch certbot.display.util yourself directly or use use certbot.tests.util.patch_display_util_with_stdout as a temporary workaround.��new)r�r��io�StringIO�%_create_display_util_mock_with_stdoutrr�)r��stdout�freezable_mockrrr�patch_get_utility_with_stdout�s

r�cCstjdtd�S)a�Patch 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 so this can be
    used like the old patch_get_utility function. 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: unittest.mock._patch

    �)certbot._internal.display.obj.get_displayr�)rr�r�rrrr�patch_display_util�s�r�cCs"|r|nt��}tjdt|�d�S)a]Patch 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 so this can be
    used like the old patch_get_utility function. 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: unittest.mock._patch

    r�r�)r�r�rr�r��r�rrr�patch_display_util_with_stdout�s�r�c@sDeZdZdZddejjfdd�Zdd�Zdd	�Z	d
d�Z
dd
�ZdS)�
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.

    FNcCs>|rt�ndh|_||_t��|_|tjjkr||_||_	dS)N�freeze)
�set�_frozen_set�_funcr�	MagicMock�_mock�sentinel�DEFAULT�return_value�_frozen)r�frozen�funcr�rrr�__init__)s

zFreezableMock.__init__cCs
d|_dS)z)Freeze object preventing further changes.TN)r�rrrrr�1s
zFreezableMock.freezecOs*|jdur
|j|i|��|j|i|��Sr)r�r�)r�args�kwargsrrr�__call__5s
zFreezableMock.__call__cCsv|dkrzt�||�WStyYdSw|dvr#tt�|d�|�S|dks,||jvr2t�||�Stt�|d�|�S)Nr�F�r��side_effectr�r�)�object�__getattribute__�AttributeError�getattrr�)r�namerrrr�:s�zFreezableMock.__getattribute__cCsb|jr||jvrtd|��t|j||�S|dkr|j�|�|dvr*t|j||�St�|||�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�r/r��__setattr__)rr��valuerrrr�Gs
zFreezableMock.__setattr__)r3r4r5r6rr�r�r�r�r�r�r�rrrrr�s
r�cCsXt�}dd�ttj�D�}|D]}|dkr!tdtd�}t|||�q|��td|d�S)NcS�*g|]}tttj|��r|�d�s|�qS��__��callabler��display_obj�FileDisplay�
startswith�rnr�rrr�
<listcomp>c�
�
�z-_create_display_util_mock.<locals>.<listcomp>�notificationT�r�r��r�r�)r��dirr�r��_assert_valid_callr�r�)�display�method_list�method�frozen_mockrrrr�`s�r�cs~�fdd���fdd�}t�}dd�ttj�D�}|D]}|dkr(td�d	�}ntd|d	�}t|||�q|��td|d
�S)Ncs|r	��|�dSdS)z$Write to message to stdout.
        N)�write)�message�unused_args�
unused_kwargsr�rr�
_write_msgos�z9_create_display_util_mock_with_stdout.<locals>._write_msgcst||��|i|��dS)z<
        Mock function for display utility methods.
        N)r�)r�r�)r�rr�mock_methodus
z:_create_display_util_mock_with_stdout.<locals>.mock_methodcSr�r�r�r�rrrr�~r�z9_create_display_util_mock_with_stdout.<locals>.<listcomp>r�Tr�r�)r�r�r�r�r�r�)r�r�r�r�r�r�r)r�r�rr�ns��r�cOs^|r|dn|dg}i}|�dd�|d<|�dd�|d<|�dd�|d<tj|i|��dS)Nrr��default�cli_flag�force_interactiveF)�get�display_util�assert_valid_call)r�r��assert_args�
assert_kwargsrrrr��sr�c@s eZdZdZdd�Zdd�ZdS)�TempDirTestCasezBBase test class which sets up and tears down a temporary directorycCst��|_dS)zExecute before testN)�tempfile�mkdtemp�tempdirrrrr�setUp�rbzTempDirTestCase.setUpcCs*t��gt��_t��t�|j�dS)zExecute after testN)	�logging�shutdown�	getLogger�handlersr�_release_locksr{�rmtreer�rrrr�tearDown�s
zTempDirTestCase.tearDownN)r3r4r5r6r�r�rrrrr��sr�cs eZdZdZ�fdd�Z�ZS)�ConfigTestCasez2Test class which sets up a NamespaceConfig object.cs�t���t�tjditj���|_d|jj	_
tj�
|jd�|jj	_tj�
|jd�|jj	_tj�
|jd�|jj	_tjd|jj	_tjd|jj	_tjd|jj	_d|jj	_dS)	N�certonly�config�work�logs�auth_cert_path�auth_chain_pathzhttps://example.comr)�superr�r
�NamespaceConfigrr�r�CLI_DEFAULTSr��	namespace�verbrr=r>r�rq�work_dir�logs_dirrr"r!�serverr��	__class__rrr��s
�
zConfigTestCase.setUp)r3r4r5r6r��
__classcell__rrr�rr��sr�cCsXtj�|�rt�|�}nt�|�}z|��|jdd�s Jd��W|��dS|��w)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)�event_in�	event_outr=�my_lockrrr�_handle_lock�s
r	cCsntt�t�}t�}tt|||fd�}|��|jdd�s!Jd��|�|��|jdd�|j	dks5J�dS)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
    )r�r��
r�z*Timeout while waiting to acquire the lock.rN)
�
reload_modulerrrr	�startrr�r>�exitcode)�callback�path_to_lock�
emit_event�
receive_event�processrrr�
lock_and_call�srcs�fdd�}|S)zFDecorator to skip permanently a test on Windows. A reason is required.cst�tjdk��|�S)zWrapped version�win32)�unittest�skipIf�sys�platform)�function��reasonrr�wrapper�sz skip_on_windows.<locals>.wrapperr)rrrrr�skip_on_windows�srcCstj�t��|�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=rrr�	temp_join�sr)F)r�)r�Nr)Ir6�	importlibrrr�r��multiprocessingrrr{rr��typingrrrrr��cryptography.hazmat.backendsr�cryptography.hazmat.primitivesr	�josepyr_rTr;�certbotr
r�certbot._internalrr
r�certbot._internal.displayrr��certbot.compatrr�certbot.displayr��certbot.pluginsrrr��PendingDeprecationWarning�ImportError�	InstallerrrArIrQr[r^rarhrjr�r�r�r�r�r�r�r�r��TestCaser�r�r	rrrrrrr�<module>s���#	

,
�
 D

Anon7 - 2022
AnonSec Team