JFIF$        dd7 

Viewing File: /usr/lib/python3.9/site-packages/certbot/_internal/tests/__pycache__/main_test.cpython-39.opt-1.pyc

a

}|�g���@s2dZddlZddlZddlmZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZddl
mZddlZddlmZddlZddlZddlZddlZddlmZddlmZddlmZdd	lmZdd
lmZddlmZddlm Z dd
lm!Z!ddlm"Z"ddlm#Z#ddl$m%Z%ddl$m&Z&ddl$m'Z'ddl$m(Z(ddl)m*Z*ddl)m+Z+ddl,m-Z-ddl.m/mZ0e0�1d�Z2e0�1d�Z3e0�1d�Z4e0�1d�Z5ej6�7e0�8d��Z9e0�1d�Z:e0�1d�Z;Gdd�dej<�Z=Gdd �d e0j>�Z?Gd!d"�d"ej<�Z@Gd#d$�d$ej<�ZAGd%d&�d&e0jB�ZCGd'd(�d(e0jB�ZDGd)d*�d*e0j>�ZEGd+d,�d,e0j>�ZFGd-d.�d.e0j>�ZGGd/d0�d0ej<�ZHGd1d2�d2e0j>�ZIGd3d4�d4e0j>�ZJGd5d6�d6e0j>�ZKGd7d8�d8ej<�ZLGd9d:�d:ej<�ZMGd;d<�d<e0j>�ZNGd=d>�d>e0j>�ZOGd?d@�d@�ZPeQdAk�r.e
�Re�"e
jSdBd�eTg��dS)Cz!Tests for certbot._internal.main.�N)�reload)�List)�mock)�Error)�crypto_util��errors)�
interfaces)�util)�account)�cli)�	constants)�main)�updater)�disco)�manual)�null)�
standalone)�
filesystem)�os)�enhancements�cert_512.pemzcsr_512.derzrsa256_key.pemzrsa512_key.pemzrsa2048_key.pemz
cert_2048.pemc@sleZdZdZe�d�dd��Ze�d�e�d�e�d�dd����Ze�d�d	d
��Ze�d�dd
��Z	dS)�TestHandleCertsz1Test for certbot._internal.main._handle_* methods�<certbot._internal.main._handle_unexpected_key_type_migrationcCs$t��}d|j_t�t��|�}dS�NF)r�Mock�ensure_deployed�return_valuer�_handle_identical_cert_request)�self�mock_handle_migration�mock_lineage�ret�r#�E/usr/lib/python3.9/site-packages/certbot/_internal/tests/main_test.py�*test_handle_identical_cert_request_pending5sz:TestHandleCerts.test_handle_identical_cert_request_pending�&certbot._internal.renewal.should_renewzcertbot.display.util.menucCs6d|_t��}d|j_d|_t�tjddd�|�}dS)NTF�run)Zverb�	reinstall)rrrrrr�	MagicMock)rr Z	mock_menuZmock_should_renewr!r"r#r#r$�*test_handle_identical_cert_key_type_change>s�z:TestHandleCerts.test_handle_identical_cert_key_type_changecCs6t��}d|_t��}ddg|j_t�|dg|�}dS)NTZdummy1Zdummy2)rr�expand�namesrrZ_handle_subset_cert_request)rr �mock_configr!r"r#r#r$�test_handle_subset_cert_requestMsz/TestHandleCerts.test_handle_subset_cert_requestz)certbot._internal.main.display_util.yesnocCs�t��}t��}||_t��}d|_d|_t�||�|��d|_d|_t�||�d|_d|_t�||�d|_t�||�d|_dd�|_	t
jtj
dd��t�||�Wd�n1s�0Yd	d�|_	t�||�dS)
NZrsa�ecdsaTFcSs|dkS)N�certnamer#��varr#r#r$�<lambda>{�zKTestHandleCerts.test_handle_unexpected_key_type_migration.<locals>.<lambda>z.Please provide both --cert-name and --key-type��matchcSs|dkS)N�key_typer#r1r#r#r$r3�r4)rrZset_by_userr7�private_key_typerZ%_handle_unexpected_key_type_migration�assert_not_calledr�side_effect�pytest�raisesrr)rZ
mock_yesno�configZmock_set�certr#r#r$�)test_handle_unexpected_key_type_migrationWs.
*
z9TestHandleCerts.test_handle_unexpected_key_type_migrationN)
�__name__�
__module__�__qualname__�__doc__r�patchr%r*r.r?r#r#r#r$r3s

	rcsveZdZdZ�fdd�Zdd�Zdd�Zdd	�Zd
d�Ze	�
d�d
d��Ze	�
d�dd��Ze	�
d�dd��Z
�ZS)�RunTestz%Tests for certbot._internal.main.run.cs�t���d|_t�d�t�d�t�d�t�d�t�d�t�d�t�d�t�d	�t�d
�g	}|d��|_|d��|_|d
��|_|d��|_	|d��|_
|d��|_|d��|_|d��|_
|d��|_|D]}|�|j�q�dS)Nzexample.org�)certbot._internal.main._get_and_save_certz7certbot._internal.main.display_ops.success_installationz2certbot._internal.main.display_ops.success_renewal�&certbot._internal.main._init_le_client�7certbot._internal.main._suggest_donation_if_appropriate�'certbot._internal.main._report_new_cert�!certbot._internal.main._find_cert�)certbot._internal.eff.handle_subscription�)certbot._internal.main._report_next_stepsr��������)�super�setUp�domainrrD�start�	mock_auth�mock_success_installation�mock_success_renewal�	mock_initZmock_suggest_donation�mock_report_cert�mock_find_cert�mock_subscription�mock_report_next_steps�
addCleanup�stop)r�patchesrD��	__class__r#r$rV�s.
�z
RunTest.setUpcCs@d�|j���}tj��}t�||�}ddlm	}|||�dS)Nz-a webroot -i null -d {0}r)r')
�formatrW�splitr�PluginsRegistry�find_allr�prepare_and_parse_args�certbot._internal.mainr')r�args�pluginsr=r'r#r#r$�_call�s

z
RunTest._callcCsHt��|j_d|j_|��|j�|jg�|j	jtj
dtj
dd�dS)N�TNT�Znew_or_renewed_cert)rrrYrr^rnrZ�assert_called_once_withrWr`�ANY�rr#r#r$�test_newcert_success�s�zRunTest.test_newcert_successcCs8t��|j_dt��f|j_|��|j�|jg�dSr)	rrrYrr^rnrZrqrWrsr#r#r$�test_reinstall_success�szRunTest.test_reinstall_successcCs8t��|j_dt��f|j_|��|j�|jg�dS�NT)	rrrYrr^rnr[rqrWrsr#r#r$�test_renewal_success�szRunTest.test_renewal_success�;certbot._internal.main.plug_sel.choose_configurator_pluginscCsdt�|jd�df|_tj��}d|j_t�	t
j��t�
|j|�Wd�n1sV0YdS�NrT)r�	Installerr=rrrhri�	auto_hstsr;r<r�NotSupportedErrorrr'�r�mock_choosermr#r#r$�"test_run_enhancement_not_supported�s

z*RunTest.test_run_enhancement_not_supported�$certbot._internal.main._install_certcCs|t�d�|_t��|j_d|j_t�	tj��|�
�Wd�n1sJ0Y|jjtj
|jtj
dd�|j��dS)NzFake installation errorroTrp)rZPluginErrorr:rrrYrr^r;r<rnr`rqrrrZr9)rZmock_install_certr#r#r$�test_cert_success_install_error�s&�z'RunTest.test_cert_success_install_errorcCsdt�|jd�df|_tj��}d|j_t�	t
j��t�
|j|�Wd�n1sV0YdSry)rrzr=rrrhriZmust_stapler;r<rr|rr'r}r#r#r$�"test_run_must_staple_not_supported�s

z*RunTest.test_run_must_staple_not_supported)r@rArBrCrVrnrtrurwrrDrr�r��
__classcell__r#r#rdr$rE�s


rEc@s�eZdZdZdd�Zdd�Zdd�Ze�d�e�d	�e�d
�dd����Z	d
d�Z
e�d�e�d�e�d�e�d�e�d�e�d
�dd�������Ze�d�e�d�e�d�e�d�e�d
�dd������Ze�d�e�d	�e�d�e�d�dd�����Z
e�d�e�d
�e�d�e�d	�e�d�dd������Ze�d�e�d
�e�d�e�d	�e�d�dd ������Ze�d�e�d
�e�d�e�d	�d!d"�����Zd#S)$�CertonlyTestz*Tests for certbot._internal.main.certonly.cCst��|_|j��|_dS�N)�	test_util�patch_display_util�get_utility_patchrX�mock_get_utilityrsr#r#r$rV�s
zCertonlyTest.setUpcCs|j��dSr��r�rbrsr#r#r$�tearDown�szCertonlyTest.tearDownc
Cs�tj��}t�||�}t�d��p}t�d��Ft�d��t�||�Wd�n1sZ0YWd�n1sx0YWd�n1s�0Y|�S)NrGrHrK)	rrhrirrjrrDr�certonly)rrlrmr=r\r#r#r$rn�s
fzCertonlyTest._callrJrFrIcCs4|��j}|j|_t��|_d|_|�d���dS)N)FNz!certonly --webroot -d example.com)	r��notification�_assert_no_pauser:rrrrnrg)rZ
unused_reportrYr^Zmock_notificationr#r#r$�test_no_reinstall_text_pause�s


z)CertonlyTest.test_no_reinstall_text_pausecOsdSr�r#)rrl�kwargsr#r#r$r��szCertonlyTest._assert_no_pauserL�3certbot._internal.cert_manager.lineage_for_certname�3certbot._internal.cert_manager.domains_for_certnamez$certbot._internal.renewal.renew_certrcCs�ddg}||_||j_|�d���|jtjdtjdd�|�d���d|��j_t	�
tj��|�d���Wd�n1s�0YdS)N�example.comztest.orgzEcertonly --webroot -d example.com -d test.org --cert-name example.comTrp�Ecertonly --webroot -d example.com -d test.com --cert-name example.comF)
rr,rnrgrqrrrr��yesnor;r<r�ConfigurationError)rr]Zmock_handle_type�mock_renew_cert�mock_domainsr!r`�domainsr#r#r$�*test_find_lineage_for_domains_and_certname�s�	z7CertonlyTest.test_find_lineage_for_domains_and_certname� certbot.display.ops.choose_namescCs4d|_|�d���dg|_d|_|�d���dS)Nr�Zsomenamez*certonly --webroot --cert-name example.com)rrnrg)rr]r!�mock_choose_namesZmock_domains_for_certnameZunused_mock_report_next_stepsr#r#r$�*test_find_lineage_for_domains_new_certname#sz7CertonlyTest.test_find_lineage_for_domains_new_certnamez-certbot._internal.main._csr_get_and_save_certcCsZd|_d|_dt��dfD]:}|�d|�d����|jtjtjtjdd�|��qdS)	zLcertonly --dry-run shouldn't report creation of a certificate in NEXT STEPS.N)z/certz/chainz
/fullchainz--csr z-d example.comz	certonly z, --webroot --cert-name example.com --dry-runFrp)r�CSRrnrgrqrrrZ
reset_mock)rr!Zmock_csr_get_certZunused_mock_get_certr`�flagr#r#r$�$test_dryrun_next_steps_no_cert_saved8s�z1CertonlyTest.test_dryrun_next_steps_no_cert_saved�?certbot._internal.plugins.selection.choose_configurator_pluginscCs>t��}|df|_t��|_d|_|�d���|j��dS)Nrozcertonly --nginx -d example.com)rr)rrnrg�restartZassert_called_once�r�mock_sel�
mock_get_certr^�unused_report_new�unused_report_nextZmock_installerr#r#r$�test_installer_runs_restartGs

