
    M/e5*                         d Z ddlZddlZddlmZ ddl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      Z	 	 	 	 	 ddZd Zy)z$Common utilities for certbot_apache.    N)mock)os)common)util)configurator)
entrypoint)objc                        e Zd Z	 	 	 ddZd Zy)
ApacheTestc                    t        j                  |t              \  | _        | _        | _        t        j                  j                  | j                  |      | _	        t        j                  j                  | j                  |      | _
        t        j                  j                  t        j                  d            | _        t#        | j                  || j                  | j
                        | _        t        j                  j                  | j                  d      }t        j                  j'                  |      sy t        j(                  |      D ]  }|dk(  r	t        j                  j                  ||      }t        j                  j+                  |      rIt        j,                  |       t        j                  j                  t        j                  j.                  d|      }t        j0                  ||        y )N)test_dirpkgzrsa512_key.pemzsites-enablednon-symlink.confzsites-available)r   	dir_setup__package__temp_dir
config_dirwork_dirr   pathjoinconfig_path
vhost_pathjoseJWKRSAload	test_utilload_vector	rsa512jwkget_apache_configuratorconfigexistslistdirislinkremovepardirsymlink)selfr   config_root
vhost_rootsites_enabledvhost_basenamevhosttargets           E/usr/lib/python3/dist-packages/certbot_apache/_internal/tests/util.pysetUpzApacheTest.setUp   s^    9?8H8H95t 77<<{C'',,t}}jA)))*?*?+  .d.>.>
.2oot}}N
 T%5%5Gww~~m, jj7 		*N!33GGLL?E77>>%(		% GGNN$5~G

65)		*    c                     t        j                  | j                         t        j                  | j                         t        j                  | j                         y )N)shutilrmtreer   r   r   )r'   s    r.   tearDownzApacheTest.tearDown5   s2    dmm$doo&dmm$r0   N!debian_apache_2_4/multiple_vhostsz)debian_apache_2_4/multiple_vhosts/apache2z9debian_apache_2_4/multiple_vhosts/apache2/sites-available)__name__
__module____qualname__r/   r4    r0   r.   r   r      s    @ET *D%r0   r   c                   &     e Zd Z	 	 	 d fd	Z xZS )
ParserTestc                 ~   t         |   |||       ddlm} t	        j
                  t        j
                  j                  t        j
                  j                  z        | _        t        j                  d      5   || j                  | j                  | j                        | _        d d d        y # 1 sw Y   y xY w)Nr   )ApacheParser)flagsEcertbot_apache._internal.parser.ApacheParser.update_runtime_variables)superr/   certbot_apache._internal.parserr>   augeasAugeasNONENO_MODL_AUTOLOADaugr   patchr   r    r   parser)r'   r   r(   r)   r>   	__class__s        r.   r/   zParserTest.setUp=   s     	hZ8@==--$$v}}'E'EEGZZ 3 4 	@&  $++t@DK	@ 	@ 	@s   <.B33B<r5   )r7   r8   r9   r/   __classcell__)rJ   s   @r.   r<   r<   ;   s    @ET@ @r0   r<   c	                    t         j                  j                  |d      }	t        j                  | dd| d|	|dt         j                  j                  |d      t         j                  j                  |	d      |      }
t        j
                  d      5  t        j
                  d	      5 }d
|_        t        j
                  d      5  t        j
                  d      5 }g |_        	 t        j                  |   } ||
d|||      }|s||j                  _        n||j                  _        |j                  j                   |j                  _        |j                  j$                  |j                  _        |j)                          ddd       ddd       ddd       ddd       S # t        $ r t        j                  }Y w xY w# 1 sw Y   BxY w# 1 sw Y   FxY w# 1 sw Y   JxY w# 1 sw Y   S xY w)zCreate an Apache Configurator with the specified options.

    :param conf: Function that returns binary paths. self.conf in Configurator

    backupsNz-le-ssl.confP   temp_checkpointsIN_PROGRESS)apache_server_rootapache_vhost_rootapache_le_vhost_extapache_challenge_locationapache_enmod
