JFIF$        dd7 

Viewing File: /usr/lib/python3.9/site-packages/certbot/tests/__pycache__/util.cpython-39.pyc

a

}|�gnF�@sBdZddlZddlmZddlZddlmZddlZddl	Z	ddl
Z
ddlZddlmZddl
Z
ddlZddlZddlmZddlmZddlmZdd	lmZdd
lmZddlmZddlmZdd
lmZddlZddlmZddlmZddlmZddlm Z ddl!Z"ddl#m$Z$ddl%m&Z&ddl%m'Z'ddl(m)Z)ddl(m*Z*ddl(m+Z+ddl,m-Z.ddl/m0Z0ddl/m1Z1ddl2m'Z3ddl4m5Z5Gdd�de5j6�Z7e8e8d�dd �Z9e8e:d�d!d"�Z;e8e<e<e<d#�d$d%�Z=e8e$j>d�d&d'�Z?e8e$j@d�d(d)�ZAe8e"jBd�d*d+�ZCe8e"jDd�d,d-�ZEe8e$jFd�d.d/�ZGdTe8e8eHe8d1�d2d3�ZIejJd4�d5d6�ZKdUeeejJd7�d8d9�ZLGd:d;�d;�ZMeMd4�d<d=�ZNeeMd7�d>d?�ZOeedd@�dAdB�ZPGdCdD�dDejQ�ZRGdEdF�dFeR�ZSejTejTe8ddG�dHdI�ZUegefe8ddJ�dKdL�ZVe8eedMefgedMeffdN�dOdP�ZWe8e8dQ�dRdS�ZXdS)VzTest 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)�commonc@s�eZdZdZeed�dd�Zeeeeedd�dd�Zdeeee	e
eefdd	�d
d�Ze
ed�dd
�Zdeee
dd�dd�Zdd�dd�Zdd�dd�Zeeddd�dd��Zdd�dd�Zed�dd�ZdS) �DummyInstallerz(Dummy installer plugin for test purpose.��returncCsgS�N���selfrr�6/usr/lib/python3.9/site-packages/certbot/tests/util.py�
get_all_names-szDummyInstaller.get_all_namesN)�domain�	cert_path�key_path�
chain_path�fullchain_pathrcCsdSrr)r!r$r%r&r'r(rrr"�deploy_cert0szDummyInstaller.deploy_cert)r$�enhancement�optionsrcCsdSrr)r!r$r*r+rrr"�enhance4szDummyInstaller.enhancecCsgSrrr rrr"�supported_enhancements8sz%DummyInstaller.supported_enhancementsF)�title�	temporaryrcCsdSrr)r!r.r/rrr"�save;szDummyInstaller.savecCsdSrrr rrr"�config_test>szDummyInstaller.config_testcCsdSrrr rrr"�restartAszDummyInstaller.restart).N)�addrcCsdSrr)�clsr3rrr"�add_parser_argumentsDsz#DummyInstaller.add_parser_argumentscCsdSrrr rrr"�prepareHszDummyInstaller.preparecCsdS)N�rr rrr"�	more_infoKszDummyInstaller.more_info)N)NF)�__name__�
__module__�__qualname__�__doc__r	�strr#r)rrr
r,r-�boolr0r1r2�classmethodrr5r6r8rrrr"r+s"���r)�namesrcGsFt�}t�|j�tj�t�jdg|�R�}|�	tj�
|��}t|�S)zPath to a test vector.�testdata)r�atexit�register�close�	importlib�	resources�files�__package__�joinpath�
enter_contextZas_filer=)r@Z
_file_manager�
vector_ref�pathrrr"�vector_pathOs
rMcGsTtj�t�jdg|�R�}|��}z|���dd���WSt	yN|YS0dS)zLoad contents of a test vector.rAz
�
N)
rErFrGrHrI�
read_bytes�decode�replace�encode�
ValueError)r@rK�datarrr"�load_vectorXsrU)�filename�
loader_pem�
loader_derrcCs<tj�|�\}}|��dkr |S|��dkr0|Std��dS)Nz.pemz.derz1Loader could not be recognized based on extension)rrL�splitext�lowerrS)rVrWrX�_�extrrr"�
_guess_loaderesr]cGs$t|dtjtj�}t�|t|��S)zLoad certificate.���)r]r�FILETYPE_PEM�
FILETYPE_ASN1Zload_certificaterU�r@�loaderrrr"�	load_certns�rccGs$t|dtjtj�}t�|t|��S)zLoad certificate request.r^)r]rr_r`Zload_certificate_requestrUrarrr"�load_csrus�rdcGst�t|��S)z(Load ComparableX509 certificate request.)�jose�ComparableX509rd)r@rrr"�load_comparable_csr|srgc	GsLt|dtjtj�}|tjkr&tj}ntj}t�t	t
|t|�dt�d���S)zLoad RSA private key.r^N)�passwordZbackend)
r]rr_r`rZload_pem_private_keyZload_der_private_keyre�ComparableRSAKeyrrrUr)r@rbZ	loader_fnrrr"�load_rsa_private_key�s
��rjcGs$t|dtjtj�}t�|t|��S)zLoad pyOpenSSL private key.r^)r]rr_r`Zload_privatekeyrUrarrr"�load_pyopenssl_private_key�s�rkT)�
config_dir�testfile�ecrc