z(CertonlyTest.test_installer_runs_restartcCs>t��}|df|_t��|_d|_|�d���|j��dS)Nroz)certonly --nginx -d example.com --dry-run)rr)rrnrgr�r9r�r#r#r$�$test_dryrun_installer_doesnt_restartVs

z1CertonlyTest.test_dryrun_installer_doesnt_restartcCs2t��|_d|_|�dt���d�d���dS)Nrozcertonly --webroot -w � z-i standalone -d example.com)rr)rrn�tempfile�
gettempdirrg)rr�r^r�r�r#r#r$�test_invalid_installeres

�z#CertonlyTest.test_invalid_installerN)r@rArBrCrVr�rnrrDr�r�r�r�r�r�r�r�r#r#r#r$r��sX

r�c@sFeZdZdZe�d�dd��Ze�d�dd��Ze�d�dd	��Zd
S)�FindDomainsOrCertnameTestz;Tests for certbot._internal.main._find_domains_or_certname.r�cCstjddd�}d|_dS)N�r�r0Z
domainname�rrr�rr�r-r#r#r$�test_display_opstsz*FindDomainsOrCertnameTest.test_display_opscCsPtjddd�}g|_t�tj��t�|d�Wd�n1sB0YdS)Nr�)	rrrr;r<rrrZ_find_domains_or_certnamer�r#r#r$�test_no_results{sz)FindDomainsOrCertnameTest.test_no_resultsr�cCstjddd�}ddg|_dS)Nzone.comr�ztwo.comr�)rr�r-r#r#r$�test_grab_domains�s
z+FindDomainsOrCertnameTest.test_grab_domainsN)	r@rArBrCrrDr�r�r�r#r#r#r$r�qs

r�cseZdZdZ�fdd�Zddd�Ze�d�e�d�d	d
���Ze�d�e�d�e�d�e�d
�dd�����Z	e�d�e�d�e�d�e�d
�dd�����Z
e�d�e�d�e�d�e�d
�dd�����Ze�d�dd��Zdd�Z
e�d�e�d�e��dd����Z�ZS)�
RevokeTestz(Tests for certbot._internal.main.revoke.cst���t�t|j�tj�tj�	|jd��|_
t�d�t�d�t�d�t�d�g}|d�
�j|_|d�
�|d�
�|_|d	�
�|_|D]}|�|j�q�dd
lm}t��|_|jdtjdd
ddddtjd�d�|_||jt|j�|_|jdf|j_dS)Nrz$certbot._internal.client.acme_clientzcertbot._internal.client.Client�)certbot._internal.main._determine_accountz5certbot._internal.main.display_ops.success_revocationrrMrNrO)�Accountztest.certbot.orgi�rSrP��
)Ztzinfo)Z
creation_hostZcreation_dt) rUrV�shutil�copy�	CERT_PATH�tempdirr�path�abspath�join�
tmp_cert_pathrrDrX�ClientV2�mock_acme_client�mock_determine_account�mock_success_revokerarbZcertbot._internal.accountr�r)�regrZMeta�datetime�pytzZUTC�meta�JWK�accr)rrcrDr�rdr#r$rV�s0
�
��zRevokeTest.setUpNcCsH|sd}|�|j���}tj��}t�||�}ddlm	}|||�dS)Nzrevoke --cert-path={0} r)�revoke)
rfr�rgrrhrirrjrkr�)rrlrmr=r�r#r#r$rn�s
zRevokeTest._call�-certbot._internal.main._delete_if_appropriate�)certbot._internal.main.client.acme_clientcCs�d|_|��j}g}tj��D]l\}}d�|j|���}|�	|�|�
t�tj
|��d�|j|�����}|�	|�|�
t�tj
|��qdS)NFz#revoke --cert-path={0} --reason {1})rr�r�r
ZREVOCATION_REASONS�itemsrfr�rgrn�appendr�callrr�upper)rr��mock_delete_if_appropriate�mock_revokeZexpected�reason�coderlr#r#r$�test_revoke_with_reason�s

�
z"RevokeTest.test_revoke_with_reason�'certbot._internal.storage.RenewableCert�3certbot._internal.storage.renewal_file_for_certnamez-certbot._internal.client.acme_from_config_keycCsD|j|_tj|jdd�|_d��}d|_|�|�|j�|j�dS)N�https://acme.example��	cert_path�server�revoke --cert-name=example.comF)	r�rrr)r�rgrnr�rq�rZmock_acme_from_configZ%unused_mock_renewal_file_for_certnameZ	mock_certr�rlr#r#r$�test_revoke_by_certname�s�
z"RevokeTest.test_revoke_by_certnamecCs<tj|jdd�|_d��}d|_|�|�|j�|j�dS)z9Revoking with --server should use the server from the CLIr�r�z=revoke --cert-name=example.com --server https://other.exampleFN�rr)r�rrgrnr�rqr�r#r#r$�"test_revoke_by_certname_and_server�s�
z-RevokeTest.test_revoke_by_certname_and_servercCs<tj|jdd�|_d��}d|_|�|�|j�|j�dS)zLRevoking with --cert-name where the lineage server is empty shouldn't crash Nr�r�Fr�r�r#r#r$�$test_revoke_by_certname_empty_server�s

z/RevokeTest.test_revoke_by_certname_empty_servercCs |��d|_|j�|j�dSr)rnrr�rqr�)rr�r#r#r$�test_revocation_success�sz"RevokeTest.test_revocation_successcCsZddlm}|��|j_t�|j��|��Wd�n1sB0Y|j�	�dS)Nrr)
�acmerZClientErrorr�r:r;r<rnr�r9)rZacme_errorsr#r#r$�test_revocation_errors
&z RevokeTest.test_revocation_error�%certbot._internal.cert_manager.deletecCsd|�j_d|_|��dSr)r�rrn)rr��mock_deleter�r#r#r$�test_revocation_with_prompts
z&RevokeTest.test_revocation_with_prompt)N)r@rArBrCrVrnrrDr�r�r�r�r�r�r�r�r�r�r#r#rdr$r��s8




r�cs�eZdZdZ�fdd�Z�fdd�Zdd�Zdd	�Ze�	d
�dd��Z
d
d�Zdd�Ze�	d�dd��Z
dd�Ze�	d�dd��Zdd�Ze�	d�dd��Z�ZS)�ReconfigureTestz,Tests for certbot._internal.main.reconfigurec
sTt���t��|_|j��|_t�d�t�d�t�d�t�d�t�d�t�d�t�d�t�d�d	�|_	d
d�|j	�
�D�|_dg|jd
_t
j�|jd�|_t
j�|jd�}t
j�|�s�t�|�t
j�|d�|_d}t|jd��}|�|�Wd�n1�s0Yt|jd��"}tj|ddd�|_Wd�n1�sF0YdS)Nz7certbot._internal.storage.RenewableCert._check_symlinksz-certbot._internal.storage.RenewableCert.namesz2certbot._internal.plugins.selection.pick_installerz6certbot._internal.plugins.selection.pick_authenticatorz9certbot._internal.plugins.disco.PluginsRegistry.find_initrFrGz"certbot._internal.hooks.list_hooks)Zcheck_symlinks�
cert_names�pick_installer�	pick_auth�	find_init�_get_and_save_certZ_init_le_clientZ
list_hookscSsi|]\}}||���qSr#�rX��.0�k�vr#r#r$�
<dictcomp>#r4z)ReconfigureTest.setUp.<locals>.<dictcomp>r�r�r=�renewalzexample.com.confa�
            version = 1.32.0
            archive_dir = /etc/letsencrypt/archive/example.com
            cert = /etc/letsencrypt/live/example.com/cert.pem
            privkey = /etc/letsencrypt/live/example.com/privkey.pem
            chain = /etc/letsencrypt/live/example.com/chain.pem
            fullchain = /etc/letsencrypt/live/example.com/fullchain.pem

            # Options used in the renewal process
            [renewalparams]
            account = ee43634db0aa4e6804f152be39990e6a
            server = https://acme-v02.api.letsencrypt.org/directory
            authenticator = nginx
            installer = nginx
            key_type = rsa
        �w�r�utf-8��encodingZdefault_encoding)rUrVr�r�r�rXr�rrD�patchersr��mocksrrr�r�r��
config_dir�existsr�makedirs�renewal_file�open�write�	configobj�	ConfigObj�original_config)rZrenewal_configs_dirr�frdr#r$rVs4

�

*�zReconfigureTest.setUpcs0t���|j��|j��D]}|��qdSr�)rUr�r�rbr��values�rrDrdr#r$r�Bs

zReconfigureTest.tearDowncCsz|d|jg}tj��}t�||�}ddlm}|||�t|j	d�� }t
j|ddd�}Wd�n1sl0Y|S)N�--config-dirr)�reconfigurer�r�r�)r�rrhrirrjrkrrrrr)rZpassed_argsZ	full_argsrmr=rrZupdated_confr#r#r$rnHs

.zReconfigureTest._callcCs>t�tj��|�d���Wd�n1s00YdS)Nz!--cert-name cert1 -d one.cert.com)r;r<rr�rnrgrsr#r#r$�test_domains_setUsz ReconfigureTest.test_domains_set�,certbot._internal.cert_manager.get_certnamescCsLt��}d|_||jd_||jd_||jd_dg|_|�d���dS)N�nginxr�r�r�r��--nginx�rr�namer�rrnrg)r�mock_cert_manager�
named_mockr#r#r$�test_asks_for_certnameYsz&ReconfigureTest.test_asks_for_certnamecCsDt��}d|_||jd_||jd_||jd_|�d���}dS)N�apacher�r�r�� --cert-name example.com --apacher�rr�
new_configr#r#r$�test_update_configuratoresz(ReconfigureTest.test_update_configuratorcCstt��}d|_||jd_||jd_||jd_|�d���}d|dd<d|dd	<|dd
=|jd|d<dS)
zI Check that we don't accidentally modify anything that we didn't mean to rr�r�r�rr�
renewalparams�
authenticator�	installerr��versionN)rrrr�rrnrgrrr#r#r$�test_only_intended_changesps
z*ReconfigureTest.test_only_intended_changesz&certbot._internal.hooks.validate_hookscCs|�d��dg�dS)z6 Check that we use the staging server for the dry run �"--cert-name example.com --pre-hook�echo preN�rnrg)r�unused_validate_hooksr#r#r$�test_staging_used�sz!ReconfigureTest.test_staging_usedc
Cs6|jdd}|jdd}z|�d���Wn&tjyT}zWYd}~n
d}~00t|jd�� }tj|ddd�}Wd�n1s�0Y|�d	|�����}z|�d
���Wn&tjy�}zWYd}~n
d}~00t|jd�� }tj|ddd�}Wd�n1�s0Y|�d|�����}dS)zx Check that we error when attempting to change the account id or server,
            but not when it's the same
        rrr�z.--cert-name example.com --account newaccountidNr�r�r�z"--cert-name example.com --account z&--cert-name example.com --server x.comz!--cert-name example.com --server )	rrnrgrr�rrrr)rZorig_account_idZorig_server�errrrr#r#r$�!test_new_account_or_server_errors�s".0z1ReconfigureTest.test_new_account_or_server_errorscCs@|�d��dg�}|�d��dg�}|�d��dg�}dS)Nrr z	echo pre2z%--cert-name example.com --deploy-hookzecho deployr!)rr"rr#r#r$�test_update_hooks�sz!ReconfigureTest.test_update_hookscCsvtj|jd_z|�d���Wntjy4Yn0t|jd�� }tj	|ddd�}Wd�n1sh0YdS)Nr�rr�r�r�)