backup_dirr   http01_porttemp_checkpoint_dirin_progress_dirr   z5certbot_apache._internal.configurator.util.run_scriptz5certbot_apache._internal.configurator.util.exe_existsTr@   z:certbot_apache._internal.apache_util.parse_from_subprocessapache)r    nameversionuse_parsernodeopenssl_version)r   r   r   r   	MagicMockrH   return_valuer   OVERRIDE_CLASSESKeyErrorr   ApacheConfiguratorOS_DEFAULTSr)   r    rR   ctl
apache_ctlbin
apache_binprepare)r   r   r   r   r\   os_infoconf_vhost_pathr]   r^   rM   mock_le_configmock_exe_existsmock_spconfig_classr    s                  r.   r   r   K   s    ggll8Y/G^^&*"-GGLL3EFWm<N 
K	L %ZZ % & 	%)8+/O( 7 8 %ZZ \] %ah+-G(G'1'B'B7'K *h29.:IKF +>H00; ;J7/;/G/G/K/KFMM,/;/G/G/K/KFMM,NN$!%%	%%. M $ G'3'F'FG	% %% %	% 	%%. Msy   G((GGG	$F%7BG	GGG(%G>G	 GG	G	GGGG%	!G((G2c                 @   |dk(  r)t         j                  j                  | |d      }d|z   }t        j                  t         j                  j                  |d      t         j                  j                  |d      t        j
                  j                  d      hddd	      t        j                  t         j                  j                  |d
      t         j                  j                  |d      t        j
                  j                  d      hdd      t        j                  t         j                  j                  |d      t         j                  j                  |d      t        j
                  j                  d      t        j
                  j                  d      hddd      t        j                  t         j                  j                  |d      t         j                  j                  |d      t        j
                  j                  d      hddddg      t        j                  t         j                  j                  |d      t         j                  j                  |d      t        j
                  j                  d      hddd      t        j                  t         j                  j                  |d      t         j                  j                  |d      t        j
                  j                  d      hdd      t        j                  t         j                  j                  |d      t         j                  j                  |d      t        j
                  j                  d      hddddg      t        j                  t         j                  j                  |d      t         j                  j                  |d      t        j
                  j                  d       hddd!      t        j                  t         j                  j                  |d"      t         j                  j                  |d#      t        j
                  j                  d      hddd$      t        j                  t         j                  j                  |d      t         j                  j                  |d%      t        j
                  j                  d      hddd&      t        j                  t         j                  j                  | |d'      dt         j                  j                  | |d(      z   t        j
                  j                  d      hddd)      t        j                  t         j                  j                  |d*      t         j                  j                  |d+      t        j
                  j                  d,      hddd-      t        j                  t         j                  j                  |d.      t         j                  j                  |d/      t        j
                  j                  d       hddd-      g}|S |d0k(  rit         j                  j                  | |d1      }d|z   }t        j                  t         j                  j                  |d2      t         j                  j                  |d3      t        j
                  j                  d      hddd      t        j                  t         j                  j                  |d2      t         j                  j                  |d4      t        j
                  j                  d      hddd5      t        j                  t         j                  j                  |d6      t         j                  j                  |d7      t        j
                  j                  d      hddd8      t        j                  t         j                  j                  |d6      t         j                  j                  |d9      t        j
                  j                  d      hddd:      t        j                  t         j                  j                  |d6      t         j                  j                  |d;      t        j
                  j                  d      hddd<      g}|S y=)>z4Return the ground truth for the specified directory.r6   zapache2/sites-enabledz/fileszencryption-example.confz#encryption-example.conf/Virtualhostz*:80FTzencryption-example.demozdefault-ssl.confz%default-ssl.conf/IfModule/VirtualHostz_default_:443z000-default.confz000-default.conf/VirtualHostz[::]:80zip-172-30-0-17zcertbot.confzcertbot.conf/VirtualHostzcertbot.demozwww.certbot.demo)aliaseszmod_macro-example.confz(mod_macro-example.conf/Macro/VirtualHost)modmacrozdefault-ssl-port-only.confz/default-ssl-port-only.conf/IfModule/VirtualHostzwildcard.confzwildcard.conf/VirtualHostz*.blue.purple.comzocsp-ssl.confz"ocsp-ssl.conf/IfModule/VirtualHostz10.2.3.4:443zocspvhost.comr   znon-symlink.conf/VirtualHostznonsym.linkz&default-ssl-port-only.conf/VirtualHost zapache2/apache2.confz apache2/apache2.conf/VirtualHostzvhost.in.rootconfzduplicatehttp.confzduplicatehttp.conf/VirtualHostz10.2.3.4:80zduplicate.example.comzduplicatehttps.confz(duplicatehttps.conf/IfModule/VirtualHostzdebian_apache_2_4/multi_vhostszapache2/sites-availablezdefault.confzdefault.conf/VirtualHost[1]zdefault.conf/VirtualHost[2]zbanana.vomit.comzmulti-vhost.confzmulti-vhost.conf/VirtualHost[1]z1.multi.vhost.tldz%multi-vhost.conf/IfModule/VirtualHostz2.multi.vhost.tldzmulti-vhost.conf/VirtualHost[2]z3.multi.vhost.tldN)r   r   r   r	   VirtualHostAddr
fromstring)r   config_nameprefixaug_prevh_truths        r.   get_vh_truthr{      sY   99k#:< V#OOV%>?W&KL$$V,-t6	8
 OOV%78WDF$$_56d	D
 OOV%78W&DE$$V,XX((35t-/ OOV^4W&@A$$V,-ud);(<	>
 OOV%=>WGI$$V,-ud OOV%ABW (> @$$_56d	D
 OOV_5W&AB$$V,-ud +>*?	A
 OOV_5W&JK$$^45tT	!
 OOV%78W&DE$$V,-ud	
 OOV%ABWEG$$V,-tT2	?
 OOX{35277<<+(JL L$$V,-ud#% OOV%9:W&FG$$]34eT'	)
 OOV%:;W&PQ$$^45tT'	)CE*L 66k#<>V#OOV^4W&CD$$V,-t-	/
 OOV^4W&CD$$V,-t/	1
 OOV%78W&GH$$V,-t0	2
 OOV%78W&MN$$V,-t0	2
 OOV%78W&GH$$V,-t0	2+34 r0   ))         genericNFz1.1.1a)__doc__r2   unittestr   rC   josepyr   certbot.compatr   certbot.pluginsr   certbot.testsr   r   certbot_apache._internalr   r   r	   TestCaser   r<   r   r{   r:   r0   r.   <module>r      sg    *       " + 1 / ('%"" '%T@ @$ '0 1hmr0   