JFIF$        dd7 

Viewing File: /usr/lib/python3.9/site-packages/certbot/_internal/tests/__pycache__/main_test.cpython-39.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��|�}|d|fks0J�|js:J�dS)NF�	reinstall)r�Mock�ensure_deployed�return_valuer�_handle_identical_cert_request�called)�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_pending5s
z:TestHandleCerts.test_handle_identical_cert_request_pending�&certbot._internal.renewal.should_renewzcertbot.display.util.menucCsZd|_t��}d|j_d|_t�tjddd�|�}|js<J�|jrFJ�|d|fksVJ�dS)NTF�run)Zverbr�renew)rrrrrr�	MagicMockr)r r!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_changecCsPt��}d|_t��}ddg|j_t�|dg|�}|d|fksBJ�|jsLJ�dS)NTZdummy1Zdummy2r))rr�expand�namesrrZ_handle_subset_cert_requestr)r r!�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�||�|��|j|jksNJ�d|_d|_t�||�|j	dkstJ�|jdks�J�d|_d|_t�||�|jdks�J�d|_t�||�|jdks�J�d|_dd�|_
tjt
jdd	��t�||�Wd�n1�s0Yd
d�|_
t�||�|jdk�s<J�dS)NZrsa�ecdsaT�FcSs|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$r3r$r$r%r5�r6)rrZset_by_userr9�private_key_typerZ%_handle_unexpected_key_type_migration�assert_not_calledr�
call_count�side_effect�pytest�raisesrr)r Z
mock_yesno�configZmock_set�certr$r$r%�)test_handle_unexpected_key_type_migrationWs8
,
z9TestHandleCerts.test_handle_unexpected_key_type_migrationN)
�__name__�
__module__�__qualname__�__doc__r�patchr&r+r/rBr$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�r1������)�super�setUp�domainrrG�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 �patchesrG��	__class__r$r%rX�s.
�z
RunTest.setUpcCs@d�|j���}tj��}t�||�}ddlm	}|||�dS)Nz-a webroot -i null -d {0}r)r()
�formatrY�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)rrr[rr`rpr\�assert_called_once_withrYrb�ANY�r r$r$r%�test_newcert_success�s�zRunTest.test_newcert_successcCs8t��|j_dt��f|j_|��|j�|jg�dS�NF)	rrr[rr`rpr\rsrYrur$r$r%�test_reinstall_success�szRunTest.test_reinstall_successcCs8t��|j_dt��f|j_|��|j�|jg�dS)NT)	rrr[rr`rpr]rsrYrur$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@rrrjrk�	auto_hstsr>r?r�NotSupportedErrorrr(�r �mock_chooseror$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 errorrqTrr)rZPluginErrorr=rrr[rr`r>r?rprbrsrtr\r;)r Zmock_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�n1sV0YdSr{)rr|r@rrrjrkZmust_stapler>r?rr~rr(rr$r$r%�"test_run_must_staple_not_supported�s

z*RunTest.test_run_must_staple_not_supported)rCrDrErFrXrprvrxryrrGr�r�r��
__classcell__r$r$rfr%rH�s


rHc@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_patchrZ�mock_get_utilityrur$r$r%rX�s
zCertonlyTest.setUpcCs|j��dSr��r�rdrur$r$r%�tearDown�szCertonlyTest.tearDownc
Cs�tj��}t�||�}t�d��p}t�d��Ft�d��t�||�Wd�n1sZ0YWd�n1sx0YWd�n1s�0Y|�S)NrJrKrN)	rrjrkrrlrrGr�certonly)r rnror@r^r$r$r%rp�s
fzCertonlyTest._callrMrIrLcCs4|��j}|j|_t��|_d|_|�d���dS)N)FNz!certonly --webroot -d example.com)	r��notification�_assert_no_pauser=rrrrpri)r Z
unused_reportr[r`Zmock_notificationr$r$r%�test_no_reinstall_text_pause�s


z)CertonlyTest.test_no_reinstall_text_pausecOs|�d�dusJ�dS)N�pauseF)�get)r rn�kwargsr$r$r%r��szCertonlyTest._assert_no_pauserO�3certbot._internal.cert_manager.lineage_for_certname�3certbot._internal.cert_manager.domains_for_certnamez$certbot._internal.renewal.renew_certrcCs ddg}||_||j_|�d���|jdks2J�|jdks@J�|jdksNJ�|jdks\J�|jdksjJ�|jtjdtjdd�|�d���|jdks�J�|jdks�J�|jdks�J�|jdks�J�|jdks�J�d	|��j	_t
�tj
��|�d���Wd�n1�s0YdS)
N�example.comztest.orgzEcertonly --webroot -d example.com -d test.org --cert-name example.comrPTrr�Ecertonly --webroot -d example.com -d test.com --cert-name example.comr1F)rr-rprir<rsrrtr��yesnor>r?r�ConfigurationError)r r_Zmock_handle_type�mock_renew_cert�mock_domainsr"rb�domainsr$r$r%�*test_find_lineage_for_domains_and_certname�s*�z7CertonlyTest.test_find_lineage_for_domains_and_certname� certbot.display.ops.choose_namescCs^d|_|�d���|jdks"J�|jdks0J�dg|_d|_|�d���|jdusZJ�dS)Nr�rPZsomenamez*certonly --webroot --cert-name example.comT)rrprir<r)r r_r"�mock_choose_namesZmock_domains_for_certnameZunused_mock_report_next_stepsr$r$r%�*test_find_lineage_for_domains_new_certname#sz7CertonlyTest.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-runFrr)r�CSRrprirsrrtZ
reset_mock)r r"Zmock_csr_get_certZunused_mock_get_certrb�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)Nrqzcertonly --nginx -d example.com)rr*rrpri�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)Nrqz)certonly --nginx -d example.com --dry-run)rr*rrprir�r;r�r$r$r%�$test_dryrun_installer_doesnt_restartVs

z1CertonlyTest.test_dryrun_installer_doesnt_restartcCs2t��|_d|_|�dt���d�d���dS)Nrqzcertonly --webroot -w � z-i standalone -d example.com)rr*rrp�tempfile�
gettempdirri)r r�r`r�r�r$r$r%�test_invalid_installeres

�z#CertonlyTest.test_invalid_installerN)rCrDrErFrXr�rprrGr�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�cCs,tjddd�}d|_t�|d�dks(J�dS)N�r�r2�
domainname)r�N�rrrr�_find_domains_or_certname�r r�r.r$r$r%�test_display_opstsz*FindDomainsOrCertnameTest.test_display_opscCsPtjddd�}g|_t�tj��t�|d�Wd�n1sB0YdS)Nr�)	rrrr>r?rrrr�r�r$r$r%�test_no_results{sz)FindDomainsOrCertnameTest.test_no_resultsr�cCs8tjddd�}ddg|_t�|d�ddgdfks4J�dS)Nzone.comr�ztwo.comr�)r r�r.r$r$r%�test_grab_domains�s