sp|dtd��}tj��tj�}tj��tj|�}tj��tj|�}|||fD]}tj�|�sPt	�
|�qPtd�|rzdnd��}t�
|�D]$}	t�tj�||	�tj�||	��q�tjD]0}	t�tj�|d�|	��tj�|d�|	���q�tj��||�}
tt|���T}t|
d��(}|��fd	d
�|D��Wd�n1�sB0YWd�n1�sb0Y|
S)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-ecr7z{0}1.pemz{0}.pem�wc3s|]}|�d��VqdS)ZMAGICDIRN)rQ)�.0�line�rlrr"�	<genexpr>�szmake_lineage.<locals>.<genexpr>)�lenrrL�joinrZRENEWAL_CONFIGS_DIRZARCHIVE_DIRZLIVE_DIR�existsr�makedirsrM�format�listdir�shutil�copyfilerZALL_FOUR�symlink�open�
writelines)
rlrmrnZlineage_nameZconf_dir�archive_dirZlive_dirZ	directoryZsample_archive�kindZ	conf_path�src�dstrrrr"�make_lineage�s:����
��Hr�rcCsttjtjdtd��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)Znew_callable)rr
�	MagicMock�patch�_create_display_util_mockrrrr"�patch_display_util�s�r�)�stdoutrcCs*|r|nt��}ttjtjdt|�d��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�StringIOrr
r�r��%_create_display_util_mock_with_stdout�r�rrr"�patch_display_util_with_stdout�s�r�c@s�eZdZdZddejjfeee	de
fe
dd�dd�Zdd�d	d
�Ze
e
ej
d�dd
�Zee
d�dd�Zee
dd�dd�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.

    FN.)�frozen�func�return_valuercCs>|r
t�ndh|_||_t��|_|tjjkr4||_||_	dS)N�freeze)
�set�_frozen_set�_funcr
r��_mock�sentinel�DEFAULTr��_frozen)r!r�r�r�rrr"�__init__s
zFreezableMock.__init__rcCs
d|_dS)z)Freeze object preventing further changes.TN)r�r rrr"r�szFreezableMock.freeze��args�kwargsrcOs*|jdur|j|i|��|j|i|��Sr)r�r�)r!r�r�rrr"�__call__s
zFreezableMock.__call__)�namercCs||dkr.zt�||�WSty*YdS0nJ|dvrHtt�|d�|�S|dksZ||jvrft�||�Stt�|d�|�SdS)Nr�F�r�Zside_effectr�r�)�object�__getattribute__�AttributeError�getattrr�)r!r�rrr"r�s
zFreezableMock.__getattribute__)r��valuercCsb|jr*||jvrtd|��t|j||�S|dkr>|j�|�|dvrTt|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�r3r��__setattr__)r!r�r�rrr"r�&s
zFreezableMock.__setattr__)r9r:r;r<r
r�r�r>rrrr�r�r�r�r=r�r�rrrr"r��s��	
r�cCsXt�}dd�ttj�D�}|D]$}|dkrtdtd�}t|||�q|��td|d�S)NcSs*g|]"}tttj|��r|�d�s|�qS��__��callabler��display_obj�FileDisplay�
startswith�rpr�rrr"�
<listcomp>Bs
�z-_create_display_util_mock.<locals>.<listcomp>�notificationT�r�r��r�r�)r��dirr�r��_assert_valid_callr�r�)�display�method_list�method�frozen_mockrrr"r�?sr�cs�tttdd��fdd��ttdd��fdd�}t�}dd�ttj�D�}|D]2}|d	krftd
�d�}ntd
|d�}t|||�qL|��td
|d�S)
N)�message�unused_args�
unused_kwargsrcs|r��|�dS)z$Write to message to stdout.
        N)�write)r�r�r�r�rr"�
_write_msgNsz9_create_display_util_mock_with_stdout.<locals>._write_msgr�cst||��|i|��dS)z<
        Mock function for display utility methods.
        N)r�)r�r�)r�rr"�mock_methodTs