rrr�r:rnrgrrrr)rrrr#r#r$�test_dry_run_fails�s.z"ReconfigureTest.test_dry_run_fails�*certbot._internal.main.display_util.notifycCs�d}t|jd��}|�|�Wd�n1s00Yt|jd��"}tj|ddd�|_Wd�n1sn0Yt��}d|_||j	d_
||j	d_
|�d	���}|�
d
�dS)Na

            version = 2.0.0
            archive_dir = /etc/letsencrypt/archive/example.com
            cert = /etc/letsencrypt/live/example.com/cert.pem
            privkey = /etc/letsencrypt/live/example.com/privkey.pem
            chain = /etc/letsencrypt/live/example.com/chain.pem
            fullchain = /etc/letsencrypt/live/example.com/fullchain.pem

            # Options used in the renewal process
            [renewalparams]
            account = ee43634db0aa4e6804f152be39990e6a
            server = https://acme-staging-v02.api.letsencrypt.org/directory
            authenticator = webroot
            installer = nginx
            key_type = ecdsa
            webroot_path = /var/www/html,
            [[webroot_map]]
            example.com = /var/www/html
        r�r�r�r�rr�r�z--cert-name example.com --nginxzT
Successfully updated configuration.
Changes will apply when the certificate renews.)rrrrrrrrrr�rrnrg�assert_called_with)r�mock_notifyrrrrr#r#r$�test_report_results�s(�&�z#ReconfigureTest.test_report_results)r@rArBrCrVr�rnrrrDrrrr#r%r&r'r+r�r#r#rdr$r�s"-



%
r�c	@sReZdZdZdd�Zdd�Ze��dd��Ze��dd	��Z	e
�d
�e
�d�e
�d�e
�d
�e
�d�e
�d�e��dd��������Ze
�d�e
�d
�e
�d�e
�d�e
�d�e��dd�������Z
e
�d�e
�d
�e
�d�e
�d�e
�d�e��dd�������Ze
�d�e
�d
�e
�d�e
�d�e
�d�e��dd�������ZdS)�DeleteIfAppropriateTestz8Tests for certbot._internal.main._delete_if_appropriate cCsddlm}||�dS)Nr)�_delete_if_appropriate)rkr-)rr-r-r#r#r$rn�szDeleteIfAppropriateTest._callcCsBt�d��}|�|j�Wd�n1s,0Y|��dS)Nr�)rrDrnr=r9)rr�r#r#r$�_test_delete_opt_out_common�s*z3DeleteIfAppropriateTest._test_delete_opt_out_commoncCsd|j_|��dSr)r=�delete_after_revoker.)rZunused_mock_get_utilityr#r#r$�test_delete_flag_opt_outsz0DeleteIfAppropriateTest.test_delete_flag_opt_outcCs|�}d|j_|��dSr)r�rr.)rr��	util_mockr#r#r$�test_delete_prompt_opt_out	sz2DeleteIfAppropriateTest.test_delete_prompt_opt_outz%certbot._internal.main.logger.warningr�r�z7certbot._internal.cert_manager.match_and_check_overlapsz+certbot._internal.storage.full_archive_pathz3certbot._internal.cert_manager.cert_path_to_lineagec	Cs8|j}d|_d|_d|_t��|_|�|�|��dS)N�/some/reasonable/path�r�)	r=r�r0rrZOverlappingMatchFoundr:rnr9)	rr��mock_cert_path_to_lineage�mock_archive�mock_match_and_check_overlapsr��mock_renewal_file_for_certnameZmock_warningr=r#r#r$�test_overlapping_archive_dirss

z5DeleteIfAppropriateTest.test_overlapping_archive_dirscCs,|j}d|_d|_d|_d|_|�|�dS)Nr3r4r�F)r=r�r0rrn)rr�r5r�r6Zmock_overlapping_archive_dirsr8r=r#r#r$�test_cert_path_only$s

z+DeleteIfAppropriateTest.test_cert_path_onlycCs8|j}d|_d|_d|_d|_d|_d|_|�|�dS�NTr3r4r�)r=Znoninteractive_moder�r0rrn�rr�r�r5Zmock_full_archive_dirr7r8r=r#r#r$�test_noninteractive_deletion6s

z4DeleteIfAppropriateTest.test_noninteractive_deletioncCs8|j}d|_d|_d|_d|_d|_d|_|�|�dSr;)r=r/r�r0rrnr<r#r#r$�test_opt_in_deletionJs	
z,DeleteIfAppropriateTest.test_opt_in_deletionN)r@rArBrCrnr.r�r�r0r2rrDr9r:r=r>r#r#r#r$r,�sH

r,cs�eZdZdZ�fdd�Zdd�Ze�d�e�d�dd	���Zd
d�Z	dd
�Z
e�d�dd��Ze�d�dd��Ze�d�e�d�dd���Z
dd�Zdd�Zdd�Zdd�Z�ZS)�DetermineAccountTestz4Tests for certbot._internal.main._determine_account.cs^t���d|j_d|j_d|j_tjdd�tjdd�g|_t�	�|_
t��|_d|jj_
dS)NF�x)�id�y�hi)rUrVr=r�emailZregister_unsafely_without_emailrr)�accsZAccountMemoryStorage�account_storage�mock_client�	directoryZ	new_authzrsrdr#r$rVbs


zDetermineAccountTest.setUpc	Cs�ddlm}t�d��X}t���0|j|_||j�Wd�Wd�S1sV0YWd�n1st0YdS)Nr)�_determine_accountz1certbot._internal.main.account.AccountFileStorage)	rkrIrrDr�r�rFrr=)rrI�mock_storager#r#r$rnns�zDetermineAccountTest._callz!certbot._internal.client.registerz.certbot._internal.client.display_ops.get_emailc
CsDd|_||_z|��Wn&tjy>}zWYd}~n
d}~00dS)N�foo@bar.baz)rr:rnrr)r�err_msg�	exception�mock_get_email�
mock_registerr$r#r#r$�_register_error_commonvsz+DetermineAccountTest._register_error_commoncCs*|j�|jd|j�|jdj|j_dS�NrM)rF�saverErGrAr=rrsr#r#r$�test_args_account_set�sz*DetermineAccountTest.test_args_account_setcCs|j�|jd|j�dS)Nr)rFrRrErGrsr#r#r$�test_single_account�sz(DetermineAccountTest.test_single_accountz3certbot._internal.client.display_ops.choose_accountcCs,|jD]}|j�||j�q|jd|_dSrQ)rErFrRrGr)r�mock_choose_accountsr�r#r#r$�test_multiple_accounts�s
z+DetermineAccountTest.test_multiple_accountsc
CsZ|jD]}|j�||j�qd|_z|��Wn&tjyT}zWYd}~n
d}~00dSr�)rErFrRrGrrnrr)rrUr�r$r#r#r$�test_multiple_accounts_canceled�s
z4DetermineAccountTest.test_multiple_accounts_canceledr(cCsld|_t�d��&}|jdtjjf|j_Wd�n1s<0Y|jj|j|j	tj
d�|�d�dS)NrK�certbot._internal.main.clientr)Ztos_cbzAccount registered.)rrrDrE�sentinelr��registerrqr=rFrr)rr*rN�clientr#r#r$�test_no_accounts_no_email�s��z.DetermineAccountTest.test_no_accounts_no_emailcCsTd|j_t�d��.}|jdtjjf|j_|�	�Wd�n1sF0YdS)Nzother emailrXrM)
r=rDrrDrErYr�rZrrn)rr[r#r#r$�test_no_accounts_email�s
&z+DetermineAccountTest.test_no_accounts_emailcCsd}|�|t�|��dS)Nz$Some error message raised by Certbot)rPrr)rrLr#r#r$�test_register_error_certbot�sz0DetermineAccountTest.test_register_error_certbotcCs d}tddd�}|�||�dS)NzAError returned by the ACME server: must agree to terms of servicez$urn:ietf:params:acme:error:malformedzmust agree to terms of service)�typZdetail��
acme_errorrP�rrLrMr#r#r$�(test_register_error_acme_type_and_detail�s
�z=DetermineAccountTest.test_register_error_acme_type_and_detailcCsd}tdd�}|�||�dS)NzKError returned by the ACME server: The server experienced an internal errorz)urn:ietf:params:acme:error:serverInternal)r_r`rbr#r#r$�"test_register_error_acme_type_only�s
z7DetermineAccountTest.test_register_error_acme_type_only)r@rArBrCrVrnrrDrPrSrTrVrWr\r]r^rcrdr�r#r#rdr$r?_s&	
	
	r?cs�eZdZdZ�fdd�Z�fdd�Zd�dd	�Zd�d
d�Zdd
�Zdd�Z	dd�Z
e�d�dd��Z
e�d�e�d�e�d�e�d�e�d�e�d�dd�������Ze�d�e�d�dd���Ze�d �e�d�e�d�d!d"����Ze�d�e�d �e�d�e�d�d#d$�����Ze�d�e�d�d%d&���Ze�d�e�d�e�d'�e�d �d(d)�����Ze�d�e�d�e�d�e�d*�d+d,�����Ze�d�d-d.��Ze�d/�d0d1��Ze�d2�d3d4��Ze�d5�e�d6�e�d�d7d8����Ze�d5�e�d6�d9d:���Ze�d5�e�d6�d;d<���Ze�d5�e�d6�d=d>���Ze�d5�e�d6�d?d@���ZdAdB�ZdCdD�ZdEdF�ZdGdH�Z dIdJ�Z!dKdL�Z"dMdN�Z#d�dOdP�Z$e�d�dQdR��Z%e�d�e�dS�e�d�e�dT�dUdV�����Z&e�d�dWdX��Z'dddYdde(j(�)�ddfdZd[�Z*e�d�e�dS�e�dT�d\d]����Z+e�d^�e�d_�e�dT�d`da����Z,dbdc�Z-ddde�Z.dfdg�Z/e�dh�didj��Z0e�dh�dkdl��Z1e�dm�dndo��Z2e�dm�dpdq��Z3e�dr�dsdt��Z4e�d�dudv��Z5dwdx�Z6dydz�Z7d{d|�Z8d}d~�Z9dd��Z:d�d��Z;d�d�d��Z<d�d��Z=d�d��Z>d�d��Z?d�d��Z@d�d��ZAe�d��d�d���ZBd�d��ZCd�d��ZDd�d��ZEd�d��ZFd�d��ZGd�d��ZHeI�J�e�d��e�d��e�d�d�d������ZKd�d�d��ZLe�d��e�dS�e�d�d�d�����ZMe�d��d�d���ZNe�d��e�d��d�d����ZOd�d��ZPe�d��e�d�d�d����ZQe�d�d�d���ZRe�d��e�d��d�d����ZSe�d��e�d��e�d��e�d�d�d������ZT�ZUS)��MainTestzTests for different commands.csLt���t�|jj�d|jjd|jjd|jjdg|_t	�
d���|_dS)Nr
�
--work-dir�
--logs-dir�--textz
time.sleep)
rUrVr�mkdirr=�logs_dirr��work_dir�
standard_argsrrDrX�
mock_sleeprsrdr#r$rV�s

