ó
¡\\c           @   s·  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 m Z d d l m	 Z	 d d l m
 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
 e j f d „  ƒ  YZ d e j f d „  ƒ  YZ d e j f d „  ƒ  YZ d e j f d „  ƒ  YZ d e j f d „  ƒ  YZ d e j f d „  ƒ  YZ e j d e j f d „  ƒ  Yƒ Z e d k r³e j ƒ  n  d S(   s   Tests for acme.standalone.iÿÿÿÿN(   t   http_client(   t   queue(   t   socketserver(   t
   challenges(   t   crypto_util(   t	   test_util(   t   Sett   TLSServerTestc           B   s    e  Z d  Z d „  Z d „  Z RS(   s$   Tests for acme.standalone.TLSServer.c         C   s6   d d l  m } | d t j d t ƒ} | j ƒ  d  S(   Niÿÿÿÿ(   t	   TLSServert    i    t   bind_and_activate(   R	   i    (   t   acme.standaloneR   R   t   BaseRequestHandlert   Truet   server_close(   t   selfR   t   server(    (    s8   /usr/lib/python2.7/dist-packages/acme/standalone_test.pyt	   test_bind   s    c         C   sH   t  j rD d d l m } | d t j d t d t ƒ} | j ƒ  n  d  S(   Niÿÿÿÿ(   R   R	   i    R
   t   ipv6(   R	   i    (   t   sockett   has_ipv6R   R   R   R   R   R   (   R   R   R   (    (    s8   /usr/lib/python2.7/dist-packages/acme/standalone_test.pyt	   test_ipv6!   s
    	(   t   __name__t
   __module__t   __doc__R   R   (    (    (    s8   /usr/lib/python2.7/dist-packages/acme/standalone_test.pyR      s   	t   TLSSNI01ServerTestc           B   s)   e  Z d  Z d „  Z d „  Z d „  Z RS(   s(   Test for acme.standalone.TLSSNI01Server.c         C   s|   i t  j d ƒ t  j d ƒ f d 6|  _ d d l m } | d	 d |  j ƒ|  _ t j d |  j j	 ƒ |  _
 |  j
 j ƒ  d  S(
   Ns   rsa2048_key.pems   rsa2048_cert.pemt	   localhostiÿÿÿÿ(   t   TLSSNI01Serveri    t   certst   target(   R   i    (   R   t   load_pyopenssl_private_keyt	   load_certR   R   R   R   t	   threadingt   Threadt   serve_forevert   threadt   start(   R   R   (    (    s8   /usr/lib/python2.7/dist-packages/acme/standalone_test.pyt   setUp-   s    c         C   s   |  j  j ƒ  |  j j ƒ  d  S(   N(   R   t   shutdownR#   t   join(   R   (    (    s8   /usr/lib/python2.7/dist-packages/acme/standalone_test.pyt   tearDown8   s    c         C   sn   |  j  j j ƒ  d  \ } } t j d d | d | d d ƒ} |  j t j | ƒ t j |  j d d ƒ ƒ d  S(   Ni   R   t   hostt   portt   timeouti   (	   R   R   t   getsocknameR   t	   probe_snit   assertEqualt   joset   ComparableX509R   (   R   R)   R*   t   cert(    (    s8   /usr/lib/python2.7/dist-packages/acme/standalone_test.pyt   test_it<   s
    (   R   R   R   R%   R(   R2   (    (    (    s8   /usr/lib/python2.7/dist-packages/acme/standalone_test.pyR   )   s   		t   HTTP01ServerTestc           B   sM   e  Z d  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z	 RS(   s'   Tests for acme.standalone.HTTP01Server.c         C   s—   t  j j t j d ƒ ƒ |  _ t ƒ  |  _ d d l m	 } | d	 d |  j ƒ|  _
 |  j
 j j ƒ  d |  _ t j d |  j
 j ƒ |  _ |  j j ƒ  d  S(
   Ns   rsa1024_key.pemiÿÿÿÿ(   t   HTTP01ServerR	   i    t	   resourcesi   R   (   R	   i    (   R/   t   JWKt   loadR   t   load_vectort   account_keyt   setR5   R   R4   R   R   R,   R*   R    R!   R"   R#   R$   (   R   R4   (    (    s8   /usr/lib/python2.7/dist-packages/acme/standalone_test.pyR%   H   s    	c         C   s   |  j  j ƒ  |  j j ƒ  d  S(   N(   R   R&   R#   R'   (   R   (    (    s8   /usr/lib/python2.7/dist-packages/acme/standalone_test.pyR(   U   s    c         C   sH   t  j d j |  j ƒ d t ƒ} |  j | j d ƒ |  j | j ƒ d  S(   Ns   http://localhost:{0}t   verifys'   ACME client standalone challenge solver(	   t   requestst   gett   formatR*   t   FalseR.   t   textt
   assertTruet   ok(   R   t   response(    (    s8   /usr/lib/python2.7/dist-packages/acme/standalone_test.pyt
   test_indexY   s
    c         C   s;   t  j d j |  j ƒ d t ƒ} |  j | j t j ƒ d  S(   Ns   http://localhost:{0}/fooR;   (	   R<   R=   R>   R*   R?   R.   t   status_codeR    t	   NOT_FOUND(   R   RC   (    (    s8   /usr/lib/python2.7/dist-packages/acme/standalone_test.pyt   test_404`   s    c         C   sœ   t  j d d ƒ } | j |  j ƒ \ } } d d l m } | j d | d | d | ƒ } | rq |  j j | ƒ n  | j	 j
 | j d	 |  j j ƒ  d
 |  j ƒS(   Nt   tokent   xi   iÿÿÿÿ(   t   HTTP01RequestHandlert   challRC   t
   validationR   R*   t   xxxxxxxxxxxxxxxx(   R   t   HTTP01t   response_and_validationR9   R   RJ   t   HTTP01ResourceR5   t   addRC   t   simple_verifyRK   t
   public_keyR*   (   R   RQ   RK   RC   RL   RJ   t   resource(    (    s8   /usr/lib/python2.7/dist-packages/acme/standalone_test.pyt   _test_http01e   s    		c         C   s   |  j  |  j d t ƒ ƒ d  S(   NRQ   (   RA   RU   R   (   R   (    (    s8   /usr/lib/python2.7/dist-packages/acme/standalone_test.pyt   test_http01_foundr   s    c         C   s   |  j  |  j d t ƒ ƒ d  S(   NRQ   (   t   assertFalseRU   R?   (   R   (    (    s8   /usr/lib/python2.7/dist-packages/acme/standalone_test.pyt   test_http01_not_foundu   s    (
   R   R   R   R%   R(   RD   RG   RU   RV   RX   (    (    (    s8   /usr/lib/python2.7/dist-packages/acme/standalone_test.pyR3   D   s   						t   BaseDualNetworkedServersTestc           B   sH   e  Z d  Z d e j f d „  ƒ  YZ e j d ƒ d „  ƒ Z d „  Z	 RS(   s2   Test for acme.standalone.BaseDualNetworkedServers.t   SingleProtocolServerc           B   s   e  Z d  Z d „  Z RS(   sU   Server that only serves on a single protocol. FreeBSD has this behavior for AF_INET6.c         O   sº   | j  d t ƒ } | r1 t j |  _ t | d <n t j |  _ t j j |  | | Ž | r¶ t	 t d d ƒ } |  j j
 | t j d ƒ y |  j ƒ  |  j ƒ  Wq¶ |  j ƒ  ‚  q¶ Xn  d  S(   NR   R
   t   IPPROTO_IPV6i)   i   (   t   popR?   R   t   AF_INET6t   address_familyt   AF_INETR   t	   TCPServert   __init__t   getattrt
   setsockoptt   IPV6_V6ONLYt   server_bindt   server_activateR   (   R   t   argst   kwargsR   t   level(    (    s8   /usr/lib/python2.7/dist-packages/acme/standalone_test.pyRa      s    

(   R   R   R   Ra   (    (    (    s8   /usr/lib/python2.7/dist-packages/acme/standalone_test.pyRZ   }   s   s   socket.socket.bindc         C   sB   t  j | _ d d l m } |  j t  j | t j d t j	 ƒ d  S(   Niÿÿÿÿ(   t   BaseDualNetworkedServersR	   i    (   R	   i    (
   R   t   errort   side_effectR   Rj   t   assertRaisesRY   RZ   R   R   (   R   t	   mock_bindRj   (    (    s8   /usr/lib/python2.7/dist-packages/acme/standalone_test.pyt   test_fail_to_bind”   s    c         C   sx   d d l  m } | t j d t j ƒ } | j ƒ  } d  } x7 | D]/ } | d } | rj |  j | | ƒ n  | } qA Wd  S(   Niÿÿÿÿ(   Rj   R	   i    i   (   R	   i    (	   R   Rj   RY   RZ   R   R   t   getsocknamest   NoneR.   (   R   Rj   t   serverst	   socknamest	   prev_portt   socknameR*   (    (    s8   /usr/lib/python2.7/dist-packages/acme/standalone_test.pyt   test_ports_equal   s    
(
   R   R   R   R   R`   RZ   t   mockt   patchRo   Rv   (    (    (    s8   /usr/lib/python2.7/dist-packages/acme/standalone_test.pyRY   y   s   	t    TLSSNI01DualNetworkedServersTestc           B   s)   e  Z d  Z d „  Z d „  Z d „  Z RS(   s6   Test for acme.standalone.TLSSNI01DualNetworkedServers.c         C   sa   i t  j d ƒ t  j d ƒ f d 6|  _ d d l m } | d d |  j ƒ|  _ |  j j ƒ  d  S(	   Ns   rsa2048_key.pems   rsa2048_cert.pemR   iÿÿÿÿ(   t   TLSSNI01DualNetworkedServersi    R   (   s	   localhosti    (   R   R   R   R   R   Rz   Rr   R"   (   R   Rz   (    (    s8   /usr/lib/python2.7/dist-packages/acme/standalone_test.pyR%   ±   s    c         C   s   |  j  j ƒ  d  S(   N(   Rr   t   shutdown_and_server_close(   R   (    (    s8   /usr/lib/python2.7/dist-packages/acme/standalone_test.pyR(   º   s    c      	   C   s‚   |  j  j ƒ  } xl | D]d } | d  \ } } t j d d | d | d d ƒ} |  j t j | ƒ t j |  j d d ƒ ƒ q Wd  S(   Ni   R   R)   R*   R+   i   (   Rr   Rp   R   R-   R.   R/   R0   R   (   R   Rs   Ru   R)   R*   R1   (    (    s8   /usr/lib/python2.7/dist-packages/acme/standalone_test.pyt   test_connect½   s    (   R   R   R   R%   R(   R|   (    (    (    s8   /usr/lib/python2.7/dist-packages/acme/standalone_test.pyRy   ­   s   			t   HTTP01DualNetworkedServersTestc           B   sM   e  Z d  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z	 RS(   s5   Tests for acme.standalone.HTTP01DualNetworkedServers.c         C   s}   t  j j t j d ƒ ƒ |  _ t ƒ  |  _ d d l m	 } | d d |  j ƒ|  _
 |  j
 j ƒ  d d |  _ |  j
 j ƒ  d  S(	   Ns   rsa1024_key.pemiÿÿÿÿ(   t   HTTP01DualNetworkedServersR	   i    R5   i   (   R	   i    (   R/   R6   R7   R   R8   R9   R:   R5   R   R~   Rr   Rp   R*   R"   (   R   R~   (    (    s8   /usr/lib/python2.7/dist-packages/acme/standalone_test.pyR%   Ì   s    	c         C   s   |  j  j ƒ  d  S(   N(   Rr   R{   (   R   (    (    s8   /usr/lib/python2.7/dist-packages/acme/standalone_test.pyR(   Ø   s    c         C   sH   t  j d j |  j ƒ d t ƒ} |  j | j d ƒ |  j | j ƒ d  S(   Ns   http://localhost:{0}R;   s'   ACME client standalone challenge solver(	   R<   R=   R>   R*   R?   R.   R@   RA   RB   (   R   RC   (    (    s8   /usr/lib/python2.7/dist-packages/acme/standalone_test.pyRD   Û   s
    c         C   s;   t  j d j |  j ƒ d t ƒ} |  j | j t j ƒ d  S(   Ns   http://localhost:{0}/fooR;   (	   R<   R=   R>   R*   R?   R.   RE   R    RF   (   R   RC   (    (    s8   /usr/lib/python2.7/dist-packages/acme/standalone_test.pyRG   â   s    c         C   sœ   t  j d d ƒ } | j |  j ƒ \ } } d d l m } | j d | d | d | ƒ } | rq |  j j | ƒ n  | j	 j
 | j d	 |  j j ƒ  d
 |  j ƒS(   NRH   RI   i   iÿÿÿÿ(   RJ   RK   RC   RL   R   R*   RM   (   R   RN   RO   R9   R   RJ   RP   R5   RQ   RC   RR   RK   RS   R*   (   R   RQ   RK   RC   RL   RJ   RT   (    (    s8   /usr/lib/python2.7/dist-packages/acme/standalone_test.pyRU   ç   s    		c         C   s   |  j  |  j d t ƒ ƒ d  S(   NRQ   (   RA   RU   R   (   R   (    (    s8   /usr/lib/python2.7/dist-packages/acme/standalone_test.pyRV   ô   s    c         C   s   |  j  |  j d t ƒ ƒ d  S(   NRQ   (   RW   RU   R?   (   R   (    (    s8   /usr/lib/python2.7/dist-packages/acme/standalone_test.pyRX   ÷   s    (
   R   R   R   R%   R(   RD   RG   RU   RV   RX   (    (    (    s8   /usr/lib/python2.7/dist-packages/acme/standalone_test.pyR}   È   s   						t   TestSimpleTLSSNI01Serverc           B   s8   e  Z d  Z d „  Z d „  Z e j d ƒ d „  ƒ Z RS(   s3   Tests for acme.standalone.simple_tls_sni_01_server.c         C   sà   t  j ƒ  |  _ t j j |  j d ƒ } t j | ƒ t j t	 j
 d ƒ t j j | d ƒ ƒ t j t	 j
 d ƒ t j j | d ƒ ƒ d d l m } t j d | d	 i d d 6t d 6ƒ |  _ t j ƒ  |  _ t j |  j ƒ d  S(   NR   s   rsa2048_cert.pems   cert.pems   rsa2048_key.pems   key.pemiÿÿÿÿ(   t   simple_tls_sni_01_serverR   Rh   t   filenamet   cli_argst   forever(   s   filename(   t   tempfilet   mkdtempt   test_cwdt   ost   pathR'   t   makedirst   shutilt   copyR   t   vector_pathR   R€   R    R!   R?   R#   t   getcwdt   old_cwdt   chdir(   R   t   localhost_dirR€   (    (    s8   /usr/lib/python2.7/dist-packages/acme/standalone_test.pyR%      s    		c         C   s1   t  j |  j ƒ |  j j ƒ  t j |  j ƒ d  S(   N(   R‡   R   RŽ   R#   R'   RŠ   t   rmtreeR†   (   R   (    (    s8   /usr/lib/python2.7/dist-packages/acme/standalone_test.pyR(     s    s   acme.standalone.loggerc            s{   t  j ƒ  ‰  ‡  f d †  | j _ |  j j ƒ  ˆ  j d d ƒ } t j d d | ƒ } |  j	 t
 j | ƒ t j d ƒ ƒ d  S(   Nc             s   ˆ  j  |  d ƒ S(   Niÿÿÿÿ(   t   put(   Rg   (   t   q(    s8   /usr/lib/python2.7/dist-packages/acme/standalone_test.pyt   <lambda>  s    R+   i   R   s   0.0.0.0s   rsa2048_cert.pem(   R   t   Queuet   infoRl   R#   R$   R=   R   R-   R.   R/   R0   R   t   load_comparable_cert(   R   t   mock_loggerR*   R1   (    (   R“   s8   /usr/lib/python2.7/dist-packages/acme/standalone_test.pyR2     s    (   R   R   R   R%   R(   Rw   Rx   R2   (    (    (    s8   /usr/lib/python2.7/dist-packages/acme/standalone_test.pyR   û   s   		t   __main__(    R   R‡   RŠ   R   R    R„   t   unittestt	   six.movesR    R   R   t   josepyR/   Rw   R<   t   acmeR   R   R   t   acme.magic_typingR   t   TestCaseR   R   R3   RY   Ry   R}   t   broken_on_windowsR   R   t   main(    (    (    s8   /usr/lib/python2.7/dist-packages/acme/standalone_test.pyt   <module>   s4   543	-