�z+FindDomainsOrCertnameTest.test_grab_domainsN)	rCrDrErFrrGr�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_revocationrrPr1rQ)�Accountztest.certbot.orgi�rUrR��
)Ztzinfo)Z
creation_hostZcreation_dt) rWrX�shutil�copy�	CERT_PATH�tempdirr�path�abspath�join�
tmp_cert_pathrrGrZ�ClientV2�mock_acme_client�mock_determine_account�mock_success_revokercrdZcertbot._internal.accountr�r*�regrZMeta�datetime�pytzZUTC�meta�JWK�accr)r rerGr�rfr$r%rX�s0
�
��zRevokeTest.setUpNcCsH|sd}|�|j���}tj��}t�||�}ddlm	}|||�dS)Nzrevoke --cert-path={0} r)�revoke)
rhr�rirrjrkrrlrmr�)r rnror@r�r$r$r%rp�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
|��q||jks�J�dS)NFz#revoke --cert-path={0} --reason {1})rr�r�r
ZREVOCATION_REASONS�itemsrhr�rirp�appendr�callrt�upper�call_args_list)r r��mock_delete_if_appropriate�mock_revokeZexpected�reason�codernr$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_keycCs`|j|_tj|jdd�|_d��}d|_|�|�|jdddjdksNJ�|j	�
|j�dS)N�https://acme.example��	cert_path�server�revoke --cert-name=example.comFr)r�rrr*r�rirpr�r�r�rs�r Zmock_acme_from_configZ%unused_mock_renewal_file_for_certnameZ	mock_certr�rnr$r$r%�test_revoke_by_certname�s�
�z"RevokeTest.test_revoke_by_certnamecCsXtj|jdd�|_d��}d|_|�|�|jdddjdksFJ�|j�	|j�dS)z9Revoking with --server should use the server from the CLIr�r�z=revoke --cert-name=example.com --server https://other.exampleFrzhttps://other.exampleN)
rr*r�rrirpr�r�r�rsr�r$r$r%�"test_revoke_by_certname_and_server�s�
�z-RevokeTest.test_revoke_by_certname_and_servercCs^tj|jdd�|_d��}d|_|�|�|jdddjtj	dksLJ�|j
�|j�dS)zLRevoking with --cert-name where the lineage server is empty shouldn't crash Nr�r�Frr�)rr*r�rrirpr�r�r
ZCLI_DEFAULTSr�rsr�r$r$r%�$test_revoke_by_certname_empty_server�s
�z/RevokeTest.test_revoke_by_certname_empty_servercCs |��d|_|j�|j�dSrw)rprr�rsr�)r r�r$r$r%�test_revocation_success�sz"RevokeTest.test_revocation_successcCsZddlm}|��|j_t�|j��|��Wd�n1sB0Y|j�	�dS)Nrr)
�acmerZClientErrorr�r=r>r?rpr�r;)r Zacme_errorsr$r$r%�test_revocation_errors
&z RevokeTest.test_revocation_error�%certbot._internal.cert_manager.deletecCs*d|�j_d|_|��|jdus&J�dSrw)r�rrpr)r r��mock_deleter�r$r$r%�test_revocation_with_prompts
z&RevokeTest.test_revocation_with_prompt)N)rCrDrErFrXrprrGr�r�r�r�r�r�r�r�r�r�r$r$rfr%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_initrIrJz"certbot._internal.hooks.list_hooks)Zcheck_symlinks�
cert_names�pick_installer�	pick_auth�	find_init�_get_and_save_cert�_init_le_clientZ
list_hookscSsi|]\}}||���qSr$�rZ��.0�k�vr$r$r%�
<dictcomp>#r6z)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)rWrXr�r�r�rZr�rrG�patchersr��mocksrrr�r�r��
config_dir�existsr�makedirs�renewal_file�open�write�	configobj�	ConfigObj�original_config)r Zrenewal_configs_dirr
�frfr$r%rXs4

�

*�zReconfigureTest.setUpcs0t���|j��|j��D]}|��qdSr�)rWr�r�rdr�values�r rGrfr$r%r�Bs

zReconfigureTest.tearDowncCsz|d|jg}tj��}t�||�}ddlm}|||�t|j	d�� }t
j|ddd�}Wd�n1sl0Y|S)N�--config-dirr)�reconfigurer�rr)rrrjrkrrlrmrr	rrr)r Zpassed_argsZ	full_argsror@rrZupdated_confr$r$r%rpHs

.zReconfigureTest._callcCs>t�tj��|�d���Wd�n1s00YdS)Nz!--cert-name cert1 -d one.cert.com)r>r?rr�rprirur$r$r%�test_domains_setUsz ReconfigureTest.test_domains_set�,certbot._internal.cert_manager.get_certnamescCsZt��}d|_||jd_||jd_||jd_dg|_|�d���|jdksVJ�dS)N�nginxr�r�r�r��--nginxrP)rr�namerrrprir<)r �mock_cert_manager�
named_mockr$r$r%�test_asks_for_certnameYsz&ReconfigureTest.test_asks_for_certnamecCsXt��}d|_||jd_||jd_||jd_|�d���}|dddksTJ�dS)N�apacher�r�r�� --cert-name example.com --apache�
renewalparams�
authenticator)rrrrrrpri�r r�
new_configr$r$r%�test_update_configuratoresz(ReconfigureTest.test_update_configuratorcCs�t��}d|_||jd_||jd_||jd_|�d���}d|dd<d|dd	<|dd
=|jd|d<||jks~J�dS)
zI Check that we don't accidentally modify anything that we didn't mean to rr�r�r�rrrr�	installerr�versionN)rrrrrrprir
rr$r$r%�test_only_intended_changesps
z*ReconfigureTest.test_only_intended_changesz&certbot._internal.hooks.validate_hookscCsf|jdddksJ�|�d��dg�d|jdjjdjvsFJ�d|jd	jjd
jvsbJ�dS)z6 Check that we use the staging server for the dry run rr�z.https://acme-v02.api.letsencrypt.org/directory�"--cert-name example.com --pre-hook�echo preZstagingr�rr�rPN)r
rprir�	call_argsrnr�)r �unused_validate_hooksr$r$r%�test_staging_used�s�z!ReconfigureTest.test_staging_usedc
Cs�|jdd}|jdd}z|�d���Wn6tjyd}zdt|�vsPJ�WYd}~n
d}~00t|jd�� }tj	|ddd	�}Wd�n1s�0Y|dd|ks�J�|�d
|�����}|dd|ks�J�z|�d���Wn:tj�y*}zdt|�v�sJ�WYd}~n
d}~00t|jd�� }tj	|ddd	�}Wd�n1�s`0Y|dd|k�s�J�|�d|�����}|dd|k�s�J�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 newaccountidz,Using reconfigure to change the ACME accountNr�rrz"--cert-name example.com --account z&--cert-name example.com --server x.comz!--cert-name example.com --server )
r
rprirr��strr	rrr)r Zorig_account_idZorig_server�errrr r$r$r%�!test_new_account_or_server_errors�s(&.(0z1ReconfigureTest.test_new_account_or_server_errorscCs�d|jvsJ�|�d��dg�}|dddks6J�|�d��dg�}|dddks^J�d|jvslJ�|�d��dg�}|dddks�J�dS)	NZpre_hookr%r&rz	echo pre2Z
renew_hookz%--cert-name example.com --deploy-hookzecho deploy)r
rpri)r r(r r$r$r%�test_update_hooks�sz!ReconfigureTest.test_update_hookscCs�tj|jd_z|�d���Wntjy4Yn0t|jd�� }tj	|ddd�}Wd�n1sh0Y|dddks�J�dS)	Nr�rr�rrrrr)
rrrr=rprir	rrr)r rr r$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
ddks�J�|�
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�rrrr�r�z--cert-name example.com --nginxrrzT
Successfully updated configuration.
Changes will apply when the certificate renews.)r	rr
rrr
rrrrrrpri�assert_called_with)r �mock_notifyr
rrr r$r$r%�test_report_results�s (�&�z#ReconfigureTest.test_report_results)rCrDrErFrXr�rprrrGrr!r$r)r,r-r.r2r�r$r$rfr%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)rmr4)r r.r4r$r$r%rp�szDeleteIfAppropriateTest._callcCsBt�d��}|�|j�Wd�n1s,0Y|��dS)Nr�)rrGrpr@r;)r r�r$r$r%�_test_delete_opt_out_common�s*z3DeleteIfAppropriateTest._test_delete_opt_out_commoncCsd|j_|��dSrw)r@�delete_after_revoker5)r Zunused_mock_get_utilityr$r$r%�test_delete_flag_opt_outsz0DeleteIfAppropriateTest.test_delete_flag_opt_outcCs|�}d|j_|��dSrw)r�rr5)r r��	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	CsF|j}d|_d|_d|_t��|_|�|�|��|j	dksBJ�dS)N�/some/reasonable/path�r�rP)
r@r�r2rrZOverlappingMatchFoundr=rpr;r<)	r r��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|_|�|�|jdks6J�dS)Nr:r;r�FrP)r@r�r2rrpr<)r r�r<r�r=Zmock_overlapping_archive_dirsr?r@r$r$r%�test_cert_path_only$s

