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

U

�]p4�@sdZddlmZddlZddlZddlZddlZddlZddlZddl	Z
ddlZddlZddl
mZddlmZddlmZddlmZddlmZdd	lmZdd
lmZdd	lmZe
j�e�d��ZGdd
�d
ej�Z Gdd�dej�Z!e"dkr�e�#�dS)z"Tests for certbot.plugins.webroot.�)�print_functionN)�
challenges)�achallenges)�errors)�os)�
filesystem)�util)�	acme_utilzrsa512_key.pemc@s�eZdZdZejejded�Z	dd�Z
dd�Zdd	�Zd
d�Z
dd
�Ze��dd��Ze��dd��Ze��dd��Ze��dd��Zdd�Zdd�Ze�d�dd��Ze��dd��Zdd �Zd!d"�Zd#d$�Zd%d&�Zd'd(�Ze�d)�d*d+��Z d,S)-�AuthenticatorTestz0Tests for certbot.plugins.webroot.Authenticator.�	thing.com�Zchallb�domainZaccount_keycCs�ddlm}t��|_tj�|jd�|_t�	|j�tj�|jd�|_
tj�|jdd�|_tj�|jd�|_t
j|jd|jid�|_||jd�|_dS)	Nr��
Authenticator�webrootz.well-knownzacme-challengeZ:ZXZhR3hmQURzNnBTUmIyTEF2OUlaZjE3RHQzanV4R0orUEN0OTJ3citvQQr)�webroot_path�webroot_map)�certbot.plugins.webrootr�tempfile�mkdtempZ	workspacer�path�joinr�mkdir�partial_root_challenge_path�root_challenge_path�validation_path�mock�	MagicMock�config�auth��selfr�r"�>/usr/lib/python3/dist-packages/certbot/plugins/webroot_test.py�setUp#s*
����zAuthenticatorTest.setUpcCst�|j�dS�N)�shutilZrmtreer�r!r"r"r#�tearDown7szAuthenticatorTest.tearDowncCs0|j��}|�t|tj��|�|j|k�dSr%)r�	more_info�
assertTrue�
isinstance�sixZstring_typesr)r!r)r"r"r#�test_more_info:s
z AuthenticatorTest.test_more_infocCs&t��}|j�|�|�d|j�dS)N�)rrrZadd_parser_arguments�assertEqualZ
call_count)r!�addr"r"r#�test_add_parser_arguments?sz+AuthenticatorTest.test_add_parser_argumentscCs|j��dSr%)r�preparer'r"r"r#�test_prepareDszAuthenticatorTest.test_preparecs�g|j_d|ji|j_|�}tjdf|j_|j�	|j
g�|�|jj�|jj
D]D�|�|j
j�ddk�|�t�fdd�t�|jj�D���qP|�|jj|j
j|j�dS)N�otherthing.com�rc3s|]}|�ddkVqdS�rr5Nr"��.0r��callr"r#�	<genexpr>Rs�z;AuthenticatorTest.test_webroot_from_list.<locals>.<genexpr>)rrrr�display_util�OK�menu�return_valuer�perform�achallr*�called�call_args_listr
�allr,�
itervaluesr/�r!�mock_get_utility�mock_displayr"r9r#�test_webroot_from_listGs��z(AuthenticatorTest.test_webroot_from_listcs�g|j_d|ji|j_|�}tjdff|j_|�t	j
|jj|j
g�|�|jj�|jjD]D�|�|j
j�ddk�|�t�fdd�t�|jj�D���qZdS)Nr4���rc3s|]}|�ddkVqdSr6r"r7r9r"r#r;cs�zKAuthenticatorTest.test_webroot_from_list_help_and_cancel.<locals>.<genexpr>)rrrrr<�CANCELr>�side_effect�assertRaisesr�PluginErrorrr@rAr*rBrCr
rDr,rErFr"r9r#�&test_webroot_from_list_help_and_cancelXs�z8AuthenticatorTest.test_webroot_from_list_help_and_cancelc	Cs�g|j_d|ji|j_|�}tjdf|j_t�	d��.}tj
dftj|jff|_|j�
|jg�W5QRX|�|jj|jj|j�dS)N�
something.comr�'certbot.display.ops.validated_directoryrJ)rrrrr<r=r>r?r�patchrKrLrr@rAr/r
�r!rGrH�mr"r"r#�test_new_webrootgs
�z"AuthenticatorTest.test_new_webrootc	Csbg|j_i|j_|�}tjdf|j_t�d��*}tj	df|_|�
tj|j
j|jg�W5QRXdS)NrrQrJ)rrrr<r=r>r?rrRrKrMrrNrr@rArSr"r"r#�!test_new_webroot_empty_map_cancelvs�z3AuthenticatorTest.test_new_webroot_empty_map_cancelcCs(d|j_i|j_|�tj|jjg�dSr%)rrrrMrrNrr@r'r"r"r#�test_perform_missing_root�sz+AuthenticatorTest.test_perform_missing_rootc	Cs�tj�|jd�|j_tj�|jd�}t|d��}|�d�W5QRXt�|jd�zt|d�t	d�Wn(t
k
r�|�tj
|jjg�YnXt�|jd�dS)	NZnullZrnd�wZthingimyr�rz9Warning, running tests as root skips permissions tests...i�)rrrr�	full_path�open�writer�chmod�print�IOErrorrMrrNr@)r!Zpermission_canary�fr"r"r#�"test_perform_reraises_other_errors�s
z4AuthenticatorTest.test_perform_reraises_other_errorsz@certbot.plugins.webroot.filesystem.copy_ownership_and_apply_modecCs"ttjd�|_|j�|jg�dS)N�msg)�OSError�errno�EACCESrLrr@rA)r!Zmock_ownershipr"r"r#�test_failed_chown�sz#AuthenticatorTest.test_failed_chownc	Cs�t��}g|j_d|ji|j_|�}tjdftj|ff|j_	t
jtj
dtd�}t�d�� }tj|f|_|j�|g�W5QRX|�|jj|j|�dS)Nzwhatever.comrrPrrQ)rrrrrrr<r=r>rLr�"KeyAuthorizationAnnotatedChallenger	�HTTP01_P�KEYrrRr?rr@r/r
)r!rGZnew_webrootrHrArTr"r"r#�#test_perform_new_webroot_not_in_map�s ��z5AuthenticatorTest.test_perform_new_webroot_not_in_mapcCs�|j��|j�|jg�|�t�|jd��t�	|j
�D]4\}}}|D]$}tj
�||�}|�t�|d��qHq:|�t�|j|j
��dS)Ni�i�)
rr2r@rAr*rZ
check_moderr�walkrrZhas_same_ownership)r!�dirpathZdirnames�_Z	directoryrZr"r"r#�test_perform_permissions�s
z*AuthenticatorTest.test_perform_permissionsc	Cs�|j��|j�|jg�}|�dt|��|�tj�	|j
��t|j
��}|��}W5QRX|�t
j|d��|jjt����|j�|jg�|�tj�	|j
��|�tj�	|j��|�tj�	|j��dS)Nr5)Zkey_authorization)rr2r@rAr/�lenr*rr�existsrr[�readrZ!KeyAuthorizationChallengeResponseZverifyZchallriZ
public_key�cleanup�assertFalserr)r!Z	responsesZvalidation_fZ
validationr"r"r#�test_perform_cleanup�s$
���z&AuthenticatorTest.test_perform_cleanupcCsbt�|j�|j��|j�|jg�|j�|jg�|�t	j
�|j��|�t	j
�|j
��dSr%)rrrrr2r@rArrrsrrrprrr'r"r"r#�"test_perform_cleanup_existing_dirs�s
z4AuthenticatorTest.test_perform_cleanup_existing_dirscCs�tjt�tjdd�d�dtd�}d}t�|j	�|j
��|j
�||j
g�|j
�|j
g�|�tj�|��|�tj�|j��|j
�|g�|�tj�|j��|�tj�|j��dS)Nsbingo)�token�pendingrrZYmluZ28)rrgr	Zchall_to_challbrZHTTP01rirrrrr2r@rArrrsrrrpr*rr)r!Zbingo_achallZbingo_validation_pathr"r"r#�(test_perform_cleanup_multiple_challenges�s$
��
z:AuthenticatorTest.test_perform_cleanup_multiple_challengescCsz|j��|j�|jg�tj�|jd�}t�	|�|j�
|jg�|�tj�|j
��|�tj�|j��t�|�dS)NZleftover)rr2r@rArrrrrrrrrsrprr*�rmdir)r!Z
leftover_pathr"r"r#�test_cleanup_leftovers�s

