
Y[c           @  s^  d  Z  d d l m Z d d l Z d d l Z d d l Z d d l Z d d l Z d d l Z d d l	 Z	 d d l
 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 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 d d l m Z d d l m Z d d l m  Z  d d l m! Z! d d l" j# j Z$ e$ j% d  Z& e$ j% d  Z' e$ j% d  Z( e$ j% d  Z) e j* j+ e$ j, d   Z- e$ j% d  Z. e$ j% d  Z/ d e j0 f d     YZ1 d e$ j2 f d     YZ3 d e j0 f d     YZ4 d  e j0 f d!     YZ5 d" e$ j6 f d#     YZ7 d$ e$ j2 f d%     YZ8 d& e$ j2 f d'     YZ9 d( e$ j2 f d)     YZ: d* e j0 f d+     YZ; d, e$ j2 f d-     YZ< d. e$ j2 f d/     YZ= d0 e$ j2 f d1     YZ> e? d2 k rZe j   n  d S(3   s   Tests for certbot.main.i(   t   print_functionN(   t   reload_module(   t   List(   t   account(   t   cli(   t	   constants(   t   configuration(   t   crypto_util(   t   errors(   t
   interfaces(   t   main(   t   updater(   t   util(   t   disco(   t   enhancements(   t   manual(   t   nulls   cert_512.pems   csr_512.ders   rsa256_key.pems   rsa512_key.pems   rsa2048_key.pems   cert_2048.pemt   TestHandleIdenticalCertsc           B  s   e  Z d  Z d   Z RS(   s4   Test for certbot.main._handle_identical_cert_requestc         C  sJ   t  j   } t | j _ t j t  j   |  } |  j | d | f  d  S(   Nt	   reinstall(   t   mockt   Mockt   Falset   ensure_deployedt   return_valueR
   t   _handle_identical_cert_requestt   assertEqual(   t   selft   mock_lineaget   ret(    (    s;   /usr/lib/python2.7/dist-packages/certbot/tests/main_test.pyt*   test_handle_identical_cert_request_pending1   s    (   t   __name__t
   __module__t   __doc__R   (    (    (    s;   /usr/lib/python2.7/dist-packages/certbot/tests/main_test.pyR   /   s   t   RunTestc           B  s\   e  Z d  Z d   Z d   Z d   Z d   Z d   Z d   Z e	 j
 d  d    Z RS(	   s   Tests for certbot.main.run.c         C  s  t  t |   j   d |  _ t j d  t j d  t j d  t j d  t j d  t j d  t j d  g |  _ |  j d	 j   |  _ |  j d
 j   |  _	 |  j d j   |  _
 |  j d j   |  _ |  j d j   |  _ |  j d j   |  _ |  j d j   |  _ d  S(   Ns   example.orgs   certbot.main._get_and_save_certs-   certbot.main.display_ops.success_installations(   certbot.main.display_ops.success_renewals   certbot.main._init_le_clients-   certbot.main._suggest_donation_if_appropriates   certbot.main._report_new_certs   certbot.main._find_certi    i   i   i   i   i   i   (   t   superR!   t   setUpt   domainR   t   patcht   patchest   startt	   mock_autht   mock_success_installationt   mock_success_renewalt	   mock_initt   mock_suggest_donationt   mock_report_certt   mock_find_cert(   R   (    (    s;   /usr/lib/python2.7/dist-packages/certbot/tests/main_test.pyR#   <   s     	c         C  s"   x |  j  D] } | j   q
 Wd  S(   N(   R&   t   stop(   R   R%   (    (    s;   /usr/lib/python2.7/dist-packages/certbot/tests/main_test.pyt   tearDownP   s    c         C  sc   d j  |  j  j   } t j j   } t j t j	 | |   } d d l
 m } | | |  d  S(   Ns   -a webroot -i null -d {0}i(   t   run(   t   formatR$   t   splitR   t   PluginsRegistryt   find_allR   t   NamespaceConfigR   t   prepare_and_parse_argst   certbot.mainR1   (   R   t   argst   pluginst   configR1   (    (    s;   /usr/lib/python2.7/dist-packages/certbot/tests/main_test.pyt   _callT   s    c         C  sH   t  j   |  j _ t d  f |  j _ |  j   |  j j	 |  j
 g  d  S(   N(   R   R   R(   R   t   Truet   NoneR.   R<   R)   t   assert_called_once_withR$   (   R   (    (    s;   /usr/lib/python2.7/dist-packages/certbot/tests/main_test.pyt   test_newcert_success]   s    
c         C  sN   t  j   |  j _ t t  j   f |  j _ |  j   |  j j |  j	 g  d  S(   N(
   R   R   R(   R   R   R.   R<   R)   R?   R$   (   R   (    (    s;   /usr/lib/python2.7/dist-packages/certbot/tests/main_test.pyt   test_reinstall_successc   s    
c         C  sN   t  j   |  j _ t t  j   f |  j _ |  j   |  j j |  j	 g  d  S(   N(
   R   R   R(   R   R=   R.   R<   R*   R?   R$   (   R   (    (    s;   /usr/lib/python2.7/dist-packages/certbot/tests/main_test.pyt   test_renewal_successi   s    
s1   certbot.main.plug_sel.choose_configurator_pluginsc         C  s\   t  j |  j d  d  f | _ t j j   } t |  j _	 |  j
 t j t j |  j |  d  S(   NR   (   R   t	   InstallerR;   R>   R   R   R4   R5   R=   t	   auto_hstst   assertRaisesR   t   NotSupportedErrorR
   R1   (   R   t   mock_chooseR:   (    (    s;   /usr/lib/python2.7/dist-packages/certbot/tests/main_test.pyt"   test_run_enhancement_not_supportedo   s    (   R   R   R    R#   R0   R<   R@   RA   RB   R   R%   RH   (    (    (    s;   /usr/lib/python2.7/dist-packages/certbot/tests/main_test.pyR!   9   s   							t   CertonlyTestc           B  s   e  Z d  Z d   Z d   Z d   Z e j d  e j d  e j d  d      Z e	 d  Z
 e j d	  e j d
  e j d  e j d  d       Z e j d
  e j d  e j d	  e j d  d       Z RS(   s    Tests for certbot.main.certonly.c         C  s%   t  j   |  _ |  j j   |  _ d  S(   N(   t	   test_utilt   patch_get_utilityt   get_utility_patchR'   t   mock_get_utility(   R   (    (    s;   /usr/lib/python2.7/dist-packages/certbot/tests/main_test.pyR#   |   s    c         C  s   |  j  j   d  S(   N(   RL   R/   (   R   (    (    s;   /usr/lib/python2.7/dist-packages/certbot/tests/main_test.pyR0      s    c         C  so   t  j j   } t j t j | |   } t j d  - } t j d   t	 j
 | |  Wd  QXWd  QX|   S(   Ns   certbot.main._init_le_clients-   certbot.main._suggest_donation_if_appropriate(   R   R4   R5   R   R6   R   R7   R   R%   R
   t   certonly(   R   R9   R:   R;   R+   (    (    s;   /usr/lib/python2.7/dist-packages/certbot/tests/main_test.pyR<      s    s   certbot.main._find_certs   certbot.main._get_and_save_certs   certbot.main._report_new_certc         C  sP   |  j    j } |  j | _ t j   | _ t d  f | _ |  j	 d j
    d  S(   Ns!   certonly --webroot -d example.com(   RM   t   notificationt   _assert_no_pauset   side_effectR   R   R   R   R>   R<   R3   (   R   t   unused_reportR(   R.   t   mock_notification(    (    s;   /usr/lib/python2.7/dist-packages/certbot/tests/main_test.pyt   test_no_reinstall_text_pause   s
    c         C  s   |  j  |  d  S(   N(   t   assertFalse(   R   t   messaget   pause(    (    s;   /usr/lib/python2.7/dist-packages/certbot/tests/main_test.pyRP      s    s)   certbot.cert_manager.lineage_for_certnames)   certbot.cert_manager.domains_for_certnames   certbot.renewal.renew_certc         C  s,  d d g } | | _  | | j _  |  j d j    |  j | j d k  |  j | j d k  |  j | j d k  |  j | j d k  |  j d j    |  j | j d k  |  j | j d k  |  j | j d k  |  j | j d k  t |  j   j _  |  j	 t
 j |  j d j    d  S(   Ns   example.coms   test.orgsE   certonly --webroot -d example.com -d test.org --cert-name example.comi   sE   certonly --webroot -d example.com -d test.com --cert-name example.comi   (   R   t   namesR<   R3   t
   assertTruet
   call_countR   RM   t   yesnoRE   R   t   ConfigurationError(   R   R-   t   mock_renew_certt   mock_domainsR   t   domains(    (    s;   /usr/lib/python2.7/dist-packages/certbot/tests/main_test.pyt*   test_find_lineage_for_domains_and_certname   s     	s    certbot.display.ops.choose_namesc         C  s   d  | _ |  j d j    |  j | j d k  |  j | j d k  d g | _ d  | _ |  j d j    |  j | j  d  S(   NsE   certonly --webroot -d example.com -d test.com --cert-name example.comi   t   somenames*   certonly --webroot --cert-name example.com(   R>   R   R<   R3   RY   RZ   t   called(   R   R-   R   t   mock_choose_namest   mock_domains_for_certname(    (    s;   /usr/lib/python2.7/dist-packages/certbot/tests/main_test.pyt*   test_find_lineage_for_domains_new_certname   s    		(   R   R   R    R#   R0   R<   R   R%   RT   R=   RP   R`   Re   (    (    (    s;   /usr/lib/python2.7/dist-packages/certbot/tests/main_test.pyRI   y   s    				!t   FindDomainsOrCertnameTestc           B  sV   e  Z d  Z e j d  d    Z e j d  d    Z e j d  d    Z RS(   s1   Tests for certbot.main._find_domains_or_certname.s    certbot.display.ops.choose_namesc         C  sA   t  j d d  d d   } d | _ |  j t j | d   d  d  S(   NR_   t   certnamet
   domainname(   Rh   N(   R   R   R>   R   R   R
   t   _find_domains_or_certname(   R   Rc   t   mock_config(    (    s;   /usr/lib/python2.7/dist-packages/certbot/tests/main_test.pyt   test_display_ops   s    	c         C  sA   t  j d d  d d   } g  | _ |  j t j t j | d   d  S(   NR_   Rg   (	   R   R   R>   R   RE   R   t   ErrorR
   Ri   (   R   Rc   Rj   (    (    s;   /usr/lib/python2.7/dist-packages/certbot/tests/main_test.pyt   test_no_results   s    	s)   certbot.cert_manager.domains_for_certnamec         C  sS   t  j d d  d d  } d d g | _ |  j t j | d   d d g d f  d  S(   NR_   Rg   s   one.coms   two.com(   R   R   R>   R   R   R
   Ri   (   R   R^   Rj   (    (    s;   /usr/lib/python2.7/dist-packages/certbot/tests/main_test.pyt   test_grab_domains   s    (   R   R   R    R   R%   Rk   Rm   Rn   (    (    (    s;   /usr/lib/python2.7/dist-packages/certbot/tests/main_test.pyRf      s   t
   RevokeTestc           B  s   e  Z d  Z d   Z d   Z d d  Z e j d  e j d  d     Z e j d  d    Z	 d	   Z
 e j d  e j d
  e j   d      Z RS(   s   Tests for certbot.main.revoke.c         C  sh  t  t |   j   t j t |  j  t j j	 t j j
 |  j d   |  _ t j d  t j d  t j d  t j d  g |  _ |  j d j   |  _ |  j d j   |  j d j   |  _ |  j d	 j   |  _ d
 d l m } t j   |  _ | j d d d t j d d d d d d d t j  |  _ | |  j t |  j  |  _ |  j d  f |  j _ d  S(   Ns   cert_512.pems'   acme.client.BackwardsCompatibleClientV2s   certbot.client.Clients   certbot.main._determine_accounts+   certbot.main.display_ops.success_revocationi    i   i   i   i(   t   Accountt   creation_hosts   test.certbot.orgt   creation_dti  i   i   i   i
   t   tzinfo(    R"   Ro   R#   t   shutilt   copyt	   CERT_PATHt   tempdirt   ost   patht   abspatht   joint   tmp_cert_pathR   R%   R&   R'   t   mock_acme_clientt   mock_determine_accountt   mock_success_revoket   certbot.accountRp   t	   MagicMockt   regrt   Metat   datetimet   pytzt   UTCt   metat   JWKt   accR>   R   (   R   Rp   (    (    s;   /usr/lib/python2.7/dist-packages/certbot/tests/main_test.pyR#      s(    	'c         C  s5   t  t |   j   x |  j D] } | j   q Wd  S(   N(   R"   Ro   R0   R&   R/   (   R   R%   (    (    s;   /usr/lib/python2.7/dist-packages/certbot/tests/main_test.pyR0   	  s    t    c         C  sm   d | } | j  |  j  j   } t j j   } t j t j	 | |   } d d l
 m } | | |  d  S(   Ns   revoke --cert-path={0} i(   t   revoke(   R2   R|   R3   R   R4   R5   R   R6   R   R7   R8   R   (   R   t
   extra_argsR9   R:   R;   R   (    (    s;   /usr/lib/python2.7/dist-packages/certbot/tests/main_test.pyR<     s    
s#   certbot.main._delete_if_appropriates   certbot.main.client.acme_clientc         C  s   t  | _ | j   j } g  } x} t j j   D]l \ } } |  j d |  | j t	 j
 t	 j |   |  j d | j    | j t	 j
 t	 j |   q. W|  j | | j  d  S(   Ns	   --reason (   R   R   t   BackwardsCompatibleClientV2R   R   t   REVOCATION_REASONSt   itemsR<   t   appendR   t   callt   ANYt   upperR   t   call_args_list(   R   R}   t   mock_delete_if_appropriatet   mock_revoket   expectedt   reasont   code(    (    s;   /usr/lib/python2.7/dist-packages/certbot/tests/main_test.pyt   test_revoke_with_reason  s    	 c         C  s*   |  j    t | _ |  j j |  j  d  S(   N(   R<   R   R   R   R?   R|   (   R   R   (    (    s;   /usr/lib/python2.7/dist-packages/certbot/tests/main_test.pyt   test_revocation_success'  s    
	c         C  sI   d d l  m } | j   |  j _ |  j | j |  j  |  j j   d  S(   Ni(   R   (	   t   acmeR   t   ClientErrorR}   RQ   RE   R<   R   t   assert_not_called(   R   t   acme_errors(    (    s;   /usr/lib/python2.7/dist-packages/certbot/tests/main_test.pyt   test_revocation_error-  s    s   certbot.cert_manager.deletec         C  s6   t  |   j _ t  | _ |  j   |  j | j  d  S(   N(   R   R[   R   R<   RU   Rb   (   R   RM   t   mock_deleteR   (    (    s;   /usr/lib/python2.7/dist-packages/certbot/tests/main_test.pyt   test_revocation_with_prompt3  s    	
(   R   R   R    R#   R0   R<   R   R%   R   R   R   RJ   RK   R   (    (    (    s;   /usr/lib/python2.7/dist-packages/certbot/tests/main_test.pyRo      s   		
	t   DeleteIfAppropriateTestc        	   B  s  e  Z d  Z d   Z d   Z e j   d    Z e j   d    Z e	 j
 d  e	 j
 d  e	 j
 d  e	 j
 d  e	 j
 d	  e j   d
         Z e	 j
 d  e	 j
 d  e	 j
 d  e	 j
 d  e	 j
 d  e j   d         Z e	 j
 d  e	 j
 d  e	 j
 d  e	 j
 d  e	 j
 d	  e j   d         Z e	 j
 d  e	 j
 d  e	 j
 d  e	 j
 d	  e	 j
 d  e j   d         Z e	 j
 d  e	 j
 d  e	 j
 d  e	 j
 d	  e	 j
 d  e j   d         Z e	 j
 d  e	 j
 d  e	 j
 d  e	 j
 d  e	 j
 d	  e j   d         Z e	 j
 d  e	 j
 d  e	 j
 d  e	 j
 d  e	 j
 d  e	 j
 d  e	 j
 d	  e j   d           Z e	 j
 d  e	 j
 d  e	 j
 d  e	 j
 d  e	 j
 d  e	 j
 d  e	 j
 d	  e j   d           Z e	 j
 d  e j   d     Z RS(   s.   Tests for certbot.main._delete_if_appropriate c         C  s   d d l  m } | |  d  S(   Ni(   t   _delete_if_appropriate(   R8   R   (   R   Rj   R   (    (    s;   /usr/lib/python2.7/dist-packages/certbot/tests/main_test.pyR<   @  s    c         C  sL   t  j d   } |  j |  j  Wd  QX| j   |  j |   j j  d  S(   Ns   certbot.cert_manager.delete(   R   R%   R<   R;   R   RY   t   add_messageRb   (   R   RM   R   (    (    s;   /usr/lib/python2.7/dist-packages/certbot/tests/main_test.pyt   _test_delete_opt_out_commonD  s    
c         C  s   t  |  j _ |  j |  d  S(   N(   R   R;   t   delete_after_revokeR   (   R   RM   (    (    s;   /usr/lib/python2.7/dist-packages/certbot/tests/main_test.pyt   test_delete_flag_opt_outJ  s    c         C  s&   |   } t  | j _ |  j |  d  S(   N(   R   R[   R   R   (   R   RM   t	   util_mock(    (    s;   /usr/lib/python2.7/dist-packages/certbot/tests/main_test.pyt   test_delete_prompt_opt_outO  s    	s)   certbot.storage.renewal_file_for_certnames   certbot.cert_manager.deletes-   certbot.cert_manager.match_and_check_overlapss!   certbot.storage.full_archive_paths)   certbot.cert_manager.cert_path_to_lineagec         C  sN   |  j  } d | _ d | _ d | _ t j   | _ |  j |  | j   d  S(   Ns   /some/reasonable/pathR   s   example.com(	   R;   t	   cert_pathRg   R   R   t   OverlappingMatchFoundRQ   R<   R   (   R   RM   t   mock_cert_path_to_lineaget   mock_archivet   mock_match_and_check_overlapsR   t   mock_renewal_file_for_certnameR;   (    (    s;   /usr/lib/python2.7/dist-packages/certbot/tests/main_test.pyt   test_overlapping_archive_dirsV  s    				s'   certbot.storage.cert_path_for_cert_namec         C  sQ   |  j  } d | _ d | _ d | _ t | _ |  j |  |  j | j d  d  S(   Ns   example.comR   s   /some/reasonable/pathi   (   R;   Rg   R   R   R   R<   R   RZ   (   R   RM   t   mock_cert_path_for_cert_nameR   R   t   mock_overlapping_archive_dirsR   R;   (    (    s;   /usr/lib/python2.7/dist-packages/certbot/tests/main_test.pyt   test_cert_name_onlyj  s    
					c         C  sQ   |  j  } d | _ d | _ d | _ t | _ |  j |  |  j | j d  d  S(   Ns   /some/reasonable/pathR   s   example.comi   (   R;   R   Rg   R   R   R<   R   RZ   (   R   RM   R   R   R   R   R   R;   (    (    s;   /usr/lib/python2.7/dist-packages/certbot/tests/main_test.pyt   test_cert_path_only}  s    
					c         C  sf   |  j  } t | j _ d | _ d | _ d | _ d | _ d | _ |  j |  |  j | j	 d  d  S(   Ns   /some/reasonable/pathR   s   example.comi   (
   R;   R=   t	   namespacet   noninteractive_modeR   Rg   R   R<   R   RZ   (   R   RM   R   R   t   mock_full_archive_dirR   R   R;   (    (    s;   /usr/lib/python2.7/dist-packages/certbot/tests/main_test.pyt   test_noninteractive_deletion  s    
						c         C  s|   |  j  } t | j _ d | _ d | _ d | _ d | _ d | _ |  j |  |  j | j	 d  |  j
 |   j j  d  S(   Ns   /some/reasonable/pathR   s   example.comi   (   R;   R=   R   R   R   Rg   R   R<   R   RZ   RU   R[   Rb   (   R   RM   R   R   R   R   R   R;   (    (    s;   /usr/lib/python2.7/dist-packages/certbot/tests/main_test.pyt   test_opt_in_deletion  s    
						c         C  sT   |  j  } d | _ d | _ | j | _ t | _ |  j |  |  j | j d  d  S(   Ns   example.coms   /some/reasonable/pathi   (   R;   Rg   R   R   R   R<   R   RZ   (   R   RM   R   R   R   R   R   R;   (    (    s;   /usr/lib/python2.7/dist-packages/certbot/tests/main_test.pyt!   test_certname_and_cert_path_match  s    
				s-   certbot.cert_manager.human_readable_cert_infos   certbot.storage.RenewableCertc	         C  s   |  j  }	 d |	 _ d |	 _ d } t j   | _ d | _ t | _ d d l m }
 |   } |
 j	 d f | j
 _ |  j |	  |  j | j d  d  S(	   Ns   example.coms   /some/reasonable/paths   something elseR   i(   R   i    i   (   R;   Rg   R   R   R   R   R   t   certbot.displayR   t   OKt   menuR<   R   RZ   (   R   RM   R   R   t   mock_RenewableCertt   mock_human_readable_cert_infoR   R   R   R;   t   display_utilR   (    (    s;   /usr/lib/python2.7/dist-packages/certbot/tests/main_test.pyt$   test_certname_and_cert_path_mismatch  s    						c	         C  s   |  j  }	 d |	 _ d |	 _ d | _ t j   | _ d | _ t | _ |   }
 t j d  |
 j	 _
 |  j t j |  j |	  | j   d  S(   Ns   example.coms   /some/reasonable/paths   some-reasonable-path.comR   s   Oh no.(   R;   Rg   R   R   R   R   R   R   t   MissingCommandlineFlagR   RQ   RE   Rl   R<   R   (   R   RM   R   R   R   R   R   R   R   R;   R   (    (    s;   /usr/lib/python2.7/dist-packages/certbot/tests/main_test.pyt/   test_noninteractive_certname_cert_path_mismatch  s    							c         C  sB   |  j  } d  | _ d  | _ |  j t j |  j |  | j   d  S(   N(	   R;   R>   Rg   R   RE   R   Rl   R<   R   (   R   RM   R   R;   (    (    s;   /usr/lib/python2.7/dist-packages/certbot/tests/main_test.pyt   test_no_certname_or_cert_path  s
    			(   R   R   R    R<   R   RJ   RK   R   R   R   R%   R   R   R   R   R   R   R   R   R   (    (    (    s;   /usr/lib/python2.7/dist-packages/certbot/tests/main_test.pyR   =  sv   		$$$$$$**t   DetermineAccountTestc           B  sk   e  Z d  Z d   Z d   Z d   Z d   Z e j d  d    Z	 e j d  d    Z
 d	   Z RS(
   s*   Tests for certbot.main._determine_account.c         C  s   t  t |   j   d  |  j _ d  |  j _ t |  j _ t	 j
 d d  t	 j
 d d  g |  _ t j   |  _ t	 j
   |  _ d |  j j _ d  S(   Nt   idt   xt   yt   hi(   R"   R   R#   R>   R;   R   t   emailR   t   register_unsafely_without_emailR   R   t   accst   AccountMemoryStoraget   account_storaget   mock_clientt	   directoryt	   new_authz(   R   (    (    s;   /usr/lib/python2.7/dist-packages/certbot/tests/main_test.pyR#     s    'c         C  sE   d d l  m } t j d    } |  j | _ | |  j  SWd  QXd  S(   Ni(   t   _determine_accounts'   certbot.main.account.AccountFileStorage(   R8   R   R   R%   R   R   R;   (   R   R   t   mock_storage(    (    s;   /usr/lib/python2.7/dist-packages/certbot/tests/main_test.pyR<     s    c         C  s   |  j  j |  j d |  j  |  j d j |  j _ |  j |  j d d  f |  j	    |  j |  j d j |  j j  |  j
 |  j j d  k  d  S(   Ni   (   R   t   saveR   R   R   R;   R   R   R>   R<   RY   R   (   R   (    (    s;   /usr/lib/python2.7/dist-packages/certbot/tests/main_test.pyt   test_args_account_set#  s
    # c         C  s}   |  j  j |  j d |  j  |  j |  j d d  f |  j    |  j |  j d j |  j j	  |  j
 |  j j d  k  d  S(   Ni    (   R   R   R   R   R   R>   R<   R   R;   R   RY   R   (   R   (    (    s;   /usr/lib/python2.7/dist-packages/certbot/tests/main_test.pyt   test_single_account*  s    # s)   certbot.client.display_ops.choose_accountc         C  s   x' |  j  D] } |  j j | |  j  q
 W|  j  d | _ |  j |  j  d d  f |  j    |  j t | j	 d d  t |  j    |  j |  j  d j
 |  j j  |  j |  j j d  k  d  S(   Ni   i    (   R   R   R   R   R   R   R>   R<   t   sett	   call_argsR   R;   R   RY   R   (   R   t   mock_choose_accountsR   (    (    s;   /usr/lib/python2.7/dist-packages/certbot/tests/main_test.pyt   test_multiple_accounts0  s    #$ s$   certbot.client.display_ops.get_emailc         C  s   d | _  t j d  O } |  j d t j j f | j _  |  j |  j d t j j f |  j    Wd  QX| j j	 |  j
 |  j d t j |  j |  j d j |  j
 j  |  j d |  j
 j  d  S(   Ns   foo@bar.bazs   certbot.main.clienti    t   tos_cb(   R   R   R%   R   t   sentinelR   t   registerR   R<   R?   R;   R   R   R   R   R   (   R   t   mock_get_emailt   client(    (    s;   /usr/lib/python2.7/dist-packages/certbot/tests/main_test.pyt   test_no_accounts_no_email;  s    	/	 c         C  s   d |  j  _ t j d  0 } |  j d t j j f | j _ |  j	   Wd  QX|  j
 |  j d j |  j  j  |  j
 d |  j  j  d  S(   Ns   other emails   certbot.main.clienti   (   R;   R   R   R%   R   R   R   R   R   R<   R   R   R   (   R   R   (    (    s;   /usr/lib/python2.7/dist-packages/certbot/tests/main_test.pyt   test_no_accounts_emailI  s     (   R   R   R    R#   R<   R   R   R   R%   R   R   R   (    (    (    s;   /usr/lib/python2.7/dist-packages/certbot/tests/main_test.pyR     s   				t   MainTestc           B  s  e  Z d  Z d   Z d   Z dg e d  Z dg d  Z d   Z	 d   Z
 d   Z d   Z e j d	  e j d
  e j d  e j d  e j d  d        Z e j d  e j d  d     Z e j d  e j d  e j d  d      Z e j d  e j d  e j d  d      Z e j d  e j d  d     Z e j d  e j d  e j d  e j d  d       Z e j d	  e j d  d     Z d   Z d   Z e j d  d    Z e j d  d    Z e j d   d!    Z d"   Z e j d#  e j d$  d%     Z e j d#  e j d$  d&     Z e j d#  e j d$  d'     Z e j d#  e j d$  d(     Z d)   Z  d*   Z! d+   Z" d,   Z# d-   Z$ d.   Z% d/   Z& dg d0  Z' e( j)   d1    Z* e j d2  e( j)   d3     Z+ d4   Z, dg dg e- e e e. j. j/   e d5  Z0 e j d2  d6    Z1 e j d2  d7    Z2 d8   Z3 d9   Z4 d:   Z5 e j d;  d<    Z6 e j d=  d>    Z7 d?   Z8 d@   Z9 dA   Z: dB   Z; dC   Z< dD   Z= dE   Z> dg dg dg dF  Z? dG   Z@ dH   ZA dI   ZB dJ   ZC dK   ZD e j dL  dM    ZE dN   ZF dO   ZG dP   ZH dQ   ZI dR   ZJ dS   ZK e( j)   e j dT  e j dU  dV      ZL dg dW  ZM dX   ZN dY   ZO e j dZ  e j d[  d\     ZP d]   ZQ e j dZ  e j d  d^     ZR d_   ZS d`   ZT da   ZU db   ZV e j dc  e( j)   dd     ZW e j dL  e j de  df     ZX RS(h   s   Tests for different commands.c         C  sZ   t  t |   j   t j |  j j  d |  j j d |  j j d |  j j d g |  _	 d  S(   Ns   --config-dirs
   --work-dirs
   --logs-dirs   --text(
   R"   R   R#   Rx   t   mkdirR;   t   logs_dirt
   config_dirt   work_dirt   standard_args(   R   (    (    s;   /usr/lib/python2.7/dist-packages/certbot/tests/main_test.pyR#   U  s
    c         C  s!   t  t  t t |   j   d  S(   N(   R   R   R"   R   R0   (   R   (    (    s;   /usr/lib/python2.7/dist-packages/certbot/tests/main_test.pyR0   ]  s    
c   	        s   | r t  j j     f d   } t j d  S } | | _ t j d  2 } |  j | |  \ } } } | | | | f SWd QXWd QXnC t j d  2 } |  j | |  \ } } } | | | | f SWd QXd S(   sa   Run the cli with output streams, actual client and optionally
        os.path.isfile() mocked outc           s?   |  j  d  s- |  j  d  s- |  j  d  r1 t S  |   Sd S(   s   Mock os.path.isfile()t   certt   chaint   privkeyN(   t   endswithR=   (   t   fnR9   t   kwargs(   t	   orig_open(    s;   /usr/lib/python2.7/dist-packages/certbot/tests/main_test.pyt   mock_isfilei  s
    s   os.path.isfiles   certbot.main.clientN(   Rx   Ry   t   isfileR   R%   RQ   t   _call_no_clientmock(	   R   R9   t   stdoutt
   mockisfileR   t   mock_ifR   R   t   stderr(    (   R   s;   /usr/lib/python2.7/dist-packages/certbot/tests/main_test.pyR<   c  s    		c         C  s   |  j  | } | r | n	 t j   } t j d d | C t j d  - } t j d   t j |  } Wd QXWd QXWd QX| | | f S(   s-   Run the client with output streams mocked outs   certbot.main.sys.stdoutt   news   certbot.main.sys.stderrs   certbot.util.atexitN(   R   t   sixt   StringIOR   R%   R
   (   R   R9   R   t
   toy_stdoutR   R   (    (    s;   /usr/lib/python2.7/dist-packages/certbot/tests/main_test.pyR   |  s    "c         C  s<   t  j d  ' } |  j g   |  j d | j  Wd  QXd  S(   Ns   certbot.main.runi   (   R   R%   R<   R   RZ   (   R   t   mock_run(    (    s;   /usr/lib/python2.7/dist-packages/certbot/tests/main_test.pyt   test_no_flags  s    c         C  s   t  j   } t  j   } t j d d |  t j d d | l z, y t j d g  Wn t k
 rn n XWd  | j   p | j   } |  j d | k d j |   XWd  QXWd  QXd  S(   Ns   certbot.main.sys.stdoutR   s   certbot.main.sys.stderrs	   --versiont   certbots   Output is {0}(	   R   R   R   R%   R
   t
   SystemExitt   getvalueRY   R2   (   R   t   toy_outt   toy_errt   output(    (    s;   /usr/lib/python2.7/dist-packages/certbot/tests/main_test.pyt    test_version_string_program_name  s     c         C  s   d } y/ t j d   t j |  j |  Wd QXWn5 t j k
 rl } | } |  j | t |  k  n X|  j | d k	  d S(   sQ   Ensure that a particular error raises a missing cli flag error containing messages   certbot.main.sys.stderrN(	   R>   R   R%   R
   R   R   R   RY   t   str(   R   R9   RV   t   exct   exc_(    (    s;   /usr/lib/python2.7/dist-packages/certbot/tests/main_test.pyt   _cli_missing_flag  s    c         C  sF   d d g } |  j  | d  | j d d d g  |  j  | d  d  S(   Ns   -nRN   s   specify a plugins   --standalones   -ds   eg.iss   register before running(   R  t   extend(   R   R9   (    (    s;   /usr/lib/python2.7/dist-packages/certbot/tests/main_test.pyt   test_noninteractive  s    s   certbot.main._report_new_certs&   certbot.main.client.acme_client.Clients   certbot.main._determine_accounts8   certbot.main.client.Client.obtain_and_enroll_certificates   certbot.main._get_and_save_certc         C  sE  d d d d d d d g |  j  } t j   d  f | _ t j   | _ t j d   } |  j |  t j   } | j	 d	 d
 }	 |  j
 | |	 k  d d  l }
 |
 j   } d | j   k r |  j
 t j   |	 k  n  Wd  QXt j d  O } d }	 | d |	 g 7} |  j |  | j t j d t j d t d
 |	 Wd  QXd  S(   Ns   --standaloneRN   s   -ms   none@none.coms   -ds   example.coms   --agree-toss-   certbot.main.client.acme_client.ClientNetworki   t
   user_agentit   linuxt   bandersnatchs   --user-agentR   t
   verify_ssl(   R   R   R   R>   R   R%   R   R   t   get_os_info_uaR   RY   t   platformt   lowerR?   R   R=   (   R   t   gsct   _obtt   dett   _clientRR   R9   t   acme_nett   os_vert   uaR  t   plat(    (    s;   /usr/lib/python2.7/dist-packages/certbot/tests/main_test.pyt   test_user_agent  s&    "s+   certbot.main.plug_sel.record_chosen_pluginss$   certbot.main.plug_sel.pick_installerc      
   C  sE   |  j  d d d d d d d d d	 g	 d
 t |  j | j d  d  S(   Nt   installs	   --domainss   foo.bars   --cert-pathR   s
   --key-pathR   s   --chain-pathR   R   i   (   R<   R=   R   RZ   (   R   t   mock_pick_installert   _rec(    (    s;   /usr/lib/python2.7/dist-packages/certbot/tests/main_test.pyt   test_installer_selection  s    s   certbot.main._install_certc      	   C  s   t  j d d d d d d d d  } t  j d  v } | | _ |  j d	 d
 d g d t | j d d } |  j | j d  |  j | j	 d  |  j | j
 d  Wd  QXd  S(   NR   s	   /tmp/certt
   chain_paths
   /tmp/chaint   fullchain_patht   key_paths   /tmp/privkeys)   certbot.cert_manager.lineage_for_certnameR  s   --cert-namet   whateverR   i    (   R   R   R%   R   R<   R=   R   R   R   R  R   (   R   t   _instR  t   mock_installR   t   mock_getlint   call_config(    (    s;   /usr/lib/python2.7/dist-packages/certbot/tests/main_test.pyt   test_installer_certname  s    		c      
   C  s>  t  j d d d d d d d d  } t  j d  } | | _ |  j d	 d
 d d d g d t | j d d } |  j | j d  |  j | j	 d  |  j | j
 d  |  j | j d  | j   |  j d	 d
 d d d g d t | j d d } |  j | j d  |  j | j	 d  |  j | j d  Wd  QXd  S(   NR   s	   /tmp/certR  s
   /tmp/chainR  R   s   /tmp/privkeys)   certbot.cert_manager.lineage_for_certnameR  s   --cert-nameR!  s
   --key-paths   /tmp/overriding_privkeyR   i    s   --cert-paths   /tmp/overriding_cert(   R   R   R%   R   R<   R=   R   R   R   R  R  R   t   reset(   R   R"  R  R#  R   R$  R%  (    (    s;   /usr/lib/python2.7/dist-packages/certbot/tests/main_test.pyt   test_installer_param_override  s&    		
c         C  s,   |  j  t j |  j d d d d d g  d  S(   NR  s   --cert-namet   notfounds
   --key-patht   invalid(   RE   R   R\   R<   (   R   R"  R  (    (    s;   /usr/lib/python2.7/dist-packages/certbot/tests/main_test.pyt   test_installer_param_error  s    	s"   certbot.cert_manager.get_certnamesc      	   C  s   t  j d d d d d d d d  } t  j d  & } | | _ |  j d	 g d
 t Wd  QX|  j | j  |  j | j  d  S(   NR   s	   /tmp/certR  s
   /tmp/chainR  R   s   /tmp/privkeys)   certbot.cert_manager.lineage_for_certnameR  R   (   R   R   R%   R   R<   R=   RY   Rb   (   R   t	   mock_instt   mock_getcertR"  R  R   R$  (    (    s;   /usr/lib/python2.7/dist-packages/certbot/tests/main_test.pyt   test_installer_select_cert  s    		s   certbot.util.exe_existsc         C  sz  t  | _ t j j   } d d d g } d d d d d d d	 d
 d d d g } d | k r |  j |  \ } } } } |  j d | k  |  j d | k  n  |  j d g d  t j	 d  v } t j	 d  ^ } t j
   | _ |  j d d d d g  | j d \ }	 }
 } |  j t |
 t j   Wd  QXWd  QXt j	 d  - } |  j d d g  |  j d | j  Wd  QXd  S(   Ns   --apaches   --authenticatort
   standaloneR  s   --nginxs   --cert-paths	   /tmp/blahs
   --key-paths   --nginx-server-roots   /nonexistent/things   -ds   example.coms   --debugt   nginxs   The nginx plugin is not workingt   MisconfigurationErrors   --standalones(   With the standalone plugin, you probablys   certbot.main._init_le_clients   certbot.main._get_and_save_certRN   s   --manuals   foo.bari    s   certbot.main.certonlyt   authi   (   R=   R   R   R4   R5   R<   RY   R  R   R%   R   R   t
   isinstanceR   t   AuthenticatorR   RZ   (   R   t   mock_exe_existsRR   t   real_pluginsR9   R   t   _R+   t   mock_gsct   unused_configR2  t   unused_installert   mock_certonly(    (    s;   /usr/lib/python2.7/dist-packages/certbot/tests/main_test.pyt   test_configurator_selection  s(    	
	%c         C  s~   |  j  d g  \ } } } } |  j d | j j  |  j  d d d g  \ } } } } | j j t j d t j t j  d  S(   Nt   rollbacki   s   --checkpointst   123i{   (   R<   R   R=  RZ   R?   R   R   (   R   R7  R   (    (    s;   /usr/lib/python2.7/dist-packages/certbot/tests/main_test.pyt   test_rollback5  s
    $	c         C  s8   |  j  d g  \ } } } } |  j d | j j  d  S(   Nt   config_changesi   (   R<   R   t   view_config_changesRZ   (   R   R7  R   (    (    s;   /usr/lib/python2.7/dist-packages/certbot/tests/main_test.pyt   test_config_changes=  s    s)   certbot.cert_manager.update_live_symlinksc         C  s'   |  j  d g  |  j d | j  d  S(   Nt   update_symlinksi   (   R   R   RZ   (   R   t   mock_cert_manager(    (    s;   /usr/lib/python2.7/dist-packages/certbot/tests/main_test.pyt   test_update_symlinksA  s    s!   certbot.cert_manager.certificatesc         C  s'   |  j  d g  |  j d | j  d  S(   Nt   certificatesi   (   R   R   RZ   (   R   RD  (    (    s;   /usr/lib/python2.7/dist-packages/certbot/tests/main_test.pyt   test_certificatesF  s    s   certbot.cert_manager.deletec         C  s'   |  j  d g  |  j d | j  d  S(   Nt   deletei   (   R   R   RZ   (   R   RD  (    (    s;   /usr/lib/python2.7/dist-packages/certbot/tests/main_test.pyt   test_deleteK  s    c           sl   d d d d g   xS t  j   f d   t j j t     D   D]  } |  j d g t |   qD Wd  S(   Ns   --inits	   --prepares   --authenticatorss   --installersc         3  s!   |  ] } t  j   |  Vq d  S(   N(   t	   itertoolst   combinations(   t   .0t   r(   t   flags(    s;   /usr/lib/python2.7/dist-packages/certbot/tests/main_test.pys	   <genexpr>S  s   R:   (   RJ  R   R   t   movest   ranget   lenR<   t   list(   R   R9   (    (   RN  s;   /usr/lib/python2.7/dist-packages/certbot/tests/main_test.pyt   test_pluginsP  s
    	#s   certbot.main.plugins_discos<   certbot.main.cli.HelpfulArgumentParser.determine_help_topicsc         C  s   g  } | j  j   } t j   } t j d |  & |  j d g |  \ } } } } Wd  QX| j j   | j   j	 j |  | j   j	   } |  j
 | j   j   t |   d  S(   NR   R:   (   R4   R5   R   R   RJ   t   patch_get_utility_with_stdoutR<   t   visibleR?   t   ifacesR   R   t   stripR  (   R   t   _dett
   mock_discoRV  R:   R   R7  t   filtered(    (    s;   /usr/lib/python2.7/dist-packages/certbot/tests/main_test.pyt   test_plugins_no_argsW  s    'c   
      C  s   g  } | j  j   } d   } t j   } t j d  J } t j d |  / | | _ |  j	 d g |  \ } } } } Wd  QXWd  QX| j
 j   | j
   j j |  | j
   j   }	 |  j | j   j   t |	   d  S(   Nc         S  s.   |  | | | f \ } } } } t  j    d S(   s   Raises error.Error.N(   R   Rl   (   R   t   modet   uidt   strictR7  (    (    s;   /usr/lib/python2.7/dist-packages/certbot/tests/main_test.pyt   throw_errorl  s    s   certbot.util.set_up_core_dirR   R:   (   R4   R5   R   R   R   R%   RJ   RT  RQ   R<   RU  R?   RV  R   R   RW  R  (
   R   RX  RY  RV  R:   R_  R   t   mock_set_up_core_dirR7  RZ  (    (    s;   /usr/lib/python2.7/dist-packages/certbot/tests/main_test.pyt!   test_plugins_no_args_unprivilegedf  s    		-c   	      C  s   g  } | j  j   } t j   } t j d |  ) |  j d d g |  \ } } } } Wd  QX| j j   | j   j	 j |  | j   j	   } |  j
 | j j d  | j j |  | j   } |  j
 | j   j   t |   d  S(   NR   R:   s   --initi   (   R4   R5   R   R   RJ   RT  R<   RU  R?   RV  R   t   initRZ   t   verifyR   RW  R  (	   R   RX  RY  RV  R:   R   R7  RZ  t   verified(    (    s;   /usr/lib/python2.7/dist-packages/certbot/tests/main_test.pyt   test_plugins_init|  s    *c   
      C  s  g  } | j  j   } t j   } t j d |  , |  j d d d g |  \ } } } } Wd  QX| j j   | j   j	 j |  | j   j	   } |  j
 | j j d  | j j |  | j   } | j j   | j j   | j   }	 |  j
 | j   j   t |	   d  S(   NR   R:   s   --inits	   --preparei   (   R4   R5   R   R   RJ   RT  R<   RU  R?   RV  R   Rb  RZ   Rc  t   preparet	   availableR   RW  R  (
   R   RX  RY  RV  R:   R   R7  RZ  Rd  Rg  (    (    s;   /usr/lib/python2.7/dist-packages/certbot/tests/main_test.pyt   test_plugins_prepare  s    -c         C  s   d } d } d } d } t  j d  / } |  j d d | d d d	 d d
 d g	  Wd  QX| j d \ } } |  j | j t j j |   |  j | j	 t j j |   |  j | j
 t j j |   |  j | j t j j |   d  S(   NR   t   keyR   t	   fullchains   certbot.main.certonlyRN   s   --cert-paths
   --key-paths   --chain-paths   --fullchain-pathi    (   R   R%   R<   R   R   R   Rx   Ry   Rz   R   R  R  (   R   R   Ri  R   Rj  R;  R;   t   unused_plugins(    (    s;   /usr/lib/python2.7/dist-packages/certbot/tests/main_test.pyt   test_certonly_abspath  s    c         C  sb   y, |  j  d d d g  t s+ t d   Wn/ t j k
 r] } |  j d t |  k  n Xd  S(   Ns   -at   bad_authRN   s!   Exception should have been raiseds-   The requested bad_auth plugin does not appear(   R<   R   t   AssertionErrorR   t   PluginSelectionErrorRY   R  (   R   t   e(    (    s;   /usr/lib/python2.7/dist-packages/certbot/tests/main_test.pyt   test_certonly_bad_args  s
    c         C  sq   |  j  t j |  j d d d g  |  j  t j |  j d d d d d g  |  j  t j |  j d d g  d  S(   Ns   -dt   ai@   i2   t   .i
   s   204.11.231.35(   RE   R   R\   R<   (   R   (    (    s;   /usr/lib/python2.7/dist-packages/certbot/tests/main_test.pyt   test_check_config_sanity_domain  s    c         C  s,   |  j  t j |  j d j t  j    d  S(   Ns*   certonly --csr {0} --allow-subset-of-names(   RE   R   Rl   R<   R2   t   CSRR3   (   R   (    (    s;   /usr/lib/python2.7/dist-packages/certbot/tests/main_test.pyt   test_csr_with_besteffort  s    c         C  s_   y |  j  d t g  Wn/ t j k
 rH } d t |  k sD t  d  SXt s[ t d   d  S(   Ns   --csrs   Please try the certonlys2   Expected supplying --csr to fail with default verb(   R<   Ru  R   Rl   t   reprRn  R   (   R   Rp  (    (    s;   /usr/lib/python2.7/dist-packages/certbot/tests/main_test.pyt   test_run_with_csr  s    c         C  s5   |  j  t j |  j d j t j d   j    d  S(   Ns   certonly --csr {0}s   csr-nonames_512.pem(   RE   R   Rl   R<   R2   RJ   t   vector_pathR3   (   R   (    (    s;   /usr/lib/python2.7/dist-packages/certbot/tests/main_test.pyt   test_csr_with_no_domains  s    c         C  s,   |  j  t j |  j d j t  j    d  S(   Ns!   certonly -d example.org --csr {0}(   RE   R   Rl   R<   R2   Ru  R3   (   R   (    (    s;   /usr/lib/python2.7/dist-packages/certbot/tests/main_test.pyt"   test_csr_with_inconsistent_domains  s    c      
   C  sx   t  j d  c } d | _ t  j d  B } | | _ | d  k rK g  } n  | d j   7} |  j |  Wd  QXWd  QXd  S(   Ns3   certbot.main._find_lineage_for_domains_and_certnamet   newcerts   certbot.main._init_le_clients!   -d foo.bar -a standalone certonly(   R|  N(   R   R%   R>   R   R3   R<   (   R   R   R9   t   mock_renewalR+   (    (    s;   /usr/lib/python2.7/dist-packages/certbot/tests/main_test.pyt   _certonly_new_request_common  s    			c         C  s   t  j   } d  | j _ |  j | d g  |  j | j j d  |  j d |   j	 j
 d d k  |  j |   j	 j d  d  S(   Ns	   --dry-runi   s   dry runi    (   R   R   R>   t   obtain_and_enroll_certificateR   R~  R   RZ   RY   R   R   (   R   RM   R   (    (    s;   /usr/lib/python2.7/dist-packages/certbot/tests/main_test.pyt)   test_certonly_dry_run_new_request_success  s    s   certbot.crypto_util.notAfterc   	   	   C  s   d } d } d } | |   j  _ t j d | d | d | d |  } t j   } | | j _ |  j |  |  j | j j d  |   j j	 d	 d	 d	 } |  j
 | | k  |  j
 | | k  |  j
 | | k  |  j
 d
 |   j j d	 d	 k  d  S(   Ns   /etc/letsencrypt/live/foo.bars   /etc/letsencrypt/live/baz.quxs
   1970-01-01R   Rj  R  R   i   i    t   donate(   t   dateR   R   R   R  R~  R   RZ   R   R   RY   R   (	   R   RM   t   mock_notAfterR   R   R  R   R   t   cert_msg(    (    s;   /usr/lib/python2.7/dist-packages/certbot/tests/main_test.pyt!   test_certonly_new_request_success  s"    c         C  s5   t  j   } t | j _ |  j t j |  j |  d  S(   N(	   R   R   R   R  R   RE   R   Rl   R~  (   R   R   (    (    s;   /usr/lib/python2.7/dist-packages/certbot/tests/main_test.pyt!   test_certonly_new_request_failure  s    c
           s+  t  j d  }
 d } t j d |
 d | d |
 d |  } | | j _ t | j _ d g | j _ t j   } t j d d	  } t j   } t	 j
     | d
 | d f | j _   f d   } zyt j d  x} | d  f | _ t j d  Q} | | _ t  j   3} | s&| |   j _ n  t j d  } t j   } d | j _ | | j j _ t j d   } | | j _ | sd d d d d g } n  | r| | 7} n  yW |  j |    \ }   } } | rt d |  t |   n  | st d   Wn& | s.t d t j     q.n XWd  QXWd  QXWd  QXWd  QXWd  QX| r|	 r| j j d g t j j |  j j d   q| j j d g d   n |  j  | j j! d  Wn |  j"     n XWd  | rt# t j j |  j j$ d     } |  j% | | j&   k  Wd  QXn  X| |   f S(   Ns   cert_512.pems+   /etc/letsencrypt/live/foo.bar/fullchain.pemR   Rj  R   R  s	   isnot.orgt   pemt   pem_keyR   t   csrc           s     j  |   d S(   s   Write message to stdout.N(   t   write(   RV   R9   R   (   R   (    s;   /usr/lib/python2.7/dist-packages/certbot/tests/main_test.pyt	   write_msg'  s    s+   certbot.cert_manager.find_duplicative_certss   certbot.main._init_le_clients   certbot.main.renewal.OpenSSLs	   Fake fakes    certbot.main.renewal.crypto_utils   -ds   -aR/  RN   t   Returneds   renewal should have erroreds   Unexpected renewal error:
s   live/sample-renewal/privkey.pemi    s   letsencrypt.log('   RJ   Ry  R   R   t   should_autorenewR   R   t   has_pending_deploymentRX   R   R   t   obtain_certificateR%   R>   RK   RO   RQ   t
   get_issuert   cryptot   load_certificatet   notAfterR<   t   printRn  t	   tracebackt
   format_excR?   Rx   Ry   R{   R;   R   R   RZ   t	   _dump_logt   openR   RY   t   read(   R   t   due_for_renewalR   t   log_outR9   t   should_renewt   error_expectedt
   quiet_modet   expiry_datet	   reuse_keyR   R  R   t
   mock_certrt   mock_keyR   R  t   mock_fdcR+   RM   t   mock_sslt   mock_latestt   mock_crypto_utilR   R7  t   lf(    (   R   s;   /usr/lib/python2.7/dist-packages/certbot/tests/main_test.pyt   _test_renewal_common  sr     	5
$#c         C  s   |  j  t g   \ } } } |  j | j j d  | j j | j    |   j j	 d d d } |  j
 d | k  |  j
 d |   j j d d k  d  S(   Ni   i    s   fullchain.pemR  (   R  R=   R   t   save_successorRZ   t   update_all_links_toR?   t   latest_common_versionR   R   RY   R   (   R   t   unused_notaftert   lineaget   get_utilityR7  R  (    (    s;   /usr/lib/python2.7/dist-packages/certbot/tests/main_test.pyt   test_certonly_renewal]  s    	c         C  s   |  j  t d d g d d \ } } } |  j |   j j d  |  j d |   j j d d k  |  j  t d d	 d
 g d d |  j |   j j d  |  j  t d	 d
 d g d d d t d  S(   Ns	   --dry-runs   --keepR  s   simulating renewali   s   dry runi    s   --renew-by-defaults   -tvvs   --debugs   Auto-renewal forceds   not yet dueR  (   R  R   R   R   RZ   RY   R   (   R   R  R7  R  (    (    s;   /usr/lib/python2.7/dist-packages/certbot/tests/main_test.pyt   test_certonly_renewal_triggersg  s    $c         C  sc   t  d  t j j |  j j d  } t j j |  r_ t |   } t  | j    Wd  QXn  d  S(   Ns   Logs:s   letsencrypt.log(	   R  Rx   Ry   R{   R;   R   t   existsR  R  (   R   t   log_pathR  (    (    s;   /usr/lib/python2.7/dist-packages/certbot/tests/main_test.pyR  v  s
    
c         C  sE   t  j |  j j d  d d d g } |  j t g  d | d t d  S(   Ns   sample-renewal.conft   renews	   --dry-runs   -tvvR9   R  (   RJ   t   make_lineageR;   R   R  R=   (   R   R9   (    (    s;   /usr/lib/python2.7/dist-packages/certbot/tests/main_test.pyt   test_renew_verb}  s    c      	   C  sK   t  j |  j j d  d d d g } |  j t g  d | d t d t d  S(   Ns   sample-renewal.confR  s	   --dry-runs   --reuse-keyR9   R  R  (   RJ   R  R;   R   R  R=   (   R   R9   (    (    s;   /usr/lib/python2.7/dist-packages/certbot/tests/main_test.pyt   test_reuse_key  s    s,   certbot.storage.RenewableCert.save_successorc      	   C  sH   t  j |  j j d  d d g } |  j t g  d | d t d t d  S(   Ns   sample-renewal.confR  s   --reuse-keyR9   R  R  (   RJ   R  R;   R   R  R=   (   R   t   unused_save_successorR9   (    (    s;   /usr/lib/python2.7/dist-packages/certbot/tests/main_test.pyt   test_reuse_key_no_dry_run  s    s   certbot.renewal.should_renewc      
   C  s   t  | _ t j |  j j d  t j j   t j d d  } |  j	 t  d d  d t  d d g d | \ } } } |  j d	 | j   k  |  j d
 | j   k  d  S(   Ns   sample-renewal.conft   daysiZ   R   R  R9   R  R  s   No renewals were attempted.s0   The following certs are not due for renewal yet:(   R   R   RJ   R  R;   R   R   t   nowt	   timedeltaR  R>   RY   R   (   R   R  t   expiryR7  R   (    (    s;   /usr/lib/python2.7/dist-packages/certbot/tests/main_test.pyt   test_renew_skips_recent_certs  s    	c      	   C  s   t  j |  j j d  d d g } |  j t g  d | d t \ } } } | j   } |  j d | k  d d d g } |  j t g  d | d t d t \ } } } | j   } |  j d |  d  S(	   Ns   sample-renewal.confR  s	   --dry-runR9   R  s   -qR  R   (	   RJ   R  R;   R   R  R=   R   RY   R   (   R   R9   R7  R   t   out(    (    s;   /usr/lib/python2.7/dist-packages/certbot/tests/main_test.pyt   test_quiet_renew  s    'c      	   C  sK   t  j |  j j d  d d d g } |  j t g  d | d t d t d  S(   Ns   sample-renewal.confR  s	   --dry-runs   --post-hook=no-such-commandR9   R  R  (   RJ   R  R;   R   R  R=   R   (   R   R9   (    (    s;   /usr/lib/python2.7/dist-packages/certbot/tests/main_test.pyt   test_renew_hook_validation  s    c         C  sd   t  j |  j j d  d d d d g } t j d  ' |  j t g  d | d t d	 t Wd  QXd  S(
   Ns   sample-renewal.confR  s	   --dry-runs   --post-hook=no-such-commands   --disable-hook-validations   certbot.hooks.post_hookR9   R  R  (	   RJ   R  R;   R   R   R%   R  R=   R   (   R   R9   (    (    s;   /usr/lib/python2.7/dist-packages/certbot/tests/main_test.pyt   test_renew_no_hook_validation  s    		c      
   C  s   t  j j |  j j d  } t  j j |  s= t  j |  n  t t  j j | d  d   Wd  QXd d d g } |  j t	 g  d | d t	 d	 t
 d  S(
   Nt   renewals
   empty.conft   wR  s	   --dry-runs   -tvvR9   R  R  (   Rx   Ry   R{   R;   R   R  t   makedirsR  R  R   R=   (   R   t   rdR9   (    (    s;   /usr/lib/python2.7/dist-packages/certbot/tests/main_test.pyt   test_renew_verb_empty_config  s    c      
   C  sB   t  j |  j j d  |  j t g  d t d d d d d g d  S(   Ns   sample-renewal.confR  R9   R  s	   --dry-runs   --cert-names   sample-renewal(   RJ   R  R;   R   R  R=   (   R   (    (    s;   /usr/lib/python2.7/dist-packages/certbot/tests/main_test.pyt   test_renew_with_certname  s    c      
   C  s2   |  j  t g  d t d d d d d g d t d  S(   NR  R9   R  s	   --dry-runs   --cert-names   sample-renewalR  (   R  R=   R   (   R   (    (    s;   /usr/lib/python2.7/dist-packages/certbot/tests/main_test.pyt   test_renew_with_bad_certname  s    c         C  s`   t  j j |  j j d  } t  j |  t t  j j | d  d   } | j d  Wd  QXd  S(   NR  s	   test.confR  s   My contents don't matter(   Rx   Ry   R{   R;   R   R  R  R  (   R   t   renewer_configs_dirt   f(    (    s;   /usr/lib/python2.7/dist-packages/certbot/tests/main_test.pyt   _make_dummy_renewal_config  s    !c         K  s   |  j    t j d   } t j   } d | _ | d  k	 rP i | d 6| _ n  | d  k	 rk | | j _ n  | | _ t j d  3 } | j	 d d g  |  j
 t d  d t | Wd  QX| d  k	 r | r |  j | j  q |  j | j  n  Wd  QXd  S(   Ns   certbot.storage.RenewableCerts   somepath/fullchain.pemt   renewalparamss   certbot.main.renew_certR9   R  R  (   R  R   R%   R   Rj  R>   R   RX   R   t
   setdefaultR  R=   R   RY   Rb   RU   (   R   R  RX   t   assert_oc_calledR   t   mock_rcR   R]   (    (    s;   /usr/lib/python2.7/dist-packages/certbot/tests/main_test.pyt   _test_renew_common  s     
		c         C  s   |  j  d t d t  d  S(   NR  R  (   R  R   R=   (   R   (    (    s;   /usr/lib/python2.7/dist-packages/certbot/tests/main_test.pyt   test_renew_no_renewalparams  s    c         C  s    |  j  d i  d t d t  d  S(   NR  R  R  (   R  R   R=   (   R   (    (    s;   /usr/lib/python2.7/dist-packages/certbot/tests/main_test.pyt   test_renew_no_authenticator  s    c         C  s4   i d d 6d d 6} |  j  d | d t d t  d  S(   Nt   webroott   authenticators	   over 9000t   rsa_key_sizeR  R  R  (   R  R=   R   (   R   R  (    (    s;   /usr/lib/python2.7/dist-packages/certbot/tests/main_test.pyt   test_renew_with_bad_int  s    

c         C  s.   i d d 6d d 6} |  j  d | d t  d  S(   NR  R  R>   t   http01_portR  R  (   R  R=   (   R   R  (    (    s;   /usr/lib/python2.7/dist-packages/certbot/tests/main_test.pyt   test_renew_with_nonetype_http01  s    

c      	   C  s<   i d d 6} d g } |  j  d | d t d | d t  d  S(   NR  R  s   uniçodé.comR  R  RX   R  (   R  R=   R   (   R   R  RX   (    (    s;   /usr/lib/python2.7/dist-packages/certbot/tests/main_test.pyt   test_renew_with_bad_domain  s    	s5   certbot.plugins.selection.choose_configurator_pluginsc         C  sN   t  j   t  j   f | _ i d d 6} |  j d | d t d d j    d  S(   NR  R  R  R  R9   s   renew --configurator apache(   R   R   R   R  R=   R3   (   R   t   mock_selR  (    (    s;   /usr/lib/python2.7/dist-packages/certbot/tests/main_test.pyt   test_renew_with_configurator  s
    	c         C  s5   i d d 6d d 6d d 6} |  j  d | d t  d  S(	   NR  R  R>   t   webroot_patht   42t   webroot_imaginary_flagR  R  (   R  R=   (   R   R  (    (    s;   /usr/lib/python2.7/dist-packages/certbot/tests/main_test.pyt$   test_renew_plugin_config_restoration  s
    

c      	   C  s6   i d d 6} |  j  d | d t d d d d g  d  S(	   NR  R  R  R  R9   R  s   --webroot-maps   {"example.com": "/tmp"}(   R  R=   (   R   R  (    (    s;   /usr/lib/python2.7/dist-packages/certbot/tests/main_test.pyt   test_renew_with_webroot_map  s    	c      	   C  s;   t  j d  & } t | _ |  j d t d t  Wd  QXd  S(   Ns"   certbot.main.renewal._reconstituteR  R  (   R   R%   t	   ExceptionRQ   R  R   R=   (   R   t   mock_reconstitute(    (    s;   /usr/lib/python2.7/dist-packages/certbot/tests/main_test.pyt   test_renew_reconstitute_error  s    	c         C  s   |  j    t j d   } t j   } d | _ | | _ i i d d 6d 6| _ t j d  5 } t | _ |  j	 t
 d  d t
 d d	 g d
 t Wd  QXWd  QXd  S(   Ns   certbot.storage.RenewableCerts   somewhere/fullchain.pemR  R  R  s   certbot.main.renew_certR  R9   R  R  (   R  R   R%   R   Rj  R   R   R  RQ   R  R=   R>   R   (   R   R  R   R]   (    (    s;   /usr/lib/python2.7/dist-packages/certbot/tests/main_test.pyt   test_renew_obtain_cert_error  s    
			c      	   C  s]   |  j  t d  d d j   d t d t |  j  t d  d d j t  j   d t d t d  S(   NR9   s   renew -d example.comR  R  s   renew --csr {0}(   R  R=   R>   R3   R   R2   Ru  (   R   (    (    s;   /usr/lib/python2.7/dist-packages/certbot/tests/main_test.pyt   test_renew_with_bad_cli_args!  s    $c         C  sS   |  j  d t d d  d t d d d d g  \ } } } |  j d | j   k  d  S(	   NR  R   R  R9   R  s   --post-hooks   echo hello worlds   No hooks were run.(   R  R   R>   RY   R   (   R   R7  R   (    (    s;   /usr/lib/python2.7/dist-packages/certbot/tests/main_test.pyt   test_no_renewal_with_hooks'  s    	s3   certbot.main._find_lineage_for_domains_and_certnames   certbot.main._init_le_clientc         C  s   d t  j   f | _ t  j   | _ } |  j d d d d d g  |  j | j j  |  j | j j  |  j |   j	 j
 d  d  S(   NR   s   -ds   foo.bars   -aR/  RN   i    (   R   R   R   R<   RU   R  Rb   R  R   R   RZ   (   R   R+   R}  RM   R   (    (    s;   /usr/lib/python2.7/dist-packages/certbot/tests/main_test.pyt   test_certonly_reinstall-  s    c         C  s  d } d } t  j   } | | f | j _ d } d } | d  | f | j _ t  j d   } | | _ t j   a } d }	 d j	 t
 | |	 |  j   }
 | r |
 | 7}
 n  t  j d   |  j |
  Wd  QXWd  QXWd  QXd	 |
 k r |  j | j j  n | j j | | | |	 |  | S(
   Nt   certrR   s.   /etc/letsencrypt/live/example.com/cert_512.pems/   /etc/letsencrypt/live/example.com/fullchain.pems   certbot.main._init_le_clients+   /etc/letsencrypt/live/example.com/chain.pemsV   -a standalone certonly --csr {0} --cert-path {1} --chain-path {2} --fullchain-path {3}s   certbot.main.crypto_utils	   --dry-run(   R   R   t   obtain_certificate_from_csrR   R>   t   save_certificateR%   RJ   RK   R2   Ru  R3   R<   RU   Rb   R?   (   R   R   R  R   R   R   t	   full_pathR+   RM   R  R9   (    (    s;   /usr/lib/python2.7/dist-packages/certbot/tests/main_test.pyt   _test_certonly_csr_common9  s,    		c         C  su   |  j    } |   j j d d d } |  j d | k  |  j d | k  |  j d |   j j d d k  d  S(   Ni    s   fullchain.pems   Your key file has been saved atR  (   R  R   R   RY   RU   R   (   R   RM   R  (    (    s;   /usr/lib/python2.7/dist-packages/certbot/tests/main_test.pyt   test_certonly_csrU  s    c         C  sS   |  j  d g  } |  j |   j j d  |  j d |   j j d d k  d  S(   Ns	   --dry-runi   s   dry runi    (   R  R   R   RZ   RY   R   (   R   RM   (    (    s;   /usr/lib/python2.7/dist-packages/certbot/tests/main_test.pyt   test_certonly_csr_dry_run]  s    s#   certbot.main._delete_if_appropriates   certbot.main.client.acme_clientc         C  s   t  | _ d } |  j d t d t d | d g  t t d  2 } | j j t j	 t
 j j | j    |  Wd  QXt t d  K } t j | j    d } | j   j } | j t
 j |  t j	  Wd  QXd  S(   Ns   foo.bars   --cert-paths
   --key-paths   --serverR   t   rbi    (   R   R   R   t   SS_CERT_PATHt   RSA2048_KEY_PATHR  R   R?   R   R   t   joseR   t   loadR  R   t   pyopenssl_load_certificateR   t   ComparableX509(   R   R}   R   t   serverR  R   R   (    (    s;   /usr/lib/python2.7/dist-packages/certbot/tests/main_test.pyt   test_revoke_with_keyc  s    		(c      
   C  s8   d } |  j  t j |  j d t d t d | d g  d  S(   Ns   foo.bars   --cert-paths
   --key-paths   --serverR   (   RE   R   Rl   R   t   CERTt   KEY(   R   R  (    (    s;   /usr/lib/python2.7/dist-packages/certbot/tests/main_test.pyt   test_revoke_with_key_mismatchu  s    c         C  s   t  | _ t j   d  f | _ |  j d t d g  \ } } } } t t  K } t j	 | j
    d } | j   j } | j t j |  t j  Wd  QXd  S(   Ns   --cert-pathR   i    (   R   R   R   R   R>   R<   R  R  R   R  R  t   acme_from_config_keyR   R?   R  R  R   (   R   R~   R   R7  R   R  R   R   (    (    s;   /usr/lib/python2.7/dist-packages/certbot/tests/main_test.pyt   test_revoke_without_key{  s    	$c         C  sH   t  j d  # } |  j d t j d  g  Wd  QX|  j | j  d  S(   Ns   certbot.main.runs   -cs   cli.ini(   R   R%   R<   RJ   Ry  RY   Rb   (   R   t
   mocked_run(    (    s;   /usr/lib/python2.7/dist-packages/certbot/tests/main_test.pyt   test_agree_dev_preview_config  s    "c         C  s   t  j d   } t  j   } d | _ | d f | j _ |  j d d d g  t  j d  ] } t  j   } | | j _ d g | j _ |  j d d d g  } |  j	 d	 | d
 k  Wd  QXWd  QXd  S(   Ns   certbot.main.clientt   imaginary_accountt   workedR   s   --emails   user@example.orgs   certbot.main.accounts
   an accounts   There is an existing accounti    (
   R   R%   R   R   R   R   R   t   AccountFileStorageR5   RY   (   R   t   mocked_clientR   t   mocked_accountt   mocked_storageR   (    (    s;   /usr/lib/python2.7/dist-packages/certbot/tests/main_test.pyt   test_register  s    	c      	   C  sr   t  j d  ] } t  j   } | | j _ g  | j _ |  j d d d d g  } |  j d | d k  Wd  QXd  S(   Ns   certbot.main.accountR   s   --update-registrations   --emails   user@example.orgs"   Could not find an existing accounti    (   R   R%   R   R  R   R5   R   RY   (   R   R  R  R   (    (    s;   /usr/lib/python2.7/dist-packages/certbot/tests/main_test.pyt-   test_update_registration_no_existing_accounts  s    	c         C  so   t  j d  Z } t  j   } | | j _ d g | j _ |  j d j    } |  j d | d k  Wd  QXd  S(   Ns   certbot.main.accounts
   an accounts@   register --update-registration --register-unsafely-without-emails!   --register-unsafely-without-emaili    (	   R   R%   R   R  R   R5   R   R3   RY   (   R   R  R  R   (    (    s;   /usr/lib/python2.7/dist-packages/certbot/tests/main_test.pyt!   test_update_registration_unsafely  s    s"   certbot.main.display_ops.get_emailc         C  sv  d } | | _  t j d  R} t j d  :} t j d  "} t j d  
} t j   } | | j _  d g | j _  t j   }	 |	 j }
 |	 d f | _  t j   } | | j _  |  j d d	 g  } |  j	 | d
 d  k  | j j j d
 d
 } |  j | |
 j    |  j	 | j j  |  j	 | |   j j d
 d
 k  |  j	 | j  Wd  QXWd  QXWd  QXWd  QXd  S(   Ns   user@example.coms   certbot.eff.handle_subscriptions   certbot.main._determine_accounts   certbot.main.accounts   certbot.main.clients
   an accountt   fooR   s   --update-registrationi    (   R   R   R%   R   R  R5   R   t   ClientR   RY   R>   R   t   update_registrationR   R   t   updatet	   save_regrRb   R   (   R   t   mock_utilityt
   mock_emailR   t   mock_handlet
   mocked_detR  R  R  t   mock_acct	   mock_regrt	   cb_clientR   t   reg_arg(    (    s;   /usr/lib/python2.7/dist-packages/certbot/tests/main_test.pyt#   test_update_registration_with_email  s.    		s   certbot.updater._run_updatersc         C  sa   t  j | _ |  j t  j t j d  d  d   t |  j _	 t
 j |  j d  d   |  j | j  d  S(   N(   R   Ro  RQ   RE   R
   t
   renew_certR>   R   R;   t   dry_runR   t   run_generic_updatersRU   Rb   (   R   R   RG   (    (    s;   /usr/lib/python2.7/dist-packages/certbot/tests/main_test.pyt   test_plugin_selection_error  s    N(Y   R   R   R    R#   R0   R>   R   R<   R   R   R  R  R	  R   R%   R  R  R&  R(  R+  R.  R<  R?  RB  RE  RG  RI  RS  R[  Ra  Re  Rh  Rl  Rq  Rt  Rv  Rx  Rz  R{  R~  RJ   RK   R  R  R  R=   R   R  R  R  R  R  R  R  R  R  R  R  R  R  R  R  R  R  R  R  R  R  R  R  R  R  R  R  R  R  R  R  R  R  R  R  R  R  R  R  R  R  R  (    (    (    s;   /usr/lib/python2.7/dist-packages/certbot/tests/main_test.pyR   R  s   						$!%											
		F
			
																				
							!t   UnregisterTestc           B  s5   e  Z d    Z d   Z d   Z d   Z d   Z RS(   c         C  sl   i t  j d  d 6t  j d  d 6t  j d  d 6t j   d 6|  _ t d   |  j j   D  |  _ d  S(	   Ns   certbot.main._determine_accountR   s   certbot.main.accountR   s   certbot.main.clientR   R  c         s  s'   |  ] \ } } | | j    f Vq d  S(   N(   R'   (   RL  t   kt   v(    (    s;   /usr/lib/python2.7/dist-packages/certbot/tests/main_test.pys	   <genexpr>  s    (   R   R%   RJ   RK   t   patcherst   dictR   t   mocks(   R   (    (    s;   /usr/lib/python2.7/dist-packages/certbot/tests/main_test.pyR#     s    c         C  s(   x! |  j  j   D] } | j   q Wd  S(   N(   R  t   valuesR/   (   R   R%   (    (    s;   /usr/lib/python2.7/dist-packages/certbot/tests/main_test.pyR0     s    c         C  ss   t  j   |  j d j _ |  j d   } t | j _ t  j   } t  j   } t j | |  } |  j	 | d  d  S(   NR   R  s   Deactivation aborted.(
   R   R   R  R  R   R   R[   R
   t
   unregisterR   (   R   R   R;   Rk  t   res(    (    s;   /usr/lib/python2.7/dist-packages/certbot/tests/main_test.pyt   test_abort_unregister  s    c         C  s   t  j   } d g | j _ | |  j d j _ t  j   d f |  j d _ t  j   } | |  j d j _ t  j   } t  j   } t j | |  } |  j	 | d  k  |  j	 | j j j  d } |  j	 | |  j d   j j d d k  d  S(	   Ns
   an accountR   R  R   R   s   Account deactivated.R  i    (   R   R   R5   R   R  R  R	  R
   R!  RY   R>   R   t   deactivate_registrationRb   R   R   (   R   R  R  R;   Rk  R"  t   m(    (    s;   /usr/lib/python2.7/dist-packages/certbot/tests/main_test.pyt   test_unregister  s    c         C  s   t  j   } g  | j _ | |  j d j _ t  j   } | |  j d j _ t  j   } t  j   } t j | |  } d } |  j	 | |  |  j
 | j j j  d  S(   NR   R   s.   Could not find existing account to deactivate.(   R   R   R5   R   R  R  R	  R
   R!  R   RU   R   R$  Rb   (   R   R  R  R;   Rk  R"  R%  (    (    s;   /usr/lib/python2.7/dist-packages/certbot/tests/main_test.pyt   test_unregister_no_account  s    (   R   R   R#   R0   R#  R&  R'  (    (    (    s;   /usr/lib/python2.7/dist-packages/certbot/tests/main_test.pyR    s
   				t   MakeOrVerifyNeededDirsc           B  s&   e  Z d  Z e j d  d    Z RS(   s2   Tests for certbot.main.make_or_verify_needed_dirs.s   certbot.main.utilc         C  s   t  j |  j  xH |  j j |  j j f D]. } | j j | t j t	 j
   |  j j  q) W|  j j |  j j |  j j f } x6 | D]. } | j j | d t	 j
   d |  j j q Wd  S(   NR]  R^  (   R
   t   make_or_verify_needed_dirsR;   R   R   t   set_up_core_dirt   assert_any_callR   t   CONFIG_DIRS_MODERx   t   geteuidt   strict_permissionst   renewal_pre_hooks_dirt   renewal_deploy_hooks_dirt   renewal_post_hooks_dirt   make_or_verify_dir(   R   t	   mock_utilt   core_dirt	   hook_dirst   hook_dir(    (    s;   /usr/lib/python2.7/dist-packages/certbot/tests/main_test.pyt   test_it&  s    					(   R   R   R    R   R%   R7  (    (    (    s;   /usr/lib/python2.7/dist-packages/certbot/tests/main_test.pyR(  #  s   t   EnhanceTestc           B  s0  e  Z d  Z d   Z d   Z d   Z e j d  e j d  e j d  e j d  d       Z e j d  e j d  e j d  e j d  d	       Z	 e j d  e j d  e j d  d
      Z
 e j d  e j d  e j d  d      Z e j d  e j d  d     Z d   Z e j d  e j d  e j d  d      Z e j d  e j d  e j d  e j d  e j   d        Z e j d  e j d  e j d  e j d  e j   d        Z d   Z RS(   s   Tests for certbot.main.enhance.c         C  sP   t  t |   j   t j   |  _ |  j j   |  _ t j	 d t
 j  |  _ d  S(   Nt   spec(   R"   R8  R#   RJ   RK   RL   R'   RM   R   R   R   t   AutoHSTSEnhancementt   mockinstaller(   R   (    (    s;   /usr/lib/python2.7/dist-packages/certbot/tests/main_test.pyR#   <  s    c         C  s   |  j  j   d  S(   N(   RL   R/   (   R   (    (    s;   /usr/lib/python2.7/dist-packages/certbot/tests/main_test.pyR0   B  s    c         C  s   t  j j   } t j t j | |   } t j d   } d g | _	 t j d  ] } d g | _	 t j d  9 } t j
   } | | _ | | _	 t j | |  | SWd  QXWd  QXWd  QXd  S(   Ns"   certbot.cert_manager.get_certnamess   example.coms)   certbot.cert_manager.domains_for_certnames   certbot.main._init_le_client(   R   R4   R5   R   R6   R   R7   R   R%   R   R   R;   R
   t   enhance(   R   R9   R:   R;   t
   mock_certst   mock_domR+   R   (    (    s;   /usr/lib/python2.7/dist-packages/certbot/tests/main_test.pyR<   E  s    		s+   certbot.main.plug_sel.record_chosen_pluginss)   certbot.cert_manager.lineage_for_certnames&   certbot.main.display_ops.choose_valuess&   certbot.main._find_domains_or_certnamec         C  s   t  j d d  | _ d g | _ d
 | _ t  j d  H } |  j d d g  |  j | j  |  j d | j d d	 k  Wd  QXd  S(   NR  s   /tmp/nonexistents   example.coms$   certbot.main.plug_sel.pick_installerR<  s
   --redirectR   i    i   (   NN(	   R   R   R   R>   R%   R<   RY   Rb   R   (   R   t	   mock_findRG   R   R  t	   mock_pick(    (    s;   /usr/lib/python2.7/dist-packages/certbot/tests/main_test.pyt   test_selection_questionU  s    	c         C  s   t  j d d  | _ d g | _ d | _ t  j d  y t  j d  c } |  j d d d d	 g  } |  j | j  |  j d
 | j d d k  |  j | j	 j  Wd  QXWd  QXd  S(   NR  s   /tmp/nonexistents   example.coms$   certbot.main.plug_sel.pick_installers$   certbot.main.plug_sel.logger.warningR<  s   -aR  s
   --redirects
   make sensei    (   NN(
   R   R   R   R>   R%   R<   RY   Rb   R   t   enhance_config(   R   R?  RG   R   R  t   mock_logR   (    (    s;   /usr/lib/python2.7/dist-packages/certbot/tests/main_test.pyt   test_selection_auth_warningc  s    	c         C  s   t  j d d  | _ d g | _ t  j d   |  j d d d g  } d d	 g } d
 g } |  j | j j  |  j t g  | D] } t	 | j
 |  ^ q   |  j t g  | D] } t	 | j
 |  ^ q   |  j d | j j d d k  Wd  QXd  S(   NR  s   /tmp/nonexistents   example.coms$   certbot.main.plug_sel.pick_installerR<  s
   --redirects   --hstst   redirectt   hstst   uiri    (   R   R   R   R%   R<   RY   RB  Rb   t   allt   getattrR;   RU   t   anyR   (   R   R  RG   R   R   t   req_enht   not_req_enhRp  (    (    s;   /usr/lib/python2.7/dist-packages/certbot/tests/main_test.pyt   test_enhance_config_callr  s    	,,c      	   C  sy   t  j d d  | _ d g | _ t  j d  C |  j d d d d g  } |  j | j j  |  j | j  Wd  QXd  S(	   NR  s   /tmp/nonexistents   example.coms$   certbot.main.plug_sel.pick_installerR<  s
   --redirects   --hstss   --non-interactive(	   R   R   R   R%   R<   RY   RB  Rb   RU   (   R   R  RG   R   R   (    (    s;   /usr/lib/python2.7/dist-packages/certbot/tests/main_test.pyt   test_enhance_noninteractive  s    	c      
   C  sE   g  | _  t j d  ' |  j t j |  j d d d g  Wd  QXd  S(   Ns$   certbot.main.plug_sel.pick_installerR<  s
   --redirects   --hsts(   R   R   R%   RE   R   Rl   R<   (   R   R  RG   (    (    s;   /usr/lib/python2.7/dist-packages/certbot/tests/main_test.pyt   test_user_abort_domains  s
    	c         C  s&   |  j  t j |  j d d d g  d  S(   NR<  s   -aR   (   RE   R   R1  R<   (   R   (    (    s;   /usr/lib/python2.7/dist-packages/certbot/tests/main_test.pyt   test_no_enhancements_defined  s    s1   certbot.main.plug_sel.choose_configurator_pluginsc         C  sP   d g | _  d | _  t j   | _ |  j d d g  } |  j | j j  d  S(   Ns   example.comR<  s   --hsts(   NN(	   R   R>   R   Ro  RQ   R<   RU   RB  Rb   (   R   R  RG   R@  R   (    (    s;   /usr/lib/python2.7/dist-packages/certbot/tests/main_test.pyR    s
    	s$   certbot.main.plug_sel.pick_installerc         C  s   |  j  | _ d d g | _ t j d d  | _ |  j d d g  |  j |  j  j j  |  j |  j  j j	 d d d d g  d  S(	   Ns   example.coms   another.tldR  s   /tmp/nonexistentR<  s   --auto-hstsi    i   (
   R;  R   R   R   R<   RY   t   enable_autohstsRb   t   assertEqualsR   (   R   R7  R  R,  RG   R   (    (    s;   /usr/lib/python2.7/dist-packages/certbot/tests/main_test.pyt   test_enhancement_enable  s    c         C  s_   t  j |  j d  | _ d d g | _ t j d d  | _ |  j t j |  j	 d d g  d  S(   NR   s   example.coms   another.tldR  s   /tmp/nonexistentR<  s   --auto-hsts(
   R   RC   R;   R   R   R   RE   R   RF   R<   (   R   R7  R  R,  RG   R   (    (    s;   /usr/lib/python2.7/dist-packages/certbot/tests/main_test.pyt%   test_enhancement_enable_not_supported  s    c         C  s&   |  j  t j |  j d d d g  d  S(   NR<  s   --auto-hstss   --hsts(   RE   R   Rl   R<   (   R   (    (    s;   /usr/lib/python2.7/dist-packages/certbot/tests/main_test.pyt    test_enhancement_enable_conflict  s    (   R   R   R    R#   R0   R<   R   R%   RA  RD  RM  RN  RO  RP  R  RJ   RK   RS  RT  RU  (    (    (    s;   /usr/lib/python2.7/dist-packages/certbot/tests/main_test.pyR8  9  sF   			!!	!
!	t   InstallTestc           B  se   e  Z d  Z d   Z e j d  e j d  d     Z e j d  e j d  d     Z RS(   s   Tests for certbot.main.install.c         C  s/   t  t |   j   t j d t j  |  _ d  S(   NR9  (   R"   RV  R#   R   R   R   R:  R;  (   R   (    (    s;   /usr/lib/python2.7/dist-packages/certbot/tests/main_test.pyR#     s    s+   certbot.main.plug_sel.record_chosen_pluginss$   certbot.main.plug_sel.pick_installerc         C  sb   t  j |  j d  | _ t j j   } t |  j _ d |  j _	 |  j
 t j t j |  j |  d  S(   NR   t   nonexistent(   R   RC   R;   R   R   R4   R5   R=   RD   Rg   RE   R   RF   R
   R  (   R   R,  R  R:   (    (    s;   /usr/lib/python2.7/dist-packages/certbot/tests/main_test.pyt&   test_install_enhancement_not_supported  s    c         C  sn   |  j  | _ t j j   } t |  j _ d  |  j _	 d |  j _
 d |  j _ |  j t j t j |  j |  d  S(   Ns   /tmp/nonexistent(   R;  R   R   R4   R5   R=   R;   RD   R>   Rg   R   R   RE   R   R\   R
   R  (   R   R,  R  R:   (    (    s;   /usr/lib/python2.7/dist-packages/certbot/tests/main_test.pyt$   test_install_enhancement_no_certname  s    (   R   R   R    R#   R   R%   RX  RY  (    (    (    s;   /usr/lib/python2.7/dist-packages/certbot/tests/main_test.pyRV    s   	
t   __main__(@   R    t
   __future__R    RJ  R   Rx   Rt   R  t   unittestR   R   t   josepyR  R   t	   six.movesR   t   acme.magic_typingR   R   R   R   R   R   R   R   R	   R
   R   R   t   certbot.pluginsR   R   R   R   t   certbot.tests.utilt   testsRJ   Ry  Rv   R  Ru  R  t   JWKRSAR  t   load_vectorR   R  R  t   TestCaseR   t   ConfigTestCaseR!   RI   Rf   t   TempDirTestCaseRo   R   R   R   R  R(  R8  RV  R   (    (    (    s;   /usr/lib/python2.7/dist-packages/certbot/tests/main_test.pyt   <module>   sh   
@UTD   > 