
    M/e                        d Z ddlZddlZddlZddlmZ ddlZddlmZ ddlm	Z	 ddl
mZ ddl
mZ ddlmZ dd	lmZ  G d
 dej"                        Zedk(  r4 ej(                   ej*                  ej,                  dd egz                yy)z*Tests for certbot._internal.plugins.manual    N)mock)
challenges)errors)
filesystem)os)	acme_util)utilc                   X     e Zd ZdZ fdZd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Z xZS )AuthenticatorTestz9Tests for certbot._internal.plugins.manual.Authenticator.c                    t         |           t        j                         }|j	                         | _        | j                  |j                         t        j                  | _
        t        j                  | _        t        j                  | _        | j                  | j                  | j                  g| _        dD ]?  }t!        j"                  t$        j&                  j)                  | j*                  |             A t-        j.                  dd d ddt$        j&                  j)                  | j*                  d      t$        j&                  j)                  | j*                  d      t$        j&                  j)                  | j*                  d      t$        j&                  j)                  | j*                  d      t$        j&                  j)                  | j*                  d      	
      | _        dd
lm}  || j0                  d      | _        y )N)
config_dirwork_dirin_progressr   Fr   r   
backup_dirtemp_checkpoint_dir
in_progess)
http01_portmanual_auth_hookmanual_cleanup_hooknoninteractive_modevalidate_hooksr   r   r   r   in_progress_dir)Authenticatormanual)name)supersetUp	test_utilpatch_display_utilstartmock_get_display
addCleanupstopr   HTTP01_Ahttp_achallDNS01_A
dns_achall	DNS01_A_2dns_achall_2achallsr   mkdirr   pathjointempdirr   	MagicMockconfig certbot._internal.plugins.manualr   auth)selfget_display_patchdr   	__class__s       M/usr/lib/python3/dist-packages/certbot/_internal/tests/plugins/manual_test.pyr   zAuthenticatorTest.setUp   s`   %88: 1 7 7 9)../$--#++%//(($//4;L;LM: 	<ARWW\\$,,:;	<
 nnDd %eww||DLL,?WW\\$,,
;ww||DLL,? "(,6K!MGGLL|DF 	C!$++H=	    c                     d| j                   _        t        j                  t        j
                        5  | j                  j                          d d d        y # 1 sw Y   y xY wNT)r0   r   pytestraisesr   PluginErrorr2   preparer3   s    r7   #test_prepare_no_hook_noninteractivez5AuthenticatorTest.test_prepare_no_hook_noninteractive0   sE    *.']]6--. 	 II	  	  	 s   AA"c                 B   t         j                  j                  t         j                        | j                  _        d| j                  _        t        j                  t        j                        5  | j                  j                          d d d        y # 1 sw Y   y xY wr:   )r   r,   abspathsepr0   r   r   r;   r<   r   HookCommandNotFoundr2   r>   r?   s    r7   test_prepare_bad_hookz'AuthenticatorTest.test_prepare_bad_hook5   sb    ')wwrvv'>$%)"]]6556 	 II	  	  	 s   1BBc                 X    t        | j                  j                         t              sJ y N)
isinstancer2   	more_infostrr?   s    r7   test_more_infoz AuthenticatorTest.test_more_info;   s    $))--/555r8   c                     | j                   j                  d      t        j                  t        j                  gk(  sJ y )Nzexample.org)r2   get_chall_prefr   HTTP01DNS01r?   s    r7   test_get_chall_prefz%AuthenticatorTest.test_get_chall_pref>   s7    yy''6$++Z-=-=>? 	? ?r8   c           
      N   dj                  t        j                        | j                  _        dj                  | j
                  j                  d| j
                  j                  | j
                  j                        dj                  d | j                  D              t        | j                        | j                  j                  | j
                        z
  dz
        }dj                  | j                  j                  | j                  j                  j                  d      | j                  j                  | j                  j                        dj                  d | j                  D              t        | j                        | j                  j                  | j                        z
  dz
        }| j                   j#                  | j                        | j                  D cg c]  }|j%                  |j                         c}k(  sJ | j                   j&                  | j
                     d	   |k(  sJ | j                   j&                  | j                     d	   |k(  sJ | j)                         j*                  j,                  t        | j                        k(  sJ t/        | j)                         j*                  j0                        D ]N  \  }\  }}t3        j4                  | j                   j&                  | j                  |      d	   d
      }||d   v rNJ  y c c}w )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}notoken,c              3   4   K   | ]  }|j                     y wrG   domain.0achalls     r7   	<genexpr>z8AuthenticatorTest.test_script_perform.<locals>.<genexpr>O        >vV]]>      tokenc              3   4   K   | ]  }|j                     y wrG   rU   rW   s     r7   rZ   z8AuthenticatorTest.test_script_perform.<locals>.<genexpr>T   r[   r\   CERTBOT_AUTH_OUTPUT r   )formatsys
executabler0   r   r'   rV   
validationaccount_keyr-   r*   lenindexr%   challencoder2   performresponseenvr!   notification
call_count	enumeratecall_args_listtextwrapindent)r3   dns_expectedhttp_expectedrY   iargs_needles           r7   test_script_performz%AuthenticatorTest.test_script_performB   s   H VCNN# 	$ 177OO""IOO&&t'B'BCHH>>> 2 24?? CCaG	I
 288##T%5%5%;%;%B%B7%K''(8(8(D(DEHH>>> 2 243C3C DDqH	J yy  .?C||LVV__V//0LM 	M Myy}}T__-.CD 	 yy}}T--./DE 	  $$&33>>#dllBSSSS%d&;&;&=&J&J&Y&YZ 	%LAya__TYY]]4<<?%CDY%Z\_`FT!W$$$	% Ms   ("L"c                     | j                   j                  | j                        | j                  D cg c]  }|j                  |j                         c}k(  sJ | j                         j                  j                  t        | j                        k(  sJ t        | j                         j                  j                        D ]B  \  }\  }}| j                  |   }|j                  |j                        |d   v sJ |d   du rBJ  y c c}w )Nr   wrapF)r2   rk   r*   rl   rf   r!   rn   ro   rg   rp   rq   re   )r3   rY   rv   rw   kwargss        r7   test_manual_performz%AuthenticatorTest.test_manual_performd   s    yy  .?C||LVV__V//0LM 	M M $$&33>>#dllBSSSS!*4+@+@+B+O+O+^+^!_ 	+A~f\\!_F$$V%7%78DGCCC&>U***	+ Ms   "Dc                 >   dj                  t        j                        | j                  _        d| j                  _        | j                  j                  | j                         | j                  D ])  }| j                  j                  |g       t        j                  d   dk(  sJ t        j                  d   |j                  k(  sJ t        |j                  t        j                   t        j"                  f      r1t        j                  d   |j%                  |j&                        k(  sJ t        |j                  t        j                         r3t        j                  d   |j                  j)                  d      k(  rJ dt        j                  vr*J  y )	Nz,{0} -c "import sys; sys.stdout.write('foo')"z	# cleanupr`   fooCERTBOT_DOMAINCERTBOT_VALIDATIONCERTBOT_TOKENr^   )rb   rc   rd   r0   r   r   r2   rk   r*   cleanupr   environrV   rH   ri   r   rN   rO   re   rf   rj   )r3   rY   s     r7   test_cleanupzAuthenticatorTest.test_cleanupn   s@   (X)/)? 	$*5'		$,,'ll 	9FIIvh'::34===::./6==@@@&,,):):J<L<L(MNzz"67%%f&8&89: : :&,,
