Your IP : 216.73.216.190


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

U

�]� �@s�dZddlZddlZddlZddlZddlmZddlmZddlm	Z	ddl
mZddlm
Z
ddlmZddlmZGdd	�d	ejej�ZGd
d�dej�ZGdd
�d
ej�ZGdd�dej�Zedkr�e��dS)z%Tests for certbot.plugins.dns_common.�N)�errors)�util)�os)�
dns_common)�dns_test_commoncs�eZdZGdd�dej�ZGdd�de�Z�fdd�Zdd�Z	d	d
�Z
e��dd��Z
e��d
d��Ze��dd��Ze��dd��Zdd�Ze��dd��Z�ZS)�DNSAuthenticatorTestc@s,eZdZe��Ze��Ze��Zdd�ZdS)z*DNSAuthenticatorTest._FakeDNSAuthenticatorcCsdS)Nz!A fake authenticator for testing.���selfrr�A/usr/lib/python3/dist-packages/certbot/plugins/dns_common_test.py�	more_infosz4DNSAuthenticatorTest._FakeDNSAuthenticator.more_infoN)	�__name__�
__module__�__qualname__�mockZ	MagicMockZ_setup_credentials�_perform�_cleanuprrrrr�_FakeDNSAuthenticatorsrc@seZdZdZdZdZdZdS)z DNSAuthenticatorTest._FakeConfigr�N)r
rrZfake_propagation_secondsZfake_config_key�fake_other_key�fake_file_pathrrrr�_FakeConfigsrcs,tt|���t��|_t�|jd�|_dS)NZfake)�superr�setUpr�configr�authr	��	__class__rrr#s
zDNSAuthenticatorTest.setUpcCs,|j�|jg�|jj�tjtjtj�dS�N)	rZperform�achallr�assert_called_once_withr�DOMAINr�ANYr	rrr�test_perform*sz!DNSAuthenticatorTest.test_performcCs4d|j_|j�|jg�|jj�tjtj	tj	�dS)NT)
rZ_attempt_cleanupZcleanuprrr rr!rr"r	rrr�test_cleanup/sz!DNSAuthenticatorTest.test_cleanupcCsB|�}tjdftjdff|j_|j�dd�|�|jjjd�dS)N��value�	other_key)	�display_util�OK�input�side_effectr�
_configure�assertEqualrr�r
�mock_get_utility�mock_displayrrr�test_prompt6s�z DNSAuthenticatorTest.test_promptcCs0|�}tjdff|j_|�tj|jjdd�dS)N�cr'r%)	r(�CANCELr*r+�assertRaisesr�PluginErrorrr,r.rrr�test_prompt_canceled?sz)DNSAuthenticatorTest.test_prompt_canceledcCsrtj�|jd�}t|d���|�}tjdftjdftj|jftj|ff|j_	|j
�dd�|�|j
j
j|�dS)N�file.ini�wbr%�not-a-file.ini�	file_path)r�path�join�tempdir�open�closer(r)�directory_selectr+r�_configure_filer-rr)r
r/r;r0rrr�test_prompt_fileFs
�z%DNSAuthenticatorTest.test_prompt_filecCs0|�}tjdff|j_|�tj|jjdd�dS)Nr2r:r%)	r(r3r@r+r4rr5rrAr.rrr�test_prompt_file_canceledTsz.DNSAuthenticatorTest.test_prompt_file_canceledcCsXtj�|jd�}t�ddi|�t|jd|�|j�	ddddi�}|�
|�d�d�dS)Nr7�	fake_testr&�fake_credentials�credentialsr%�test)rr;r<r=r�write�setattrrr�_configure_credentialsr-�conf)r
r;rFrrr�test_configure_credentials[s
z/DNSAuthenticatorTest.test_configure_credentialscCs�tj�|jd�}t�ddi|�tj�|jd�}t�ddi|�t|jdd�|�}tj	dftj	d	ftj	|jftj	|ftj	|ff|j
_|j�
d
dddi�}|�|�d�d�dS)Nzbad-file.iniZ
fake_otherZother_valuer7rDr&rEr%r9rFrG)rr;r<r=rrHrIrr(r)r@r+rrJr-rK)r
r/Zbad_pathr;r0rFrrr�test_prompt_credentialsds
�z,DNSAuthenticatorTest.test_prompt_credentials)r
rrrZDNSAuthenticatorr�objectrrr#r$�	test_utilZpatch_get_utilityr1r6rBrCrLrM�
__classcell__rrrrrs 




	rc@s6eZdZGdd�dej�Zdd�Zdd�Zdd�Zd	S)
