a }|g@sdZddlZddlZddlZddlmZddlZddlmZddlm Z ddl m Z ddl m Z ddl mZdd l mZGd d d ejZed kreeejd degdS)z*Tests for certbot._internal.plugins.manualN)mock) challenges)errors) filesystem)os) acme_util)utilcsheZdZdZfddZddZddZdd Zd d Zd d Z ddZ ddZ ddZ ddZ ZS)AuthenticatorTestz9Tests for certbot._internal.plugins.manual.Authenticator.cstt}||_||jtj |_ tj |_ tj |_|j |j |jg|_dD]}ttj|j|qVtjdddddtj|jdtj|jdtj|jdtj|jdtj|jdd |_dd lm}||jd d |_dS) N) config_dirwork_dirZ in_progressrFr r backup_dirtemp_checkpoint_dirZ in_progess) Z http01_portmanual_auth_hookmanual_cleanup_hooknoninteractive_modevalidate_hooksr r r r Zin_progress_dir) AuthenticatorZmanual)name)supersetUp test_utilZpatch_display_utilstartmock_get_displayZ addCleanupstoprHTTP01_A http_achallDNS01_A dns_achallZ DNS01_A_2Z dns_achall_2achallsrmkdirrpathjoinZtempdirrZ MagicMockconfigZ certbot._internal.plugins.manualrauth)selfZget_display_patchdr __class__O/usr/lib/python3.9/site-packages/certbot/_internal/tests/plugins/manual_test.pyrs.    zAuthenticatorTest.setUpcCsBd|j_ttj|jWdn1s40YdSNT)r"rpytestraisesrZ PluginErrorr#preparer$r(r(r)#test_prepare_no_hook_noninteractive0sz5AuthenticatorTest.test_prepare_no_hook_noninteractivecCsTtjtj|j_d|j_tt j |j Wdn1sF0YdSr*) rr abspathsepr"rrr+r,rZHookCommandNotFoundr#r-r.r(r(r)test_prepare_bad_hook5sz'AuthenticatorTest.test_prepare_bad_hookcCst|jtsJdSN) isinstancer#Z more_infostrr.r(r(r)test_more_info;sz AuthenticatorTest.test_more_infocCs |jdtjtjgksJdS)Nz example.org)r#Zget_chall_prefrHTTP01DNS01r.r(r(r)test_get_chall_pref>s  z%AuthenticatorTest.test_get_chall_prefc Cszdtj|j_d|jjd|j|jjd dd|j Dt |j |j |jd}d|j j|j jd|j |j jd d d|j Dt |j |j |j d}|j|j d d |j DksJ|jj|jd |ksJ|jj|j d |ks J|jjt |j ks&Jt|jjD]>\}\}}t|jj|j |d d }||dvs6Jq6dS)Na {0} -c "from certbot.compat import os;print(os.environ.get('CERTBOT_DOMAIN'));print(os.environ.get('CERTBOT_TOKEN', 'notoken'));print(os.environ.get('CERTBOT_VALIDATION', 'novalidation'));print(os.environ.get('CERTBOT_ALL_DOMAINS'));print(os.environ.get('CERTBOT_REMAINING_CHALLENGES'));"z{0} {1} {2} {3} {4}Znotoken,css|] }|jVqdSr3domain.0achallr(r(r) Oz8AuthenticatorTest.test_script_perform..tokencss|] }|jVqdSr3r;r=r(r(r)r@TrAcSsg|]}||jqSr(Zresponse account_keyr=r(r(r) XrAz9AuthenticatorTest.test_script_perform..CERTBOT_AUTH_OUTPUT r)formatsys executabler"rrr< validationrEr!rlenindexrchallencoder#performenvr notification call_count enumeratecall_args_listtextwrapindent)r$Z dns_expectedZ http_expectediargs_Zneedler(r(r)test_script_performBs:   z%AuthenticatorTest.test_script_performcCs|j|jdd|jDks"J|jjt|jks\}\}}|j|}| |j |dvszJ|ddusLJqLdS)NcSsg|]}||jqSr(rDr=r(r(r)rFfrAz9AuthenticatorTest.test_manual_perform..rwrapF) r#rQrrrSrTrMrUrVrLrE)r$rYrZkwargsr?r(r(r)test_manual_performds  z%AuthenticatorTest.test_manual_performcCsdtj|j_d|j_|j|j|jD]}|j |gt j ddksPJt j d|j ksdJt |jtjtjfrt j d||jksJt |jtjrt j d|jdksJq,dt j vs,Jq,dS) Nz,{0} -c "import sys; sys.stdout.write('foo')"z # cleanuprGZfooZCERTBOT_DOMAINZCERTBOT_VALIDATIONZ CERTBOT_TOKENrC)rIrJrKr"rrr#rQrZcleanuprenvironr<r4rOrr7r8rLrErP)r$r?r(r(r) test_cleanupns$   zAuthenticatorTest.test_cleanupcCs@d|j_|jtjtjgdks$J|jtjgdkss