a }|gn8@szdZddlZddlZddlZddlZddlmZddlZddlZddl m Z ddl m Z ddl m Z ddl mZddl mZdd lmZdd lmZdd lmZdd lmZejed Ze jee jdde jdedZGdddej Z!Gdddej Z"Gdddej#Z$Gdddej Z%Gdddej Z&Gdddej'Z(e)dkrve*e+ej,dde-gdS) z!Tests for certbot.plugins.common.N)mock) challenges)messages) achallenges) crypto_util)errors) filesystem)os) acme_util)utilzrsa512_key.pemstoken1)tokenzencryption-example.demo)ZchallbdomainZ account_keyc@s(eZdZdZddZddZddZdS) NamespaceFunctionsTestz7Tests for certbot.plugins.common.*_namespace functions.cCsddlm}dS)Nr)option_namespace)certbot.plugins.commonr)selfrrO/usr/lib/python3.9/site-packages/certbot/_internal/tests/plugins/common_test.pytest_option_namespaces z,NamespaceFunctionsTest.test_option_namespacecCsddlm}dSNr)dest_namespacerrrrrrrtest_dest_namespace#s z*NamespaceFunctionsTest.test_dest_namespacecCsddlm}dSrrrrrrtest_dest_namespace_with_dashes's z6NamespaceFunctionsTest.test_dest_namespace_with_dashesN)__name__ __module__ __qualname____doc__rrrrrrrrsrc@sXeZdZdZddZddZddZdd Zd d Zd d Z ddZ ddZ ddZ dS) PluginTestz'Test for certbot.plugins.common.Plugin.cCs@ddlm}Gddd|}||_t|_||jdd|_dS)Nr)Pluginc@s4eZdZddddZedddZeddZdS) z$PluginTest.setUp..MockPluginN)returncSsdSNrrrrrprepare3sz,PluginTest.setUp..MockPlugin.preparecSsdS)Ninforr#rrr more_info6sz.PluginTest.setUp..MockPlugin.more_infocSs|ddddddS)Nzfoo-bardifferent_to_foo_bardestxyr)clsaddrrradd_parser_arguments9sz9PluginTest.setUp..MockPlugin.add_parser_arguments)rrrr$strr& classmethodr/rrrr MockPlugin2sr2rconfigname)rr plugin_clsr MagicMockr4Zplugin)rr r2rrrsetUp/s    zPluginTest.setUpcCsdSr"rr#rrr test_initAszPluginTest.test_initcCsdSr"rr#rrrrEsz PluginTest.test_option_namespacecCsdSr"rr#rrrtest_option_nameHszPluginTest.test_option_namecCsdSr"rr#rrrrKszPluginTest.test_dest_namespacecCsdSr"rr#rrr test_destNszPluginTest.test_destcCsdSr"rr#rrr test_confRszPluginTest.test_confcCs.t}|j|d|jjddddddS)Nrz--mock-foo-barr'r(r))rr7r6Zinject_parser_options add_argumentassert_called_once_with)rparserrrrtest_inject_parser_optionsUs z%PluginTest.test_inject_parser_optionscCsdSr"rr#rrrtest_fallback_auth_hint]sz"PluginTest.test_fallback_auth_hintN) rrrrr8r9rr:rr;r<r@rArrrrr,srcseZdZdZfddZddZddZdd Zd d Zd d Z ddZ ddZ ddZ ddZ ddZddZddZddZZS) InstallerTestz+Tests for certbot.plugins.common.Installer.csBtt|jjddlm}||jdd|_|jj |_ dS)Nr)DummyInstallerZ Installerr3) superr8rmkdirr4Z config_dirZcertbot.tests.utilrC installerreverter)rrC __class__rrr8hs  zInstallerTest.setUpcCsddh}d}|d||dS)Nfoo.barbaz.quxfoo bar baz quxadd_to_checkpoint_test_wrapped_method)rfiles save_notesrrrtest_add_to_real_checkpointqsz)InstallerTest.test_add_to_real_checkpointcCs|ddS)NF_test_add_to_checkpoint_commonr#rrrtest_add_to_real_checkpoint2vsz*InstallerTest.test_add_to_real_checkpoint2cCs|ddS)NTrSr#rrr test_add_to_temporary_checkpointysz.InstallerTest.test_add_to_temporary_checkpointcCs@ddh}d}tj|jj|d}|r(d}nd}|||||dS)NrJrKrL) temporaryZadd_to_temp_checkpointrM) functoolspartialrFrM_test_adapted_method)rrWrPrQinstaller_funcreverter_func_namerrrrT|s z,InstallerTest._test_add_to_checkpoint_commoncCs|dddS)NZfinalize_checkpointZfoorNr#rrrtest_finalize_checkpointsz&InstallerTest.test_finalize_checkpointcCs|ddS)NZrecovery_routinerNr#rrrtest_recovery_routinesz#InstallerTest.test_recovery_routinecCs|ddS)NZrevert_temporary_configrNr#rrrtest_revert_temporary_configsz*InstallerTest.test_revert_temporary_configcCs|dddS)NZrollback_checkpoints*rNr#rrrtest_rollback_checkpointssz'InstallerTest.test_rollback_checkpointscOs*t|j|}|j||g|Ri|dS)zTest 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)getattrrFrZ)rr5argskwargsr[rrrrOs z"InstallerTest._test_wrapped_methodc Ostj|j|p}||i||j|i|tj|_t tj ||i|Wdn1sh0YWdn1s0YdS)aTest 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) rpatchobjectrGr>rZ ReverterErrorZ side_effectpytestraisesZ PluginError)rr[r\Z passed_argsZ passed_kwargsZ reverter_funcrrrrZs z"InstallerTest._test_adapted_methodcCs|jdSr")rFZinstall_ssl_dhparamsr#rrrtest_install_ssl_dhparamss z'InstallerTest.test_install_ssl_dhparamscCsddlm}t|S)Nr)SSL_DHPARAMS_SRC)certbot._internal.constantsrjr sha256sum)rrjrrr_current_ssl_dhparams_hashs z(InstallerTest._current_ssl_dhparams_hashcCsddlm}dS)Nr)ALL_SSL_DHPARAMS_HASHES)rkrn)rrnrrr$test_current_file_hash_in_all_hashess z2InstallerTest.test_current_file_hash_in_all_hashes)rrrrr8rRrUrVrTr]r^r_rarOrZrirmro __classcell__rrrHrrBes  rBc@s@eZdZdZddZddZddZdd Zd d Zd d Z dS)AddrTestz&Tests for certbot.plugins.common.Addr.cCspddlm}|d|_|d|_|d|_|d|_|d|_|d|_|d |_ |d |_ dS) NrAddr 192.168.1.1 192.168.1.1:*z192.168.1.1:80 [fe00::1] [fe00::1]:*z [fe00::1]:80z [fe00::1]:5z[fe00:1:2:3:4:5:6:7:8:9]:8080) rrs fromstringaddr1addr2Zaddr3addr4addr5Zaddr6Zaddr7Zaddr8rrsrrrr8s        zAddrTest.setUpcCsdSr"rr#rrrtest_fromstringszAddrTest.test_fromstringcCsdSr"rr#rrrtest_strszAddrTest.test_strcCsdSr"rr#rrrtest_get_addr_objszAddrTest.test_get_addr_objcCsddlm}dS)Nrrr)rrsr}rrrtest_eqs zAddrTest.test_eqc Cs`ddlm}|j|jh}|d}|d}||h}|j|jh}|d}|d}||h} dS)Nrrrrtrurvrw)rrsryrzrxr{r|) rrsZset_aZaddr1bZaddr2bZset_bZset_cZaddr4bZaddr5bZset_drrrtest_set_inclusions       zAddrTest.test_set_inclusionN) rrrrr8r~rrrrrrrrrqs  rqc@s(eZdZdZddZddZddZdS) ChallengePerformerTestz4Tests for certbot.plugins.common.ChallengePerformer.cCs"t}ddlm}|||_dS)Nr)ChallengePerformer)rr7rr performer)rZ configuratorrrrrr8s zChallengePerformerTest.setUpcCs|jtddS)Nr)rZ add_challACHALLr#rrrtest_add_challsz%ChallengePerformerTest.test_add_challcCs8tt|jWdn1s*0YdSr")rgrhNotImplementedErrorrZperformr#rrr test_perform#s z#ChallengePerformerTest.test_performN)rrrrr8rrrrrrrsrcs`eZdZdZfddZddZddZdd Zd d Zd d Z ddZ ddZ ddZ Z S) InstallVersionControlledFileTestzATests for certbot.plugins.common.install_version_controlled_file.c stdg|_tj|jd|_tj|jd|_tj|jd|_ tj|jd|_ |j |j fD]J}t |d}| |Wdn1s0Y|j t|qfdS)NZ someotherhashzoptions-ssl-dest.confz.options-ssl-conf.txtzoptions-ssl-old.confzoptions-ssl-src.confw)rDr8hashesr pathjoinZtempdir dest_path hash_pathold_path source_pathopenwriteappendrrl)rrfrHrrr8+s  (z&InstallVersionControlledFileTest.setUpcCs&ddlm}||j|j|j|jdS)Nr)install_version_controlled_file)rrrrrr)rrrrr_call7s  z&InstallVersionControlledFileTest._callcCs t|jSr")rrlrr#rrr_current_file_hash>sz3InstallVersionControlledFileTest._current_file_hashcCsdSr"rr#rrr_assert_current_fileAsz5InstallVersionControlledFileTest._assert_current_filecCs||dSr")rrr#rrr test_no_fileFsz-InstallVersionControlledFileTest.test_no_filecCs"tdD]}||qdS)N)rangerr)r_rrrtest_current_fileKs z2InstallVersionControlledFileTest.test_current_filecCs$t|j|j||dSr")shutilcopyfilerrrrr#rrr!test_prev_file_updates_to_currentQszBInstallVersionControlledFileTest.test_prev_file_updates_to_currentcCst|t|jd}|dWdn1s40Ytd}|Wdn1sf0YdS)Naa new line for the wrong hash certbot.plugins.common.logger)rrrrrre)r mod_ssl_conf mock_loggerrrr3test_manually_modified_current_file_does_not_updateVs( zTInstallVersionControlledFileTest.test_manually_modified_current_file_does_not_updatecCst|jd}|dWdn1s,0Yt|jd}|dWdn1sb0Ytd}|Wdn1s0Ytd}|Wdn1s0YdS)NrrrZhashofanoldversionr)rrrrrrer)rrrrrrr&test_manually_modified_past_file_warnscs((  zGInstallVersionControlledFileTest.test_manually_modified_past_file_warns)rrrrr8rrrrrrrrrprrrHrr(s  r__main__r().rrXrsysZunittestrZjosepyZjosergZacmerrZcertbotrrrZcertbot.compatrr Z certbot.testsr r Z test_utilZJWKRSAloadZ load_vectorZAUTH_KEYZ"KeyAuthorizationAnnotatedChallengeZchall_to_challbZHTTP01ZSTATUS_PENDINGrZTestCaserrZConfigTestCaserBrqrZTempDirTestCaserrexitmainargv__file__rrrrs>          9_QL