(9(9:zz/2LL''01 1 1 'bjj888	9r8   c                     d| j                   _        | j                  j                  t        j
                  t        j                  g      dk(  sJ | j                  j                  t        j                  g      dk(  sJ y )Nz	/bin/truea&  The Certificate Authority failed to verify the DNS TXT records and challenge files created by the --manual-auth-hook. Ensure that this hook is functioning correctly and that it waits a sufficient duration of time for DNS propagation. Refer to "certbot --help manual" and the Certbot User Guide.zThe Certificate Authority failed to verify the challenge files created by the --manual-auth-hook. Ensure that this hook is functioning correctly. Refer to "certbot --help manual" and the Certbot User Guide.)r0   r   r2   	auth_hintr   r&   r$   r?   s    r7   test_auth_hint_hookz%AuthenticatorTest.test_auth_hint_hook   s~    '2$yy""I$5$5y7I7I#JKKK 	K K
 yy""I$6$6#78BB 	B Br8   c                    | j                   j                  t        j                  t        j                  g      dk(  sJ | j                   j                  t        j                  t        j                  t        j                  g      dk(  sJ y )NzThe Certificate Authority failed to verify the manually created DNS TXT records and challenge files. Ensure that you created these in the correct location, or try waiting longer for DNS propagation on the next attempt.zThe Certificate Authority failed to verify the manually created challenge files. Ensure that you created these in the correct location.)r2   r   r   r&   r$   r?   s    r7   test_auth_hint_no_hookz(AuthenticatorTest.test_auth_hint_no_hook   s    yy""I$5$5y7I7I#JKJJ 	J J yy""I$6$6	8J8JIL^L^#_`EE 	E Er8   )__name__
__module____qualname____doc__r   r@   rE   rK   rP   rz   r~   r   r   r   __classcell__)r6   s   @r7   r   r      s;    C>8 
 6? %D+9&
BEr8   r   __main__r]   )r   rc   rr   unittestr   r;   acmer   certbotr   certbot.compatr   r   certbot.testsr   r	   r   TempDirTestCaser   r   exitmainargv__file__ r8   r7   <module>r      sy    0 
       %  # +CE	11 CEL zCHH[V[[!"
234 r8   