
    M/e&                        d Z ddlZddlm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 G d dej(                        Z G d dej(                        Z G d dej0                        Z G d dej(                        Zedk(  r4 ej8                   ej:                  ej<                  dd egz                yy)z'Tests for letsencrypt.plugins.selection    N)List)mock)errors)
interfaces)obj)PluginsRegistry)utilc                   (    e Zd ZdZd Zd Zd Zd Zy)ConveniencePickPluginTestz5Tests for certbot._internal.plugins.selection.pick_*.c                 *   t        j                         }t        j                         }t        j                         }t        j                  d      5 }d|_        d ||||d      k(  sJ 	 d d d        j	                  |||d|       y # 1 sw Y   xY w)Nz/certbot._internal.plugins.selection.pick_pluginfoo	Question?)r   Mockpatchreturn_valueassert_called_once_with)selffunifacesconfigdefaultpluginsmock_ps          P/usr/lib/python3/dist-packages/certbot/_internal/tests/plugins/selection_test.py_testzConveniencePickPluginTest._test   s    ))+))+ZZIJ 	Gf"'FC+FFFF	G 	&&GWk6	;	G 	Gs   B		Bc                 R    ddl m} | j                  |t        j                  f       y )Nr   )pick_authenticator)#certbot._internal.plugins.selectionr   r   r   Authenticator)r   r   s     r   test_authenticatorz,ConveniencePickPluginTest.test_authenticator   s    J

%
(@(@'BC    c                 R    ddl m} | j                  |t        j                  f       y )Nr   )pick_installer)r   r#   r   r   	Installer)r   r#   s     r   test_installerz(ConveniencePickPluginTest.test_installer#   s    F

>J$8$8#:;r!   c                 p    ddl m} | j                  |t        j                  t        j
                  f       y )Nr   )pick_configurator)r   r'   r   r   r   r$   )r   r'   s     r   test_configuratorz+ConveniencePickPluginTest.test_configurator'   s(    I

$%%z';';<	>r!   N)__name__
__module____qualname____doc__r   r    r%   r(    r!   r   r   r      s    ?	;D<>r!   r   c                   L    e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zy)PickPluginTestz:Tests for certbot._internal.plugins.selection.pick_plugin.c                     t        j                  d      | _        d | _        t        j                         | _        d| _        g | _        y )NF)noninteractive_moder   )r   r   r   r   	MagicMockregquestionr   r   s    r   setUpzPickPluginTest.setUp0   s5    iiE:>>##/1r!   c                     ddl m}  || j                  | j                  | j                  | j
                  | j                        S )Nr   )pick_plugin)r   r8   r   r   r3   r4   r   )r   r8   s     r   _callzPickPluginTest._call7   s1    C4;;dhh==$++7 	7r!   c                 |    d| _         | j                          d| j                  j                  j                  k(  sJ y Nr      )r   r9   r3   filter
call_countr5   s    r   test_default_providedz$PickPluginTest.test_default_provided<   s.    

DHHOO.....r!   c                     | j                          d| j                  j                         j                  j                  k(  sJ y Nr<   )r9   r3   visibler   r>   r5   s    r   test_no_defaultzPickPluginTest.test_no_defaultA   s2    

DHH$$&--88888r!   c                 (    | j                         J y N)r9   r5   s    r   test_no_candidatez PickPluginTest.test_no_candidateE   s    zz|###r!   c                     t        j                         }d|j                  _        d|_        d|i| j
                  j                         j                         j                  _        d| j                         k(  sJ y )Nr   Fbar
r   r2   initr   misconfiguredr3   rB   r   	availabler9   r   	plugin_eps     r   test_singlezPickPluginTest.test_singleH   sc    NN$	&+	#"'	 9>!!#--:

$$$r!   c                     t        j                         }d|j                  _        d|_        d|i| j
                  j                         j                         j                  _        | j                         J y )Nr   TrH   rI   rM   s     r   test_single_misconfiguredz(PickPluginTest.test_single_misconfiguredQ   sa    NN$	&+	#"&	 9>!!#--:zz|###r!   c                    t        j                         }d|j                  _        ||d| j                  j                         j                         j                  _        t        j                  d      5 }||_        d| j                         k(  sJ 	 d d d        j                  ||g| j                         y # 1 sw Y   (xY w)Nr   rH   baz1certbot._internal.plugins.selection.choose_plugin)r   r2   rJ   r   r3   rB   r   rL   r   r9   r   r4   )r   rN   mock_chooses      r   test_multiplezPickPluginTest.test_multipleZ   s    NN$	&+	#>
!!#--: ZZKL 	)P['0K$DJJL(((	) 	++	"DMM	3	) 	)s   5B::Cc                     d d d| j                   j                         j                         j                  _        t        j                  d      5 }d |_        | j                         J 	 d d d        y # 1 sw Y   y xY w)NrS   rU   )r3   rB   r   rL   r   r   r   r9   )r   rV   s     r   test_choose_plugin_nonez&PickPluginTest.test_choose_plugin_noneg   so    >
!!#--:
 ZZKL 	(P['+K$::<'''	( 	( 	(s   A44A=c                     d| _         t        j                         }|| j                  j                  _        | j                          |j                  j                  dk(  sJ y r;   )	r   r   r2   r3   r=   r   r9   r   r>   )r   filtereds     r   test_default_must_be_filteredz,PickPluginTest.test_default_must_be_filteredq   sF    >>#'/$

))Q...r!   N)r)   r*   r+   r,   r6   r9   r?   rC   rF   rO   rQ   rW   rY   r\   r-   r!   r   r/   r/   -   s7    D27
/
9$%$3(/r!   r/   c                       e Zd ZdZd Zd Z ej                         d        Z ej                         d        Z	 ej                         d        Z
y)ChoosePluginTestz<Tests for certbot._internal.plugins.selection.choose_plugin.c                    t        j                  t        j                  t        j                  d             t        j                  dd      | _        d| j                  _        t        j                  dd      | _	        d| j                  j                         j                  _        | j                  | j                  g| _        y )NFaT)description_with_namerK   apaches
standalone)display_objset_displayFileDisplaysysstdoutr   r   mock_apachename
mock_standrJ   	more_infor   r   r5   s    r   r6   zChoosePluginTest.setUp}   s     7 7

E JK99"%T; ())"%U<8D((5OO
r!   c                 4    ddl m}  || j                  d      S )Nr   )choose_pluginr   )r   ro   r   )r   ro   s     r   r9   zChoosePluginTest._call   s    ET\\;77r!   c                     t         j                  dft         j                  dfg |       j                  _        | j                  | j                         k(  sJ  |       j                  j                  dk(  sJ y )Nr   r<   )display_utilOKmenuside_effectrl   r9   notificationr>   r   	mock_utils     r   test_selectionzChoosePluginTest.test_selection   s`    )5!(<)5!(<(>	$$**,...{''22a777r!   c                     t         j                  dfg |       j                  _        | j                  | j                         k(  sJ y rA   )rq   rr   rs   rt   rl   r9   rv   s     r   test_more_infozChoosePluginTest.test_more_info   s<     __a (
	$ $**,...r!   c                 t    t         j                  df |       j                  _        | j	                         J y )Nr   )rq   CANCELrs   r   r9   rv   s     r   test_no_choicezChoosePluginTest.test_no_choice   s/    )5)<)<a(@	%zz|###r!   N)r)   r*   r+   r,   r6   r9   	test_utilpatch_display_utilrx   rz   r}   r-   r!   r   r^   r^   z   sl    F
8 "Y!!#8 $8 "Y!!#/ $/ "Y!!#$ $$r!   r^   c                   @     e Zd ZdZ fdZd Zd Zd Zd Zd Z	 xZ
S )GetUnpreparedInstallerTestzGTests for certbot._internal.plugins.selection.get_unprepared_installer.c                    t         |           t        j                  d      | _        d | j                  _        t        j                  d      | _        d | j                  _        t        j                         | _        | j                  | j                  j                  _
        t        | j                  | j                  d      | _        y )Nafailra   c                     | dk(  S )Nr   r-   rk   s    r   <lambda>z2GetUnpreparedInstallerTest.setUp.<locals>.<lambda>   s
    47? r!   rb   c                     | dk(  S Nrb   r-   r   s    r   r   z2GetUnpreparedInstallerTest.setUp.<locals>.<lambda>   s    dh6F r!   )r   rb   )superr6   r   r   mock_apache_fail_ep
check_namemock_apache_epr2   mock_apache_pluginrJ   r   r   r   )r   	__class__s    r   r6   z GetUnpreparedInstallerTest.setUp   s    #'99")$+ .J  +"ii"*,)F&"&.."2040G0G  -&--))(
 r!   c                 H    ddl m}  || j                  | j                        S )Nr   )get_unprepared_installer)r   r   r   r   )r   r   s     r   r9   z GetUnpreparedInstallerTest._call   s    P'T\\BBr!   c                 J    d | j                   _        | j                         J y rE   )r   configuratorr9   r5   s    r   test_no_installer_definedz4GetUnpreparedInstallerTest.test_no_installer_defined   s     #' zz|###r!   c                     d| j                   _        t        i       | _        t	        j
                  t        j                        5  | j                          d d d        y # 1 sw Y   y xY wr   )	r   r   r   r   pytestraisesr   PluginSelectionErrorr9   r5   s    r   test_no_available_installersz7GetUnpreparedInstallerTest.test_no_available_installers   sJ    #+ &r*]]6667 	JJL	 	 	s   AA(c                 f    d| j                   _        | j                         }|| j                  u sJ y r   )r   r   r9   r   )r   	installers     r   test_get_pluginz*GetUnpreparedInstallerTest.test_get_plugin   s-    #+ JJL	D33333r!   c                     d| j                   _        d | j                  _        t	        j
                  t        j                        5  | j                          d d d        y # 1 sw Y   y xY w)Nrb   c                     | dk(  S r   r-   r   s    r   r   zNGetUnpreparedInstallerTest.test_multiple_installers_returned.<locals>.<lambda>   s    48;K r!   )	r   r   r   r   r   r   r   r   r9   r5   s    r   !test_multiple_installers_returnedz<GetUnpreparedInstallerTest.test_multiple_installers_returned   sL    #+ .K  +]]6667 	JJL	 	 	s   A!!A*)r)   r*   r+   r,   r6   r9   r   r   r   r   __classcell__)r   s   @r   r   r      s%    QC$4
r!   r   c                   4    e Zd ZdZd Zd Zd Zd Zd Zd Z	y)	TestChooseConfiguratorPluginszJTests for certbot._internal.plugins.selection.choose_configurator_plugins.c                     t        j                        }fd|_        t        j                         }|_        ||j
                  _        d|_        |S )Nr   c                     | k(  S rE   r-   )nrk   s    r   r   z@TestChooseConfiguratorPlugins._setupMockPlugin.<locals>.<lambda>   s    qDy r!   F)r   r   r   r2   rk   rJ   r   rK   )r   rk   mock_epmock_plugins    `  r   _setupMockPluginz.TestChooseConfiguratorPlugins._setupMockPlugin   sI    ))"&(0nn&$/! %r!   c                 n    ddl m} ddlm} |j	                  | j
                  |j                               S )Nr   )configuration)cli)certbotr   certbot._internalr   prepare_and_parse_argsr   split)r   argsr   r   s       r   