z+DeleteIfAppropriateTest.test_cert_path_onlycCsF|j}d|_d|_d|_d|_d|_d|_|�|�|jdksBJ�dS�NTr:r;r�rP)r@Znoninteractive_moder�r2rrpr<�r r�r�r<Zmock_full_archive_dirr>r?r@r$r$r%�test_noninteractive_deletion6s

z4DeleteIfAppropriateTest.test_noninteractive_deletioncCsT|j}d|_d|_d|_d|_d|_d|_|�|�|jdksBJ�|�jjrPJ�dSrB)	r@r6r�r2rrpr<r�rrCr$r$r%�test_opt_in_deletionJs	
z,DeleteIfAppropriateTest.test_opt_in_deletionN)rCrDrErFrpr5r�r�r7r9rrGr@rArDrEr$r$r$r%r3�sH

r3cs�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)rWrXr@r�emailZregister_unsafely_without_emailrr*�accsZAccountMemoryStorage�account_storage�mock_client�	directoryZ	new_authzrurfr$r%rXbs


zDetermineAccountTest.setUpc	Cs�ddlm}t�d��X}t���0|j|_||j�Wd�Wd�S1sV0YWd�n1st0YdS)Nr)�_determine_accountz1certbot._internal.main.account.AccountFileStorage)	rmrPrrGr�r�rMrr@)r rP�mock_storager$r$r%rpns�zDetermineAccountTest._callz!certbot._internal.client.registerz.certbot._internal.client.display_ops.get_emailc
CsZd|_||_z|��Wn<tjyT}z"d|��t|�ks@J�WYd}~n
d}~00dS)N�foo@bar.bazz0Unable to register an account with ACME server. )rr=rprrr*)r �err_msg�	exception�mock_get_email�
mock_registerr+r$r$r%�_register_error_commonvs�z+DetermineAccountTest._register_error_commoncCsl|j�|jd|j�|jdj|j_|jddf|��ks@J�|jdj|jjksXJ�|jjdushJ�dS)NrP)	rM�saverLrNrHr@rrprKrur$r$r%�test_args_account_set�s
z*DetermineAccountTest.test_args_account_setcCs\|j�|jd|j�|jddf|��ks0J�|jdj|jjksHJ�|jjdusXJ�dS)Nr)	rMrXrLrNrprHr@rrKrur$r$r%�test_single_account�sz(DetermineAccountTest.test_single_accountz3certbot._internal.client.display_ops.choose_accountcCs�|jD]}|j�||j�q|jd|_|jddf|��ksBJ�t|jdd�t|j�ksbJ�|jdj|j	j
kszJ�|j	jdus�J�dS)NrPr)rLrMrXrNrrp�setr'rHr@rrK)r �mock_choose_accountsr�r$r$r%�test_multiple_accounts�s
 z+DetermineAccountTest.test_multiple_accountsc
Csj|jD]}|j�||j�qd|_z|��Wn6tjyd}zdt|�vsPJ�WYd}~n
d}~00dS)NzNo account has been chosen)	rLrMrXrNrrprrr*)r r\r�r+r$r$r%�test_multiple_accounts_canceled�s
z4DetermineAccountTest.test_multiple_accounts_canceledr/cCs�d|_t�d��D}|jdtjjf|j_|jdtjjf|��ksFJ�Wd�n1sZ0Y|jj|j	|j
tjd�|jdj|j	j
ks�J�d|j	jks�J�|�d�dS)NrR�certbot._internal.main.clientr)Ztos_cbzAccount registered.)rrrGrL�sentinelr��registerrprsr@rMrtrHrrK)r r1rU�clientr$r$r%�test_no_accounts_no_email�s�<�z.DetermineAccountTest.test_no_accounts_no_emailcCs|d|j_t�d��.}|jdtjjf|j_|�	�Wd�n1sF0Y|jdj
|jjkshJ�d|jjksxJ�dS)Nzother emailr_rP)r@rKrrGrLr`r�rarrprHr)r rbr$r$r%�test_no_accounts_email�s&z+DetermineAccountTest.test_no_accounts_emailcCsd}|�|t�|��dS)Nz$Some error message raised by Certbot)rWrr)r rSr$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_errorrW�r rSrTr$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)rfrgrir$r$r%�"test_register_error_acme_type_only�s
z7DetermineAccountTest.test_register_error_acme_type_only)rCrDrErFrXrprrGrWrYrZr]r^rcrdrerjrkr�r$r$rfr%rF_s&	
	
	rFcs�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)
rWrXr�mkdirr@�logs_dirr�work_dir�
standard_argsrrGrZ�
mock_sleeprurfr$r%rX�s

�zMainTest.setUpcstt�t���dSr�)�
reload_modulerrWr�rurfr$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()rA�chain�privkeyT)�endswith)�fnrnr��Z	orig_openr$r%�mock_isfile�s
��z#MainTest._call.<locals>.mock_isfilezcertbot.compat.os.path.isfiler_N)rr��isfilerrGr=�_call_no_clientmock)	r rn�stdout�
mockisfiler{Zmock_ifrbr#�stderrr$rzr%rp�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)rs�io�StringIOrrGr)r rnr~Z
toy_stdoutr�r#r$r$r%r}�s
lzMainTest._call_no_clientmockcCsFt�d��(}|�g�d|jks$J�Wd�n1s80YdS)Nzcertbot._internal.main.runrP)rrGrpr<)r �mock_runr$r$r%�
test_no_flagss
zMainTest.test_no_flagscCs�t��}t��}tjd|d���tjd|d���zNzt�dg�WntyTYn0W|��pf|��}d|vs�Jd�|���n(|��p�|��}d|vs�Jd�|���0Wd�n1s�0YWd�n1s�0YdS)Nr�r�r�z	--version�certbotz
Output is {0})r�r�rrGr�
SystemExit�getvaluerh)r Ztoy_outZtoy_err�outputr$r$r%� test_version_string_program_names�z)MainTest.test_version_string_program_namec
Cs�d}zFt�d��(t�|j|dd��Wd�n1s>0YWn:tjy�}z |}|t|�vspJ�WYd}~n
d}~00|dus�J�dS)zQEnsure that a particular error raises a missing cli flag error containing messageNr�)rrGrrsrZMissingCommandlineFlagr*)r rn�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 �_rnr$r$r%�test_noninteractiveszMainTest.test_noninteractiverNrLr�zBcertbot._internal.main.client.Client.obtain_and_enroll_certificaterIcCsgd�|j}t��df|_t��|_t�d��n}|j}	|�|�t��}
|	j	dd}|
|vsdJ�ddl
}|�
�}
d|
��vr�t��|vs�J�Wd�n1s�0Yt�d��J}|j}	d}|d|g7}|�|�|	jtj
tj
d	|tjd
�Wd�n1�s
0YdS)N)r�r��-mz
none@none.comr�r�z--agree-tosr�rP�
user_agentrZlinuxZbandersnatchz--user-agentT)rZ
verify_sslr�Zalg)rsrr*rrG�
ClientNetworkr}r
Zget_os_info_uar'�platform�lowerrsrt�joseZRS256)r ZgscZ_obtZdetr��__�___rnZacme_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�|jdks J�dS)N)	�installz	--domains�foo.bar�--cert-pathrA�
--key-pathrw�--chain-pathrvT�rrP)rpr<)r Zmock_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��r}||_|jgd�dd�|jd	d	}|jt�d�kspJ�|j	t�d�ks�J�|j
t�d�ks�J�Wd�n1s�0YdS)
NrArvrw�r��
chain_path�fullchain_path�key_pathr�)r��--cert-name�whateverTr�r)rr*r��	temp_joinrGrrpr'r�r�r�)r �_instr��mock_installr"�mock_getlin�call_configr$r$r%�test_installer_certnameMs�z MainTest.test_installer_certnamec	CsTtjt�d�t�d�t�d�t�d�d�}t�d���}||_|jdddd	t�d
�gdd�|jd
d
}|jt�d�ks~J�|j	t�d�ks�J�|j
t�d�ks�J�|jt�d
�ks�J�|��|jddddt�d�gdd�|jd
d
}|jt�d�k�sJ�|j	t�d�k�sJ�|jt�d�k�s0J�Wd�n1�sF0YdS)NrArvrwr�r�r�r�r�r�Zoverriding_privkeyTr�rr�Zoverriding_cert)
rr*r�r�rGrrpr'r�r�r�r��reset)r r�r�r�r�r"r�r�r$r$r%�test_installer_param_override^s6�

��

��z&MainTest.test_installer_param_overridecCs>t�tj��|�gd��Wd�n1s00YdS)N)r�r�Znotfoundr�Zinvalid�r>r?rr�rp)r r�r�r$r$r%�test_installer_param_errorzsz#MainTest.test_installer_param_errorrcCs�tjt�d�t�d�t�d�t�d�d�}t�d��&}||_|jdgdd�Wd�n1s`0Y|jstJ�|js~J�dS)	NrArvrwr�r�r�Tr�)rr*r�r�rGrrpr)r �	mock_instZmock_getcertr�r�r"r�r$r$r%�test_installer_select_cert�s�.
z#MainTest.test_installer_select_certzcertbot.util.exe_existscCsZd|_tj��}gd�}dddt�d�dt�d�dd	d
ddg}d
|vrp|�|�\}}}}d|vsdJ�d|vspJ�|�dgd�t�	d��r}t�	d��H}	t�
�|	_|�gd��|jd\}
}}t|t
j�s�J�Wd�n1s�0YWd�n1�s0Yt�	d��.}
|�ddg�d|
jk�s6J�Wd�n1�sL0YdS)NT)z--apachez--authenticatorrr�rr�Zblahr�z--nginx-server-rootz/nonexistent/thingr�r��--debugrzThe nginx plugin is not working�MisconfigurationErrorr�z(With the standalone plugin, you probablyrJrI)r�z--manualr�r�r�certbot._internal.main.certonly�authrP)rrrjrkr�r�rpr�rrGr*r'�
isinstancer�
Authenticatorr<)r Zmock_exe_existsr�r�r�Zreal_pluginsrnr#r^Zmock_gscZ
unused_configr�Zunused_installer�
mock_certonlyr$r$r%�test_configurator_selection�s,