�zMainTest.setUpcstt�t���dSr�)�
reload_modulerrUr�rsrdr#r$r��szMainTest.tearDownNFc		s�|r�tjj��fdd�}t�d��l}||_t�d��<}|�||�\}}}||||fWd�Wd�S1sv0YWd�n1s�0YnHt�d��.}|�||�\}}}||||fWd�S1s�0YdS)zaRun the cli with output streams, actual client and optionally
        os.path.isfile() mocked outcs*|�d�s|�d�s|�d�r"dS�|�S)zMock os.path.isfile()r>�chain�privkeyT)�endswith)�fnrlr��Z	orig_openr#r$�mock_isfile�s
��z#MainTest._call.<locals>.mock_isfilezcertbot.compat.os.path.isfilerXN)rr��isfilerrDr:�_call_no_clientmock)	rrl�stdout�
mockisfilertZmock_ifr[r"�stderrr#rsr$rn�sXzMainTest._callc
Cs�|j|}|r|nt��}tjd|d��vt�d��L}t�d��"t�|dd��}Wd�n1sh0YWd�n1s�0YWd�n1s�0Y|||fS)z-Run the client with output streams mocked out�!certbot._internal.main.sys.stdout��new�!certbot._internal.main.sys.stderr�certbot.util.atexitN)rl�io�StringIOrrDr)rrlrwZ
toy_stdoutryr"r#r#r$rv�s
lzMainTest._call_no_clientmockcCs8t�d��}|�g�Wd�n1s*0YdS)Nzcertbot._internal.main.run)rrDrn)r�mock_runr#r#r$�
test_no_flagss
zMainTest.test_no_flagsc
Cs�t��}t��}tjd|d���tjd|d��\z8zt�dg�WntyTYn0W|��pf|��}n|��px|��}0Wd�n1s�0YWd�n1s�0YdS)Nrzr{r}z	--version)rr�rrDr�
SystemExit�getvalue)rZtoy_outZtoy_err�outputr#r#r$� test_version_string_program_names�z)MainTest.test_version_string_program_namec
Cszd}zFt�d��(t�|j|dd��Wd�n1s>0YWn*tjyt}z|}WYd}~n
d}~00dS)zQEnsure that a particular error raises a missing cli flag error containing messageNr})rrDrrlrZMissingCommandlineFlag)rrl�message�excZexc_r#r#r$�_cli_missing_flags:zMainTest._cli_missing_flagz*certbot._internal.log.post_arg_parse_setupcCs2ddg}|�|d�|�gd��|�|d�dS)Nz-nr�zspecify a plugin)�--standalone�-dzeg.iszregister before running)r��extend)r�_rlr#r#r$�test_noninteractiveszMainTest.test_noninteractiverKrIr�zBcertbot._internal.main.client.Client.obtain_and_enroll_certificaterFcCs�gd�|j}t��df|_t��|_t�d��R}|j}	|�|�t��}
|	j	dd}ddl
}|�
�}
d|
��vrtWd�n1s�0Yt�d��J}|j}	d}|d|g7}|�|�|	jtj
tj
d	|tjd
�Wd�n1s�0YdS)N)r�r��-mz
none@none.comr�r�z--agree-tosr�rM�
user_agentrZlinuxZbandersnatchz--user-agentT)rZ
verify_sslr�Zalg)rlrr)rrDZ
ClientNetworkrvr
Zget_os_info_ua�	call_args�platform�lowerrqrr�joseZRS256)rZgscZ_obtZdetr��__�___rlZacme_clientZacme_netZos_verZuar�Zplatr#r#r$�test_user_agent%s,	�


�zMainTest.test_user_agent�5certbot._internal.main.plug_sel.record_chosen_plugins�.certbot._internal.main.plug_sel.pick_installercCs|jgd�dd�dS)N)	�installz	--domains�foo.bar�--cert-pathr>�
--key-pathrp�--chain-pathroT�rx)rn)rZmock_pick_installer�_recr#r#r$�test_installer_selectionFs
�z!MainTest.test_installer_selectionr�cCs~tjt�d�t�d�t�d�t�d�d�}t�d��6}||_|jgd�dd�|jd	d	}Wd�n1sp0YdS)
Nr>rorp�r��
chain_path�fullchain_path�key_pathr�)r��--cert-name�whateverTr�r)rr)r��	temp_joinrDrrnr�)r�_instr��mock_installr!�mock_getlin�call_configr#r#r$�test_installer_certnameMs�z MainTest.test_installer_certnamec	Cs�tjt�d�t�d�t�d�t�d�d�}t�d��v}||_|jdddd	t�d
�gdd�|jd
d
}|��|jddddt�d�gdd�|jd
d
}Wd�n1s�0YdS)Nr>rorpr�r�r�r�r�r�Zoverriding_privkeyTr�rr�Zoverriding_cert)	rr)r�r�rDrrnr��reset)rr�r�r�r�r!r�r�r#r#r$�test_installer_param_override^s*�

��

