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__/hook_test.cpython-38.pyc
U

�]�E�@s4dZddlZddlZddlmZddlmZddlmZddlm	Z	ddlm
Z
ddlmZGdd	�d	ej
�ZGd
d�dej�ZGdd
�d
ej�ZGdd�de�ZGdd�de�ZGdd�de�ZGdd�de�ZGdd�de�ZGdd�de�ZGdd�dej
�ZGdd�dej�Zdd�Zed k�r0e��dS)!zTests for certbot.hooks.�N)�List)�errors)�util)�os)�
filesystemc@s.eZdZdZedd��Ze�d�dd��ZdS)�ValidateHooksTestz'Tests for certbot.hooks.validate_hooks.cOsddlm}|||�S)Nr)�validate_hooks)�
certbot.hooksr)�cls�args�kwargsr�r
�9/usr/lib/python3/dist-packages/certbot/tests/hook_test.py�_callszValidateHooksTest._callzcertbot.hooks.validate_hookcCsRt��}|�|�dd�|jD�}|�td�t|dd���|�d|d�dS)NcSsg|]}|dd�qS)r�r
)�.0Zcallr
r
r�
<listcomp>sz-ValidateHooksTest.test_it.<locals>.<listcomp>)ZpreZpostZdeploy����renew)�mockZ	MagicMockr�call_args_list�assertEqual�set)�selfZmock_validate_hook�config�typesr
r
r�test_its

zValidateHooksTest.test_itN)	�__name__�
__module__�__qualname__�__doc__�classmethodrr�patchrr
r
r
rrs

rc@sHeZdZdZedd��Zdd�Ze�d�dd��Z	e�d	�d
d��Z
dS)
�ValidateHookTestz&Tests for certbot.hooks.validate_hook.cOsddlm}|||�S)Nr)�
validate_hook)r	r$)r
rrr$r
r
rr$szValidateHookTest._callc
CsHt�d��4tjddd��|�tj|jdd�W5QRXW5QRXdS)N�$certbot.hooks.plug_util.path_surgeryz&certbot.hooks.filesystem.is_executableF)�return_valueZdummy�foo)rr"�assertRaisesr�HookCommandNotFoundr�rr
r
r�test_hook_not_executable)sz)ValidateHookTest.test_hook_not_executablezcertbot.hooks.util.exe_existsc	Cs@d|_t�d��}|�tj|jdd�W5QRX|�|j�dS)NFr%r'�bar)	r&rr"r(rr)r�
assertTrue�called)rZmock_exe_existsZmock_psr
r
r�test_not_found2szValidateHookTest.test_not_foundzcertbot.hooks._progcCs|�dd�|�|j�dS�Nr')r�assertFalser.)rZ	mock_progr
r
r�
test_unset9szValidateHookTest.test_unsetN)rrrr r!rr+rr"r/r2r
r
r
rr#!s
	
r#c@s(eZdZdZedd��Zedd��ZdS)�HookTestz!Common base class for hook tests.cOst�dS)z7Calls the method being tested with the given arguments.N)�NotImplementedError)r
rrr
r
rrBszHookTest._callc	Os,t�d��}d|_|j||�W5QRX|S)z�Calls self._call after mocking out certbot.hooks.execute.

        The mock execute object is returned rather than the return value
        of self._call.

        �certbot.hooks.execute��r7)rr"r&r)r
rr�mock_executer
r
r�_call_with_mock_executeGsz HookTest._call_with_mock_executeN)rrrr r!rr9r
r
r
rr3?s

