Your IP : 216.73.216.172


Current Path : /lib/python3/dist-packages/certbot/plugins/__pycache__/
Upload File :
Current File : //lib/python3/dist-packages/certbot/plugins/__pycache__/manual_test.cpython-38.pyc

U

�]b�@s�dZddlZddlZddlZddlZddlmZddlmZddl	m
Z
ddl	mZddlm
Z
ddlmZGd	d
�d
ej�Zedkr�e��dS)z Tests for certbot.plugins.manual�N)�
challenges)�errors)�os)�
filesystem)�	acme_util)�utilcs�eZdZdZ�fdd�Zdd�Zdd�Zdd	�Zd
d�Ze	�
�dd
��Ze	�
�dd��Zdd�Z
e	�
�dd��Zdd�Z�ZS)�AuthenticatorTestz/Tests for certbot.plugins.manual.Authenticator.cs�tt|���tj|_tj|_tj|_	|j|j|j	g|_
dD]}t�t
j�|j|��q<tjddddddt
j�|jd�t
j�|jd�t
j�|jd�t
j�|jd�t
j�|jd�d	�|_dd
lm}||jdd�|_dS)
N)�
config_dir�work_dirZin_progressrFr	r
�
backup_dir�temp_checkpoint_dirZ
in_progess)Zhttp01_port�manual_auth_hook�manual_cleanup_hook�manual_public_ip_logging_ok�noninteractive_mode�validate_hooksr	r
rrZin_progress_dir)�
AuthenticatorZmanual)�name)�superr�setUprZHTTP01_A�http_achallZDNS01_A�
dns_achallZ	DNS01_A_2Zdns_achall_2�achallsr�mkdirr�path�joinZtempdir�mockZ	MagicMock�configZcertbot.plugins.manualr�auth)�self�dr��	__class__��=/usr/lib/python3/dist-packages/certbot/plugins/manual_test.pyrs2��zAuthenticatorTest.setUpcCsd|j_|�tj|jj�dS�NT)rr�assertRaisesr�PluginErrorr�prepare�rr#r#r$�#test_prepare_no_hook_noninteractive-sz5AuthenticatorTest.test_prepare_no_hook_noninteractivecCs0tj�tj�|j_d|j_|�tj	|j
j�dSr%)rr�abspath�seprr
rr&rZHookCommandNotFoundrr(r)r#r#r$�test_prepare_bad_hook1sz'AuthenticatorTest.test_prepare_bad_hookcCs|�t|j��tj��dS)N)�
assertTrue�
isinstancerZ	more_info�sixZstring_typesr)r#r#r$�test_more_info6sz AuthenticatorTest.test_more_infocCs |�|j�d�tjtjg�dS)Nzexample.org)�assertEqualrZget_chall_prefr�HTTP01�DNS01r)r#r#r$�test_get_chall_pref9s
�z%AuthenticatorTest.test_get_chall_prefcCs"d|�j_|�tj|jjg�dS)NF)�yesno�return_valuer&rr'r�perform�r�mock_get_utilityr#r#r$�test_ip_logging_not_ok=s
z(AuthenticatorTest.test_ip_logging_not_okcCs(d|�j_|j�g�|�|jj�dSr%)r6r7rr8r.rrr9r#r#r$�test_ip_logging_okBs
z$AuthenticatorTest.test_ip_logging_okcCs�d|j_d�tj�|j_d�|jjd|j�|jj	��}d�|j
j|j
j�d�|j
�|j
j	��}|�
|j�|j�dd�|jD��|�
|jj|jd|�|�
|jj|j
d|�dS)	NTz�{0} -c "from __future__ import print_function;from certbot.compat import os;  print(os.environ.get('CERTBOT_DOMAIN'));print(os.environ.get('CERTBOT_TOKEN', 'notoken'));print(os.environ.get('CERTBOT_VALIDATION', 'novalidation'));"z{0}
{1}
{2}Znotoken�tokencSsg|]}|�|j��qSr#�Zresponse�account_key��.0�achallr#r#r$�
<listcomp>Ysz9AuthenticatorTest.test_script_perform.<locals>.<listcomp>�CERTBOT_AUTH_OUTPUT)rr�format�sys�
executabler
r�domain�
validationr?r�chall�encoder2rr8r�env)rZdns_expectedZ
http_expectedr#r#r$�test_script_performHs6�������z%AuthenticatorTest.test_script_performcCs|d|j_|�|j�|j�dd�|jD��t|�jj�D]>\}\}}|j|}|�	|�
|j�|dk�|�|d�q8dS)NTcSsg|]}|�|j��qSr#r>r@r#r#r$rCfsz9AuthenticatorTest.test_manual_perform.<locals>.<listcomp>rZwrap)
rrr2rr8r�	enumerateZnotificationZcall_args_listr.rIr?�assertFalse)rr:�i�args�kwargsrBr#r#r$�test_manual_performas�
�z%AuthenticatorTest.test_manual_performcCs�d|j_d�tj�|j_d|j_|j�|j	�|j	D]�}|j�
|g�|�tj
dd�|�tj
d|j�t|jtjtjf�r�|�tj
d|�|j��t|jtj�r�|�tj
d|j�d	��q4|�dtj
k�q4dS)
NTz,{0} -c "import sys; sys.stdout.write('foo')"z	# cleanuprDZfooZCERTBOT_DOMAINZCERTBOT_VALIDATIONZ
CERTBOT_TOKENr=)rrrErFrGr
rrr8rZcleanupr2r�environrHr/rJrr3r4rIr?rKrO)rrBr#r#r$�test_cleanupms*�

�
�zAuthenticatorTest.test_cleanup)�__name__�
__module__�__qualname__�__doc__rr*r-r1r5�	test_utilZpatch_get_utilityr;r<rMrSrU�
__classcell__r#r#r!r$rs


r�__main__)rYZunittestrFrr0ZacmerZcertbotrZcertbot.compatrrZ
certbot.testsrrrZZTempDirTestCaserrV�mainr#r#r#r$�<module>ss