�
Nz$MainTest.test_configurator_selectioncCsV|�dg�\}}}}d|jjks$J�|�gd��\}}}}|j�tjdtjtj�dS)N�rollbackrP)r�z
--checkpointsZ123�{)rpr�r<rsrrt)r r�rbr$r$r%�
test_rollback�s�zMainTest.test_rollbackz+certbot._internal.cert_manager.certificatescCs|�dg�d|jksJ�dS)NZcertificatesrP�r}r<�r rr$r$r%�test_certificates�szMainTest.test_certificatesr�cCs|�dg�d|jksJ�dS)N�deleterPr�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>ro)r�rv�range�lenrp�list)r r��_det�
mock_discornr$r�r%�test_plugins�s

��zMainTest.test_pluginscCs�g}|j��}t��}tj|d��&|�dg|�\}}}}Wd�n1sN0Y|j��|��j	�|�|���	�}|�
���t|�ks�J�dS)N�r~ro)
rjrkr�r�r��patch_display_util_with_stdoutrp�visiblers�ifacesr��stripr*�r r�r�r�ror~r��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�|�|�
���}	|�
���t|	�ks�J�dS)NcSs|||}}}t���dS)zRaises error.Error.N)rr)rO�mode�strictr�r$r$r%�throw_error�sz?MainTest.test_plugins_no_args_unprivileged.<locals>.throw_errorzcertbot.util.set_up_core_dirr�ro)rjrkr�r�rrGr�r�r=rpr�rsr�r�r�r*)
r r�r�r�ror�r~Zmock_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	�|�|���	�}|j
jdks�J�|���
�t|�ks�J�dS)Nr�ror�rP)rjrkr�r�r�r�rpr�rsr��initr<r�r�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
jdks�J�|j��|j
��|�
�}|����t|�ks�J�dS)Nr�)ror�r�rP)rjrkr�r�r�r�rpr�rsr�r�r<�prepare�	availabler�r�r*)	r r�r�r�ror~r�r�r�r$r$r%�test_plugins_prepares
6


