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

U

e�_�;�@sHdZddlZddlZddlZddlZddlZddlZddlm	Z	ddl
mZddl
mZddl
m
Z
ddlmZddlmZdd	lmZdd
lmZej�e�d��Zeje�e	jdd
�d�ded�ZGdd�dej�ZGdd�dej�ZGdd�dej �Z!Gdd�dej�Z"Gdd�dej�Z#Gdd�dej$�Z%e&dk�rDe�'�dS)z!Tests for certbot.plugins.common.�N)�
challenges)�achallenges)�crypto_util)�errors)�os)�
filesystem)�	acme_util)�utilzrsa512_key.pemstoken1)�token�pendingzencryption-example.demo)ZchallbZdomainZaccount_keyc@s(eZdZdZdd�Zdd�Zdd�ZdS)	�NamespaceFunctionsTestz7Tests for certbot.plugins.common.*_namespace functions.cCs ddlm}|�d|d��dS)Nr)�option_namespacezfoo-�foo)�certbot.plugins.commonr
�assertEqual)�selfr
�r�=/usr/lib/python3/dist-packages/certbot/plugins/common_test.py�test_option_namespacesz,NamespaceFunctionsTest.test_option_namespacecCs ddlm}|�d|d��dS)Nr��dest_namespaceZfoo_r�rrr�rrrrr�test_dest_namespace!sz*NamespaceFunctionsTest.test_dest_namespacecCs ddlm}|�d|d��dS)NrrZfoo_bar_�foo-barrrrrr�test_dest_namespace_with_dashes%sz6NamespaceFunctionsTest.test_dest_namespace_with_dashesN)�__name__�
__module__�__qualname__�__doc__rrrrrrrrsrc@sPeZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�ZdS)�
PluginTestz'Test for certbot.plugins.common.Plugin.cCs@ddlm}Gdd�d|�}||_t��|_||jdd�|_dS)Nr)�Pluginc@seZdZedd��ZdS)z$PluginTest.setUp.<locals>.MockPlugincSs|ddddd�dS)Nr�different_to_foo_bar���dest�x�yr)�cls�addrrr�add_parser_arguments1sz9PluginTest.setUp.<locals>.MockPlugin.add_parser_argumentsN)rrr�classmethodr*rrrr�
MockPlugin0sr,�mock��config�name)rr!�
plugin_clsr-�	MagicMockr/�plugin)rr!r,rrr�setUp-s

zPluginTest.setUpcCs&|�d|jj�|�|j|jj�dS)Nr-)rr3r0r/�rrrr�	test_init9szPluginTest.test_initcCs|�d|jj�dS)Nzmock-)rr3r
r5rrrr=sz PluginTest.test_option_namespacecCs|�d|j�d��dS)Nzmock-foo_bar�foo_bar)rr3Zoption_namer5rrr�test_option_name@szPluginTest.test_option_namecCs|�d|jj�dS)NZmock_)rr3rr5rrrrCszPluginTest.test_dest_namespacecCs,|�d|j�d��|�d|j�d��dS)N�mock_foo_barrr7)rr3r%r5rrr�	test_destFszPluginTest.test_destcCs|�|jj|j�d��dS)Nr)rr/r9r3�confr5rrr�	test_confJszPluginTest.test_confcCs.t��}|j�|d�|jjddddd�dS)Nr-z--mock-foo-barr"r#r$)r-r2r1Zinject_parser_options�add_argument�assert_called_once_with)r�parserrrr�test_inject_parser_optionsMs�z%PluginTest.test_inject_parser_optionsN)rrrrr4r6rr8rr:r<r@rrrrr *sr cs�eZdZdZ�fdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�Zd d!�Z�ZS)"�
InstallerTestz+Tests for certbot.plugins.common.Installer.csFtt|���t�|jj�ddlm}||jdd�|_	|j	j
|_
dS)Nr)�	InstallerrBr.)�superrAr4r�mkdirr/Z
config_dirrrB�	installer�reverter)rrB��	__class__rrr4Ys�zInstallerTest.setUpcCstd�}d}|�d||�dS)N�zfoo.barzbaz.qux�foo bar baz qux�add_to_checkpoint)�set�_test_wrapped_method)r�files�
save_notesrrr�test_add_to_real_checkpointbsz)InstallerTest.test_add_to_real_checkpointcCs|�d�dS)NF��_test_add_to_checkpoint_commonr5rrr�test_add_to_real_checkpoint2gsz*InstallerTest.test_add_to_real_checkpoint2cCs|�d�dS)NTrQr5rrr� test_add_to_temporary_checkpointjsz.InstallerTest.test_add_to_temporary_checkpointcCs@td�}d}tj|jj|d�}|r(d}nd}|�||||�dS)NrIrJ)�	temporaryZadd_to_temp_checkpointrK)rL�	functools�partialrErK�_test_adapted_method)rrUrNrO�installer_func�reverter_func_namerrrrRms
�z,InstallerTest._test_add_to_checkpoint_commoncCs|�dd�dS)NZfinalize_checkpointr�rMr5rrr�test_finalize_checkpoint{sz&InstallerTest.test_finalize_checkpointcCs|�d�dS)NZrecovery_routiner[r5rrr�test_recovery_routine~sz#InstallerTest.test_recovery_routinecCs|�d�dS)NZrevert_temporary_configr[r5rrr�test_revert_temporary_config�sz*InstallerTest.test_revert_temporary_configcCs|�dd�dS)NZrollback_checkpoints�*r[r5rrr�test_rollback_checkpoints�sz'InstallerTest.test_rollback_checkpointscCs|�d�dS)N�view_config_changesr[r5rrr�test_view_config_changes�sz&InstallerTest.test_view_config_changesc	Cs2t��� tjdddd�|j��W5QRXdS)N�errorz.*view_config_changesz	.*common$)�module)�warnings�catch_warnings�filterwarningsrErar5rrr�+test_view_config_changes_warning_supression�s
	z9InstallerTest.test_view_config_changes_warning_supressioncOs$t|j|�}|j||f|�|�dS)z�Test a wrapped reverter method.

        :param str name: name of the method to test
        :param tuple args: position arguments to method
        :param dict kwargs: keyword arguments to method

        N)�getattrrErX)rr0�args�kwargsrYrrrrM�sz"InstallerTest._test_wrapped_methodc	OsTtj�|j|��:}|||�|j||�tj|_|jtj	|f|�|�W5QRXdS)a�Test an adapted reverter method

        :param callable installer_func: installer method to test
        :param str reverter_func_name: name of the method on the
            reverter that should be called
        :param tuple passed_args: positional arguments passed from
            installer method to the reverter method
        :param dict passed_kargs: keyword arguments passed from
            installer method to the reverter method

        N)