r3cs�eZdZdZedd��Z�fdd�Z�fdd�Zdd	�Zd
d�Z	dd
�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Z�ZS)�PreHookTestz!Tests for certbot.hooks.pre_hook.cOsddlm}|||�S)Nr)�pre_hook)r	r;)r
rrr;r
r
rrXszPreHookTest._callcsNtt|���d|j_t�|jj�tj	�
|jjd�|_t|j�|�
�dS�Nr'r,)�superr:�setUprr;r�makedirsZrenewal_pre_hooks_dirr�path�join�dir_hook�create_hook�_reset_pre_hook_alreadyr*��	__class__r
rr>]s
zPreHookTest.setUpcs|��tt|���dS�N)rDr=r:�tearDownr*rEr
rrHhszPreHookTest.tearDowncCsddlm}|��dS)Nr)�executed_pre_hooks)r	rI�clear)rrIr
r
rrDmsz#PreHookTest._reset_pre_hook_alreadycCsd|j_|��dS)N�certonly�r�verb�_test_nonrenew_commonr*r
r
r�
test_certonlyqszPreHookTest.test_certonlycCsd|j_|��dS)N�runrLr*r
r
r�test_runuszPreHookTest.test_runcCs(|�|j�}|�d|jj�|��dS)N�pre-hook)r9r�assert_called_once_withr;�_test_no_executions_common�rr8r
r
rrNysz!PreHookTest._test_nonrenew_commonc	Cs\d|j_d|j_t�|j�t�d��}|�|j�}W5QRX|�	|j
�|�	|jj
�dS)Nr�certbot.hooks.logger)rr;rMr�removerBrr"r9r1r.�info�r�mock_loggerr8r
r
r�
test_no_hooks~szPreHookTest.test_no_hookscCs0d|j_|�|j�}|�d|jj�|��dS)NFrR)r�directory_hooksr9rSr;rTrUr
r
r�test_renew_disabled_dir_hooks�sz)PreHookTest.test_renew_disabled_dir_hookscCs>d|j_|�|j�}|�d|j�|�d|jj�|��dS�NrrR)rrMr9�assert_any_callrB�assert_called_withr;rTrUr
r
r�test_renew_no_overlap�s
z!PreHookTest.test_renew_no_overlapcCs8|j|j_d|j_|�|j�}|�d|j�|��dSr^)rBrr;rMr9rSrTrUr
r
r�test_renew_with_overlap�s

z#PreHookTest.test_renew_with_overlapc	Cs@t�d��}|�|j�}W5QRX|�|j�|�|jj�dS)NrV)rr"r9rr1r.r-rXrYr
r
rrT�sz&PreHookTest._test_no_executions_common)rrrr r!rr>rHrDrOrQrNr[r]rarbrT�
__classcell__r
r
rErr:Us

r:cs�eZdZdZedd��Z�fdd�Z�fdd�Zdd	�Zd
d�Z	dd
�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�Z�ZS)�PostHookTestz"Tests for certbot.hooks.post_hook.cOsddlm}|||�S)Nr)�	post_hook)r	re)r
rrrer
r
rr�szPostHookTest._callcsNtt|���d|j_t�|jj�tj	�
|jjd�|_t|j�|�
�dS)Nr,r')r=rdr>rrerr?Zrenewal_post_hooks_dirrr@rArBrC�_reset_post_hook_eventuallyr*rEr
rr>�s
zPostHookTest.setUpcs|��tt|���dSrG)rfr=rdrHr*rEr
rrH�szPostHookTest.tearDowncCsddlm}|dd�=dS�Nr)�
post_hooks�r	rh�rrhr
r
rrf�sz(PostHookTest._reset_post_hook_eventuallycCs@dD]6}||j_|�|j�}|�d|jj�|�|���qdS)N�rKrP�	post-hook)rrMr9rSrer1�_get_eventually)rrMr8r
r
r�test_certonly_and_run_with_hook�s
z,PostHookTest.test_certonly_and_run_with_hookcCs@d|j_dD].}||j_|�|�|j�j�|�|���qdS)Nrk)rrerMr1r9r.rm)rrMr
r
r�#test_cert_only_and_run_without_hook�s
z0PostHookTest.test_cert_only_and_run_without_hookcCsd|j_|�|jjg�dS)NF)rr\�_test_renew_commonrer*r
r
rr]�sz*PostHookTest.test_renew_disabled_dir_hookscCsd|j_|�|jg�dSrG)rrerprBr*r
r
r�test_renew_no_config_hook�sz&PostHookTest.test_renew_no_config_hookcCs t�|j�|�|jjg�dSrG)rrWrBrprrer*r
r
r�test_renew_no_dir_hook�sz#PostHookTest.test_renew_no_dir_hookcCs"d|j_t�|j�|�g�dSrG)rrerrWrBrpr*r
r
r�test_renew_no_hooks�sz PostHookTest.test_renew_no_hookscCs<|j|jjg}|�|�d|j_|�|jj�|�|�dS)N�baz)rBrrerp�append)r�expectedr
r
rra�s