zMainTest.test_plugins_preparecCs�d}d}d}d}t�d��,}|�dd|ddd	dd
dg	�Wd�n1sL0Y|jd\}}|jtj�|�kszJ�|jtj�|�ks�J�|j	tj�|�ks�J�|j
tj�|�ks�J�dS)NrA�keyrv�	fullchainr�r�r�r�r�z--fullchain-pathr)rrGrpr'r�rr�r�r�r�r�)r rAr�rvr�r�r@�unused_pluginsr$r$r%�test_certonly_abspaths�$zMainTest.test_certonly_abspathc
CsXz|�gd��t�d�Wn6tjyR}zdt|�vs>J�WYd}~n
d}~00dS)N)�-aZbad_authr�z!Exception should have been raisedz-The requested bad_auth plugin does not appear)rpr>�failr�PluginSelectionErrorr*�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�rur$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?rrrprhr�rirur$r$r%�test_csr_with_besteffortDsz!MainTest.test_csr_with_besteffortc
CsZz|�dtg�Wn8tjyJ}zdt|�vs4J�WYd}~dSd}~00t�d�dS)Nz--csrzPlease try the certonlyz2Expected supplying --csr to fail with default verb)rpr�rr�reprr>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?rrrprhr��vector_pathrirur$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�rur$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)ZnewcertNrJz!-d foo.bar -a standalone certonly)rrGrrirp)r rNrn�mock_renewalr^r$r$r%�_certonly_new_request_commonZs
z%MainTest._certonly_new_request_commoncCsXt��}d|j_|�|dg�|jjdks.J�|jdks<J�|jddjdusTJ�dS�N�	--dry-runrPrT)rr*�obtain_and_enroll_certificaterr�r<r'�dry_run)r �mock_reportrNr$r$r%�)test_certonly_dry_run_new_request_successesz2MainTest.test_certonly_dry_run_new_request_successz+certbot._internal.main.util.atexit_registerzcertbot.crypto_util.notAfterc
Cs�tj�tj�|jjd��}tj�tj�|jjd��}d}||�j_tj	||||d�}t�	�}	||	j
_|�|	�|	j
jdks~J�|jdks�J�||j
ddvs�J�||j
ddvs�J�d	|j
ddvs�J�|jd
us�J�dS)Nzlive/foo.barzlive/baz.quxz
1970-01-01)rAr�r�r�rPrr1rQ�donateT)rr��normpathr�r@r�daterrr*rr�r<r'r)
r Z
mock_notAfterrarVrr�r�rr"rNr$r$r%�!test_certonly_new_request_successns 
�
z*MainTest.test_certonly_new_request_successcCsXt��}d|j_t�tj��|�|�Wd�n1s<0Y|j	dusTJ�dSrw)
rr*rrr>r?rrr�r)r rarNr$r$r%�!test_certonly_new_request_failure�s
(z*MainTest.test_certonly_new_request_failureTcsZt�d�}tj�tj�|jjd��}tj	||||d�}
||
j
_d|
j_dg|
j
_d|
_d|
_|	|
_t�	�}tj	dd	�}t�	�}t���|d
|df|j_�fdd
�}�zX�z�t�d���f}|
df|_t�d���.}||_t�d���}|s�||�j_t�d���}||j_t�d���|�sgd�}|�r,||7}z>|�|��\}�}}|�rZtd|�t|��|�rhJd��Wn"|�s�tdt����Yn0Wd�n1�s�0YWd�n1�s�0YWd�n1�s�0YWd�n1�s0YWd�n1�s$0Y|�r~|	�rj|
�sj|j�tjgtj�tj�|jjd���n|j�tjgd�n|jjdk�s�J�Wn|� ��Yn0W|�rPt!tj�|jj"d���"}||�#�v�s�J�Wd�n1�s�0YnR|�rNt!tj�|jj"d���"}||�#�v�s.J�Wd�n1�sD0Y0|
|�fS)Nrzlive/foo.bar/fullchain.pem)rAr�r�r�F�	isnot.orgr0Z	secp256r1Zpem_key)Zpemrv�csrcs��|�dS)zWrite message to stdout.N)r
)r�rnr�r�r$r%�	write_msg�sz0MainTest._test_renewal_common.<locals>.write_msgz5certbot._internal.cert_manager.find_duplicative_certsrJz)certbot._internal.display.obj.get_displayz*certbot._internal.main.renewal.crypto_utilrN)r�r
r�rr�ZReturnedzrenewal should have erroredzUnexpected renewal error:
zlive/sample-renewal/privkey.pemr�letsencrypt.log)$r�r�rr�rr�r@rrr*Zshould_autorenewrZhas_pending_deploymentr-r:Zelliptic_curve�	reuse_keyr�r��obtain_certificaterGr�r=ZnotAfterrp�print�AssertionError�	traceback�
format_excrsrtr<�	_dump_logr	rq�read)r �due_for_renewal�
extra_args�log_outrn�should_renew�error_expected�
quiet_mode�expiry_dater�new_keyr�r�r"Z
mock_certrZmock_keyrNrZmock_fdcr^Zmock_displayZmock_crypto_utilr#r��lfr$r�r%�_test_renewal_common�s�
��
�



�����
4�4zMainTest._test_renewal_commoncCsp|�dg�\}}}|jjdks"J�|j�|���|jdks@J�d|jddvsVJ�d|jddvslJ�dS)NTrP�
fullchain.pemrr1r)rZsave_successorr<Zupdate_all_links_torsZlatest_common_versionr')r r�rVrZlineager$r$r%�test_certonly_renewal�s�zMainTest.test_certonly_renewalr/zEcertbot._internal.log.logging.handlers.RotatingFileHandler.doRollovercCsp|jdddgdd�\}}}|�d�|jdgd�dd�|jdgd	�dd
�\}}}d|�jjddvslJ�dS)
NFr�--keepzsimulating renewal)r�The dry run was successful.)z--renew-by-default�-tvvr�zAuto-renewal forced)r$r�r")rznot yet duer)r�assert_any_callr�r')r r�r�r1Zmock_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@rqrr	r)r Zlog_pathrr$r$r%r�s

zMainTest._dump_logcCs.t�|jjd�gd�}|jdg|dd�dS)N�sample-renewal.conf�r)rr$T�rnr�r��make_lineager@rr�r rnr$r$r%�test_renew_verb�szMainTest.test_renew_verbcCs4tj|jjddd�gd�}|jdg|ddd�dS)Nr'F�Zec)r)r�--reuse-keyT�rnrrr*r,r$r$r%�test_reuse_keyszMainTest.test_reuse_keyz6certbot._internal.storage.RenewableCert.save_successorcCs4tj|jjddd�ddg}|jdg|ddd�dS)Nr'Fr.r)r/Tr0r*�r Zunused_save_successorrnr$r$r%�test_reuse_key_no_dry_runsz"MainTest.test_reuse_key_no_dry_runcCs2t�|jjd�gd�}|jdg|dddd�dS)Nr')r)r/z	--new-keyT)rnrrrr*r2r$r$r%�test_new_keys
�zMainTest.test_new_keyz	sys.stdincCspd|j_t�|jjd�gd�}|jdg|dd�|jjdksBJ�|jj	dd}d|krfdkslnJ�dS)	NFr'r(Tr)rPri�)
�isattyrr�r+r@rrrtr<r')r �stdinrnZsleep_call_argr$r$r%�!test_noninteractive_renewal_delaysz*MainTest.test_noninteractive_renewal_delaycCsFd|j_t�|jjd�gd�}|jdg|dd�|jjdksBJ�dS)NTr'r(r)r)	r5rr�r+r@rrrtr<)r r6rnr$r$r%�!test_interactive_no_renewal_delays
z*MainTest.test_interactive_no_renewal_delayr'cCsld|_t�|jjd�tj��tjdd�}|jddddg|d�\}}}d|�	�vsXJ�d|�	�vshJ�dS)	NFr'�Z)Zdaysr))rrrnrzNo renewals were attempted.z7The following certificates are not due for renewal yet:)
rr�r+r@rr��nowZ	timedeltarr�)r rZexpiryr�r~r$r$r%�test_renew_skips_recent_certs&s
�z&MainTest.test_renew_skips_recent_certscCs~t�|jjd�ddg}|jdg|dd�\}}}|��}d|vsDJ�gd�}|jdg|ddd�\}}}|��}d|kszJ�dS)	Nr'r)rTr))r)rz-q)rnrrr;)r�r+r@rrr�)r r�rnr~�outr$r$r%�test_quiet_renew0s
�zMainTest.test_quiet_renewcCs0t�|jjd�gd�}|jdg|ddd�dS)Nr')r)r�--post-hook=no-such-commandTF�rnrrr*r,r$r$r%�test_renew_hook_validation>s
�z#MainTest.test_renew_hook_validationcCsZt�|jjd�gd�}t�d��$|jdg|ddd�Wd�n1sL0YdS)Nr')r)rr>z--disable-hook-validationz!certbot._internal.hooks.post_hookTFr?)r�r+r@rrrGrr,r$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�r(FTr?)
rr�r�r@rrrrr	r)r Zrdrnr$r$r%�test_renew_verb_empty_configLs
z%MainTest.test_renew_verb_empty_configcCs*t�|jjd�|jdgdgd�d�dS)Nr'T�r)rr�zsample-renewal)rrnr*rur$r$r%�test_renew_with_certnameUs
�z!MainTest.test_renew_with_certnamecCs|jdgdgd�dd�dS)NTFrC)rrnr)rrur$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@rrrr	r
)r Zrenewer_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�|j
s�J�n|j
d	us�J�Wd�n1s�0YdS)Nr�zsomepath/fullchain.pemr�!certbot._internal.main.renew_certrnr)TrF)TN)rFrrGr*r��
configurationr-r�
setdefaultrr)r rr-�assert_oc_calledr��mock_rcr"r�r$r$r%�_test_renew_commones 
2zMainTest._test_renew_commoncCs|jddd�dS)NFT�rJr�rLrur$r$r%�test_renew_no_renewalparamszsz$MainTest.test_renew_no_renewalparamscCs|jiddd�dS)NFT)rrJrrNrur$r$r%�test_renew_no_authenticator}s�z$MainTest.test_renew_no_authenticatorcCsddd�}|j|ddd�dS)N�webrootz	over 9000)rZrsa_key_sizeTF)rrrJrN�r rr$r$r%�test_renew_with_bad_int�s��z MainTest.test_renew_with_bad_intcCsddd�}|j|dd�dS)NrQ�None)rZhttp01_portT�rrJrNrRr$r$r%�test_renew_with_nonetype_http01�s��z(MainTest.test_renew_with_nonetype_http01cCs$ddi}dg}|j|d|dd�dS)NrrQu
uniçodé.comTF)rrr-rJrN)r rr-r$r$r%�test_renew_with_bad_domain�s
�z#MainTest.test_renew_with_bad_domainr�cCs2t��t��f|_ddi}|j|dd��d�dS)NrrQTzrenew --configurator apache�rrJrn)rr*rrLri)r r�rr$r$r%�test_renew_with_configurator�s�z%MainTest.test_renew_with_configuratorcCsdddd�}|j|dd�dS)NrQrTZ42)rZwebroot_pathZwebroot_imaginary_flagTrUrNrRr$r$r%�$test_renew_plugin_config_restoration�s��z-MainTest.test_renew_plugin_config_restorationc
Cs0ddi}|j|dddt�dt��i�gd�dS)NrrQTr)z
--webroot-mapr�rX)rL�json�dumpsr�r�rRr$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.reconstituteFTrM)rrG�	Exceptionr=rL)r Zmock_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.pemrrrQrGTr)F)rrnr)
rFrrGr*r�rrHr^r=r)r rKr"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})rrirhr�rur$r$r%�test_renew_with_bad_cli_args�s��z%MainTest.test_renew_with_bad_cli_argsc	Cs:|jdddddd�tj�gd�\}}}d|��vs6J�dS)NFr)z--post-hookz{0} -c "print('hello world');")rrrrnzNo hooks were run.)rrh�sys�
executabler�)r r�r~r$r$r%�test_no_renewal_with_hooks�s���z#MainTest.test_no_renewal_with_hooksr�rJcCshdt��f|_t��|_}|�gd��|jjdus:J�|jjdusJJ�|�jjdks\J�|�	�dS)Nr)r�r�r�rr�Fr)
rr*rrprrrZadd_messager<r;)r Zmock_report_new_certr^r�r�rNr$r$r%�test_certonly_reinstall�sz MainTest.test_certonly_reinstallc
	Cs2d}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�r|j