��z&MainTest.test_installer_param_overridecCs>t�tj��|�gd��Wd�n1s00YdS)N)r�r�Znotfoundr�Zinvalid�r;r<rr�rn)rr�r�r#r#r$�test_installer_param_errorzsz#MainTest.test_installer_param_errorr
cCsntjt�d�t�d�t�d�t�d�d�}t�d��&}||_|jdgdd�Wd�n1s`0YdS)	Nr>rorpr�r�r�Tr�)rr)r�r�rDrrn)r�	mock_instZmock_getcertr�r�r!r�r#r#r$�test_installer_select_cert�s�.z#MainTest.test_installer_select_certzcertbot.util.exe_existscCs d|_tj��}gd�}dddt�d�dt�d�dd	d
ddg}d
|vrX|�|�\}}}}|�dgd�t�	d��b}t�	d��8}	t�
�|	_|�gd��|jd\}
}}Wd�n1s�0YWd�n1s�0Yt�	d��}
|�ddg�Wd�n1�s0YdS)NT)z--apachez--authenticatorrr�rr�Zblahr�z--nginx-server-rootz/nonexistent/thingr�r��--debugrr�z(With the standalone plugin, you probablyrGrF)r�z--manualr�r�r�certbot._internal.main.certonly�auth)rrrhrir�r�rnr�rrDr)r�)rZmock_exe_existsr�r�r�Zreal_pluginsrlr"r\Zmock_gscZ
unused_configr�Zunused_installer�
mock_certonlyr#r#r$�test_configurator_selection�s(

�
<z$MainTest.test_configurator_selectioncCsF|�dg�\}}}}|�gd��\}}}}|j�tjdtjtj�dS)N�rollback)r�z
--checkpointsZ123�{)rnr�rqrrr)rr�r[r#r#r$�
test_rollback�s
�zMainTest.test_rollbackz+certbot._internal.cert_manager.certificatescCs|�dg�dS)NZcertificates�rv�rrr#r#r$�test_certificates�szMainTest.test_certificatesr�cCs|�dg�dS)N�deleter�r�r#r#r$�test_delete�szMainTest.test_deletez$certbot._internal.main.plugins_discozFcertbot._internal.main.cli.HelpfulArgumentParser.determine_help_topicscsFgd��tj�fdd�tt���D��D]}|�dgt|��q(dS)N)�--init�	--preparez--authenticatorsz--installersc3s|]}t��|�VqdSr�)�	itertools�combinations)r�r���flagsr#r$�	<genexpr>�s�z(MainTest.test_plugins.<locals>.<genexpr>rm)r�ro�range�lenrn�list)rr��_det�
mock_discorlr#r�r$�test_plugins�s

��zMainTest.test_pluginscCs�g}|j��}t��}tj|d��&|�dg|�\}}}}Wd�n1sN0Y|j��|��j	�|�|���	�}dS)N�rwrm�
rhrirr�r��patch_display_util_with_stdoutrn�visiblerq�ifaces�rr�r�r�rmrwr��filteredr#r#r$�test_plugins_no_args�s
4
zMainTest.test_plugins_no_argsc
	Cs�g}|j��}dd�}t��}t�d��X}tj|d��,||_|�	dg|�\}}}}Wd�n1sh0YWd�n1s�0Y|j
��|�
�j�|�|�
���}	dS)NcSs|||}}}t���dS)zRaises error.Error.N)rr)rH�mode�strictr�r#r#r$�throw_error�sz?MainTest.test_plugins_no_args_unprivileged.<locals>.throw_errorzcertbot.util.set_up_core_dirr�rm)
rhrirr�rrDr�r�r:rnr�rqr�)
rr�r�r�rmr�rwZmock_set_up_core_dirr�r�r#r#r$�!test_plugins_no_args_unprivileged�s
R
z*MainTest.test_plugins_no_args_unprivilegedcCs�g}|j��}t��}tj|d��(|�ddg|�\}}}}Wd�n1sP0Y|j��|��j	�|�|���	�}dS)Nr�rmr�r�r�r#r#r$�test_plugins_init�s
6
zMainTest.test_plugins_initc	Cs�g}|j��}t��}tj|d��(|�gd�|�\}}}}Wd�n1sP0Y|j��|��j	�|�|���	�}|j
��|j��|��}dS)Nr�)rmr�r�)rhrirr�r�r�rnr�rqr��prepare�	available)	rr�r�r�rmrwr�r�r�r#r#r$�test_plugins_prepares
6


zMainTest.test_plugins_preparecCshd}d}d}d}t�d��,}|�dd|ddd	dd
dg	�Wd�n1sL0Y|jd\}}dS)Nr>�keyro�	fullchainr�r�r�r�r�z--fullchain-pathr)rrDrnr�)rr>r�ror�r�r=�unused_pluginsr#r#r$�test_certonly_abspaths�$zMainTest.test_certonly_abspathc
CsHz|�gd��t�d�Wn&tjyB}zWYd}~n
d}~00dS)N)�-aZbad_authr�z!Exception should have been raised)rnr;�failr�PluginSelectionError�r�er#r#r$�test_certonly_bad_args/s
zMainTest.test_certonly_bad_argscCs�t�tj��|�ddg�Wd�n1s00Yt�tj��|�ddg�Wd�n1sj0Yt�tj��|�ddg�Wd�n1s�0Yt�tj��|�ddg�Wd�n1s�0YdS)Nr�Z@aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa�aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.z
204.11.231.35z%2001:db8:ac69:3ff:b1cb:c8c6:5a84:a31br�rsr#r#r$�test_check_config_sanity_domain6s,,,z(MainTest.test_check_config_sanity_domaincCsDt�tj��$|�d�t����Wd�n1s60YdS)Nz*certonly --csr {0} --allow-subset-of-names�r;r<rrrnrfr�rgrsr#r#r$�test_csr_with_besteffortDsz!MainTest.test_csr_with_besteffortc
CsJz|�dtg�Wn(tjy:}zWYd}~dSd}~00t�d�dS)Nz--csrz2Expected supplying --csr to fail with default verb)rnr�rrr;r�r�r#r#r$�test_run_with_csrHs
zMainTest.test_run_with_csrcCsJt�tj��*|�d�t�d�����Wd�n1s<0YdS)Nzcertonly --csr {0}zcsr-nonames_512.pem)	r;r<rrrnrfr��vector_pathrgrsr#r#r$�test_csr_with_no_domainsQs�z!MainTest.test_csr_with_no_domainscCsDt�tj��$|�d�t����Wd�n1s60YdS)Nz!certonly -d example.org --csr {0}r�rsr#r#r$�"test_csr_with_inconsistent_domainsVsz+MainTest.test_csr_with_inconsistent_domainsc	Cs�t�d��h}d|_t�d��8}||_|dur0g}|d��7}|�|�Wd�n1sZ0YWd�n1sx0YdS)N�=certbot._internal.main._find_lineage_for_domains_and_certname)ZnewcertNrGz!-d foo.bar -a standalone certonly)rrDrrgrn)rrGrl�mock_renewalr\r#r#r$�_certonly_new_request_commonZs
z%MainTest._certonly_new_request_commoncCs"t��}d|j_|�|dg�dS�N�	--dry-run)rr)�obtain_and_enroll_certificaterr�)r�mock_reportrGr#r#r$�)test_certonly_dry_run_new_request_successesz2MainTest.test_certonly_dry_run_new_request_successz+certbot._internal.main.util.atexit_registerzcertbot.crypto_util.notAfterc
Csrtj�tj�|jjd��}tj�tj�|jjd��}d}||�j_tj	||||d�}t�	�}	||	j
_|�|	�dS)Nzlive/foo.barzlive/baz.quxz
1970-01-01)r>r�r�r�)rr��normpathr�r=r��daterrr)r�r�)
rZ
mock_notAfterr_rOr�r�r�r�r!rGr#r#r$�!test_certonly_new_request_successns
�
z*MainTest.test_certonly_new_request_successcCsJt��}d|j_t�tj��|�|�Wd�n1s<0YdSr)	rr)r�rr;r<rrr�)rr_rGr#r#r$�!test_certonly_new_request_failure�s
(z*MainTest.test_certonly_new_request_failureTcst�d�}tj�tj�|jjd��}tj	||||d�}
||
j
_d|
j_dg|
j
_d|
_d|
_|	|
_t�	�}tj	dd	�}t�	�}t���|d
|df|j_�fdd
�}�z&�z�t�d���X}|
df|_t�d��� }||_t�d���}|s�||�j_t�d���}||j_t�d���|�sgd�}|�r,||7}z0|�|��\}�}}|�rZtd|�t|��Wn"|�sztdt����Yn0Wd�n1�s�0YWd�n1�s�0YWd�n1�s�0YWd�n1�s�0YWd�n1�s0Y|�rp|	�r\|
�s\|j�tjgtj�tj�|jjd���n|j�tjgd�nWn|���Yn0W|�rt tj�|jj!d���}Wd�n1�s�0Yn@|�r
t tj�|jj!d���}Wd�n1�s0Y0|
|�fS)Nrzlive/foo.bar/fullchain.pem)r>r�r�r�F�	isnot.orgr/Z	secp256r1Zpem_key)Zpemro�csrcs��|�dS)zWrite message to stdout.N)r)r�rlr�r�r#r$�	write_msg�sz0MainTest._test_renewal_common.<locals>.write_msgz5certbot._internal.cert_manager.find_duplicative_certsrGz)certbot._internal.display.obj.get_displayz*certbot._internal.main.renewal.crypto_utilrK)r�r�r�rr�ZReturnedzUnexpected renewal error:
zlive/sample-renewal/privkey.pem�letsencrypt.log)"r�r�rr�r�r�r=r�rr)Zshould_autorenewrZhas_pending_deploymentr,r8Zelliptic_curve�	reuse_keyrr�Zobtain_certificaterDr�r:ZnotAfterrn�print�AssertionError�	traceback�
format_excrqrr�	_dump_logrrj)r�due_for_renewal�
extra_args�log_outrl�should_renew�error_expected�
quiet_mode�expiry_dater��new_keyr�r�r!Z
mock_certrZmock_keyrGr�Zmock_fdcr\Zmock_displayZmock_crypto_utilr"r��lfr#r�r$�_test_renewal_common�s�
��
�



�����
"�"zMainTest._test_renewal_commoncCs&|�dg�\}}}|j�|���dSrv)rZupdate_all_links_torqZlatest_common_version)rr�rOr�Zlineager#r#r$�test_certonly_renewal�s
�zMainTest.test_certonly_renewalr(zEcertbot._internal.log.logging.handlers.RotatingFileHandler.doRollovercCsV|jdddgdd�\}}}|�d�|jdgd�dd�|jdgd	�dd
�\}}}dS)NFr��--keepzsimulating renewal)r�The dry run was successful.)z--renew-by-default�-tvvr�zAuto-renewal forced)rr�r)r)r�assert_any_call)rr�r�r*Zmock_displayerr#r#r$�test_certonly_renewal_triggers�s�
��z'MainTest.test_certonly_renewal_triggerscCs^td�tj�|jjd�}tj�|�rZt|��}t|���Wd�n1sP0YdS)NzLogs:r�)	rrr�r�r=rjr�r�read)rZlog_pathr
r#r#r$r�s

zMainTest._dump_logcCs.t�|jjd�gd�}|jdg|dd�dS)N�sample-renewal.conf��renewr�rT�rlr�r��make_lineager=r�r�rrlr#r#r$�test_renew_verb�szMainTest.test_renew_verbcCs4tj|jjddd�gd�}|jdg|ddd�dS)NrF�Zec)rr��--reuse-keyT�rlrr�rrr#r#r$�test_reuse_keyszMainTest.test_reuse_keyz6certbot._internal.storage.RenewableCert.save_successorcCs4tj|jjddd�ddg}|jdg|ddd�dS)NrFrrrTr r�rZunused_save_successorrlr#r#r$�test_reuse_key_no_dry_runsz"MainTest.test_reuse_key_no_dry_runcCs2t�|jjd�gd�}|jdg|dddd�dS)Nr)rrz	--new-keyT)rlrr�rrr"r#r#r$�test_new_keys
�zMainTest.test_new_keyz	sys.stdincCsFd|j_t�|jjd�gd�}|jdg|dd�|jjdd}dS)NFrrTrr)	�isattyrr�rr=r�rrmr�)r�stdinrlZsleep_call_argr#r#r$�!test_noninteractive_renewal_delaysz*MainTest.test_noninteractive_renewal_delaycCs6d|j_t�|jjd�gd�}|jdg|dd�dS)NTrrr)r%rr�rr=r�r)rr&rlr#r#r$�!test_interactive_no_renewal_delays
z*MainTest.test_interactive_no_renewal_delayr&cCsLd|_t�|jjd�tj��tjdd�}|jddddg|d�\}}}dS)NFr�Z)Zdaysr)rrrlr)	rr�rr=r�r��nowZ	timedeltar)rrZexpiryr�rwr#r#r$�test_renew_skips_recent_certs&s
�z&MainTest.test_renew_skips_recent_certscCsft�|jjd�ddg}|jdg|dd�\}}}|��}gd�}|jdg|ddd�\}}}|��}dS)Nrrr�Tr)rr�z-q)rlrr
)r�rr=r�rr�)rr�rlrw�outr#r#r$�test_quiet_renew0s
�zMainTest.test_quiet_renewcCs0t�|jjd�gd�}|jdg|ddd�dS)Nr)rr��--post-hook=no-such-commandTF�rlrr	rrr#r#r$�test_renew_hook_validation>s
�z#MainTest.test_renew_hook_validationcCsZt�|jjd�gd�}t�d��$|jdg|ddd�Wd�n1sL0YdS)Nr)rr�r.z--disable-hook-validationz!certbot._internal.hooks.post_hookTFr/)r�rr=r�rrDrrr#r#r$�test_renew_no_hook_validationDs�z&MainTest.test_renew_no_hook_validationcCs|tj�|jjd�}tj�|�s(t�|�ttj�|d�d��Wd�n1sR0Ygd�}|j	dg|ddd�dS)Nr�z
empty.confr�rFTr/)
rr�r�r=r�r�rrrr)rZrdrlr#r#r$�test_renew_verb_empty_configLs
z%MainTest.test_renew_verb_empty_configcCs*t�|jjd�|jdgdgd�d�dS)NrT�rr�r�zsample-renewal)rrlrrsr#r#r$�test_renew_with_certnameUs
�z!MainTest.test_renew_with_certnamecCs|jdgdgd�dd�dS)NTFr3)rrlr	)rrsr#r#r$�test_renew_with_bad_certnameZs
�z%MainTest.test_renew_with_bad_certnamecCs^tj�|jjd�}t�|�ttj�|d�d��}|�d�Wd�n1sP0YdS)Nr�z	test.confr�zMy contents don't matter)	rr�r�r=r�rrrr)rZrenewer_configs_dirrr#r#r$�_make_dummy_renewal_config_s
z#MainTest._make_dummy_renewal_configc	Ks�|��t�d���}t��}d|_|dur4d|i|_|durD||j_||_t�d��2}|�ddg�|j	d
dd	i|��Wd�n1s�0Y|dur�|r�nWd�n1s�0YdS)Nr�zsomepath/fullchain.pemr�!certbot._internal.main.renew_certrlrTrF)TN)
r6rrDr)r��
configurationr,r�
setdefaultr)rrr,�assert_oc_calledr��mock_rcr!r�r#r#r$�_test_renew_commones 
2zMainTest._test_renew_commoncCs|jddd�dS)NFT�r:r	�r<rsr#r#r$�test_renew_no_renewalparamszsz$MainTest.test_renew_no_renewalparamscCs|jiddd�dS)NFT)rr:r	r>rsr#r#r$�test_renew_no_authenticator}s�z$MainTest.test_renew_no_authenticatorcCsddd�}|j|ddd�dS)N�webrootz	over 9000)rZrsa_key_sizeTF)rr	r:r>�rrr#r#r$�test_renew_with_bad_int�s��z MainTest.test_renew_with_bad_intcCsddd�}|j|dd�dS)NrA�None)rZhttp01_portT�rr:r>rBr#r#r$�test_renew_with_nonetype_http01�s��z(MainTest.test_renew_with_nonetype_http01cCs$ddi}dg}|j|d|dd�dS)NrrAu
uniçodé.comTF)rr	r,r:r>)rrr,r#r#r$�test_renew_with_bad_domain�s
�z#MainTest.test_renew_with_bad_domainr�cCs2t��t��f|_ddi}|j|dd��d�dS)NrrATzrenew --configurator apache�rr:rl)rr)rr<rg)rr�rr#r#r$�test_renew_with_configurator�s�z%MainTest.test_renew_with_configuratorcCsdddd�}|j|dd�dS)NrArDZ42)rZwebroot_pathZwebroot_imaginary_flagTrEr>rBr#r#r$�$test_renew_plugin_config_restoration�s��z-MainTest.test_renew_plugin_config_restorationc
Cs0ddi}|j|dddt�dt��i�gd�dS)NrrATrz
--webroot-mapr�rH)r<�json�dumpsr�r�rBr#r#r$�test_renew_with_webroot_map�s
�z$MainTest.test_renew_with_webroot_mapcCsBt�d��$}t|_|jddd�Wd�n1s40YdS)Nz+certbot._internal.main.renewal.reconstituteFTr=)rrD�	Exceptionr:r<)rZmock_reconstituter#r#r$�test_renew_reconstitute_error�sz&MainTest.test_renew_reconstitute_errorc	Cs�|��t�d��x}t��}d|_||_dddii|_t�d��,}t|_|j	ddddgd	d
�Wd�n1sr0YWd�n1s�0YdS)Nr�zsomewhere/fullchain.pemrrrAr7TrF)r	rlr)
r6rrDr)r�rr8rNr:r)rr;r!r�r#r#r$�test_renew_obtain_cert_error�s�
�z%MainTest.test_renew_obtain_cert_errorcCs:|jddd��ddd�|jddd�t���ddd�dS)NTzrenew -d example.comFr/zrenew --csr {0})rrgrfr�rsr#r#r$�test_renew_with_bad_cli_args�s��z%MainTest.test_renew_with_bad_cli_argsc	Cs*|jdddddd�tj�gd�\}}}dS)NFrz--post-hookz{0} -c "print('hello world');")rrrrl)rrf�sys�
executable)rr�rwr#r#r$�test_no_renewal_with_hooks�s���z#MainTest.test_no_renewal_with_hooksr�rGcCs6dt��f|_t��|_}|�gd��|��dS)Nr()r�r�r�rr�)rr)rrnr9)rZmock_report_new_certr\r�r�rGr#r#r$�test_certonly_reinstall�sz MainTest.test_certonly_reinstallc
	Cs d}d}t��}||f|j_tj�tj�|jj	d��}tj�tj�|jj	d��}|d|f|j
_t�d���}||_tj�tj�|jj	d��}d�t
|||���}	|r�|	|7}	t�d��|�|	�Wd�n1s�0YWd�n1s�0Yd	|	v�rn|j
�|||||�dS)
N�certrrozlive/example.com/cert_512.pemzlive/example.com/fullchain.pemrGzlive/example.com/chain.pemzV-a standalone certonly --csr {0} --cert-path {1} --chain-path {2} --fullchain-path {3}z"certbot._internal.main.crypto_utilr�)rr)Zobtain_certificate_from_csrrrr�r�r�r=r�Zsave_certificaterDrfr�rgrnrq)
rrrVrorGr��	full_pathr\r�rlr#r#r$�_test_certonly_csr_common�s>����F

�z"MainTest._test_certonly_csr_commonz+certbot._internal.main._csr_report_new_certcCs|��dSr��rX)rr_rO�mock_csr_reportr#r#r$�test_certonly_csr�szMainTest.test_certonly_csrcCs|�dg�dSr�rY)rrZr#r#r$�test_certonly_csr_dry_runsz"MainTest.test_certonly_csr_dry_runr�r�c	Cs�d|_d}|�dtdtd|dg�ttd��}Wd�n1sB0Yttd��@}t�|���d}|��j	}|�
t�|�t
j�Wd�n1s�0YdS)	NFr�r�r��--serverr��rbr)rrv�SS_CERT_PATH�RSA2048_KEY_PATHrr�pyopenssl_load_certificaterr�r�rqr��ComparableX509rrr)rr�r�r�rr>r�r#r#r$�test_revoke_with_key	s�
�zMainTest.test_revoke_with_keyc
CsLd}t�tj��(|�dtdtd|dg�Wd�n1s>0YdS)Nr�r�r�r]r�)r;r<rrrv�CERT�KEY)rr�r#r#r$�test_revoke_with_key_mismatchs
�z&MainTest.test_revoke_with_key_mismatchcCs�d|_t��df|_|�dtdg�\}}}}tt��@}t�|���d}|�	�j
}|�t�
|�tj�Wd�n1sz0YdS)NFr�r�r)rrr)rnrdrrrarZacme_from_config_keyr�rqr�rbrr)rr�r�r�r[rr>r�r#r#r$�test_revoke_without_key"s

�z MainTest.test_revoke_without_keyc	Cs�t�d���}t��}d|_|df|j_|�gd��t�d��8}t��}||j_dg|j_|�gd��}Wd�n1s|0YWd�n1s�0YdS)NrXZimaginary_accountZworked)rZz--emailzuser@example.org�certbot._internal.main.account�
an account)	rrDr)rArZrrv�AccountFileStorageri)rr�Z
mocked_clientr�Zmocked_account�mocked_storager@r#r#r$�
test_register0s
zMainTest.test_registerz'certbot._internal.updater._run_updaterscCs^tj|_t�tj��t�ddd�Wd�n1s80Yd|j_t	�
|jdd�dSr)rr�r:r;r<r�
renew_certr=�dry_runrZrun_generic_updaters)rr�r~r#r#r$�test_plugin_selection_errorAs,z$MainTest.test_plugin_selection_errorz3certbot._internal.main.updater.run_renewal_deployercCsDd|j_t��}|t��f|_t�|jdd�|j��|��dS)z8A dry-run renewal shouldn't try to restart the installerTN)	r=rnrr)rrrmr�r9)rr�r\r~Zmock_run_renewal_deployerrr#r#r$�#test_renew_doesnt_restart_on_dryrunNs
z,MainTest.test_renew_doesnt_restart_on_dryrun)NF)N)N)NNN)N)Vr@rArBrCrVr�rnrvr�r�r�rrDr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r*rrrrrr!r#r$r'r(r+r-r0r1r2r4r5r6r<r?r@rCrFrGrIrJrMrOrPrQrTr�r�rUrXr[r\rcrfrgrlrorpr�r#r#rdr$re�s@




%



	



�
K	





	

	�



	

rec@s>eZdZdd�Zdd�Zdd�Ze�d�dd	��Zd
d�Z	dS)
�UnregisterTestcCs@t�d�t�d�t�d�t��d�|_dd�|j��D�|_dS)Nr�rhrX)rIrr[�get_utilitycSsi|]\}}||���qSr#r�r�r#r#r$r�hr4z(UnregisterTest.setUp.<locals>.<dictcomp>)rrDr�r�r�r�r�rsr#r#r$rVbs�zUnregisterTest.setUpcCs|j��D]}|��q
dSr�)r�rrbr	r#r#r$r�jszUnregisterTest.tearDowncCsFt��|jdj_|jd�}d|j_t��}t��}t�||�}dS)NrrrF)rrr�rjrr�r�
unregister)rr1r=r��resr#r#r$�test_abort_unregisternsz$UnregisterTest.test_abort_unregisterr(cCstt��}dg|j_||jdj_t��df|jd_t��}||jdj_t��}t��}t�||�}|�	d�dS)NrirZfoorIr[zAccount deactivated.)
rr)rirr�rj�Clientrrsrq)rr*rk�	cb_clientr=r�rtr#r#r$�test_unregisterzs
zUnregisterTest.test_unregistercCs^t��}g|j_||jdj_t��}||jdj_t��}d|_t��}t�	||�}d}dS)Nrr[z"https://acme.example.com/directoryzNCould not find existing account for server https://acme.example.com/directory.)
rr)rirr�rjrvr�rrs)rrkrwr=r�rt�mr#r#r$�test_unregister_no_account�sz)UnregisterTest.test_unregister_no_accountN)
r@rArBrVr�rurrDrxrzr#r#r#r$rqas
rqc@s"eZdZdZe�d�dd��ZdS)�MakeOrVerifyNeededDirsz<Tests for certbot._internal.main.make_or_verify_needed_dirs.zcertbot._internal.main.utilcCspt�|j�|jj|jjfD]}|j�|tj|jj	�q|jj
|jj|jjf}|D]}|j
j||jj	d�qRdS)N)r�)rZmake_or_verify_needed_dirsr=r�rkZset_up_core_dirrr
ZCONFIG_DIRS_MODEZstrict_permissionsZrenewal_pre_hooks_dirZrenewal_deploy_hooks_dirZrenewal_post_hooks_dirZmake_or_verify_dir)rZ	mock_utilZcore_dirZ	hook_dirsZhook_dirr#r#r$�test_it�s���zMakeOrVerifyNeededDirs.test_itN)r@rArBrCrrDr|r#r#r#r$r{�sr{cs�eZdZdZ�fdd�Zdd�Zdd�Ze�d�e�d	�e�d
�e�d�dd
�����Z	e�d�e�d	�e�d
�e�d�dd�����Z
e�d	�e�d
�e�d�dd����Ze�d	�e�d
�e�d�dd����Ze�d
�e�d�dd���Z
dd�Ze�d�e�d
�e�d�dd����Ze�d	�e�d
�e�d�e�d�e��dd������Ze�d	�e�d
�e�d�e�d�e��dd������Zd d!�Z�ZS)"�EnhanceTestz)Tests for certbot._internal.main.enhance.cs4t���t��|_|j��|_tjt	j
d�|_dS�N)�spec)rUrVr�r�r�rXr�rr)r�AutoHSTSEnhancement�
mockinstallerrsrdr#r$rV�s

zEnhanceTest.setUpcCs|j��dSr�r�rsr#r#r$r��szEnhanceTest.tearDownc
Cs�tj��}t�||�}t�d���}dg|_t�d���}dg|_t�d��P}t��}||_	||_t
�||�|Wd�Wd�Wd�S1s�0YWd�n1s�0YWd�n1s�0YdS)Nr
r�r�rG)rrhrirrjrrDrr)r=r�enhance)rrlrmr=Z
mock_certsZmock_domr\rGr#r#r$rn�s
zEnhanceTest._callr�r�z0certbot._internal.main.display_ops.choose_valuesz0certbot._internal.main._find_domains_or_certnamecCsXtjdd�|_dg|_d|_t�d��}|�ddg�Wd�n1sJ0YdS)N�/tmp/nonexistent�r�r��NNr�r��
--redirect�rr)rrDrn)r�	mock_findr~r!r��	mock_pickr#r#r$�test_selection_question�sz#EnhanceTest.test_selection_questionc	Cs�tjdd�|_dg|_d|_t�d��Ht�d��}|�gd��}Wd�n1sV0YWd�n1st0YdS)Nr�r�r�r�r�z.certbot._internal.main.plug_sel.logger.warning)r�r�rAr�r�)rr�r~r!r�Zmock_logrGr#r#r$�test_selection_auth_warning�sz'EnhanceTest.test_selection_auth_warningcs`tjdd�|_dg|_t�d��,|�gd���ddg}dg}Wd�n1sR0YdS)	Nr�r�r�r��r�r��--hstsZredirectZhstsZuirr�)rr�r~r!Zreq_enhZnot_req_enhr#)rGr$�test_enhance_config_call�sz$EnhanceTest.test_enhance_config_callcCsRtjdd�|_dg|_t�d��|�gd��}Wd�n1sD0YdS)Nr�r�r�r�)r�r�r�z--non-interactiver�)rr�r~r!rGr#r#r$�test_enhance_noninteractive�s�z'EnhanceTest.test_enhance_noninteractivec	Csng|_t�d��Jt�tj��|�gd��Wd�n1sB0YWd�n1s`0YdS)Nr�r�)rrrDr;r<rrrn)rr�r~r#r#r$�test_user_abort_domainssz#EnhanceTest.test_user_abort_domainscCs>t�tj��|�gd��Wd�n1s00YdS)N)r�r�r)r;r<rZMisconfigurationErrorrnrsr#r#r$�test_no_enhancements_definedsz(EnhanceTest.test_no_enhancements_definedrxcCs*dg|_d|_t��|_|�ddg�}dS)Nr�r�r�r�)rrr�r:rn)rr�r~r�rGr#r#r$ros