z(AuthenticatorTest.test_cleanup_leftoverszcertbot.compat.os.rmdircCsj|j��|j�|jg�t�}tj|_||_|j�|jg�|�	t
j�|j
��|�t
j�|j��dSr%)rr2r@rArcrdrerLrrrsrrrprr*r)r!Z
mock_rmdirZos_errorr"r"r#�test_cleanup_failure�s
z&AuthenticatorTest.test_cleanup_failureN)!�__name__�
__module__�__qualname__�__doc__rrgr	rhrirAr$r(r-r1r3�	test_utilZpatch_get_utilityrIrOrUrVrWrarrRrfrjrnrtrurxrzr{r"r"r"r#r
s@�







r
c@sZeZdZdZejejded�Z	dd�Z
dd�Zdd	�Zd
d�Z
dd
�Zdd�Zdd�ZdS)�WebrootActionTestz#Tests for webroot argparse actions.rrcCsFddlm}t��|_t��|_|jjdddgd�|�	|jd�dS)Nrrz-dz	--domains�append)�action�defaultr)
rrrrr�argparse�ArgumentParser�parser�add_argumentZinject_parser_optionsr r"r"r#r$s


�zWebrootActionTest.setUpcCs4|j�dt�d|ji�g�}|�|jd|j�dS)Nz
--webroot-mapr)r��
parse_args�json�dumpsrr/r)r!�argsr"r"r#�test_webroot_map_actions�z)WebrootActionTest.test_webroot_map_actioncCsD|j�d�|jj|j����}|�|�}|�|j	|jj|j�dS)Nz
-d {0} -w {1})
r�r��formatrAr
r�split�_get_config_after_performr/r�r!r�rr"r"r#�test_domain_before_webroots
�
z,WebrootActionTest.test_domain_before_webrootcCs4|�tj|jjd���|�tj|jjd���dS)Nz-d foo -w bar -w bazz-d foo -w bar -d baz -w qux)rMrrNr�r�r�r'r"r"r#� test_domain_before_webroot_errors��z2WebrootActionTest.test_domain_before_webroot_errorcCsb|j�d�|j|jjt������}|�	|j
|jj|j�|�|�}|�	|j
|jj|j�dS�Nz-w {0} -d {1} -w {2} -d bar)r�r�r�rrAr
rrr�r/rr�r�r"r"r#�test_multiwebroot!s
�

�z#WebrootActionTest.test_multiwebrootcCsXt��}|j�d�|j|jj|����}|�	|j
|jj|ji�|�	|j|j|g�dSr�)rrr�r�r�rrAr
r�r/rr)r!Zother_webroot_pathr�r"r"r#�(test_webroot_map_partial_without_perform)s
�
z:WebrootActionTest.test_webroot_map_partial_without_performcCs*ddlm}||d�}|�|jg�|jS)Nrrr)rrr@rAr)r!rrrr"r"r#r�6s
z+WebrootActionTest._get_config_after_performN)r|r}r~rrrgr	rhrirAr$r�r�r�r�r�r�r"r"r"r#r�s�
r��__main__)$rZ
__future__rr�rdr�r&rZunittestZjosepyZjoserr,ZacmerZcertbotrrZcertbot.compatrrZcertbot.displayrr<Z
certbot.testsr	r�ZJWKRSA�loadZload_vectorriZTestCaser
r�r|�mainr"r"r"r#�<module>s0f;