ó
P'^c           @@  s²   d  Z  d d l m Z d d l m Z d d l m Z 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 m Z m Z d e f d     YZ d S(   sĜ  
Keys and certificates for tests (KEY1 is a private key of CERT1, etc.)

Generated with:

.. code-block:: bash

    $ openssl genrsa -des3 -passout pass:test -out key1.key 1024
    $ openssl req -new -key key1.key -out key1.csr -passin pass:test
    $ cp key1.key key1.key.org
    $ openssl rsa -in key1.key.org -out key1.key -passin pass:test
    $ openssl x509 -req -days 365 -in cert1.csr               -signkey key1.key -out cert1.crt
    $ rm key1.key.org cert1.csr

i    (   t   absolute_import(   t   disable_insecure_serializers(   t   ImproperlyConfiguredt   SecurityError(   t   builtins(   t   reraise_errors(   t   registryi   (   t   SecurityCase(   t   Mockt	   mock_opent   patcht   test_securityc           B@  s\   e  Z d    Z d   Z d   Z e d  e d  d d d    Z d   Z d	   Z RS(
   c         C@  s   t  j j   d  S(   N(   R   t   _disabled_content_typest   clear(   t   self(    (    sE   /tmp/pip-unpacked-wheel-gV1wwp/celery/tests/security/test_security.pyt   teardown!   s    c         C@  sı   zĦ t  j } |  j |  t d d g  |  j d |  |  j d |  |  j d |  | j   t d d   |  j d |  |  j d |  |  j d |  Wd  t d d g  Xd  S(   Ns   application/jsons   application/x-python-serializes   application/x-yamlt   allowedt   json(   R   R   t
   assertTrueR   t   assertInt   assertNotInR   t   None(   R   t   disabled(    (    sE   /tmp/pip-unpacked-wheel-gV1wwp/celery/tests/security/test_security.pyt!   test_disable_insecure_serializers$   s    	
c         C@  sY   t  j } |  j d t |   d |  j j _ |  j j   |  j d |  | j	   d  S(   Ni    R   s   application/x-python-serialize(
   R   R   t   assertEqualt   lent   appt   conft   CELERY_TASK_SERIALIZERt   setup_securityR   R   (   R   R   (    (    sE   /tmp/pip-unpacked-wheel-gV1wwp/celery/tests/security/test_security.pyt   test_setup_security8   s    	s   celery.security.register_auths-   celery.security._disable_insecure_serializerst   KEYt   CERTc         @  s´   d g     f d   } d |  j  j _ t d |  x t d  e } t   } |  j  j d g | | |  | j d g  | j d d | d	 d  | j j d  Wd  QXWd  QXd  S(
   Ni    c          @  sE   z- t    }   d r d n d | j _ | SWd    d c d 7<Xd  S(   Ni    t   Bt   Ai   (   R   t   readt   return_value(   t   argst   m(   t   calls(    sE   /tmp/pip-unpacked-wheel-gV1wwp/celery/tests/security/test_security.pyt   effectF   s
    	t   autht   side_effects   celery.security.registryR   R"   R!   t   sha1(	   R   R   R   R	   R
   R   R   t   assert_called_witht   _set_default_serializer(   R   t   dist   regt   keyt   certR(   R   t   store(    (   R'   sE   /tmp/pip-unpacked-wheel-gV1wwp/celery/tests/security/test_security.pyt   test_setup_registry_completeA   s    		c         @  s   d |  j  j _ |  j t   |  j  j   Wd  QXt j     f d   } | t _ |  j t   |  j  j   Wd  QX  t _ d  S(   NR)   c         @  s%   |  d k r t   n    |  | |  S(   Nt   OpenSSL(   t   ImportError(   t   nameR%   t   kwargs(   t   _import(    sE   /tmp/pip-unpacked-wheel-gV1wwp/celery/tests/security/test_security.pyt   import_hook^   s    	(   R   R   R   t   assertRaisesR   R   R   t
   __import__(   R   R9   (    (   R8   sE   /tmp/pip-unpacked-wheel-gV1wwp/celery/tests/security/test_security.pyt   test_security_confW   s    		c         C@  sz   |  j  t  * t d t f   t d   Wd  QXWd  QX|  j  t  * t d t f   t d   Wd  QXWd  QXd  S(   Nt   errorst   foot   bar(   R:   R   R   t   KeyErrort
   ValueError(   R   (    (    sE   /tmp/pip-unpacked-wheel-gV1wwp/celery/tests/security/test_security.pyt   test_reraise_errorsh   s    (	   t   __name__t
   __module__R   R   R   R
   R3   R<   RB   (    (    (    sE   /tmp/pip-unpacked-wheel-gV1wwp/celery/tests/security/test_security.pyR      s   							N(   t   __doc__t
   __future__R    t   kombu.serializationR   t   celery.exceptionsR   R   t   celery.fiveR   t   celery.security.utilsR   R   t   caseR   t   celery.tests.caseR   R	   R
   R   (    (    (    sE   /tmp/pip-unpacked-wheel-gV1wwp/celery/tests/security/test_security.pyt   <module>   s   