
    	]j;                         d Z ddlZddlZddlmZ ddlmZ ej                  j                  d        Z	ej                  j                  d        Z
ej                  j                  d        Zy)zThis file and its contents are licensed under the Apache License 2.0. Please see the included NOTICE for copyright information and LICENSE for a copy of the license.
    N)
FileUpload)settingsc                    dt         _        d}t        j                  |      }d| j                  j
                   d}| j                  |d|i      }|j                  dk(  sJ d}t        j                  j                  |j                  d   d	   
      j                         j                  j                         }t        dj!                  |j#                  d      j%                                     dkD  sJ dj!                  |j%                               dj!                  |j#                  d      j%                               k(  sJ y)z2Upload malicious SVG file - remove harmful contentT  <?xml version="1.0" standalone="no"?>
                <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
                <svg version="1.1" baseProfile="full" xmlns="http://www.w3.org/2000/svg">
                <polygon id="triangle" points="0,0 0,50 50,0" fill="#009900" stroke="#004400"/>
                <script type="text/javascript">alert(document.cookie);</script>
                </svg>/api/projects//import?commit_to_project=truexss_svg.svg   z<svg version="1.1" baseprofile="full" xmlns="http://www.w3.org/2000/svg">
    <polygon id="triangle" points="0,0 0,50 50,0" fill="#009900" stroke="#004400"></polygon>

    </svg>
file_upload_idsr   id UTF-8d   N)r   SVG_SECURITY_CLEANUPioStringIOprojectr   poststatus_coder   objectsfilterdatalastfilereadlenjoindecodesplitsetup_project_dialog	xml_dirtyfendpointrexpectedactuals          L/root/env/lib/python3.12/site-packages/label_studio/tests/test_upload_svg.pytest_svg_upload_sanitizer*   
   s    %)H!I 	IA 4 < < ? ?@@^_H!!(]A,>?A==CH &&!&&1B*CA*F&GLLNSSXXZFrwwv}}W-33567#===778>>#$g0F0L0L0N(OOOO    c                    dt         _        d}t        j                  |      }d| j                  j
                   d}| j                  |d|i      }|j                  dk(  sJ d}t        j                  j                  |j                  d   d	   
      j                         j                  j                         }dj                  |j!                               dj                  |j#                  d      j!                               k(  sJ y)z(Upload invalid SVG file - still acceptedTa  <?xml version="1.0" standalone="no"?>
                <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
                <svg version="1.1" baseProfile="full" xmlns="http://www.w3.org/2000/svg">gibberish</svg>r   r   r	   r
   z_
    <svgversion="1.1"baseprofile="full"xmlns="http://www.w3.org/2000/svg">gibberish</svg>
    r   r   r   r   r   N)r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r    r   r!   s          r)   test_svg_upload_invalid_formatr-   (   s     %)H!lI 	IA 4 < < ? ?@@^_H!!(]A,>?A==CH &&!&&1B*CA*F&GLLNSSXXZF778>>#$g0F0L0L0N(OOOOr+   c                 2   dt         _        d}t        j                  |      }d| j                  j
                   d}| j                  |d|i      }|j                  dk(  sJ t        j                  j                  |j                  d   d   	      j                         j                  j                         }d
j                  |j!                               d
j                  |j#                  d      j%                  dd
      j!                               k(  sJ y)z.Upload SVG file - do not sanitize file contentFr   r   r   r	   r
   r   r   r   r   r   
N)r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r    r   replace)r"   r#   r$   r%   r&   r(   s         r)   test_svg_upload_do_not_sanitizer1   @   s     %*H!I 	IA 4 < < ? ?@@^_H!!(]A,>?A==C&&!&&1B*CA*F&GLLNSSXXZF779??$%w1G1O1OPTVX1Y1_1_1a)bbbbr+   )__doc__r   pytestdata_import.modelsr   django.confr   mark	django_dbr*   r-   r1    r+   r)   <module>r9      sv    	  )   P P: P P. c cr+   