r-�patch�objectrFr>rZ
ReverterErrorZside_effect�assertRaisesZPluginError)rrYrZZpassed_argsZ
passed_kwargsZ
reverter_funcrrrrX�s

���z"InstallerTest._test_adapted_methodcCs$|j��|�tj�|jj��dS�N)rEZinstall_ssl_dhparams�
assertTruer�path�isfileZssl_dhparamsr5rrr�test_install_ssl_dhparams�s
z'InstallerTest.test_install_ssl_dhparamscCsddlm}t�|�S)Nr)�SSL_DHPARAMS_SRC)�certbot.constantsrtr�	sha256sum)rrtrrr�_current_ssl_dhparams_hash�sz(InstallerTest._current_ssl_dhparams_hashcCs$ddlm}|�|��|kd�dS)Nr)�ALL_SSL_DHPARAMS_HASHESzwConstants.ALL_SSL_DHPARAMS_HASHES must be appended with the sha256 hash of self.config.ssl_dhparams when it is updated.)rurxrprw)rrxrrr�$test_current_file_hash_in_all_hashes�s�z2InstallerTest.test_current_file_hash_in_all_hashes)rrrrr4rPrSrTrRr\r]r^r`rbrhrMrXrsrwry�
__classcell__rrrGrrAVs"	
rAc@s@eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dS)�AddrTestz-Tests for certbot.client.plugins.common.Addr.cCspddlm}|�d�|_|�d�|_|�d�|_|�d�|_|�d�|_|�d�|_|�d	�|_	|�d
�|_
dS)Nr��Addr�192.168.1.1�
192.168.1.1:*�192.168.1.1:80�	[fe00::1]�[fe00::1]:*�[fe00::1]:80z[fe00::1]:5z[fe00:1:2:3:4:5:6:7:8:9]:8080)rr}�
fromstring�addr1�addr2�addr3�addr4�addr5�addr6�addr7�addr8�rr}rrrr4�szAddrTest.setUpcCs$|�|j��d�|�|j��d�|�|j��d�|�|j��d�|�|j��d�|�|j��d�|�|j��d�|�|j��d�|�|j��d�|�|j��d�|�|j��d�|�|j��d�|�|j�	�d�|�|j�	�d�|�|j
��d�|�|j�	�d�dS)	Nr~��*Z80r�zfe00:0:0:0:0:0:0:1�5zfe00:1:2:3:4:5:6:7)rr�Zget_addrZget_portr�r�r�r�r�Zget_ipv6_explodedr�r�r5rrr�test_fromstring�s,���zAddrTest.test_fromstringcCsp|�t|j�d�|�t|j�d�|�t|j�d�|�t|j�d�|�t|j�d�|�t|j�d�dS)Nr~rr�r�r�r�)r�strr�r�r�r�r�r�r5rrr�test_str�szAddrTest.test_strcCs�|�t|j�d��d�|�t|j�d��d�|�t|j�d��d�|�t|j�d��d�|�t|j�d��d�|�t|j�d��d	�dS)
NZ443z192.168.1.1:443r�r~r�rz
[fe00::1]:443r�r�)rr�r��get_addr_objr�r�r�r5rrr�test_get_addr_obj�szAddrTest.test_get_addr_objcCs�|�|j|j�d��|�|j|j�|�|jdk�|�|j|j�d��|�|j|j�|�|jdk�ddlm	}|�|j|�
d��|�|j|�
d��dS)Nr�i
rr|z
[fe00:0:0::1]z[fe00:0::0:0:1])rr�r�r��assertNotEqual�assertFalser�r�rr}r�r�rrr�test_eq�szAddrTest.test_eqc
Cs�ddlm}t|j|jg�}|�d�}|�d�}t||g�}|�||�t|j|jg�}|�d�}|�d�}t||g�}	|�||	�dS)Nrr|r~rr�r�)	rr}rLr�r�r�rr�r�)
rr}Zset_aZaddr1bZaddr2bZset_bZset_cZaddr4bZaddr5bZset_drrr�test_set_inclusions