z:_create_display_util_mock_with_stdout.<locals>.mock_methodcSs*g|]"}tttj|��r|�d�s|�qSr�r�r�rrr"r�]s
�z9_create_display_util_mock_with_stdout.<locals>.<listcomp>r�Tr�r�)r=rr�r�r�r�r�r�)r�r�r�r�r�r�r)r�r�r"r�Ms��r�r�cOsN|r|dn|dg}|�dd�|�dd�|�dd�d�}tj|i|��dS)Nrr��default�cli_flag�force_interactiveF)r�r�r�)�get�display_utilZassert_valid_call)r�r�Zassert_argsZ
assert_kwargsrrr"r�ls


�r�c@s,eZdZdZdd�dd�Zdd�dd�ZdS)�TempDirTestCasezBBase test class which sets up and tears down a temporary directoryNrcCst��|_dS)zExecute before testN)�tempfileZmkdtemp�tempdirr rrr"�setUp{szTempDirTestCase.setUpcCs*t��gt��_t��t�|j�dS)zExecute after testN)	�loggingZshutdownZ	getLogger�handlersrZ_release_locksrz�rmtreer�r rrr"�tearDowns
zTempDirTestCase.tearDown)r9r:r;r<r�r�rrrr"r�xsr�cs&eZdZdZdd��fdd�Z�ZS)�ConfigTestCasez2Test class which sets up a NamespaceConfig object.Nrcs�t���t�tjfit�tj	����|_
|j
�i�d|j
j_
tj�|jd�|j
j_tj�|jd�|j
j_tj�|jd�|j
j_tj	d|j
j_tj	d|j
j_tj	d|j
j_d|j
j_dS)NZcertonly�configZworkZlogsZauth_cert_pathZauth_chain_pathzhttps://example.com)�superr�rZNamespaceConfigr
r��copy�deepcopyrZCLI_DEFAULTSr�Zset_argument_sources�	namespaceZverbrrLrur�rlZwork_dirZlogs_dirr%r(r'Zserverr ��	__class__rr"r��s
�
zConfigTestCase.setUp)r9r:r;r<r��
__classcell__rrr�r"r��sr�)�event_in�	event_outrLrcCsZtj�|�rt�|�}n
t�|�}z(|��|jdd�s@Jd��W|��n
|��0dS)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)	rrL�isdirrZlock_dirZLockFiler��wait�release)r�r�rLZmy_lockrrr"�_handle_lock�s
r�)�callback�path_to_lockrcCsttt�t��}t��}tjt|||fd�}|��|jdd�sHJd��|�|��|j	dd�|j
dkspJ�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
    )�targetr��
r�z*Timeout while waiting to acquire the lock.rN)�
reload_moduler�multiprocessing�EventZProcessr��startr�r�ruZexitcode)r�r�Z
emit_eventZ
receive_eventZprocessrrr"�
lock_and_call�s�r�.)�reasonrcs(tdtftdtfd��fdd�}|S)zFDecorator to skip permanently a test on Windows. A reason is required..)�functionrcst�tjdk��|�S)zWrapped version�win32)�unittestZskipIf�sys�platform)r��r�rr"�wrapper�sz skip_on_windows.<locals>.wrapper)rr)r�r�rr�r"�skip_on_windows�s$r�)rLrcCstj�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)
    )rrLrur�Z
gettempdir)rLrrr"�	temp_join�sr�)T)N)Yr<rB�
contextlibrr�rErr�Zimportlib.resourcesr�r�r�rrzr�r��typingrrrrr	r
rrr�r
Zcryptography.hazmat.backendsrZcryptography.hazmat.primitivesrZ-cryptography.hazmat.primitives.asymmetric.rsarZjosepyreZOpenSSLrZcertbotrrZcertbot._internalrrrZcertbot._internal.displayrr�Zcertbot.compatrrZcertbot.displayr�Zcertbot.pluginsrZ	Installerrr=rM�bytesrU�intr]ZX509rcZX509ReqrdrfrgrirjZPKeyrkr>r�r�r�r�r�r�r�r�ZTestCaser�r�r�r�r�r�r�rrrr"�<module>s|$	
	
-�
� E*
Back to Directory  nL+D550H?Mx ,D"v]qv;6*Zqn)ZP0!1 A "#a$2Qr D8 a Ri[f\mIykIw0cuFcRı?lO7к_f˓[C$殷WF<_W ԣsKcëIzyQy/_LKℂ;C",pFA:/]=H  ~,ls/9ć:[=/#f;)x{ٛEQ )~ =𘙲r*2~ a _V=' kumFD}KYYC)({ *g&f`툪ry`=^cJ.I](*`wq1dđ#̩͑0;H]u搂@:~וKL Nsh}OIR*8:2 !lDJVo(3=M(zȰ+i*NAr6KnSl)!JJӁ* %݉?|D}d5:eP0R;{$X'xF@.ÊB {,WJuQɲRI;9QE琯62fT.DUJ;*cP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