jd
u�s.J�n|j
�|||||�dS)N�certrrvzlive/example.com/cert_512.pemzlive/example.com/fullchain.pemrJzlive/example.com/chain.pemzV-a standalone certonly --csr {0} --cert-path {1} --chain-path {2} --fullchain-path {3}z"certbot._internal.main.crypto_utilrF)rr*Zobtain_certificate_from_csrrrr�rr�r@rZsave_certificaterGrhr�rirprrs)
r rrfrvrNr��	full_pathr^r�rnr$r$r%�_test_certonly_csr_common�s>����F

�z"MainTest._test_certonly_csr_commonz+certbot._internal.main._csr_report_new_certcCs�|��|jdksJ�d|jddvs,J�|jdddusBJ�d|jddvsXJ�d|jddvsnJ�|jdus|J�dS)	NrPrrr1r rQrT)rhr<r'r)r rarV�mock_csr_reportr$r$r%�test_certonly_csr�szMainTest.test_certonly_csrcCs6|�dg�|jdksJ�|jddjdus2J�dSr�)rhr<r'r)r rir$r$r%�test_certonly_csr_dry_runsz"MainTest.test_certonly_csr_dry_runr�r�c	Cs�d|_d}|�dtdtd|dg�ttd��D}|jjdks>J�|jjd	d	t	j
�|���ksbJ�Wd�n1sv0Yttd��@}t
�|���d	}|��j}|�t	�|�tj�Wd�n1s�0YdS)
NFr�r�r��--serverr��rbrPr)rr}�SS_CERT_PATH�RSA2048_KEY_PATHr	r�r<r�r'r�r��loadrr�pyopenssl_load_certificater�rs�ComparableX509rrt)r r�r�r�rrAr�r$r$r%�test_revoke_with_key	s"��&
�zMainTest.test_revoke_with_keyc
CsLd}t�tj��(|�dtdtd|dg�Wd�n1s>0YdS)Nr�r�r�rlr�)r>r?rrr}�CERT�KEY)r r�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*rprtr	rrqrZacme_from_config_keyr�rsr�rrrt)r r�r�r�rbrrAr�r$r$r%�test_revoke_without_key"s

�z MainTest.test_revoke_without_keyc	Cs�t�d���}t��}d|_|df|j_|�gd��t�d��H}t��}||j_dg|j_|�gd��}d|dvsxJ�Wd�n1s�0YWd�n1s�0YdS)	Nr_Zimaginary_accountZworked)ra�--email�user@example.org�certbot._internal.main.account�
an accountzThere is an existing accountr)	rrGr*rHrarr}�AccountFileStoragerk)r r�Z
mocked_clientr�Zmocked_account�mocked_storagerGr$r$r%�
test_register0s
zMainTest.test_registerz'certbot._internal.updater._run_updaterscCsltj|_t�tj��t�ddd�Wd�n1s80Yd|j_t	�
|jdd�|jdushJ�dSrw)rr�r=r>r?r�
renew_certr@rrZrun_generic_updatersr)r r�r�r$r$r%�test_plugin_selection_errorAs,z$MainTest.test_plugin_selection_errorz3certbot._internal.main.updater.run_renewal_deployercCs`d|j_t��}|t��f|_t�|jdd�|jdks<J�|jdksJJ�|j�	�|�	�dS)z8A dry-run renewal shouldn't try to restart the installerTNrP)
r@rrr*rrrr<r�r;)r r�r^r�Zmock_run_renewal_deployerr"r$r$r%�#test_renew_doesnt_restart_on_dryrunNs
z,MainTest.test_renew_doesnt_restart_on_dryrun)NF)N)N)NNN)N)VrCrDrErFrXr�rpr}r�r�r�rrGr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrr	r�r:rr!r&rr-r1r3r4r7r8r;r=r@rArBrDrErFrLrOrPrSrVrWrYrZr]r_r`rardr�r�rerhrjrkrsrvrwr~r�r�r�r$r$rfr%rl�s@




%



	



�
K	





	

	�



	

rlc@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�rzr_)rPrrb�get_utilitycSsi|]\}}||���qSr$r�r�r$r$r%r�hr6z(UnregisterTest.setUp.<locals>.<dictcomp>)rrGr�r�rr�rrur$r$r%rXbs�zUnregisterTest.setUpcCs|j��D]}|��q
dSr�)rrrdrr$r$r%r�jszUnregisterTest.tearDowncCsRt��|jdj_|jd�}d|j_t��}t��}t�||�}|dksNJ�dS)Nrr�FzDeactivation aborted.)rrrr|rr�r�
unregister)r r8r@r��resr$r$r%�test_abort_unregisternsz$UnregisterTest.test_abort_unregisterr/cCs�t��}dg|j_||jdj_t��df|jd_t��}||jdj_t��}t��}t�||�}|dusrJ�|�	d�dS)Nr{rZfoorPrbzAccount deactivated.)
rr*rkrrr|�Clientrr�rs)r r1r}�	cb_clientr@r�r�r$r$r%�test_unregisterzs
zUnregisterTest.test_unregistercCs|t��}g|j_||jdj_t��}||jdj_t��}d|_t��}t�	||�}d}||ksfJ�|j
jjdusxJ�dS)Nrrbz"https://acme.example.com/directoryzNCould not find existing account for server https://acme.example.com/directory.F)
rr*rkrrr|r�r�rr�r�Zdeactivate_registrationr)r r}r�r@r�r��mr$r$r%�test_unregister_no_account�sz)UnregisterTest.test_unregister_no_accountN)
rCrDrErXr�r�rrGr�r�r$r$r$r%r�as
r�c@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@rrrZset_up_core_dirr%r
ZCONFIG_DIRS_MODEZstrict_permissionsZrenewal_pre_hooks_dirZrenewal_deploy_hooks_dirZrenewal_post_hooks_dirZmake_or_verify_dir)r Z	mock_utilZcore_dirZ	hook_dirsZhook_dirr$r$r%�test_it�s���zMakeOrVerifyNeededDirs.test_itN)rCrDrErFrrGr�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)rWrXr�r�r�rZr�rr*r�AutoHSTSEnhancement�
mockinstallerrurfr$r%rX�s