z"PostHookTest.test_renew_no_overlapcCs|j|j_|�|jg�dSrG)rBrrerpr*r
r
rrb�s
z$PostHookTest.test_renew_with_overlapcCs6d|j_td�D] }|�|j�|�|��|�qdS)Nr�)rrM�rangerrrm)rrv�_r
r
rrp�szPostHookTest._test_renew_commoncCsddlm}|Srgrirjr
r
rrm�szPostHookTest._get_eventually)rrrr r!rr>rHrfrnror]rqrrrsrarbrprmrcr
r
rErrd�s 
rdcsLeZdZdZedd��Zdd�Z�fdd�Zdd	�Zd
d�Z	dd
�Z
�ZS)�RunSavedPostHooksTestz-Tests for certbot.hooks.run_saved_post_hooks.cOsddlm}|�S)Nr)�run_saved_post_hooks)r	r{)r
rrr{r
r
rr�szRunSavedPostHooksTest._callc
Os8d}tj||jd��|j||�W5QR�SQRXdS)z�Call run_saved_post_hooks but mock out execute and eventually

        certbot.hooks.post_hooks is replaced with
        self.eventually. The mock execute object is returned rather than
        the return value of run_saved_post_hooks.

        zcertbot.hooks.post_hooks)�newN)rr"�
eventuallyr9)rrrZeventually_pathr
r
r�&_call_with_mock_execute_and_eventually�sz<RunSavedPostHooksTest._call_with_mock_execute_and_eventuallycstt|���g|_dSrG)r=rzr>r}r*rEr
rr>
szRunSavedPostHooksTest.setUpcCs|�|��j�dSrG)r1r~r.r*r
r
r�
test_emptysz RunSavedPostHooksTest.test_emptycCsJddddg|_|��}|j}t||j�D]\}}|�|dd|�q(dS)Nr'r,rt�quxrr)r}r~r�zipr)rr8ZcallsZactual_callZexpected_argr
r
r�
test_multiples
z#RunSavedPostHooksTest.test_multiplecCs&dg|_|��}|�d|jd�dS)Nr'rlr)r}r~rSrUr
r
r�test_singlesz!RunSavedPostHooksTest.test_single)rrrr r!rr~r>rr�r�rcr
r
rErrz�s
rzcs4eZdZdZdd�Z�fdd�Z�fdd�Z�ZS)�RenewalHookTestz1Common base class for testing deploy/renew hooks.c	sld|kr|dn|d�d|kr(|dn|d����fdd�}t�d��}||_�j||�W5QRX|S)z�Calls self._call after mocking out certbot.hooks.execute.

        The mock execute object is returned rather than the return value
        of self._call. The mock execute object asserts that environment
        variables were properly set.

        �domainsr�lineagerwcs.��tjdd������tjd��dS)z�Assert environment variables are properly set.

            :returns: two strings imitating no output from the hook
            :rtype: `tuple` of `str`

            �RENEWED_DOMAINS� �RENEWED_LINEAGEr6)rr�environrA)Zunused_argsZ
unused_kwargs�r�r�rr
r�execute_side_effect/szDRenewalHookTest._call_with_mock_execute.<locals>.execute_side_effectr5)rr"Zside_effectr)rrrr�r8r
r�rr9$sz'RenewalHookTest._call_with_mock_executecs&tt|���tdd�dD��|_dS)Ncss|]}|tjkr|VqdSrG)rr�)r�varr
r
r�	<genexpr>As
�z(RenewalHookTest.setUp.<locals>.<genexpr>)r�r�)r=r�r>r�
vars_to_clearr*rEr
rr>?s�zRenewalHookTest.setUpcs,|jD]}tj�|d�qtt|���dSrG)r�rr��popr=r�rH)rr�rEr
rrHEs
zRenewalHookTest.tearDown)rrrr r9r>rHrcr
r
rErr�sr�c@sHeZdZdZedd��Ze�d�dd��Ze�d�dd��Z	d	d
�Z
dS)�DeployHookTestz$Tests for certbot.hooks.deploy_hook.cOsddlm}|||�S)Nr)�deploy_hook)r	r�)r
rrr�r
r
rrNszDeployHookTest._callrVcCs@d|j_d|j_|�|jdgd�}|�|j�|�|jj�dS)Nr'T�example.org�/foo/bar)rr��dry_runr9r1r.r-�warningrYr
r
r�test_dry_runSs�zDeployHookTest.test_dry_runcCs8d|j_|�|jdgd�}|�|j�|�|jj�dS)Nr�r�)rr�r9r1r.rXrYr
r
r�test_no_hook\s�zDeployHookTest.test_no_hookcCs8ddg}d}d|j_|�|j||�}|�d|jj�dS)Nr��example.netr�r'�deploy-hook)rr�r9rS)rr�r�r8r
r
r�test_successds�zDeployHookTest.test_successN)rrrr r!rrr"r�r�r�r
r
r
rr�Ks