_parseArgsz(TestChooseConfiguratorPlugins._parseArgs   s%    ))))$,,

EEr!   c                     t        | j                  d      | j                  d      | j                  d      d      | _        y )Nnginxrb   manual)r   rb   r   )r   r   r   r5   s    r   r6   z#TestChooseConfiguratorPlugins.setUp   s=    &**73++H5++H5(
 r!   c                 T    ddl m}  || j                  |      | j                  d      S )Nr   )choose_configurator_pluginscertonly)r   r   r   r   )r   r   r   s      r   _runWithArgsz*TestChooseConfiguratorPlugins._runWithArgs   s"    S*4??4+@$,,PZ[[r!   c                     | j                  d      \  }}|j                  dk(  sJ |j                  dk(  sJ | j                  d      \  }}|j                  dk(  sJ |j                  dk(  sJ y )Nzcertonly --nginxr   zcertonly --apacherb   r   rk   r   instauths      r    test_noninteractive_configuratorz>TestChooseConfiguratorPlugins.test_noninteractive_configurator   sv     &&'9:
dyyG###yyG###&&':;
dyyH$$$yyH$$$r!   c                 <   | j                  d      \  }}|j                  dk(  sJ |j                  dk(  sJ | j                  d      \  }}|j                  dk(  sJ |j                  dk(  sJ | j                  d      \  }}|d k(  sJ |j                  dk(  sJ | j                  d      \  }}|d k(  sJ |j                  dk(  sJ | j                  d      \  }}|d k(  sJ |j                  dk(  sJ | j                  d      \  }}|d k(  sJ |j                  dk(  sJ y )	Nzcertonly -a nginx -i nginxr   zcertonly -a apache -i apacherb   zcertonly -a nginxzcertonly -a nginx -i nonezcertonly -a apachezcertonly -a apache -i noner   r   s      r   test_noninteractive_inst_argz:TestChooseConfiguratorPlugins.test_noninteractive_inst_arg   sB   &&'CD
dyyG###yyG###&&'EF
dyyH$$$yyH$$$ &&':;
dt||yyG###&&'BC
dt||yyG###&&';<
dt||yyH$$$&&'CD
dt||yyH$$$r!   N)
r)   r*   r+   r,   r   r   r6   r   r   r   r-   r!   r   r   r      s%    TF
\	%%r!   r   __main__r<   ) r,   rh   typingr   unittestr   r   r   r   r   certbot._internal.displayr   re   certbot._internal.plugins.discor   certbot.displayr	   rq   certbot.testsr~   TestCaser   r/   r^   ConfigTestCaser   r   r)   exitmainargv__file__r-   r!   r   <module>r      s    - 
       8 ; 0 +> 1 1 >8J/X&& J/Z'$x(( '$T*!9!9 *Z?%H$5$5 ?%B zCHH[V[[!"
234 r!   