zAddrTest.test_set_inclusionN)
rrrrr4r�r�r�r�r�rrrrr{�s
r{c@s(eZdZdZdd�Zdd�Zdd�ZdS)	�ChallengePerformerTestz4Tests for certbot.plugins.common.ChallengePerformer.cCs"t��}ddlm}||�|_dS)Nr)�ChallengePerformer)r-r2rr��	performer)rZconfiguratorr�rrrr4szChallengePerformerTest.setUpcCs8|j�td�|�dt|jj��|�dg|jj�dS)Nrr#)r�Z	add_chall�ACHALLr�lenZachalls�indicesr5rrr�test_add_challsz%ChallengePerformerTest.test_add_challcCs|�t|jj�dSro)rn�NotImplementedErrorr�Zperformr5rrr�test_perform$sz#ChallengePerformerTest.test_performN)rrrrr4r�r�rrrrr�sr�cs`eZdZdZ�fdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Z�Z
S)� InstallVersionControlledFileTestzATests for certbot.plugins.common.install_version_controlled_file.c
s�tt|���dg|_tj�|jd�|_tj�|jd�|_	tj�|jd�|_
tj�|jd�|_|j|j
fD]6}t|d��}|�
|�W5QRX|j�t�|��qjdS)NZ
someotherhashzoptions-ssl-dest.confz.options-ssl-conf.txtzoptions-ssl-old.confzoptions-ssl-src.conf�w)rCr�r4�hashesrrq�joinZtempdir�	dest_path�	hash_path�old_path�source_path�open�write�appendrrv)rrq�frGrrr4+sz&InstallVersionControlledFileTest.setUpcCs&ddlm}||j|j|j|j�dS)Nr)�install_version_controlled_file)rr�r�r�r�r�)rr�rrr�_call7s�z&InstallVersionControlledFileTest._callcCst�|j�Sro)rrvr�r5rrr�_current_file_hash>sz3InstallVersionControlledFileTest._current_file_hashcCs0|�tj�|j��|�t�|j�|���dSro)	rprrqrrr�rrrvr�r5rrr�_assert_current_fileAs�z5InstallVersionControlledFileTest._assert_current_filecCs(|�tj�|j��|��|��dSro)r�rrqrrr�r�r�r5rrr�test_no_fileFsz-InstallVersionControlledFileTest.test_no_filecCs"td�D]}|��|��qdS)N�)�ranger�r�)r�_rrr�test_current_fileKsz2InstallVersionControlledFileTest.test_current_filecCs$t�|j|j�|��|��dSro)�shutilZcopyfiler�r�r�r�r5rrr�!test_prev_file_updates_to_currentQszBInstallVersionControlledFileTest.test_prev_file_updates_to_currentc	Cs�|��t|jd��}|�d�W5QRXt�d��}|��|�|jj�W5QRX|�	t
j�|j��|�
t�|j�|���|�t�|j�|���dS)N�a�a new line for the wrong hash
�certbot.plugins.common.logger)r�r�r�r�r-rlr��warning�calledrprrqrrrrrvr�r�r�)r�mod_ssl_conf�mock_loggerrrr�3test_manually_modified_current_file_does_not_updateVs��zTInstallVersionControlledFileTest.test_manually_modified_current_file_does_not_updatec	Cs�t|jd��}|�d�W5QRXt|jd��}|�d�W5QRXt�d��&}|��|�|jj	ddd�W5QRX|�t
�|j�|�
��t�d��}|��|�|jj�W5QRXdS)Nr�r�r�Zhashofanoldversionr�rzh%s has been manually modified; updated file saved to %s. We recommend updating %s for security purposes.)r�r�r�r�r-rlr�rr�Z	call_argsrrvr�r�r�r�)rr�r�r�rrr�&test_manually_modified_past_file_warnscs��zGInstallVersionControlledFileTest.test_manually_modified_past_file_warns)rrrrr4r�r�r�r�r�r�r�r�rzrrrGrr�(s
r��__main__)(rrVr�ZunittestreZjosepyZjoser-ZacmerZcertbotrrrZcertbot.compatrrZ
certbot.testsrr	Z	test_utilZJWKRSA�loadZload_vectorZAUTH_KEYZ"KeyAuthorizationAnnotatedChallengeZchall_to_challbZHTTP01r�ZTestCaserr ZConfigTestCaserAr{r�ZTempDirTestCaser�r�mainrrrr�<module>s<��,oQL