zEnhanceTest.setUpcCs|j��dSr�r�rur$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)Nrr�r�rJ)rrjrkrrlrrGrr*r@r�enhance)r rnror@Z
mock_certsZmock_domr^rNr$r$r%rp�s
zEnhanceTest._callr�r�z0certbot._internal.main.display_ops.choose_valuesz0certbot._internal.main._find_domains_or_certnamecCsxtjdd�|_dg|_d|_t�d��>}|�ddg�|js@J�d|jd	d
vsVJ�Wd�n1sj0YdS)N�/tmp/nonexistent�r�r��NNr�r��
--redirectrrrQ)rr*rrGrprr')r �	mock_findr�r"r��	mock_pickr$r$r%�test_selection_question�s
z#EnhanceTest.test_selection_questionc	Cs�tjdd�|_dg|_d|_t�d��tt�d��J}|�gd��}|jsLJ�d|jd	d	vsbJ�|jjsnJ�Wd�n1s�0YWd�n1s�0YdS)
Nr�r�r�r�r�z.certbot._internal.main.plug_sel.logger.warning)r�r�rQr�z
make senser)rr*rrGrprr'�enhance_config)r r�r�r"r�Zmock_logrNr$r$r%�test_selection_auth_warning�s
z'EnhanceTest.test_selection_auth_warningcs�tjdd�|_dg|_t�d���|�gd���ddg}dg}�jjsJJ�t�fd	d
�|D��sdJ�t�fdd
�|D��r~J�d�jj	ddvs�J�Wd�n1s�0YdS)
Nr�r�r�r��r�r��--hstsZredirectZhstsZuirc3s|]}t�j|�VqdSr���getattrr@�r�r��rNr$r%r��r6z7EnhanceTest.test_enhance_config_call.<locals>.<genexpr>c3s|]}t�j|�VqdSr�r�r�r�r$r%r��r6r)
rr*rrGrpr�r�all�anyr')r r�r�r"Zreq_enhZnot_req_enhr$r�r%�test_enhance_config_call�sz$EnhanceTest.test_enhance_config_callcCsltjdd�|_dg|_t�d��8|�gd��}|jjs<J�|jdusJJ�Wd�n1s^0YdS)Nr�r�r�r�)r�r�r�z--non-interactiveF)rr*rrGrpr�r)r r�r�r"rNr$r$r%�test_enhance_noninteractive�s�z'EnhanceTest.test_enhance_noninteractivec	Csng|_t�d��Jt�tj��|�gd��Wd�n1sB0YWd�n1s`0YdS)Nr�r�)rrrGr>r?rrrp)r r�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?rr�rprur$r$r%�test_no_enhancements_definedsz(EnhanceTest.test_no_enhancements_definedrzcCs:dg|_d|_t��|_|�ddg�}|jjdus6J�dS)Nr�r�r�r�F)rrr�r=rpr�r)r r�r�r�rNr$r$r%r�s

z'EnhanceTest.test_plugin_selection_errorr�cCs^|j|_ddg|_tjdd�|_|�ddg�|jjjs<J�|jjjddddgksZJ�dS)	Nr��another.tldr�r�r��--auto-hstsrrP)r�rrr*rpZenable_autohstsrr'�r r�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�)rr|r@rrr*r>r?rr~rpr�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?rrrprur$r$r%� test_enhancement_enable_conflict8sz,EnhanceTest.test_enhancement_enable_conflict)rCrDrErFrXr�rprrGr�r�r�r�r�r�r�r�r�r�r�r�r�r$r$rfr%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�)rWrXrr*rr�r�rurfr$r%rX@s
zInstallTest.setUpr�r�cCsht�|jd�|_tj��}d|j_d|j_t	�
tj��t
�|j|�Wd�n1sZ0YdS)NrTZnonexistent)rr|r@rrrjrkr}r2r>r?rr~rr��r r�r�ror$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�rrrjrkr@r}r2r�r�r>r?rr�rr�r�r$r$r%�$test_install_enhancement_no_certnameNs
z0InstallTest.test_install_enhancement_no_certname)
rCrDrErFrXrrGr�r�r�r$r$rfr%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�rPr)	rrG�notify_patchrZr1�notafter_patchZ
mock_notafterr�rrur$r$r%rX`s
zReportNewCertTest.setUpcCs|j��|j��dSr�)r�rdr�rur$r$r%r�hs
zReportNewCertTest.tearDowncOsddlm}||i|��S)Nr)�_report_new_cert)rmr�)�clsrnr�r�r$r$r%rplszReportNewCertTest._callcOsddlm}||i|��S)Nr)�_csr_report_new_cert)rmr�)r�rnr�r�r$r$r%�	_call_csrqszReportNewCertTest._call_csrcCs(|�tjdd�ddd�|j�d�dS�NT�rr#�rprrr1r0rur$r$r%�test_report_dry_runvsz%ReportNewCertTest.test_report_dry_runcCs(|�tjdd�ddd�|j�d�dSr��r�rrr1r0rur$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?rrprrr�rur$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�rur$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�rur$r$r%�test_report_no_key�s��z$ReportNewCertTest.test_report_no_keycCs*|�tjddd�ddd�|j�d�dS)NF)r�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�rur$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�rur$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)rr�manual_auth_hookr�r�r�r�r�rur$r$r%�test_manual_no_hooks_report�s��z-ReportNewCertTest.test_manual_no_hooks_reportN)rCrDrErFrXr��classmethodrpr�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�rrr�r/)
rr*r@rGrZr1rcrdrbr~�
old_stdoutr�r�)r r�r$r$r%rX�s�

zReportNextStepsTest.setUpcCs|jt_dSr�)r�rbr~rur$r$r%r��szReportNextStepsTest.tearDowncOsddlm}||i|��dS)Nr)�_report_next_steps)rmr�)r�rnr�r�r$r$r%rp�szReportNextStepsTest._call)�returncCs@|jjdksJ�|jjddddks,J�|jjdddS)Nr1rzNEXT STEPS:rP)r1r<r�rur$r$r%�_output�szReportNextStepsTest._outputcCs.d|j_d|j_|�|jdd�|j��dS)zNo steps for a normal renewalrz	/bin/trueN)r@rr�rpr1r;rur$r$r%r��szReportNextStepsTest.test_reportcCs,d|j_|�|jdd�d|��vs(J�dS)z--csr requires manual renewalzfoo.csrNz--csr will not be renewed)r@rrpr�rur$r$r%r��sz#ReportNextStepsTest.test_csr_reportcCs,d|j_|�|jdd�d|��vs(J�dS)z/--manual without a hook requires manual renewalrNz--manual certificates requires)r@rrpr�rur$r$r%�test_manual_no_hook_renewal�sz/ReportNextStepsTest.test_manual_no_hook_renewalcCs,d|j_|�|jdd�d|��vs(J�dS)z2No --preconfigured-renewal needs manual cron setupFNz!https://certbot.org/renewal-setup)r@r�rpr�rur$r$r%�test_no_preconfigured_renewal�sz1ReportNextStepsTest.test_no_preconfigured_renewalN)rCrDrErFrXr�r�rpr*r�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)
Nrzr�r_r�r/z*certbot._internal.eff.prepare_subscription)r�atexitrb�determine_account�notify�prepare_subr
csi|]}|�|���qSr$r��r�r��rer$r%r�	r6z+UpdateAccountTest.setUp.<locals>.<dictcomp>�
rrGr�r�rrrcrdrWrXrrfr�r%rX	s�	zUpdateAccountTest.setUpc	Cs�t�d��|t�d��Rd|jjd|jjd|jjdg|}t�|dd��Wd�Wd�S1sn0YWd�n1s�0YdS�Nr�r�rrmrnro�rrGr@rrrrqrr,r$r$r%rp	s�
��zUpdateAccountTest._callcCsXt��}t��}t��}|g|j_||jdj_|j|j_|t��f|jd_|||fS)Nrr�)rr*rkrrr|�bodyr��r rQZmock_account�	mock_regrr$r$r%�_prepare_mock_account	s

