a }|gX:@sdZddlZddlZddlZddlmZddlZddlmZddlm Z ddlm Z ddl m Z ddl mmZGdd d ejZGd d d ejZGd d d ejZedkreeejddegdS)z#Tests for certbot._internal.renewalN)mock) challenges) configuration)errors)storagec@seZdZejejdddZejejdddZ edddZ edd d Z ejejdd d Z ed ejejdddZ eejejdddZejejdddZdS) RenewalTest set_by_usercCsld|_t|jjd}d|j_d|j_d|j_t |j}t ||}|jd}ddl m }|||dS)NFzsample-renewal-ancient.conf renewalparamsrrenewal) return_value test_util make_lineageconfig config_diraccountZemail webroot_pathrNamespaceConfigr RenewableCertcertbot._internalr _restore_webroot_config)selfmock_set_by_userrc_pathrlineager r rH/usr/lib/python3.9/site-packages/certbot/_internal/tests/renewal_test.py!test_ancient_webroot_renewal_confs     z-RenewalTest.test_ancient_webroot_renewal_confcCsNddlm}d|_ddiddgd}||j|idd}||j|dS)Nrr Fztest.example.comz /var/www/testz/var/www/other)Z webroot_mapr)rr r rr)rrr r rrr test_webroot_params_conservation!s z,RenewalTest.test_webroot_params_conservationz4certbot._internal.renewal._avoid_reuse_key_conflictscCsd|j_d|j_d|j_t|j}t|jjd}t ||}t }d|j _ddlm}t d"||jd||Wdn1s0YdS)NZ INVALID_VALUETsample-renewal.confNNNNrr *certbot._internal.renewal.hooks.renew_hook)relliptic_curve reuse_keydry_runrrr rrrrr MagicMockobtain_certificater rr patch renew_certrZ!unused_mock_avoid_reuse_conflictsrrr le_clientr rrrtest_reuse_key_renewal_params9s    0z)RenewalTest.test_reuse_key_renewal_paramscCsd|j_d|j_d|j_d|j_t|j}tj|jj ddd}t ||}t }d|j_ddlm}t d "||jd||Wdn1s0YdS) NZ INVALID_CURVETZecdsazsample-renewal-ec.confZecr rr r!)rr"r#r$key_typerrr rrrrrr%r&r rr r'r(r)rrr test_reuse_ec_key_renewal_paramsNs"    0z,RenewalTest.test_reuse_ec_key_renewal_paramscCsd|_d|j_d|j_d|j_t|j}t|jj d}t ||}t }d|j_ddlm}t d"||jd||Wdn1s0Y|jt jddS)NFTrr rr r!)r rr#Znew_keyr$rrr rrrrrr%r&rr r'r(Zassert_called_withANY)rrrrrr*r rrr test_new_keygs    0zRenewalTest.test_new_keyr!cCsd|_d|j_d|j_d|j_d|j_t|j}t |jj d}t ||}d|jdd<t }d|j_d d lm}tjtjd d "||jd||Wdn1s0Yd d|_d|j_||jd||dS)NFTZrsairr r#r rr zUnable to change the --key-type)matchcSs|dkS)Nr#r)varrrrz6RenewalTest.test_reuse_key_conflicts..)r rr#r-Z rsa_key_sizer$rrr rrrrrr%r&rr pytestraisesrErrorr(Z side_effect)rrZunused_mock_renew_hookrrrr*r rrrtest_reuse_key_conflictss&   0 z$RenewalTest.test_reuse_key_conflictscCsPd|_t|j}d|_t|jjd}ddlm }t |j}| ||}dS)NFz sample-renewal-deprecated-optionz%sample-renewal-deprecated-option.confrr ) r rrrZcertnamer rrrr copydeepcopy reconstitute)rrZunused_mock_get_utilityrrr lineage_configZrenewal_candidaterrr&test_remove_deprecated_config_elementss    z2RenewalTest.test_remove_deprecated_config_elementscCsBd|_tj|jjddd}ddlm}t|j}| ||dS)NFrr,rr ) r r rrrrr r9r:r;)rrrr r<rrrtest_absent_key_type_restoreds    z)RenewalTest.test_absent_key_type_restoredN)__name__ __module__ __qualname__rr'objectrrrrr+r.r0r8r Zpatch_display_utilr=r>rrrrrs$       rc@seZdZdZeddZeje j dddZ eje j dddZ eje j dd d Z eje j dd d Zeje j dd dZeje j dddZeje j dddZeje j dddZddZdS)!RestoreRequiredConfigElementsTestzETests for certbot._internal.renewal.restore_required_config_elements.cOsddlm}||i|S)Nr) restore_required_config_elements)certbot._internal.renewalrD)clsargskwargsrDrrr_calls z'RestoreRequiredConfigElementsTest._callrcCsd|_||jddidS)NFallow_subset_of_namesTruer rIrrrrrr"test_allow_subset_of_names_successszDRestoreRequiredConfigElementsTest.test_allow_subset_of_names_successcCsLd|_ddi}ttj||j|Wdn1s>0YdS)NFrJmayber r5r6rr7rIrrrr rrr"test_allow_subset_of_names_failureszDRestoreRequiredConfigElementsTest.test_allow_subset_of_names_failurecCs6d|_dddi}||j|tjjtjjg}dS)NF pref_challsz http-01, dns,)r splitrIrrZHTTP01typDNS01rrr Zexpectedrrrtest_pref_challs_lists z7RestoreRequiredConfigElementsTest.test_pref_challs_listcCs*d|_ddi}||j|tjjg}dS)NFrSZdns)r rIrrrWrVrXrrrtest_pref_challs_strs  z6RestoreRequiredConfigElementsTest.test_pref_challs_strcCsLd|_ddi}ttj||j|Wdn1s>0YdS)NFrSzfinding-a-shrubberyrPrQrrrtest_pref_challs_failuresz:RestoreRequiredConfigElementsTest.test_pref_challs_failurecCsd|_||jddidS)NF must_staplerKrLrMrrrtest_must_staple_successsz:RestoreRequiredConfigElementsTest.test_must_staple_successcCsLd|_ddi}ttj||j|Wdn1s>0YdS)NFr\rOrPrQrrrtest_must_staple_failuresz:RestoreRequiredConfigElementsTest.test_must_staple_failurecCs2ddlm}d|j_d|_||jd|jidS)Nr) constantsFserver)rr_rr`r rIZV1_URI)rrr_rrr test_ancient_server_renewal_confs  zBRestoreRequiredConfigElementsTest.test_ancient_server_renewal_confcCs0ddd}||j|||jj|ddS)Nzhttps://example.orgZsomehash)r`rr)rIrZ assertEqualr)rr rrrtest_related_valuess z5RestoreRequiredConfigElementsTest.test_related_valuesN)r?r@rA__doc__ classmethodrIrr'rBrrrNrRrYrZr[r]r^rarbrrrrrCs(         rCc@sTeZdZdZddZddZeddZdd Zd d Z d d Z ddZ ddZ dS)DescribeResultsTestz r4z>DescribeResultsTest._assert_success_output..)rjassert_has_calls)rlinesrrr_assert_success_outputsz*DescribeResultsTest._assert_success_outputcCs*|tjddgggg|dgdS)NTr$z%No simulated renewals were attempted.rIrr%rxrlrrrtest_no_renewal_attempts"sz,DescribeResultsTest.test_no_renewal_attemptscCs.|tjdddgddd|gddS)NFrygood.pem)P - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -z)Congratulations, all renewals succeeded: z good.pem (success)O- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -rzrlrrrtest_successful_renewal&sz+DescribeResultsTest.test_successful_renewalcCsL|tjddgdggg|ddg|jtddtdgdS) NFrybad.pemr}r~z@All %ss failed. The following certificates could not be renewed:r z bad.pem (failure)rIrr%rxrkrvrrrlrrrtest_failed_renewal/s z'DescribeResultsTest.test_failed_renewalcCsV|tjddddgddgdgdg|gd |jtd d td gdS) NTryr|z good2.pemrzbad2.pemzfoo.pem expires on 123z errored.conf)r}z7The following certificates are not due for renewal yet:z" foo.pem expires on 123 (skipped)z+The following simulated renewals succeeded:z+ good.pem (success) good2.pem (success) zB Additionally, the following renewal configurations were invalid: z errored.conf (parsefail)r~zThe following %ss failed:zsimulated renewalz( bad.pem (failure) bad2.pem (failure)rrlrrrtest_all_renewal:s   z$DescribeResultsTest.test_all_renewalN) r?r@rArcrmrprdrIrxr{rrrrrrrre s   re__main__)rcr9sysZunittestrr5ZacmerZcertbotrrrrZcertbot.tests.utilZtestsutilr ZConfigTestCaserrCZTestCaserer?exitmainargv__file__rrrrs      1MA