KGRKJGETMRETU895U-589TY5MIGM5JGB5SDFESFREWTGR54TY
Server : Apache/2.4.41 (Ubuntu)
System : Linux vmi1525618.contaboserver.net 5.4.0-105-generic #119-Ubuntu SMP Mon Mar 7 18:49:24 UTC 2022 x86_64
User : www-data ( 33)
PHP Version : 8.2.12
Disable Function : NONE
Directory :  /lib/python3/dist-packages/certbot/tests/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

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

�]7�@s�dZddlZddlZddlZddlZddlZddlmZmZddl	Z	ddl
ZddlZddl
Z
ddlZddlmZddlmZddlmZddlmZddlmZdd	lmZdd
lmZddlmZddlmZdd
lmZddlmZddlmZ dd�Z!dd�Z"dd�Z#dd�Z$dd�Z%dd�Z&dd�Z'dd�Z(dd �Z)d:d"d#�Z*d;d$d%�Z+Gd&d'�d'e,�Z-d(d)�Z.d*d+�Z/d,d-�Z0Gd.d/�d/ej1�Z2Gd0d1�d1e2�Z3d2d3�Z4d4d5�Z5d6d7�Z6d8d9�Z7dS)<zJTest utilities.

.. warning:: This module is not part of the public API.

�N)�Process�Event)�
reload_module)�default_backend)�
serialization)�
configuration)�	constants)�
interfaces)�lock)�storage)�util)�os)�
filesystemcGst�ttjjd|���S)zPath to a test vector.�testdata)r)�
pkg_resourcesZresource_filename�__name__r
�path�join��names�r�4/usr/lib/python3/dist-packages/certbot/tests/util.py�vector_path!s�rcGsLt�ttjjd|���}z|���dd���WSt	k
rF|YSXdS)zLoad contents of a test vector.rz
�
N)r)
rZresource_stringrr
rr�decode�replace�encode�
ValueError)r�datarrr�load_vector's�rcCs<tj�|�\}}|��dkr |S|��dkr0|Std��dS)Nz.pemz.derz1Loader could not be recognized based on extension)r
r�splitext�lowerr)�filenameZ
loader_pemZ
loader_der�_Zextrrr�
_guess_loader5sr$cGs*t|dtjjtjj�}tj�|t|��S)zLoad certificate.���)r$�OpenSSL�crypto�FILETYPE_PEM�
FILETYPE_ASN1Zload_certificater�r�loaderrrr�	load_cert?s�r,cGs*t|dtjjtjj�}tj�|t|��S)zLoad certificate request.r%)r$r&r'r(r)Zload_certificate_requestrr*rrr�load_csrFs�r-cGst�t|��S)z(Load ComparableX509 certificate request.)�joseZComparableX509r-rrrr�load_comparable_csrMsr/cGs.t|dtjtj�}t�|t|�dt�d��S)zLoad RSA private key.r%N)ZpasswordZbackend)r$rZload_pem_private_keyZload_der_private_keyr.ZComparableRSAKeyrrr*rrr�load_rsa_private_keyRs��r0cGs*t|dtjjtjj�}tj�|t|��S)zLoad pyOpenSSL private key.r%)r$r&r'r(r)Zload_privatekeyrr*rrr�load_pyopenssl_private_keyZs�r1c
s6|dtd��}tj��tj�}tj��tj|�}tj��tj|�}|||fD]}tj�|�sPt	�
|�qPtd�}t�|�D]$}t
�tj�||�tj�||��q~tjD]0}t�tj�|d�|��tj�|d�|���q�tj��||�}	tt|���4}
t|	d��}|��fdd�|
D��W5QRXW5QRX|	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-archivez{0}1.pemz{0}.pem�wc3s|]}|�d��VqdS)ZMAGICDIRN)r)�.0�line��
config_dirrr�	<genexpr>�szmake_lineage.<locals>.<genexpr>)�lenr
rrrZRENEWAL_CONFIGS_DIRZARCHIVE_DIRZLIVE_DIR�existsr�makedirsr�listdir�shutilZcopyfilerZALL_FOUR�symlink�format�open�
writelines)r6ZtestfileZlineage_nameZconf_dirZarchive_dirZlive_dirZ	directoryZsample_archiveZkindZ	conf_path�srcZdstrr5r�make_lineageasD
����
��rB�zope.component.getUtilitycCstj|td�S)a;Patch zope.component.getUtility to use a special mock IDisplay.

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

    :param str target: path to patch

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

    )Znew_callable)�mock�patch�_create_get_utility_mock)�targetrrr�patch_get_utility�srHcCs&|r|nt��}t|�}tj||d�S)aPatch zope.component.getUtility to use a special mock IDisplay.

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

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

    :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

    )�new)�six�StringIO�$_create_get_utility_mock_with_stdoutrDrE)rG�stdoutZfreezable_mockrrr�patch_get_utility_with_stdout�srNc@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>|r
