ó
Y[c           @   sY  d  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 j j Z e j d ƒ Z d „  Z d „  Z d	 e j f d
 „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ e d k rUe j ƒ  n  d S(   s   Tests for certbot.storage.iÿÿÿÿN(   t   cli(   t   errors(   t   ALL_FOURs   cert_512.pemc         C   s+   x$ t  D] } t j t |  | ƒ ƒ q Wd S(   s9   Unlink all four items associated with this RenewableCert.N(   R   t   ost   unlinkt   getattr(   t	   rc_objectt   kind(    (    s>   /usr/lib/python2.7/dist-packages/certbot/tests/storage_test.pyt
   unlink_all   s    c         C   sC   x< t  D]4 } t t |  | ƒ d ƒ  } | j | ƒ Wd QXq Wd S(   s9   Put dummy data into all four files of this RenewableCert.t   wN(   R   t   openR   t   write(   R   R   t   f(    (    s>   /usr/lib/python2.7/dist-packages/certbot/tests/storage_test.pyt   fill_with_sample_data    s    t   BaseRenewableCertTestc           B   s,   e  Z d  Z d „  Z d d „ Z d „  Z RS(   s¿   Base class for setting up Renewable Cert tests.

    .. note:: It may be required to write out self.config for
    your test.  Check :class:`.cli_test.DuplicateCertTest` for an example.

    c         C   sÝ  d d l  m } t t |  ƒ j ƒ  t j t j j |  j	 j
 d d ƒ ƒ t j j |  j	 j
 d d ƒ } t j | ƒ t j t j j |  j	 j
 d ƒ ƒ t j ƒ  } x= t D]5 } t j j |  j	 j
 d d | d ƒ } | | | <q¨ Wt t j j |  j	 j
 d d d ƒ d	 ƒ  Wd  QX| | d <t j j |  j	 j
 d d
 ƒ | _ | j ƒ  | |  _ t t j j |  j	 j
 d d ƒ d ƒ } | j d ƒ | j ƒ  t j ƒ  |  _ t j d ƒ + } t | _ | j | j |  j	 ƒ |  _ Wd  QXd  S(   Niÿÿÿÿ(   t   storaget   lives   example.orgt   archivet   renewals   .pemt   READMEt   as   example.org.confs   IGNORE.THISR	   s   This file should be ignored!s-   certbot.storage.RenewableCert._check_symlinks(   t   certbotR   t   superR   t   setUpR   t   makedirst   patht   joint   configt
   config_dirt	   configobjt	   ConfigObjR   R
   t   filenameR   t   config_filet   closet   defaultst   mockt   patcht   Truet   return_valuet   RenewableCertt   test_rc(   t   selfR   t   archive_pathR    R   t	   kind_patht   junkt   check(    (    s>   /usr/lib/python2.7/dist-packages/certbot/tests/storage_test.pyR   /   s4    %"

	'
	c      	   C   s¸   t  |  j | ƒ } t j j | ƒ r4 t j | ƒ n  t j t j j t j j t j j d d d j	 | | ƒ ƒ | ƒ t
 | d ƒ / } | j | d  k r§ | j d ƒ n | ƒ Wd  QXd  S(   NR   s   example.orgs
   {0}{1}.pemt   wbt   ascii(   R   R(   R   R   t   lexistsR   t   symlinkR   t   pardirt   formatR
   R   t   Nonet   encode(   R)   R   t   vert   valuet   linkR   (    (    s>   /usr/lib/python2.7/dist-packages/certbot/tests/storage_test.pyt   _write_out_kindV   s    $c         C   s5   x. t  D]& } |  j | d ƒ |  j | d ƒ q Wd  S(   Ni   i   (   R   R9   (   R)   R   (    (    s>   /usr/lib/python2.7/dist-packages/certbot/tests/storage_test.pyt   _write_out_ex_kinds`   s    N(   t   __name__t
   __module__t   __doc__R   R4   R9   R:   (    (    (    s>   /usr/lib/python2.7/dist-packages/certbot/tests/storage_test.pyR   '   s   	'
t   RenewableCertTestsc           B   s6  e  Z d  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 d	 „  Z d
 „  Z e j d ƒ d „  ƒ Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z e j d ƒ e j d ƒ d „  ƒ ƒ Z d „  Z d „  Z d „  Z e j d ƒ e j d ƒ d „  ƒ ƒ Z e j d ƒ d „  ƒ Z d „  Z d „  Z d  „  Z d! „  Z  d" „  Z! d# „  Z" d$ „  Z# e j d% ƒ e j d& ƒ d' „  ƒ ƒ Z$ d( „  Z% e j d ƒ d) „  ƒ Z& e j d ƒ d* „  ƒ Z' e j d+ ƒ d, „  ƒ Z( d- „  Z) d. „  Z* d/ „  Z+ d0 „  Z, d1 „  Z- d2 „  Z. d3 „  Z/ RS(4   s   Tests for certbot.storage.c      	   C   sf   |  j  |  j j d ƒ xI t D]A } |  j  t |  j | ƒ t j j |  j j	 d d | d ƒ ƒ q Wd  S(   Ns   example.orgR   s   .pem(
   t   assertEqualR(   t   lineagenameR   R   R   R   R   R   R   (   R)   R   (    (    s>   /usr/lib/python2.7/dist-packages/certbot/tests/storage_test.pyt   test_initializationj   s
    c         C   sŸ   d d l  m } t j j |  j j d ƒ } t | d ƒ  } | j d ƒ Wd QX|  j	 t
 j | j | |  j ƒ t j | ƒ |  j	 t
 j | j d |  j ƒ d S(   s€   Test that the RenewableCert constructor will complain if
        the renewal configuration file doesn't end in ".conf"

        iÿÿÿÿ(   R   s   broken.confR	   s   [No closing bracket for you!Nt   fun(   R   R   R   R   R   R   R   R
   R   t   assertRaisesR   t   CertStorageErrorR'   R   (   R)   R   t   brokenR   (    (    s>   /usr/lib/python2.7/dist-packages/certbot/tests/storage_test.pyt   test_renewal_bad_configq   s    c         C   sˆ   d d l  m } t j ƒ  } d | d <d | d <d | d <t j j |  j j d	 ƒ | _	 | j
 ƒ  |  j t j | j | j	 |  j ƒ d
 S(   sƒ   Test that the RenewableCert constructor will complain if
        the renewal configuration file is missing a required file element.iÿÿÿÿ(   R   s   imaginary_cert.pemt   certs   imaginary_chain.pemt   chains   imaginary_fullchain.pemt	   fullchains   imaginary_config.confN(   R   R   R   R   R   R   R   R   R   R   R   RC   R   RD   R'   (   R)   R   R   (    (    s>   /usr/lib/python2.7/dist-packages/certbot/tests/storage_test.pyt   test_renewal_incomplete_config€   s    



c         C   sx   d d l  m } |  j ƒ  |  j d |  j k ƒ t j d ƒ   } | j |  j j |  j	 ƒ Wd  QX|  j
 | j j ƒ d  S(   Niÿÿÿÿ(   R   t   versions   certbot.storage.logger(   R   R   R:   t
   assertTrueR    R#   R$   R'   R   R   t   assertFalset   warningt   called(   R)   R   t   mock_logger(    (    s>   /usr/lib/python2.7/dist-packages/certbot/tests/storage_test.pyt   test_no_renewal_versionŽ   s    
c         C   s   d d l  m } |  j ƒ  d |  j d <|  j j ƒ  t j d ƒ   } | j |  j j |  j	 ƒ Wd  QX|  j
 | j j ƒ |  j
 d | j j d d k ƒ d  S(   Niÿÿÿÿ(   R   s   99.99.99RK   s   certbot.storage.loggeri    (   R   R   R:   R    R   R#   R$   R'   R   R   RL   t   infoRO   t	   call_args(   R)   R   RP   (    (    s>   /usr/lib/python2.7/dist-packages/certbot/tests/storage_test.pyt   test_renewal_newer_version˜   s    
c      	   C   sT  |  j  j } d |  j  _ |  j |  j  j ƒ  ƒ | |  j  _ |  j |  j  j ƒ  ƒ t |  j  ƒ |  j |  j  j ƒ  ƒ t |  j  ƒ x= t D]5 } t j t j	 j
 d | d ƒ t |  j  | ƒ ƒ q‡ W|  j |  j  j ƒ  ƒ t |  j  ƒ xC t D]; } t j t j	 j
 |  j j | d ƒ t |  j  | ƒ ƒ qê W|  j |  j  j ƒ  ƒ t |  j  ƒ xF t D]> } t j t j	 j
 d d d d | d ƒ t |  j  | ƒ ƒ qSW|  j |  j  j ƒ  ƒ t |  j  ƒ |  j |  j  j ƒ  ƒ t j |  j  j ƒ t j t j	 j
 d d d d d ƒ |  j  j ƒ t |  j  j d ƒ  } | j d ƒ Wd  QX|  j |  j  j ƒ  ƒ d  S(	   Ns   relative/paths   ..s   17.pemR   s   example.orgs   fullchain_17.pemR	   s   wrongly-named fullchain(   R(   RG   RM   t   _consistentR   R   R   R   R1   R   R   R   R   R   RL   R   RI   R
   R   (   R)   t   oldcertR   R   (    (    s>   /usr/lib/python2.7/dist-packages/certbot/tests/storage_test.pyt   test_consistent¤   s>    "
c      	   C   s	  |  j  d d ƒ |  j t j j |  j j d ƒ t j j |  j j	 d d d ƒ ƒ ƒ t j
 |  j j ƒ t j t j j |  j j	 d d d ƒ |  j j ƒ t |  j j d ƒ  } | j d ƒ Wd  QX|  j t j j |  j j d ƒ t j j |  j j	 d d d ƒ ƒ ƒ d  S(   NRG   i   R   s   example.orgs
   cert17.pemR	   (   R9   RL   R   R   t   samefileR(   t   current_targetR   R   R   R   RG   R1   R
   R   (   R)   R   (    (    s>   /usr/lib/python2.7/dist-packages/certbot/tests/storage_test.pyt   test_current_targetÎ   s    c         C   s‚   x d
 D] } |  j  d | ƒ q Wt j |  j j ƒ t j t j j d d d d d	 ƒ |  j j ƒ |  j |  j j	 d ƒ d ƒ d  S(   Ni   i   i
   i   RG   s   ..R   s   example.orgs
   cert10.pem(   i   i   i
   i   (
   R9   R   R   R(   RG   R1   R   R   R?   t   current_version(   R)   R6   (    (    s>   /usr/lib/python2.7/dist-packages/certbot/tests/storage_test.pyt   test_current_versionà   s    c         C   s    |  j  |  j j d ƒ d  ƒ d  S(   NRG   (   R?   R(   R[   R4   (   R)   (    (    s>   /usr/lib/python2.7/dist-packages/certbot/tests/storage_test.pyt   test_no_current_versionè   s    c         C   sE  x> t  j j d d ƒ D]' } x t D] } |  j | | ƒ q# Wq W|  j |  j j ƒ  d ƒ |  j |  j j ƒ  d ƒ |  j d d ƒ |  j |  j j ƒ  d ƒ |  j |  j j ƒ  d ƒ |  j d d ƒ |  j d d ƒ |  j |  j j ƒ  d ƒ x t D] } |  j | d	 ƒ qõ W|  j |  j j ƒ  d	 ƒ |  j |  j j ƒ  d
 ƒ d  S(   Ni   i   i   t   privkeyi   i   RG   RI   i   i   (	   t   sixt   movest   rangeR   R9   R?   R(   t   latest_common_versiont   next_free_version(   R)   R6   R   (    (    s>   /usr/lib/python2.7/dist-packages/certbot/tests/storage_test.pyt   test_latest_and_next_versionsë   s    s   certbot.storage.loggerc         C   sØ   t  j ƒ  } |  j _ t  j ƒ  } |  j _ t  j ƒ  |  j _ t | _ |  j |  j j	 ƒ  t
 ƒ |  j | j d ƒ |  j | j j d ƒ t
 | _ |  j |  j j	 ƒ  t ƒ |  j | j d ƒ |  j | j j d ƒ d  S(   Ni    i   (   R#   t   MockR(   t   update_all_links_tot   has_pending_deploymentRb   t   FalseR&   R?   t   ensure_deployedR%   t
   call_countt   warn(   R)   RP   t   mock_updatet   mock_has_pending(    (    s>   /usr/lib/python2.7/dist-packages/certbot/tests/storage_test.pyt   test_ensure_deployed  s    		c         C   s5  xZ t  j j d d ƒ D]C } x: t D]2 } |  j | | ƒ |  j | |  j j | ƒ ƒ q# Wq W|  j j d d ƒ |  j j d d ƒ |  j d |  j j d ƒ ƒ |  j d |  j j d ƒ ƒ |  j d |  j j d ƒ ƒ |  j d |  j j d	 ƒ ƒ |  j j d d
 ƒ |  j t	 j
 j t	 j |  j j ƒ ƒ d ƒ d  S(   Ni   i   RG   i   R^   i   i   RH   RI   i¸  s   chain3000.pem(   R_   R`   Ra   R   R9   R?   R(   R[   t   _update_link_toR   R   t   basenamet   readlinkRH   (   R)   R6   R   (    (    s>   /usr/lib/python2.7/dist-packages/certbot/tests/storage_test.pyt   test_update_link_to  s    $$c         C   s?   |  j  d d ƒ |  j d t j j |  j j d d ƒ ƒ ƒ d  S(   NRG   i   s	   cert8.pemi   (   R9   R?   R   R   Rp   R(   RK   (   R)   (    (    s>   /usr/lib/python2.7/dist-packages/certbot/tests/storage_test.pyt   test_version&  s    	c         C   sð   xZ t  j j d d ƒ D]C } x: t D]2 } |  j | | ƒ |  j | |  j j | ƒ ƒ q# Wq W|  j |  j j ƒ  d ƒ xs t  j j d d ƒ D]\ } |  j j	 | ƒ x* t D]" } |  j | |  j j | ƒ ƒ q© W|  j |  j j ƒ  d ƒ qŒ Wd  S(   Ni   i   i   (
   R_   R`   Ra   R   R9   R?   R(   R[   Rb   Rf   (   R)   R6   R   (    (    s>   /usr/lib/python2.7/dist-packages/certbot/tests/storage_test.pyt    test_update_all_links_to_success.  s    $ c         C   s„   t  j d „ } |  j ƒ  t j d ƒ ) } | | _ |  j t |  j j	 d ƒ Wd  QXx* t
 D]" } |  j |  j j | ƒ d ƒ qZ Wd  S(   Nc         S   sD   t  j j |  ƒ } d | k r6 | j d ƒ r6 t ‚ n
 | |  ƒ d  S(   NRI   t   prev(   R   R   Rp   t
   startswitht
   ValueError(   R   t   real_unlinkRp   (    (    s>   /usr/lib/python2.7/dist-packages/certbot/tests/storage_test.pyt   unlink_or_raise;  s    	s   certbot.storage.os.unlinki   (   R   R   R:   R#   R$   t   side_effectRC   Rw   R(   Rf   R   R?   R[   (   R)   Ry   t   mock_unlinkR   (    (    s>   /usr/lib/python2.7/dist-packages/certbot/tests/storage_test.pyt(   test_update_all_links_to_partial_failure:  s    
	c         C   s„   t  j d „ } |  j ƒ  t j d ƒ ) } | | _ |  j t |  j j	 d ƒ Wd  QXx* t
 D]" } |  j |  j j | ƒ d ƒ qZ Wd  S(   Nc         S   s/   d t  j j |  ƒ k r! t ‚ n
 | |  ƒ d  S(   NRI   (   R   R   Rp   Rw   (   R   Rx   (    (    s>   /usr/lib/python2.7/dist-packages/certbot/tests/storage_test.pyRy   L  s    	s   certbot.storage.os.unlinki   i   (   R   R   R:   R#   R$   Rz   RC   Rw   R(   Rf   R   R?   R[   (   R)   Ry   R{   R   (    (    s>   /usr/lib/python2.7/dist-packages/certbot/tests/storage_test.pyt%   test_update_all_links_to_full_failureK  s    
	c         C   sù   xZ t  j j d d ƒ D]C } x: t D]2 } |  j | | ƒ |  j | |  j j | ƒ ƒ q# Wq Wx• t  j j d d ƒ D]~ } |  j j | ƒ x* t D]" } |  j | |  j j | ƒ ƒ q W| d k  rÛ |  j	 |  j j
 ƒ  ƒ qs |  j |  j j
 ƒ  ƒ qs Wd  S(   Ni   i   i   (   R_   R`   Ra   R   R9   R?   R(   R[   Rf   RL   Rg   RM   (   R)   R6   R   (    (    s>   /usr/lib/python2.7/dist-packages/certbot/tests/storage_test.pyt   test_has_pending_deployment[  s    $ c         C   s  |  j  d d t j d ƒ ƒ |  j |  j j ƒ  d d g ƒ |  j  d d t j d ƒ ƒ |  j |  j j d ƒ d d g ƒ |  j  d d t j d ƒ ƒ |  j |  j j d ƒ d g g  d	 D] } d
 j | ƒ ^ q· ƒ t j |  j j	 ƒ |  j
 t j |  j j ƒ d  S(   NRG   i   s   cert-san_512.pems   example.coms   www.example.comi   s   cert_512.pems   cert-5sans_512.pemt   abcds   {0}.example.com(   R9   t	   test_utilt   load_vectorR?   R(   t   namesR3   R   R   RG   RC   R   RD   (   R)   t   c(    (    s>   /usr/lib/python2.7/dist-packages/certbot/tests/storage_test.pyt
   test_namesi  s    *s   certbot.storage.clis   certbot.storage.datetimec   	      C   s  t  j d ƒ } |  j ƒ  |  j j d ƒ t |  j j d ƒ  } | j | ƒ Wd QX|  j j d ƒ t |  j j d ƒ  } | j | ƒ Wd QXt j	 | _	 t
 | j _ i  |  j j d <xVd d t f d d	 t f d d
 t
 f d d t
 f d d t f d d t f d d t
 f d d t
 f d d t
 f d d t
 f d d t f d d t f d d t f d d t f d d t f d d t f d d t f g D]‚ \ } } } t j j | ƒ } | | j j _ | |  j j d <| |  j j d <|  j |  j j ƒ  | ƒ |  j |  j j ƒ  | ƒ qŠWd S(   s\   Test should_autodeploy() and should_autorenew() on the basis
        of expiry time windows.s   cert_512.pemi   R.   Ni   t   renewalparamsi@*ŒTs   2 monthss   1 weeks   4 dayss   2 daysi@äúIs   7 yearss   11 years 2 monthss   8 hourss   40 dayss   9 monthsi Ž¤Ts	   0 secondss
   10 secondss
   10 minutess   10 weekss	   10 monthss   10 yearss	   99 monthst   deploy_before_expiryt   renew_before_expiry(   R€   R   R:   R(   Rf   R
   RG   R   t   datetimet	   timedeltaRh   t
   set_by_cliR&   t   configurationR%   t   utcfromtimestampt   utcnowR?   t   should_autodeployt   should_autorenew(	   R)   t   mock_datetimet   mock_clit	   test_certR   t   current_timet   intervalt   resultt   sometime(    (    s>   /usr/lib/python2.7/dist-packages/certbot/tests/storage_test.pyt   test_time_interval_judgments‚  s:    
+c         C   sf   |  j  |  j j ƒ  ƒ d |  j j d <|  j  |  j j ƒ  ƒ d |  j j d <|  j |  j j ƒ  ƒ d  S(   Nt   1t
   autodeployt   0(   RL   R(   t   autodeployment_is_enabledR‹   RM   (   R)   (    (    s>   /usr/lib/python2.7/dist-packages/certbot/tests/storage_test.pyt   test_autodeployment_is_enabled²  s
    c         C   s‘   d |  j  j d <|  j |  j  j ƒ  ƒ d |  j  j d <x> t j j d d ƒ D]' } x t D] } |  j | | ƒ qY WqL W|  j |  j  j ƒ  ƒ d S(   sW   Test should_autodeploy() on the basis of reasons other than
        expiry time window.Rš   R™   R˜   i   i   N(	   R(   R‹   RM   RŽ   R_   R`   Ra   R   R9   (   R)   R6   R   (    (    s>   /usr/lib/python2.7/dist-packages/certbot/tests/storage_test.pyt   test_should_autodeployº  s    c         C   s~   i  |  j  j d <|  j |  j  j ƒ  ƒ d |  j  j d d <|  j |  j  j ƒ  ƒ d |  j  j d d <|  j |  j  j ƒ  ƒ d  S(   NR…   R%   t	   autorenewRh   (   R(   R‹   RL   t   autorenewal_is_enabledRM   (   R)   (    (    s>   /usr/lib/python2.7/dist-packages/certbot/tests/storage_test.pyt   test_autorenewal_is_enabledÈ  s    s*   certbot.storage.RenewableCert.ocsp_revokedc         C   sš   t  | j _ i d d 6|  j j d <|  j |  j j ƒ  ƒ d |  j j d d <x t D] } |  j | d ƒ qT Wt	 | _ |  j
 |  j j ƒ  ƒ t  | _ d S(   sT   Test should_autorenew on the basis of reasons other than
        expiry time window.Rh   Rž   R…   R%   i   N(   Rh   RŠ   R&   R(   R‹   RM   R   R   R9   R%   RL   (   R)   t	   mock_ocspR‘   R   (    (    s>   /usr/lib/python2.7/dist-packages/certbot/tests/storage_test.pyt   test_should_autorenewÑ  s    	s   certbot.storage.relevant_valuesc         C   s\  d „  | _  x> t j j d d ƒ D]' } x t D] } |  j | | ƒ q/ Wq" W|  j j d ƒ |  j d |  j j	 d d d  d |  j ƒ ƒ t |  j j d d ƒ ƒ  } |  j | j ƒ  d ƒ Wd  QXt |  j j d d ƒ ƒ  } |  j | j ƒ  d ƒ Wd  QXt |  j j d	 d ƒ ƒ  } |  j | j ƒ  d ƒ Wd  QX|  j t j j |  j j d
 d ƒ ƒ ƒ |  j t j j |  j j d
 d ƒ ƒ ƒ |  j d |  j j	 d d d  d |  j ƒ ƒ |  j d |  j j	 d d d  d |  j ƒ ƒ xj d D]b } |  j t j j |  j j d
 | ƒ ƒ ƒ |  j d t j j t j |  j j d
 | ƒ ƒ ƒ ƒ qãWx[ t D]S } |  j |  j j | ƒ t t j j d d ƒ ƒ ƒ |  j |  j j | ƒ d ƒ qPW|  j j d ƒ |  j d |  j j	 d d d  d |  j ƒ ƒ x[ t D]S } |  j |  j j | ƒ t t j j d d ƒ ƒ ƒ |  j |  j j | ƒ d ƒ qéWt |  j j d	 d ƒ ƒ  } |  j | j ƒ  d ƒ Wd  QXt j j |  j j |  j j ƒ d } t | d ƒ  } | j d ƒ Wd  QX|  j d |  j j	 d d d d |  j ƒ ƒ |  j t j j |  j j d
 d ƒ ƒ ƒ |  j t j j |  j j d
 d ƒ ƒ ƒ |  j t j j | ƒ ƒ d  S(   Nc         S   s   |  S(   N(    (   t   x(    (    s>   /usr/lib/python2.7/dist-packages/certbot/tests/storage_test.pyt   <lambda>ç  s    i   i   i   s   new certs	   new chainRG   RH   RI   R^   i   t   agains   newer chaini   t   hellos   other chains   privkey3.pemi	   t   lastt   attempti
   s	   .conf.newR	   s)   We previously crashed while writing me :(t   withR   t   keys   new certnew chain(   i   i   i   t   lastattempt(   Rz   R_   R`   Ra   R   R9   R(   Rf   R?   t   save_successorR4   R   R
   RK   t   readRM   R   R   t   islinkRL   Rp   Rq   t   available_versionst   listR[   R   t   renewal_configs_dirR@   R   t   exists(   R)   t   mock_rvR6   R   R   t   it   temp_config_file(    (    s>   /usr/lib/python2.7/dist-packages/certbot/tests/storage_test.pyt   test_save_successorã  sb    ((( 1  ((c         C   sÀ   t  d „  d Dƒ ƒ } t j d g  d d d	 | ƒ } | j ƒ  } | j d | d ƒ | d } d
 d l m } t j d | ƒ  | | ƒ } Wd  QX|  j d | ƒ |  j	 | j
 d ƒ | ƒ | S(   Nc         s   s$   |  ] } | t  j | ƒ f Vq d  S(   N(   R    t   flag_default(   t   .0t   option(    (    s>   /usr/lib/python2.7/dist-packages/certbot/tests/storage_test.pys	   <genexpr>#  s   t   authenticatort	   installert   rsa_key_sizet   servert   argst   verbt   pluginsR"   iÿÿÿÿ(   t   relevant_valuess   certbot.cli.helpful_parser(   Rº   R»   R¼   R½   (   t   dictR#   Re   t   copyt
   setdefaultt   certbot.storageRÁ   R$   t   assertInR?   t   pop(   R)   t   valuesR"   t   mock_parsert   expected_serverRÁ   t   rv(    (    s>   /usr/lib/python2.7/dist-packages/certbot/tests/storage_test.pyt   _test_relevant_values_common"  s    	 	
c         C   s$   |  j  |  j i d d 6ƒ i  ƒ d S(   s;   Test that relevant_values() can reject an irrelevant value.t   thereR¦   N(   R?   RÌ   (   R)   (    (    s>   /usr/lib/python2.7/dist-packages/certbot/tests/storage_test.pyt   test_relevant_values5  s    c         C   s9   d } i t  j | ƒ | 6} |  j |  j | ƒ i  ƒ d S(   s7   Test that relevant_values() can reject a default value.R¼   N(   R    R·   R?   RÌ   (   R)   R¹   RÈ   (    (    s>   /usr/lib/python2.7/dist-packages/certbot/tests/storage_test.pyt   test_relevant_values_default:  s    c         C   s*   i d d 6} |  j  |  j | ƒ | ƒ d S(   s;   Test that relevant_values() can retain a non-default value.i   R¼   N(   R?   RÌ   (   R)   RÈ   (    (    s>   /usr/lib/python2.7/dist-packages/certbot/tests/storage_test.pyt   test_relevant_values_nondefault@  s    c         C   s*   i t  d 6} |  j |  j | ƒ | ƒ d  S(   Nt   allow_subset_of_names(   R%   R?   RÌ   (   R)   RÈ   (    (    s>   /usr/lib/python2.7/dist-packages/certbot/tests/storage_test.pyt   test_relevant_values_boolF  s    c         C   s*   i d d 6} |  j  |  j | ƒ | ƒ d  S(   Nt   apacheRº   (   R?   RÌ   (   R)   RÈ   (    (    s>   /usr/lib/python2.7/dist-packages/certbot/tests/storage_test.pyt   test_relevant_values_strK  s    c         C   s+   |  j  |  j i d  d 6d  d 6ƒ i  ƒ d  S(   NRº   R»   (   R?   RÌ   R4   (   R)   (    (    s>   /usr/lib/python2.7/dist-packages/certbot/tests/storage_test.pyt!   test_relevant_values_plugins_noneP  s    s   certbot.cli.set_by_clis.   certbot.plugins.disco.PluginsRegistry.find_allc         C   s?   t  | _ d g | _ i d d 6} |  j |  j | ƒ | ƒ d  S(   Ns   certbot-foo:bari*   s   certbot_foo:bar_baz(   R%   R&   R?   RÌ   (   R)   t   mock_find_allt   mock_set_by_cliRÈ   (    (    s>   /usr/lib/python2.7/dist-packages/certbot/tests/storage_test.pyt   test_relevant_values_namespaceU  s
    	c         C   s$   |  j  |  j i d d 6ƒ i  ƒ d  S(   Ns   example.orgR½   (   R?   RÌ   (   R)   (    (    s>   /usr/lib/python2.7/dist-packages/certbot/tests/storage_test.pyt   test_relevant_values_server^  s    c      	   C   s  d „  | _  d d l m } | j j d d d d |  j ƒ } |  j | j ƒ  ƒ |  j t j	 j
 t j	 j |  j j d ƒ ƒ ƒ |  j t j	 j
 t j	 j |  j j d d	 ƒ ƒ ƒ t | j d
 ƒ  } |  j | j ƒ  d ƒ Wd QX| j j d d d d |  j ƒ } |  j t j	 j
 t j	 j |  j j d ƒ ƒ ƒ |  j t j	 j
 t j	 j |  j j d d	 ƒ ƒ ƒ t j t j	 j |  j j d ƒ ƒ |  j t j | j j d d d d |  j ƒ t j t j	 j |  j j d ƒ ƒ |  j t j | j j d d d d |  j ƒ | j j d d d d |  j ƒ } d S(   s$   Test for new_lineage() class method.c         S   s   |  S(   N(    (   R£   (    (    s>   /usr/lib/python2.7/dist-packages/certbot/tests/storage_test.pyR¤   i  s    iÿÿÿÿ(   R   s   the-lineage.comRG   R^   RH   s   the-lineage.com.confR   t   rbNt   cert2t   privkey2t   chain2s   the-lineage.com-0001.confs   the-lineage.com-0001s   the-lineage.com-0002t   cert3t   privkey3t   chain3s   other-example.comt   cert4t   privkey4t   chain4t	   certchain(   Rz   R   R   R'   t   new_lineageR   RL   RU   R   R   R²   R   R±   t   live_dirR
   RI   R?   R­   t   mkdirRC   R   RD   t   default_archive_dir(   R)   R³   R   R•   R   (    (    s>   /usr/lib/python2.7/dist-packages/certbot/tests/storage_test.pyt   test_new_lineaged  s:    		"		c         C   s  d „  | _  d d l m } t j |  j j ƒ t j |  j j ƒ t j |  j j ƒ | j	 j
 d d d d |  j ƒ |  j t j j t j j |  j j d ƒ ƒ ƒ |  j t j j t j j |  j j d d	 ƒ ƒ ƒ |  j t j j t j j |  j j d d
 ƒ ƒ ƒ d S(   s9   Test that directories can be created if they don't exist.c         S   s   |  S(   N(    (   R£   (    (    s>   /usr/lib/python2.7/dist-packages/certbot/tests/storage_test.pyR¤   •  s    iÿÿÿÿ(   R   s   the-lineage.comRÛ   RÜ   RÝ   s   the-lineage.com.confs   privkey.pems   privkey1.pemN(   Rz   R   R   t   shutilt   rmtreeR   R±   Rè   Ræ   R'   Rå   RL   R   R   R²   R   (   R)   R³   R   (    (    s>   /usr/lib/python2.7/dist-packages/certbot/tests/storage_test.pyt!   test_new_lineage_nonexistent_dirs  s    		s(   certbot.storage.util.unique_lineage_namec         C   sH   d d l  m } d	 | _ |  j t j | j j d d d d |  j ƒ d  S(
   Niÿÿÿÿ(   R   t   this_does_not_end_with_dot_conft   yikess   example.comRG   R^   RH   (   Rí   Rî   (	   R   R   R&   RC   R   RD   R'   Rå   R   (   R)   t   mock_ulnR   (    (    s>   /usr/lib/python2.7/dist-packages/certbot/tests/storage_test.pyt   test_invalid_config_filename¦  s
    	c         C   s²   |  j  t j |  j j d ƒ |  j  t j |  j j d ƒ |  j  t j |  j j d d ƒ |  j  t j |  j j d ƒ |  j  t j |  j j d ƒ |  j  t j |  j j	 d d ƒ d  S(   Nt   elephanti   (
   RC   R   RD   R(   RY   R[   RK   R¯   t   newest_available_versionRo   (   R)   (    (    s>   /usr/lib/python2.7/dist-packages/certbot/tests/storage_test.pyt   test_bad_kind®  s    c         C   s   |  j  |  j j ƒ  ƒ d  S(   N(   RM   R(   t   ocsp_revoked(   R)   (    (    s>   /usr/lib/python2.7/dist-packages/certbot/tests/storage_test.pyt   test_ocsp_revokedÀ  s    c   
      C   sª  d d l  m } t j j t j d d d d d d ƒ ƒ } t j j t j d d	 d
 d d d ƒ ƒ } t j d ƒ j t j d d	 d d d d ƒ ƒ } i | | d f 6| | d f 6| | d f 6| t j d ƒ | d f 6| t j d ƒ | d f 6| t j d ƒ | d f 6| t j d ƒ | d f 6| t j d ƒ | d f 6| t j d ƒ | d f 6| t j d ƒ | d f 6| t j d ƒ | d f 6| t j d ƒ | d f 6| t j d ƒ | d f 6| t j d ƒ | d f 6| t j d ƒ | d f 6| t j d ƒ | d  f 6| t j d! ƒ | d  f 6| t j d" ƒ | d# f 6| t j d" ƒ | d# f 6} xB | j ƒ  D]4 \ } } | \ } }	 |  j	 | j
 | |	 ƒ | ƒ qnWd  S($   Niÿÿÿÿ(   R   iÓ  i   i   i;   i   iÜ  i
   i   i   i   s   Asia/Shanghaiiß  i   i   i   i)   t    i   s   17 daysi   t   30i1   s   7 weekss   1 monthin  s   1 yearim  io  s   1 year 1 days   1 year-1 dayil  iµ  s   4 years(   R   R   t   pytzt   UTCt   fromutcRˆ   t   timezoneR‰   t   itemsR?   t   add_time_interval(
   R)   R   t   time_1t   time_2t   time_3t   intendedt
   parameterst   exceptedt	   base_timeR”   (    (    s>   /usr/lib/python2.7/dist-packages/certbot/tests/storage_test.pyt   test_add_time_intervalÅ  s:    **!c         C   sº   i  |  j  j d <|  j  j d } |  j |  j  j t ƒ d | d <|  j |  j  j t ƒ d | d <|  j |  j  j t ƒ d | d <|  j |  j  j t ƒ d | d <|  j |  j  j t ƒ d  S(   NR…   s6   https://acme-staging-v02.api.letsencrypt.org/directoryR½   s)   https://staging.someotherca.com/directorys.   https://acme-v01.api.letsencrypt.org/directorys.   https://acme-v02.api.letsencrypt.org/directory(   R(   R‹   R?   t   is_test_certRh   R%   (   R)   t   rp(    (    s>   /usr/lib/python2.7/dist-packages/certbot/tests/storage_test.pyt   test_is_test_certï  s    



c         C   sy   d d l  m } |  j t j | j |  j j |  j ƒ t	 j
 d |  j t d ƒ |  j t j | j |  j j |  j ƒ d  S(   Niÿÿÿÿ(   R   t   missingi    (   R   R   RC   R   RD   R'   R    R   R   R   R1   R   (   R)   R   (    (    s>   /usr/lib/python2.7/dist-packages/certbot/tests/storage_test.pyt   test_missing_certü  s    c   
      C   s‚  t  j j |  j j d ƒ } t  j j |  j j d ƒ } t | d ƒ  } | j d ƒ Wd  QXt  j | d ƒ i  } x t D] } d | | <qx Wd } i d d	 6} d
 d l	 m
 } | j | | | | | ƒ t | d ƒ  } | j ƒ  }	 Wd  QX|  j d |	 k ƒ |  j d |	 k ƒ |  j d |	 k ƒ |  j d j t	 j ƒ |	 k ƒ |  j t j t  j | ƒ j ƒ t j t  j | ƒ j ƒ ƒ d  S(   Ns   sample-files   sample-file.newR	   sM   [renewalparams]
useful = value # A useful value
useless = value # Not needed
i   t	   somewheret   the_archivet	   new_valuet   usefuliÿÿÿÿ(   R   t   rs   useful = new_values   A useful valuet   uselesss   version = {0}(   R   R   R   R   R   R
   R   t   chmodR   R   R   t   write_renewal_configR­   RL   R3   t   __version__R?   t   statt   S_IMODEt   lstatt   st_mode(
   R)   t   tempt   temp2R   t   targetR£   t   archive_dirt   relevant_dataR   t   content(    (    s>   /usr/lib/python2.7/dist-packages/certbot/tests/storage_test.pyt   test_write_renewal_config  s(    c         C   së   d d l  m } t j j |  j j d d ƒ } xr t D]j } |  j | } | d } t j j | | ƒ } t	 | d ƒ j
 ƒ  t j t j j |  j j | ƒ | ƒ q5 W|  j t j | j |  j j |  j ƒ | j |  j j |  j d t ƒd  S(   Niÿÿÿÿ(   R   R   s   example.orgs   1.pemR   t   update_symlinks(   R   R   R   R   R   R   R   R   R    R
   R!   R1   RC   R   RD   R'   R   R%   (   R)   R   t   archive_dir_pathR   t	   live_pathRp   R*   (    (    s>   /usr/lib/python2.7/dist-packages/certbot/tests/storage_test.pyt   test_update_symlinks'  s    
)
(0   R;   R<   R=   RA   RF   RJ   RQ   RT   RW   RZ   R\   R]   Rd   R#   R$   Rn   Rr   Rs   Rt   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/storage_test.pyR>   f   s^   				
		*											/				?								,			*		
	!t   DeleteFilesTestc           B   s_   e  Z d  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 d	 „  Z RS(
   s&   Tests for certbot.storage.delete_filesc         C   sý   t  t |  ƒ j ƒ  xI t D]A } t j j |  j j d d | d ƒ } t	 | d ƒ  Wd  QXq W|  j
 j ƒ  |  j t j j t j j |  j j d ƒ ƒ ƒ |  j t j j t j j |  j j d ƒ ƒ ƒ |  j t j j t j j |  j j d d ƒ ƒ ƒ d  S(   NR   s   example.orgs   .pemR   s   example.org.confR   (   R   R#  R   R   R   R   R   R   R   R
   R    R   RL   R²   R±   Ræ   (   R)   R   R+   (    (    s>   /usr/lib/python2.7/dist-packages/certbot/tests/storage_test.pyR   8  s    
c         C   s=   d d l  m } t j d ƒ  | j |  j d ƒ Wd  QXd  S(   Niÿÿÿÿ(   R   s   certbot.storage.loggers   example.org(   R   R   R#   R$   t   delete_filesR   (   R)   R   (    (    s>   /usr/lib/python2.7/dist-packages/certbot/tests/storage_test.pyt   _callH  s    c         C   s›   |  j  ƒ  |  j t j j t j j |  j j d ƒ ƒ ƒ |  j t j j t j j |  j j d ƒ ƒ ƒ |  j t j j t j j |  j j	 d d ƒ ƒ ƒ d  S(   Ns   example.org.confs   example.orgR   (
   R%  RM   R   R   R²   R   R   R±   Ræ   R   (   R)   (    (    s>   /usr/lib/python2.7/dist-packages/certbot/tests/storage_test.pyt   test_delete_all_filesM  s    
c         C   s¡   t  |  j j d ƒ  } | j d ƒ Wd  QX|  j t j |  j ƒ |  j t	 j
 j t	 j
 j |  j j d ƒ ƒ ƒ |  j t	 j
 j t	 j
 j |  j j d ƒ ƒ ƒ d  S(   NR   t   asdfasfasdfasdfs   example.orgs   example.org.conf(   R
   R    R   R   RC   R   RD   R%  RL   R   R   R²   R   R   Ræ   RM   R±   (   R)   R    (    (    s>   /usr/lib/python2.7/dist-packages/certbot/tests/storage_test.pyt   test_bad_renewal_configW  s    c         C   sz   t  j |  j j ƒ |  j t j |  j ƒ |  j t  j	 j
 t  j	 j |  j j d ƒ ƒ ƒ |  j t  j	 j
 |  j j ƒ ƒ d  S(   Ns   example.org(   R   t   removeR    R   RC   R   RD   R%  RL   R   R²   R   R   Ræ   RM   (   R)   (    (    s>   /usr/lib/python2.7/dist-packages/certbot/tests/storage_test.pyt   test_no_renewal_configa  s
    c         C   s±   t  j t  j j |  j j d d ƒ ƒ |  j ƒ  |  j t  j j |  j	 j
 ƒ ƒ |  j t  j j t  j j |  j j d ƒ ƒ ƒ |  j t  j j t  j j |  j j d d ƒ ƒ ƒ d  S(   Ns   example.orgs   cert.pemR   (   R   R)  R   R   R   Ræ   R%  RM   R²   R    R   R   (   R)   (    (    s>   /usr/lib/python2.7/dist-packages/certbot/tests/storage_test.pyt   test_no_cert_fileh  s    
c         C   s±   t  j t  j j |  j j d d ƒ ƒ |  j ƒ  |  j t  j j |  j	 j
 ƒ ƒ |  j t  j j t  j j |  j j d ƒ ƒ ƒ |  j t  j j t  j j |  j j d d ƒ ƒ ƒ d  S(   Ns   example.orgR   R   (   R   R)  R   R   R   Ræ   R%  RM   R²   R    R   R   (   R)   (    (    s>   /usr/lib/python2.7/dist-packages/certbot/tests/storage_test.pyt   test_no_readme_filer  s    
c         C   sº   t  t j j |  j j d d ƒ d ƒ  Wd  QX|  j ƒ  |  j t j j |  j	 j
 ƒ ƒ |  j t j j t j j |  j j d ƒ ƒ ƒ |  j t j j t j j |  j j d d ƒ ƒ ƒ d  S(   Ns   example.orgt
   other_fileR   R   (   R
   R   R   R   R   Ræ   R%  RM   R²   R    R   RL   R   (   R)   (    (    s>   /usr/lib/python2.7/dist-packages/certbot/tests/storage_test.pyt   test_livedir_not_empty|  s    
c         C   sŸ   t  j j |  j j d d ƒ } t  j | ƒ |  j ƒ  |  j t  j j |  j	 j
 ƒ ƒ |  j t  j j t  j j |  j j d ƒ ƒ ƒ |  j t  j j | ƒ ƒ d  S(   NR   s   example.org(   R   R   R   R   R   t   rmdirR%  RM   R²   R    R   Ræ   (   R)   R  (    (    s>   /usr/lib/python2.7/dist-packages/certbot/tests/storage_test.pyt   test_no_archive‡  s    
(   R;   R<   R=   R   R%  R&  R(  R*  R+  R,  R.  R0  (    (    (    s>   /usr/lib/python2.7/dist-packages/certbot/tests/storage_test.pyR#  6  s   			
	
		
	
	t   CertPathForCertNameTestc           B   s2   e  Z d  Z d „  Z d „  Z d „  Z d „  Z RS(   s0   Test for certbot.storage.cert_path_for_cert_namec         C   sg   t  t |  ƒ j ƒ  |  j j ƒ  |  j ƒ  t j j |  j	 j
 d d d ƒ |  _ |  j d f |  j	 _ d  S(   NR   s   example.orgs   fullchain.pemRö   (   R   R1  R   R    R   R:   R   R   R   R   R   RI   t	   cert_path(   R)   (    (    s>   /usr/lib/python2.7/dist-packages/certbot/tests/storage_test.pyR   ’  s    
c         C   s   d d l  m } | | | ƒ S(   Niÿÿÿÿ(   t   cert_path_for_cert_name(   RÅ   R3  (   R)   t
   cli_configt   certnameR3  (    (    s>   /usr/lib/python2.7/dist-packages/certbot/tests/storage_test.pyR%  š  s    c         C   s,   |  j  |  j |  j d ƒ |  j d f ƒ d  S(   Ns   example.orgRI   (   R?   R%  R   RI   (   R)   (    (    s>   /usr/lib/python2.7/dist-packages/certbot/tests/storage_test.pyt   test_simple_cert_namež  s    c         C   s#   |  j  t j |  j |  j d ƒ d  S(   Ns   fake-example.org(   RC   R   RD   R%  R   (   R)   (    (    s>   /usr/lib/python2.7/dist-packages/certbot/tests/storage_test.pyt   test_no_such_cert_name¡  s    (   R;   R<   R=   R   R%  R6  R7  (    (    (    s>   /usr/lib/python2.7/dist-packages/certbot/tests/storage_test.pyR1    s
   			t   __main__(   R=   Rˆ   R   Rê   R  t   unittestR   R#   Rø   R_   R   R    R   RÅ   R   t   certbot.tests.utilt   testst   utilR€   t	   load_certt   CERTR   R   t   ConfigTestCaseR   R>   R#  R1  R;   t   main(    (    (    s>   /usr/lib/python2.7/dist-packages/certbot/tests/storage_test.pyt   <module>   s2   		?ÿ ÿ ÒZ