ó
§‰]c           @   sP   d  Z  d d l m Z d d l m Z d d l m Z d e f d „  ƒ  YZ d	 S(
   s'   Tests for the HTMLSanitize preprocessori   (   t   PreprocessorTestsBasei   (   t   SanitizeHTMLiÿÿÿÿ(   t   v4t   TestSanitizerc           B   sw   e  Z d  Z d Z d „  Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 d „  Z d „  Z d	 „  Z d
 „  Z d „  Z RS(   s'   Contains test functions for sanitize.pyc         C   s   t  ƒ  } t | _ | S(   s"   Make an instance of a preprocessor(   R   t   Truet   enabled(   t   selft   preprocessor(    (    sJ   lib/python2.7/site-packages/nbconvert/preprocessors/tests/test_sanitize.pyt   build_preprocessor   s    		c         C   s[   |  j  ƒ  } |  j ƒ  } | | j d _ | | j d _ | | | ƒ \ } } | j d j S(   Ni    (   t   build_notebookt   build_resourcest   cellst	   cell_typet   source(   R   R   R   R   t   nbt   res(    (    sJ   lib/python2.7/site-packages/nbconvert/preprocessors/tests/test_sanitize.pyt   preprocess_source   s    c         C   s   |  j  ƒ  d S(   s"   Can a SanitizeHTML be constructed?N(   R   (   R   (    (    sJ   lib/python2.7/site-packages/nbconvert/preprocessors/tests/test_sanitize.pyt   test_constructor   s    c         C   sD   |  j  ƒ  } t | _ |  j |  j d d | ƒ j ƒ  d j ƒ  ƒ d S(   sÚ   
        Test to make sure that svgs are handled 'properly'

        We only allow <img> tags (via markdown syntax) and not all the other ways
        to embed svg: <object>, <embed>, <iframe> nor inline <svg>
        t   markdowns  
                ![some image](http://example.com/something.svg)

                <object data="something.svg" type="image/svg+xml"></object>

                <embed data="something.svg" type="image/svg+xml" />

                <iframe src="http://example.com/something.svg"></iframe>

                <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 68 65">
                    <path fill="#1A374D" d="M42 27v-20c0-3.7-3.3-7-7-7s-7 3.3-7 7v21l12 15-7 15.7c14.5 13.9 35 2.8 35-13.7 0-13.3-13.4-21.8-26-18zm6 25c-3.9 0-7-3.1-7-7s3.1-7 7-7 7 3.1 7 7-3.1 7-7 7z"/>
                    <path d="M14 27v-20c0-3.7-3.3-7-7-7s-7 3.3-7 7v41c0 8.2 9.2 17 20 17s20-9.2 20-20c0-13.3-13.4-21.8-26-18zm6 25c-3.9 0-7-3.1-7-7s3.1-7 7-7 7 3.1 7 7-3.1 7-7 7z"/>
                </svg>
                sI   
            ![some image](http://example.com/something.svg)
            N(   R   R   t   stript   assertEqualR   (   R   R   (    (    sJ   lib/python2.7/site-packages/nbconvert/preprocessors/tests/test_sanitize.pyt   test_svg_handling"   s    	c         C   s8   |  j  ƒ  } t | _ |  j |  j d d | ƒ d ƒ d S(   s4   Test tag whitelisting + stripping out offending tagsR   s&   _A_ <em>few</em> <script>tags</script>s   _A_ <em>few</em> tagsN(   R   R   R   R   R   (   R   R   (    (    sJ   lib/python2.7/site-packages/nbconvert/preprocessors/tests/test_sanitize.pyt   test_tag_whitelist_strippingD   s    	c         C   sW   |  j  ƒ  } |  j |  j d d | ƒ d ƒ t | _ |  j |  j d d | ƒ d ƒ d S(   s   Test HTML comment strippingR   s   _A_ <em>few</em> <!-- tags -->s   _A_ <em>few</em> N(   R   R   R   t   Falset   strip_comments(   R   R   (    (    sJ   lib/python2.7/site-packages/nbconvert/preprocessors/tests/test_sanitize.pyt   test_comment_strippingR   s    	c         C   sB   |  j  ƒ  } d d g | j d <|  j |  j d d | ƒ d ƒ d S(   s
   Test stylet   hreft   titlet   aR   s$   <a href="link" rel="nofollow">Hi</a>s   <a href="link">Hi</a>N(   R   t
   attributesR   R   (   R   R   (    (    sJ   lib/python2.7/site-packages/nbconvert/preprocessors/tests/test_sanitize.pyt   test_attributes_whitelisti   s    c         C   sq   |  j  ƒ  } d | j k r2 | j d j d ƒ n d g | j d <d g | _ |  j |  j d d | ƒ d ƒ d S(   s
   Test stylet   *t   stylet   colorR   sR   _A_ <em style="color: blue; background-color: pink">few</em> <script>tags</script>sG   _A_ <em style="color: blue;">few</em> &lt;script&gt;tags&lt;/script&gt;N(   R   R   t   appendt   stylesR   R   (   R   R   (    (    sJ   lib/python2.7/site-packages/nbconvert/preprocessors/tests/test_sanitize.pyt   test_style_whitelistx   s    c         C   s/   |  j  ƒ  } |  j |  j d d | ƒ d ƒ d S(   s   Test passing through raw outputt   raws&   _A_ <em>few</em> <script>tags</script>s2   _A_ <em>few</em> &lt;script&gt;tags&lt;/script&gt;N(   R   R   R   (   R   R   (    (    sJ   lib/python2.7/site-packages/nbconvert/preprocessors/tests/test_sanitize.pyt   test_tag_passthrough   s    c         C   s   |  j  ƒ  } |  j ƒ  } t j d d i d d 6d d 6d d 6ƒt j d	 d
 d d d ƒt j d	 d
 d d d ƒg } | | j d _ |  j ƒ  } | | | ƒ \ } } i i d d 6d d 6d 6i  d 6d d 6i d d
 6d	 d 6d d 6i d d
 6d	 d 6d d 6g } |  j | j d j | ƒ d S(   s-   Test that outputs are also sanitized properlyt   display_datat   datat   bs
   text/plains   <script>more evil</script>s	   text/htmls    <style> * {display:none}</style>s   text/csst   streamt   namet   stdoutt   textt   wats   <script>Evil tag</script>i    s&   &lt;script&gt;more evil&lt;/script&gt;t   metadatat   output_typeN(   R   R	   t   nbformatt
   new_outputR   t   outputsR
   R   (   R   R   R   R3   R   t   expected_output(    (    sJ   lib/python2.7/site-packages/nbconvert/preprocessors/tests/test_sanitize.pyt   test_output_sanitizingœ   s2    
c         C   s/   |  j  ƒ  } |  j |  j d d | ƒ d ƒ d S(   s   Test tag whitelistingR   s&   _A_ <em>few</em> <script>tags</script>s2   _A_ <em>few</em> &lt;script&gt;tags&lt;/script&gt;N(   R   R   R   (   R   R   (    (    sJ   lib/python2.7/site-packages/nbconvert/preprocessors/tests/test_sanitize.pyt   test_tag_whitelistÅ   s    N(   t   __name__t
   __module__t   __doc__t   Nonet   maxDiffR   R   R   R   R   R   R   R$   R&   R5   R6   (    (    (    sJ   lib/python2.7/site-packages/nbconvert/preprocessors/tests/test_sanitize.pyR      s   				"						)N(   R9   t   baseR    t   sanitizeR   R1   R   R   (    (    (    sJ   lib/python2.7/site-packages/nbconvert/preprocessors/tests/test_sanitize.pyt   <module>   s   