r�cs^eZdZdZedd��Z�fdd�Zdd�Ze�	d�d	d
��Z
dd�Zd
d�Zdd�Z
�ZS)�
RenewHookTestz"Tests for certbot.hooks.renew_hookcOsddlm}|||�S)Nr)�
renew_hook)r	r�)r
rrr�r
r
rrpszRenewHookTest._callcsFtt|���d|j_t�|jj�tj	�
|jjd�|_t|j�dSr<)
r=r�r>rr�rr?Zrenewal_deploy_hooks_dirrr@rArBrCr*rEr
rr>us�zRenewHookTest.setUpcCs.d|j_|�|jdgd�}|�d|jj�dS)NFr�r�r�)rr\r9rSr�rUr
r
r�test_disabled_dir_hooks~s�z%RenewHookTest.test_disabled_dir_hooksrVcCs:d|j_|�|jdgd�}|�|j�|�|jjd�dS)NTr�r�rw)rr�r9r1r.rr�Z
call_countrYr
r
rr��s�zRenewHookTest.test_dry_runc	CsZd|j_t�|j�t�d��}|�|jdgd�}W5QRX|�|j	�|�|j
j	�dS)NrVr�r�)rr�rrWrBrr"r9r1r.rXrYr
r
rr[�s�zRenewHookTest.test_no_hookscCs0|j|j_|�|jddgd�}|�d|j�dS)Nr�r�r�r�)rBrr�r9rSrUr
r
r�test_overlap�s
�zRenewHookTest.test_overlapcCs4|�|jdgd�}|�d|j�|�d|jj�dS)Nr�r�r�)r9rr_rBr`r�rUr
r
r�test_no_overlap�s�zRenewHookTest.test_no_overlap)rrrr r!rr>r�rr"r�r[r�r�rcr
r
rErr�ms
	

r�c@s,eZdZdZedd��Zdd�Zdd�ZdS)	�ExecuteTestz Tests for certbot.hooks.execute.cOsddlm}|||�S)Nr)�execute)r	r�)r
rrr�r
r
rr�szExecuteTest._callcCs6tdd�D]&}dD]}dD]}|�|||�qqq
dS)Nrrw)r7zHello World!)r7zGoodbye Cruel World!)rx�_test_common)r�
returncode�stdout�stderrr
r
rr�szExecuteTest.test_itc	
Cs�d}d}t�d��J}||f|jj_||j_t�d��}|�|�||�||f�W5QRXW5QRX|jd�d|jdd�}|�||�|j	�
d||�|r�|j	�
tjtjtj|�|s�|r�|�|j
j�dS)	Nr'zfoo-hookzcertbot.hooks.PopenrVrrrzRunning %s command: %s)rr"r&Zcommunicater�rrZ	call_args�getrXr_�ANYr-�errorr.)	rr�r�r�Z
given_commandZ
given_nameZ
mock_popenrZZexecuted_commandr
r
rr��s.,
���zExecuteTest._test_commonN)rrrr r!rrr�r
r
r
rr��s

r�c@s<eZdZdZedd��Zdd�Zdd�Zdd	�Zd
d�Z	dS)
�
ListHooksTestz#Tests for certbot.hooks.list_hooks.cOsddlm}|||�S)Nr)�
list_hooks)r	r�)r
rrr�r
r
rr�szListHooksTest._callcCs|�|�|j��dSrG)r1r�tempdirr*r
r
rr�szListHooksTest.test_emptycs@t�fdd�dD��}|D]}t|�q�����j�|�dS)Nc3s|]}tj��j|�VqdSrG)rr@rAr�)r�basenamer*r
rr��s�z.ListHooksTest.test_multiple.<locals>.<genexpr>)r'r,rtr�)�sortedrCrrr�)r�names�namer
r*rr��s�
zListHooksTest.test_multiplecCs2tj�|jd�}t|�|�|�|j�|g�dSr0�rr@rAr�rCrr�rr�r
r
rr��szListHooksTest.test_singlecCs0tj�|jd�}t|�|�|�|j�g�dS)Nzfoo~r�r�r
r
r�test_ignore_tilde�szListHooksTest.test_ignore_tildeN)
rrrr r!rrr�r�r�r
r
r
rr��s

r�cCstj|ddd���dS)zmCreates an executable file at the specified path.

    :param str file_path: path to create the file at

    �wi�)�mode�chmodN)rZ	safe_open�close)Z	file_pathr
r
rrC�srC�__main__)r ZunittestrZacme.magic_typingrZcertbotrrZcertbot.compatrrZ
certbot.testsZ	test_utilZTestCaserZTempDirTestCaser#ZConfigTestCaser3r:rdrzr�r�r�r�r�rCr�mainr
r
r
r�<module>s,NS),"6$"	


Anon7 - 2021