t�ndh|_||_t��|_|tjjkr4||_||_	dS)N�freeze)
�set�_frozen_set�_funcrD�	MagicMock�_mock�sentinel�DEFAULT�return_value�_frozen)�self�frozen�funcrXrrr�__init__�s
zFreezableMock.__init__cCs
d|_dS)z)Freeze object preventing further changes.TN)rY�rZrrrrP�szFreezableMock.freezecOs"|jdk	r|j||�|j||�S)N)rSrU)rZ�args�kwargsrrr�__call__�s
zFreezableMock.__call__cCs~|dkr0zt�||�WStk
r,YdSXnJ|dkrJtt�|d�|�S|dks\||jkrht�||�Stt�|d�|�SdS)NrYF�rXZside_effectrUrR)�object�__getattribute__�AttributeError�getattrrR)rZ�namerrrrd�s
zFreezableMock.__getattribute__cCsd|jr,||jkrtd|��nt|j||�S|dkr@|j�|�|dkrVt|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 rRrb)rYrRre�setattrrU�addrc�__setattr__)rZrg�valuerrrrj�s
zFreezableMock.__setattr__)r�
__module__�__qualname__�__doc__rDrVrWr]rPrardrjrrrrrO�s
rOcCsJt�}tj��D]$}|dkrtdtd�}t|||�q|��td|d�S)N�notificationT�r[r\�r[rX)rOr	�IDisplayr�_assert_valid_callrhrP)�displayrg�frozen_mockrrrrF�srFcs|�fdd���fdd�}t�}tj��D]>}|dkrNtd�d�}t|||�q(td|d�}t|||�q(|��td|d�S)	Ncs|r��|�dS)z$Write to message to stdout.
        N)�write)�messageZunused_argsZ
unused_kwargs)rMrr�
_write_msgsz8_create_get_utility_mock_with_stdout.<locals>._write_msgcst||��||�dS)z5
        Mock function for IDisplay methods.
        N)rs)r_r`)rxrr�mock_methods
z9_create_get_utility_mock_with_stdout.<locals>.mock_methodroTrprq)rOr	rrrrhrP)rMryrtrgrur)rxrMrrLs��rLcOsZ|r|dn|dg}i}|�dd�|d<|�dd�|d<|�dd�|d<tj||�dS)Nrrw�defaultZcli_flagZforce_interactiveF)�get�display_utilZassert_valid_call)r_r`Zassert_argsZ
assert_kwargsrrrrs#srsc@s eZdZdZdd�Zdd�ZdS)�TempDirTestCasezBBase test class which sets up and tears down a temporary directorycCst��|_dS)zExecute before testN)�tempfileZmkdtemp�tempdirr^rrr�setUp1szTempDirTestCase.setUpcCs*t��gt��_t��t�|j�dS)zExecute after testN)	�loggingZshutdownZ	getLoggerZhandlersrZ_release_locksr<Zrmtreerr^rrr�tearDown5s
zTempDirTestCase.tearDownN)rrlrmrnr�r�rrrrr}.sr}cs eZdZdZ�fdd�Z�ZS)�ConfigTestCasez2Test class which sets up a NamespaceConfig object.cs�tt|���t�tjftj��|_	d|j	_
tj�
|jd�|j	_tj�
|jd�|j	_tj�
|jd�|j	_tjd|j	_tjd|j	_tjd|j	_d|j	_dS)NZcertonly�configZworkZlogsZauth_cert_pathZauth_chain_pathzhttps://example.com)�superr�r�rZNamespaceConfigrDrTrZCLI_DEFAULTSr�Zverbr
rrrr6Zwork_dirZlogs_dirZ	cert_pathZfullchain_pathZ
chain_pathZserverr^��	__class__rrr�Fs�zConfigTestCase.setUp)rrlrmrnr��
__classcell__rrr�rr�Dsr�cCsRtj�|�rt�|�}n
t�|�}z |��|jdd�s@t	d��W5|��XdS)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
    ��Ztimeoutz*Timeout while waiting to release the lock.N)
r
r�isdirr
Zlock_dirZLockFile�releaserQ�wait�AssertionError)Zevent_inZ	event_outrZmy_lockrrr�_handle_lockUs
r�cCsntt�t�}t�}tt|||fd�}|��|jdd�sBtd��|�|��|j	dd�|j
dksjt�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
    )rGr_�
r�z*Timeout while waiting to acquire the lock.rN)rrrrr��startr�r�rQrZexitcode)�callbackZpath_to_lockZ
emit_eventZ
receive_eventZprocessrrr�
lock_and_callhsr�cs�fdd�}|S)zFDecorator to skip permanently a test on Windows. A reason is required.cst�tjdk��|�S)zWrapped versionZwin32)�unittestZskipIf�sys�platform)Zfunction��reasonrr�wrapper�sz skip_on_windows.<locals>.wrapperr)r�r�rr�r�skip_on_windows�sr�cCstj�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)
    )r
rrr~Z
gettempdir)rrrr�	temp_join�sr�)rC)rCN)8rnr�r<r�r~r�Zmultiprocessingrrr&Zjosepyr.rDrrJZ	six.movesrZcryptography.hazmat.backendsrZcryptography.hazmat.primitivesrZcertbotrrr	r
rrZcertbot.compatr
rZcertbot.displayr|rrr$r,r-r/r0r1rBrHrNrcrOrFrLrsZTestCaser}r�r�r�r�r�rrrr�<module>s\
,
�
E

Anon7 - 2021