z'UpdateAccountTest._prepare_mock_accountcCs�|��\}}}|�|�}|dus$J�|jd��jjjdks@J�|jjj	dd�|j
jdks`J�|jd�	d�|jd��dS)	z9Utility to assert that email removal is handled correctlyNrbrPr$��contactr�zFAny contact information associated with this account has been removed.r�)r�rprr�r��update_registrationr<r��updater0�update_regrr;)r rnr�rQr��resultr$r$r%�_test_update_no_contact#	s

�z)UpdateAccountTest._test_update_no_contactcCs8t��}g|j_||jdj_|�gd��dks4J�dS)�2Test that no existing account is handled correctlyr)�update_accountrxry�]Could not find an existing account for server https://acme-v02.api.letsencrypt.org/directory.N�rr*rkrrr|rp�r rQr$r$r%�test_no_existing_accounts5	s�z+UpdateAccountTest.test_no_existing_accountscCs|�ddg�dS)zBTest that --register-unsafely-without-email is handled as no emailr�z!--register-unsafely-without-emailN�r�rur$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�r;Nr�rur$r$r%�test_update_account_empty_emailB	sz1UpdateAccountTest.test_update_account_empty_emailz,certbot._internal.main.display_ops.get_emailcCs�d|_|��\}}}t��}||jdj_|�dg�}|dusBJ�|jjj	dksTJ�|j
j	dksdJ�|jdj	dksxJ�|jd�d�dS)	z=Test that updating with a singular email is handled correctlyzuser@example.comrbr�NrPr�r�z4Your e-mail address was updated to user@example.com.)rr�rr*rr�rpr�r�r<r�r0)r Z
mock_emailr�rQrNr�r$r$r%�test_update_account_with_emailF	s
�z0UpdateAccountTest.test_update_account_with_emailcCs\|��\}}}|�gd��dus$J�|jjjddgd�|jjdksHJ�|jd�d�dS)	z8Test that multiple email addresses are handled correctly)r�r�z!user@example.com,user@example.orgNzmailto:user@example.comzmailto:user@example.orgr�rPr�zEYour e-mail address was updated to user@example.com,user@example.org.)r�rpr�r�r0r�r<r)r r�rQr�r$r$r%�(test_update_account_with_multiple_emails[	s�
�z:UpdateAccountTest.test_update_account_with_multiple_emails)rCrDrErFrXrpr�r�r�r�r�rrGr�r�r�r$r$rfr%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)	Nrzr�r_r�r/)rr�rbr�r�r
csi|]}|�|���qSr$r�r�r�r$r%r�s	r6z)ShowAccountTest.setUp.<locals>.<dictcomp>r�rrfr�r%rXj	s�zShowAccountTest.setUpc	Cs�t�d��|t�d��Rd|jjd|jjd|jjdg|}t�|dd��Wd�Wd�S1sn0YWd�n1s�0YdSr�r�r,r$r$r%rpy	s�
��zShowAccountTest._callcCs\t��}t��}t��}|g|j_||jdj_|j|j_d|jj	_|t��f|jd_dS)Nrs	foobarbazr�)
rr*rkrrr|r�r�r�Z
thumbprintr�r$r$r%r��	s


z%ShowAccountTest._prepare_mock_accountcCsd|��t��}t��}||j_d|_||jj_||j	dj
_dg}|�|�|jjjdks`J�dS)Nz+https://www.letsencrypt-demo.org/acme/reg/1rb�show_accountrP)
r�rr*r�r�Zurir�Zquery_registrationrrr�rpr<)r r�rNr�rnr$r$r%�_test_show_account�	s

z"ShowAccountTest._test_show_accountcCs6t��}g|j_||jdj_|�dg�dks2J�dS)r�rr�r�Nr�r�r$r$r%r��	s
�z)ShowAccountTest.test_no_existing_accountsc
Csp|��t��}d|_||jdj_z|�dg�Wn6tj	yj}zdt
|�ksVJ�WYd}~n
d}~00dS)z;Test that issues with the ACME client are handled correctlyNrbr�zACME client is not set.)r�rr*r�rr�rrprrr*)r rNr�r$r$r%�test_no_existing_client�	sz'ShowAccountTest.test_no_existing_clientcCs:|�d�|jdjdksJ�|jd�t�d�g�dS)Nr$r�rPz�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�rr<Zassert_has_callsrr�rur$r$r%�test_no_contacts�	s


�z ShowAccountTest.test_no_contactscCs>d}|�|�|jdjdks"J�|jd�t�d�g�dS)N)�mailto:foo@example.comr�rPz�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��r r�r$r$r%�test_single_email�	s

�z!ShowAccountTest.test_single_emailcCs>d}|�|�|jdjdks"J�|jd�t�d�g�dS)N)r�zmailto:bar@example.comr�rPz�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)rCrDrErFrXrpr�r�r�r�r�r�r�r�r$r$rfr%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)rrG)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�r r$r%�authenticator_lock�	sz=TestLockOrder.mock_plugin_prepare.<locals>.authenticator_lockcs ����dkr���j��dS)Nr�rr)�
installer_dirr�r �
subcommandr$r%�installer_lock�	sz9TestLockOrder.mock_plugin_prepare.<locals>.installer_lockr�N)rrG�objectrr�rr|)r rrr�rrrr$)rrr�r rr%�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@r"ZlogsZworkr�rz-irz--no-random-sleep-on-renewrrnrmr'r�N)r*Zparamr�r+r
)r r�ZrequestZtmp_pathrrrrqrrrrn�
lock_orderr$r$r%�args_and_lock_order�	s 
�z!TestLockOrder.args_and_lock_ordercCs�|\}}tj|j|jd��t�|�Wd�n1s:0Y|jt|�ksVJ�t|j|�D]\}}|dd|ksbJ�qbdS)Nr7r)	r>r?r�EXPECTED_ERROR_STR_REGEXrr<r��zipr�)r r
r�rnrr�Z
locked_dirr$r$r%�test_lock_order
s(zTestLockOrder.test_lock_orderN)rCrDrErFrrrrrr>Zfixturer��
contextlib�contextmanagerr
rir
rr$r$r$r%r��	s



 r��__main__rP)UrFrr��	importlibrrur�r�r[r�rbr�r�typingrZunittestrrZjosepyr�r>r�Z
acme.messagesrrhr�rrr	r
Zcertbot._internalrrr
rrZcertbot._internal.pluginsrrrrZcertbot.compatrrZcertbot.pluginsrZcertbot.tests.utilZtestsr�r�r�rtr�ruZJWKRSArpZload_vectorr�rornZTestCaserZConfigTestCaserHr�r�ZTempDirTestCaser�r�r3rFrlr�r�r�r�r�r�r�r�r�rC�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