�CredentialsConfigurationTestc@s(eZdZdZdd�Zdd�Zdd�ZdS)z0CredentialsConfigurationTest._MockLoggingHandlerNcOs |��tjj|f|�|�dSr)�reset�logging�Handler�__init__)r
�args�kwargsrrrrU|sz9CredentialsConfigurationTest._MockLoggingHandler.__init__cCs|j|j���|���dSr)�messagesZ	levelname�lower�appendZ
getMessage)r
�recordrrr�emit�sz5CredentialsConfigurationTest._MockLoggingHandler.emitcCst�t�|_dS)z-Allows the handler to be reset between tests.N)�collections�defaultdict�listrXr	rrrrR�sz6CredentialsConfigurationTest._MockLoggingHandler.reset)r
rrrXrUr\rRrrrr�_MockLoggingHandlerysr`cCsTtj�|jd�}t�ddd�|�t�|�}|�d|�	d��|�d|�	d��dS)N�too-permissive-file.inir&r�rG�otherrG�1rc)
rr;r<r=rrHr�CredentialsConfigurationr-rK)r
r;�credentials_configurationrrr�test_valid_file�s

z,CredentialsConfigurationTest.test_valid_filecCs&tj�|jd�}|�tjtj|�dS)Nr9)	rr;r<r=r4rr5rre)r
r;rrr�test_nonexistent_file�sz2CredentialsConfigurationTest.test_nonexistent_filecCsd|��}tj�|�tj�|jd�}t�	|dd��
�t�|�|�dt
dd�|jdD���dS)Nrar8i�rcSsg|]}|�d�r|�qS)ZUnsafe)�
startswith)�.0�_rrr�
<listcomp>�s
zXCredentialsConfigurationTest.test_valid_file_with_unsafe_permissions.<locals>.<listcomp>Zwarning)r`rZloggerZ
addHandlerrr;r<r=rZ	safe_openr?rer-�lenrX)r
�logr;rrr�'test_valid_file_with_unsafe_permissions�s
zDCredentialsConfigurationTest.test_valid_file_with_unsafe_permissionsN)	r
rrrSrTr`rgrhrorrrrrQxs	rQcsTeZdZ�fdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
�ZS)�#CredentialsConfigurationRequireTestcs$tt|���tj�|jd�|_dS)Nr7)rrprrr;r<r=r	rrrr�sz)CredentialsConfigurationRequireTest.setUpcCst�||j�dSr)rrHr;)r
�valuesrrr�_write�sz*CredentialsConfigurationRequireTest._writecCs0|�ddd��t�|j�}|�ddd��dS)Nr&rrbr%�rrrrer;�require�r
rfrrr�
test_valid�sz.CredentialsConfigurationRequireTest.test_validcCs.|�ddd��t�|j�}|�ddi�dS)Nr&rrbrGr%rsrurrr�test_valid_but_extra�sz8CredentialsConfigurationRequireTest.test_valid_but_extracCs$|�i�t�|j�}|�i�dSrrsrurrr�test_valid_empty�s
z4CredentialsConfigurationRequireTest.test_valid_emptycCs0|�i�t�|j�}|�tj|jddi�dS�NrGr%�rrrrer;r4rr5rtrurrr�test_missing�s
z0CredentialsConfigurationRequireTest.test_missingcCs4|�ddi�t�|j�}|�tj|jddi�dSryrzrurrr�
test_blank�sz.CredentialsConfigurationRequireTest.test_blankcCs4|�ddi�t�|j�}|�tj|jddi�dS)NZtetsztypo!rGr%rzrurrr�	test_typo�sz-CredentialsConfigurationRequireTest.test_typo)r
rrrrrrvrwrxr{r|r}rPrrrrrp�srpc@s$eZdZdd�Zdd�Zdd�ZdS)�DomainNameGuessTestcCs|�dt�d�k�dS)N�example.com�Z
assertTruerZbase_domain_name_guessesr	rrr�test_simple_case�s
��z$DomainNameGuessTest.test_simple_casecCs|�dt�d�k�dS)Nrzfoo.bar.baz.example.comr�r	rrr�test_sub_domain�s
��z#DomainNameGuessTest.test_sub_domaincCs|�dt�d�k�dS)Nz
example.co.ukzfoo.bar.baz.example.co.ukr�r	rrr�test_second_level_domain�s
��z,DomainNameGuessTest.test_second_level_domainN)r
rrr�r�r�rrrrr~�sr~�__main__)�__doc__r]rSZunittestrZcertbotrrZcertbot.compatrZcertbot.displayr(Zcertbot.pluginsrrZ
certbot.testsrOZTempDirTestCaseZBaseAuthenticatorTestrrQrpZTestCaser~r
�mainrrrr�<module>s"f)/