z'EnhanceTest.test_plugin_selection_errorr�cCs2|j|_ddg|_tjdd�|_|�ddg�dS)Nr��another.tldr�r�r��--auto-hsts)r�rrr)rn�rr�r�r�r~r!r#r#r$�test_enhancement_enables

z#EnhanceTest.test_enhancement_enablecCsft�|jd�|_ddg|_tjdd�|_t�tj	��|�
ddg�Wd�n1sX0YdS)Nrr�r�r�r�r�r�)rrzr=rrr)r;r<rr|rnr�r#r#r$�%test_enhancement_enable_not_supported,s

z1EnhanceTest.test_enhancement_enable_not_supportedcCs>t�tj��|�gd��Wd�n1s00YdS)N)r�r�r�)r;r<rrrnrsr#r#r$� test_enhancement_enable_conflict8sz,EnhanceTest.test_enhancement_enable_conflict)r@rArBrCrVr�rnrrDr�r�r�r�r�r�ror�r�r�r�r�r�r#r#rdr$r}�sV

	r}csXeZdZdZ�fdd�Ze�d�e�d�dd���Ze�d�e�d�dd	���Z�Z	S)
�InstallTestz)Tests for certbot._internal.main.install.cst���tjtjd�|_dSr~)rUrVrr)rr�r�rsrdr#r$rV@s
zInstallTest.setUpr�r�cCsht�|jd�|_tj��}d|j_d|j_t	�
tj��t
�|j|�Wd�n1sZ0YdS)NrTZnonexistent)rrzr=rrrhrir{r0r;r<rr|rr��rr�r�rmr#r#r$�&test_install_enhancement_not_supportedDs
z2InstallTest.test_install_enhancement_not_supportedcCsp|j|_tj��}d|j_d|j_d|j_d|j_	t
�tj
��t�|j|�Wd�n1sb0YdS)NTr�)r�rrrhrir=r{r0r�r�r;r<rr�rr�r�r#r#r$�$test_install_enhancement_no_certnameNs
z0InstallTest.test_install_enhancement_no_certname)
r@rArBrCrVrrDr�r�r�r#r#rdr$r�=sr�c@sxeZdZdZdd�Zdd�Zedd��Zedd	��Zd
d�Z	dd
�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�ZdS)�ReportNewCertTestznTests for certbot._internal.main._report_new_cert and
       certbot._internal.main._csr_report_new_cert.
    cCsJt�d�|_|j��|_t�d�|_|j��|_t�ddddd�|j_dS)Nr(z+certbot._internal.main.crypto_util.notAfteri�rMr)	rrD�notify_patchrXr*�notafter_patchZ
mock_notafterr�rrsr#r#r$rV`s
zReportNewCertTest.setUpcCs|j��|j��dSr�)r�rbr�rsr#r#r$r�hs
zReportNewCertTest.tearDowncOsddlm}||i|��S)Nr)�_report_new_cert)rkr�)�clsrlr�r�r#r#r$rnlszReportNewCertTest._callcOsddlm}||i|��S)Nr)�_csr_report_new_cert)rkr�)r�rlr�r�r#r#r$�	_call_csrqszReportNewCertTest._call_csrcCs(|�tjdd�ddd�|j�d�dS�NT�rnr�rnrrr*r)rsr#r#r$�test_report_dry_runvsz%ReportNewCertTest.test_report_dry_runcCs(|�tjdd�ddd�|j�d�dSr��r�rrr*r)rsr#r#r$�test_csr_report_dry_runzsz)ReportNewCertTest.test_csr_report_dry_runcCs�t�t��(|�tjdd�ddd�Wd�n1s80Yt�t��(|�tjdd�ddd�Wd�n1sz0YdS)NFr�)r;r<rrnrrr�rsr#r#r$�test_report_no_paths~s6z&ReportNewCertTest.test_report_no_pathscCs(|�tjdd�ddd�|j�d�dS)NFr��/path/to/cert.pem�/path/to/fullchain.pem�/path/to/privkey.pemaA
Successfully received certificate.
Certificate is saved at: /path/to/fullchain.pem
Key is saved at:         /path/to/privkey.pem
This certificate expires on 1970-01-01.
These files will be updated when the certificate renews.
Certbot has set up a scheduled task to automatically renew this certificate in the background.r�rsr#r#r$�test_report�s��zReportNewCertTest.test_reportcCs(|�tjdd�ddd�|j�d�dS)NFr�r�r�a
Successfully received certificate.
Certificate is saved at: /path/to/fullchain.pem
This certificate expires on 1970-01-01.
These files will be updated when the certificate renews.
Certbot has set up a scheduled task to automatically renew this certificate in the background.r�rsr#r#r$�test_report_no_key�s��z$ReportNewCertTest.test_report_no_keycCs*|�tjddd�ddd�|j�d�dS)NF)rn�preconfigured_renewalr�r�r���
Successfully received certificate.
Certificate is saved at: /path/to/fullchain.pem
Key is saved at:         /path/to/privkey.pem
This certificate expires on 1970-01-01.
These files will be updated when the certificate renews.r�rsr#r#r$�$test_report_no_preconfigured_renewal�s��z6ReportNewCertTest.test_report_no_preconfigured_renewalcCs(|�tjdd�ddd�|j�d�dS)NFr�r�z/path/to/chain.pemr�z�
Successfully received certificate.
Certificate is saved at:            /path/to/cert.pem
Intermediate CA chain is saved at:  /path/to/chain.pem
Full certificate chain is saved at: /path/to/fullchain.pem
This certificate expires on 1970-01-01.r�rsr#r#r$�test_csr_report�s��z!ReportNewCertTest.test_csr_reportcCs,|�tjdddd�ddd�|j�d�dS)	zBShouldn't get a message about autorenewal if no --manual-auth-hookFrN)rnr�manual_auth_hookr�r�r�r�r�rsr#r#r$�test_manual_no_hooks_report�s��z-ReportNewCertTest.test_manual_no_hooks_reportN)r@rArBrCrVr��classmethodrnr�r�r�r�r�r�r�r�r�r#r#r#r$r�[s


r�c@sZeZdZdZdd�Zdd�Zedd��Zed�d	d
�Z	dd�Z
d
d�Zdd�Zdd�Z
dS)�ReportNextStepsTestz3Tests for certbot._internal.main._report_next_stepscCsLtjdddddd�|_t�d�}|��|_|�|j�tj	|_
t��t_	dS)Nr�Tr)Z	cert_namer�r�rr�r()
rr)r=rDrXr*rarbrRrw�
old_stdoutrr�)rr�r#r#r$rV�s�

zReportNextStepsTest.setUpcCs|jt_dSr�)r�rRrwrsr#r#r$r��szReportNextStepsTest.tearDowncOsddlm}||i|��dS)Nr)�_report_next_steps)rkr�)r�rlr�r�r#r#r$rn�szReportNextStepsTest._call)�returncCs|jjdddS)NrMr)r*�call_args_listrsr#r#r$�_output�szReportNextStepsTest._outputcCs.d|j_d|j_|�|jdd�|j��dS)zNo steps for a normal renewalrz	/bin/trueN)r=rr�rnr*r9rsr#r#r$r��szReportNextStepsTest.test_reportcCsd|j_|�|jdd�dS)z--csr requires manual renewalzfoo.csrN)r=r�rnrsr#r#r$r��sz#ReportNextStepsTest.test_csr_reportcCsd|j_|�|jdd�dS)z/--manual without a hook requires manual renewalrN)r=rrnrsr#r#r$�test_manual_no_hook_renewal�sz/ReportNextStepsTest.test_manual_no_hook_renewalcCsd|j_|�|jdd�dS)z2No --preconfigured-renewal needs manual cron setupFN)r=r�rnrsr#r#r$�test_no_preconfigured_renewal�sz1ReportNextStepsTest.test_no_preconfigured_renewalN)r@rArBrCrVr�r�rn�strr�r�r�r�r�r#r#r#r$r��s

r�csjeZdZdZ�fdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
e�d�dd��Z
dd�Z�ZS)�UpdateAccountTestz/Tests for certbot._internal.main.update_accountcstt�d�t�d�t�d�t�d�t�d�t�d�t��d���fdd	��D�|_���D]}|�|j�qXt��	�S)
Nrhr~rXr�r(z*certbot._internal.eff.prepare_subscription)r�atexitr[�determine_account�notify�prepare_subr
csi|]}|�|���qSr#r��r�r��rcr#r$r�	r4z+UpdateAccountTest.setUp.<locals>.<dictcomp>�
rrDr�r�r�rrarbrUrVr	rdr�r$rV	s�	zUpdateAccountTest.setUpc	Cs�t�d��|t�d��Rd|jjd|jjd|jjdg|}t�|dd��Wd�Wd�S1sn0YWd�n1s�0YdS�Nrzr}r
rfrgrh�rrDr=r�rkrjrrr#r#r$rn	s�
��zUpdateAccountTest._callcCsXt��}t��}t��}|g|j_||jdj_|j|j_|t��f|jd_|||fS)Nrr�)rr)rirr�rj�bodyr��rrJZmock_account�	mock_regrr#r#r$�_prepare_mock_account	s

z'UpdateAccountTest._prepare_mock_accountcCsJ|��\}}}|�|�}|jjjdd�|jd�d�|jd��dS)z9Utility to assert that email removal is handled correctlyr#��contactr�zFAny contact information associated with this account has been removed.r�N)r�rnr��updater)r�r9)rrlr�rJr��resultr#r#r$�_test_update_no_contact#	s

�z)UpdateAccountTest._test_update_no_contactcCs"t��}g|j_||jdj_dS�z2Test that no existing account is handled correctlyrN�rr)rirr�rj�rrJr#r#r$�test_no_existing_accounts5	sz+UpdateAccountTest.test_no_existing_accountscCs|�ddg�dS)zBTest that --register-unsafely-without-email is handled as no email�update_accountz!--register-unsafely-without-emailN�r�rsr#r#r$� test_update_account_remove_email>	sz2UpdateAccountTest.test_update_account_remove_emailcCs|�gd��dS)z9Test that providing an empty email is handled as no email)r�r�r4Nr�rsr#r#r$�test_update_account_empty_emailB	sz1UpdateAccountTest.test_update_account_empty_emailz,certbot._internal.main.display_ops.get_emailcCsJd|_|��\}}}t��}||jdj_|�dg�}|jd�d�dS)z=Test that updating with a singular email is handled correctlyzuser@example.comr[r�r�z4Your e-mail address was updated to user@example.com.N)rr�rr)r�rvrnr))rZ
mock_emailr�rJrGr�r#r#r$�test_update_account_with_emailF	s

�z0UpdateAccountTest.test_update_account_with_emailcCs6|��\}}}|jjjddgd�|jd�d�dS)z8Test that multiple email addresses are handled correctlyzmailto:user@example.comzmailto:user@example.orgr�r�zEYour e-mail address was updated to user@example.com,user@example.org.N)r�r�r�r)r�)rr�rJr�r#r#r$�(test_update_account_with_multiple_emails[	s�
�z:UpdateAccountTest.test_update_account_with_multiple_emails)r@rArBrCrVrnr�r�r�r�r�rrDr�r�r�r#r#rdr$r��s
	
r�cs`eZdZdZ�fdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Z�Z
S)�ShowAccountTestz-Tests for certbot._internal.main.show_accountcslt�d�t�d�t�d�t�d�t�d�t��d���fdd��D�|_���D]}|�|j�qPt��	�S)	Nrhr~rXr�r()rr�r[r�r�r
csi|]}|�|���qSr#r�r�r�r#r$r�s	r4z)ShowAccountTest.setUp.<locals>.<dictcomp>r�r	rdr�r$rVj	s�zShowAccountTest.setUpc	Cs�t�d��|t�d��Rd|jjd|jjd|jjdg|}t�|dd��Wd�Wd�S1sn0YWd�n1s�0YdSr�r�rr#r#r$rny	s�
��zShowAccountTest._callcCs\t��}t��}t��}|g|j_||jdj_|j|j_d|jj	_|t��f|jd_dS)Nrs	foobarbazr�)
rr)rirr�rjr�r�r�Z
thumbprintr�r#r#r$r��	s


z%ShowAccountTest._prepare_mock_accountcCsR|��t��}t��}||j_d|_||jj_||j	dj
_dg}|�|�dS)Nz+https://www.letsencrypt-demo.org/acme/reg/1r[�show_account)r�rr)r�r�Zurir�Zquery_registrationrr�rvrn)rr�rGr�rlr#r#r$�_test_show_account�	s

z"ShowAccountTest._test_show_accountcCs"t��}g|j_||jdj_dSr�r�r�r#r#r$r��	sz)ShowAccountTest.test_no_existing_accountsc
Cs`|��t��}d|_||jdj_z|�dg�Wn&tj	yZ}zWYd}~n
d}~00dS)z;Test that issues with the ACME client are handled correctlyNr[r�)
r�rr)r�r�rvrrnrr)rrGr�r#r#r$�test_no_existing_client�	sz'ShowAccountTest.test_no_existing_clientcCs&|�d�|jd�t�d�g�dS)Nr#r�z�Account details for server https://acme-v02.api.letsencrypt.org/directory:
  Account URL: https://www.letsencrypt-demo.org/acme/reg/1
  Account Thumbprint: Zm9vYmFyYmF6
  Email contact: none�r�r�Zassert_has_callsrr�rsr#r#r$�test_no_contacts�	s

�z ShowAccountTest.test_no_contactscCs*d}|�|�|jd�t�d�g�dS)N)�mailto:foo@example.comr�z�Account details for server https://acme-v02.api.letsencrypt.org/directory:
  Account URL: https://www.letsencrypt-demo.org/acme/reg/1
  Account Thumbprint: Zm9vYmFyYmF6
  Email contact: foo@example.comr��rr�r#r#r$�test_single_email�	s


�z!ShowAccountTest.test_single_emailcCs*d}|�|�|jd�t�d�g�dS)N)r�zmailto:bar@example.comr�z�Account details for server https://acme-v02.api.letsencrypt.org/directory:
  Account URL: https://www.letsencrypt-demo.org/acme/reg/1
  Account Thumbprint: Zm9vYmFyYmF6
  Email contacts: foo@example.com, bar@example.comr�r�r#r#r$�test_double_email�	s


�z!ShowAccountTest.test_double_email)r@rArBrCrVrnr�r�r�r�r�r�r�r�r#r#rdr$r�g	s
	
r�c@s`eZdZdZejZdZe�d�Ze	j
dd��Zej
dd��Ze	j
d��d	�d
d��Zdd
�ZdS)�
TestLockOrderzFTests that Certbot's directory locks were acquired in the right order.zExpected TestLockOrder errorz|1 renew failureccs4t�d��}|VWd�n1s&0YdS)Nzcertbot._internal.lock.lock_dir)rrD)r�
mock_lock_dirr#r#r$r��	szTestLockOrder.mock_lock_dirc	#s����fdd�}����fdd�}tj�tjd|��Htj�tjd|��dVWd�n1sd0YWd�n1s�0YdS)zJPatches plugin prepare to call mock_lock_dir and raise the expected error.cs������j��dSr���EXPECTED_ERROR_TYPE�EXPECTED_ERROR_STR�Zunused_self)�authenticator_dirr�rr#r$�authenticator_lock�	sz=TestLockOrder.mock_plugin_prepare.<locals>.authenticator_lockcs ����dkr���j��dS)Nr�r�r�)�
installer_dirr�r�
subcommandr#r$�installer_lock�	sz9TestLockOrder.mock_plugin_prepare.<locals>.installer_lockr�N)rrD�objectrZ
Authenticatorrrz)rr�r�r�r�r�r�r#)r�r�r�rr�r$�mock_plugin_prepare�	s
	z!TestLockOrder.mock_plugin_preparezcertonly install renew run)�paramsccs�t|d�}t|d�}t|d�}t|d�}t|d�}|j}	|	dddd	d
d|d|d
|g}
t�|d�|�||||	��@||||g}|	dkr�|
|fVn|
||gfVWd�n1s�0YdS)aRSets up Certbot with args and mocks to error after acquiring the last lock.

        This fixture yields the CLI arguments that should be given to Certbot
        and the expected order of directories to be locked. An error is raised
        after acquiring the last lock just as a means of stopping Certbot's
        execution.

        rr=rZlogsZworkr�rz-irz--no-random-sleep-on-renewr
rgrfrr�N)r�Zparamr�rr�)rr�ZrequestZtmp_pathr�r�r�rjrkr�rl�
lock_orderr#r#r$�args_and_lock_order�	s 
�z!TestLockOrder.args_and_lock_ordercCs^|\}}tj|j|jd��t�|�Wd�n1s:0Yt|j|�D]\}}qPdS)Nr5)r;r<r��EXPECTED_ERROR_STR_REGEXr�zipr�)rr�r�rlr�r�Z
locked_dirr#r#r$�test_lock_order
s
(zTestLockOrder.test_lock_orderN)r@rArBrCrrr�r�r�r;Zfixturer��
contextlib�contextmanagerr�rgr�r�r#r#r#r$r��	s



 r��__main__rM)UrCr�r��	importlibrrnrr�rKr�rRr�r�typingrZunittestrrZjosepyr�r;r�Z
acme.messagesrraZcertbotrrr	r
Zcertbot._internalrrr
rrZcertbot._internal.pluginsrrrrZcertbot.compatrrZcertbot.pluginsrZcertbot.tests.utilZtestsr�r�r�rdr�reZJWKRSA�loadZload_vectorr�r`r_ZTestCaserZConfigTestCaserEr�r�ZTempDirTestCaser�r�r,r?rerqr{r}r�r�r�r�r�r�r@�exit�argv�__file__r#r#r#r$�<module>s�





RXggk>
o4ihK

Back to Directory  nL+D550H?Mx ,D"v]qv;6*Zqn)ZP0!1 A "#a$2Qr D8 a Ri[f\mIykIw0cuFcRı?lO7к_f˓[C$殷WF<_W ԣsKcëIzyQy/_LKℂ;C",pFA:/]=H  ~,ls/9ć:[=/#f;)x{ٛEQ )~ =𘙲r*2~ a _V=' kumFD}KYYC)({ *g&f`툪ry`=^cJ.I](*`wq1dđ#̩͑0;H]u搂@:~וKL Nsh}OIR*8:2 !lDJVo(3=M(zȰ+i*NAr6KnSl)!JJӁ* %݉?|D}d5:eP0R;{$X'xF@.ÊB {,WJuQɲRI;9QE琯62fT.DUJ;*cP A\ILNj!J۱+O\͔]ޒS߼Jȧc%ANolՎprULZԛerE2=XDXgVQeӓk yP7U*omQIs,K`)6\G3t?pgjrmۛجwluGtfh9uyP0D;Uڽ"OXlif$)&|ML0Zrm1[HXPlPR0'G=i2N+0e2]]9VTPO׮7h(F*癈'=QVZDF,d߬~TX G[`le69CR(!S2!P <0x<!1AQ "Raq02Br#SCTb ?Ζ"]mH5WR7k.ۛ!}Q~+yԏz|@T20S~Kek *zFf^2X*(@8r?CIuI|֓>^ExLgNUY+{.RѪ τV׸YTD I62'8Y27'\TP.6d&˦@Vqi|8-OΕ]ʔ U=TL8=;6c| !qfF3aů&~$l}'NWUs$Uk^SV:U# 6w++s&r+nڐ{@29 gL u"TÙM=6(^"7r}=6YݾlCuhquympǦ GjhsǜNlɻ}o7#S6aw4!OSrD57%|?x>L |/nD6?/8w#[)L7+6〼T ATg!%5MmZ/c-{1_Je"|^$'O&ޱմTrb$w)R$& N1EtdU3Uȉ1pM"N*(DNyd96.(jQ)X 5cQɎMyW?Q*!R>6=7)Xj5`J]e8%t!+'!1Q5 !1 AQaqё#2"0BRb?Gt^## .llQT $v,,m㵜5ubV =sY+@d{N! dnO<.-B;_wJt6;QJd.Qc%p{ 1,sNDdFHI0ГoXшe黅XۢF:)[FGXƹ/w_cMeD,ʡcc.WDtA$j@:) -# u c1<@ۗ9F)KJ-hpP]_x[qBlbpʖw q"LFGdƶ*s+ډ_Zc"?%t[IP 6J]#=ɺVvvCGsGh1 >)6|ey?Lӣm,4GWUi`]uJVoVDG< SB6ϏQ@ TiUlyOU0kfV~~}SZ@*WUUi##; s/[=!7}"WN]'(L! ~y5g9T̅JkbM' +s:S +B)v@Mj e Cf jE 0Y\QnzG1д~Wo{T9?`Rmyhsy3!HAD]mc1~2LSu7xT;j$`}4->L#vzŏILS ֭T{rjGKC;bpU=-`BsK.SFw4Mq]ZdHS0)tLg