o
    wÖiýì ã                   @   sô  d dl Z d dlmZ d dlmZ d dlmZmZmZm	Z	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 d d
lmZmZ d dlmZ d dlmZ d dlmZmZmZm Z  d dl!m"Z" d dl#m$Z$m%Z% d dl&m'Z'm(Z(m)Z)m*Z+m,Z,m-Z-m.Z.m/Z/m0Z0m1Z1m2Z2m3Z3m4Z4m5Z5m6Z6m7Z7m8Z8m9Z9m:Z: d dl;Z;d dl<Z<d dl=Z=d dl>Z>d dl?Z@d dlAZAd dlBmCZC d dlDZDd dlEZEd dlFZFd dlGZGd dlHZHd dlIZId dlJZJd dlKZLdd„ ZMG dd„ deƒZNG dd„ deNƒZOG dd„ de(ƒZPG dd„ de(ƒZQG dd„ deJjRƒZSG dd„ deJjRƒZTG d d!„ d!eNƒZUG d"d#„ d#eNƒZVG d$d%„ d%e(ƒZWG d&d'„ d'eNƒZXG d(d)„ d)e(ƒZYG d*d+„ d+eNƒZZG d,d-„ d-e(ƒZ[G d.d/„ d/eNƒZ\G d0d1„ d1e(ƒZ]G d2d3„ d3e(ƒZ^G d4d5„ d5e(ƒZ_G d6d7„ d7e(ƒZ`G d8d9„ d9e(ƒZaG d:d;„ d;e(ƒZbG d<d=„ d=e(ƒZ*G d>d?„ d?e(ƒZcG d@dA„ dAe(ƒZdG dBdC„ dCe(ƒZeG dDdE„ dEe(ƒZfG dFdG„ dGe(ƒZgG dHdI„ dIeNƒZhG dJdK„ dKeNƒZiG dLdM„ dMeNƒZjG dNdO„ dOeNƒZkG dPdQ„ dQeNƒZlG dRdS„ dSeNƒZmG dTdU„ dUeNƒZnG dVdW„ dWeNƒZoG dXdY„ dYeNƒZpG dZd[„ d[eNƒZqG d\d]„ d]eNƒZrG d^d_„ d_eOƒZsG d`da„ daeOƒZtG dbdc„ dceOƒZuG ddde„ deeOƒZvG dfdg„ dgeOƒZwG dhdi„ dieOƒZxG djdk„ dkeNƒZyG dldm„ dmeOƒZzG dndo„ doeNƒZ{G dpdq„ dqeOƒZ|G drds„ dse}ƒZ~G dtdu„ dueOƒZG dvdw„ dweOƒZ€G dxdy„ dyeOƒZG dzd{„ d{eOƒZ‚G d|d}„ d}eOƒZƒG d~d„ deNƒZ„G d€d„ deOƒZ…G d‚dƒ„ dƒeOƒZ†G d„d…„ d…eOƒZ‡G d†d‡„ d‡eOƒZˆG dˆd‰„ d‰eOƒZ‰G dŠd‹„ d‹eNƒZŠG dŒd„ deNƒZ‹G dŽd„ deNƒZŒG dd‘„ d‘eNƒZG d’d“„ d“eNƒZŽe7G d”d•„ d•e(ƒƒZG d–d—„ d—ƒZG d˜d™„ d™eeNƒZ‘G dšd›„ d›eeNƒZ’G dœd„ deOƒZ“G dždŸ„ dŸeOƒZ”G d d¡„ d¡eJjRƒZ•G d¢d£„ d£eOƒZ–G d¤d¥„ d¥eOƒZ—G d¦d§„ d§eOƒZ˜G d¨d©„ d©eOƒZ™G dªd«„ d«eNƒZšG d¬d­„ d­eNƒZ›G d®d¯„ d¯eOƒZœG d°d±„ d±eJjRƒZG d²d³„ d³eƒZžG d´dµ„ dµeJjRƒZŸG d¶d·„ d·eNƒZ G d¸d¹„ d¹eNƒZ¡dS )ºé    N)ÚFuture)Úgen)Újson_decodeÚutf8Ú
to_unicodeÚrecursive_unicodeÚ
native_strÚto_basestring)ÚHTTPClientError)Úformat_timestamp)ÚIOStream)Úlocale)ÚEvent)Úapp_logÚgen_log©ÚSimpleAsyncHTTPClient©Ú
DictLoader)ÚAsyncHTTPTestCaseÚAsyncTestCaseÚ	ExpectLogÚgen_test)Úignore_deprecation)Ú
ObjectDictÚunicode_type)ÚApplicationÚRequestHandlerÚStaticFileHandlerÚRedirectHandlerÚ	HTTPErrorÚMissingArgumentErrorÚErrorHandlerÚauthenticatedÚurlÚ_create_signature_v1Úcreate_signed_valueÚdecode_signed_valueÚget_signature_key_versionÚUIModuleÚFinishÚstream_request_bodyÚremoveslashÚaddslashÚGZipContentEncoding)ÚBytesIOc                  G   s   t jjt j t¡g| ¢R Ž S ©N)ÚosÚpathÚjoinÚdirnameÚ__file__)Úa© r7   úR/home/ubuntu/sommelier/.venv/lib/python3.10/site-packages/tornado/test/web_test.pyÚrelpath?   ó   r9   c                   @   s(   e Zd ZdZdd„ Zdd„ Zdd„ ZdS )	ÚWebTestCasezÂBase class for web tests that also supports WSGI mode.

    Override get_handlers and get_app_kwargs instead of get_app.
    This class is deprecated since WSGI mode is no longer supported.
    c                 C   s    t |  ¡ fi |  ¡ ¤Ž| _| jS r0   )r   Úget_handlersÚget_app_kwargsÚapp©Úselfr7   r7   r8   Úget_appJ   s   zWebTestCase.get_appc                 C   ó   t ƒ ‚r0   ©ÚNotImplementedErrorr?   r7   r7   r8   r<   N   ó   zWebTestCase.get_handlersc                 C   s   i S r0   r7   r?   r7   r7   r8   r=   Q   ó   zWebTestCase.get_app_kwargsN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__rA   r<   r=   r7   r7   r7   r8   r;   C   s
    r;   c                   @   s   e Zd ZdZdZdd„ ZdS )ÚSimpleHandlerTestCasezSimplified base class for tests that work with a single handler class.

    To use, define a nested class named ``Handler``.
    Nc                 C   s   d| j fgS )Nú/©ÚHandlerr?   r7   r7   r8   r<   ]   ó   z"SimpleHandlerTestCase.get_handlers)rG   rH   rI   rJ   rN   r<   r7   r7   r7   r8   rK   U   s    rK   c                   @   ó   e Zd Zdd„ ZdS )ÚHelloHandlerc                 C   ó   |   d¡ d S ©NÚhello©Úwriter?   r7   r7   r8   Úgetb   ó   zHelloHandler.getN©rG   rH   rI   rW   r7   r7   r7   r8   rQ   a   ó    rQ   c                   @   s(   e Zd Zd	dd„Zdd„ Zd
dd„ZdS )ÚCookieTestRequestHandlerÚ
0123456789Nc                 C   s<   i | _ |d u rtt|dd| _d S tt||dd| _d S )N)Úcookie_secret)Úsettings©r]   Úkey_version)Ú_cookiesr   ÚdictÚapplication)r@   r]   r`   r7   r7   r8   Ú__init__h   s   ÿ
ÿz!CookieTestRequestHandler.__init__c                 C   s   | j  |¡S r0   )ra   rW   )r@   Únamer7   r7   r8   Ú
get_cookiet   rO   z#CookieTestRequestHandler.get_cookiec                 C   s   || j |< d S r0   )ra   )r@   re   ÚvalueÚexpires_daysr7   r7   r8   Ú
set_cookiew   rX   z#CookieTestRequestHandler.set_cookie)r\   Nr0   )rG   rH   rI   rd   rf   ri   r7   r7   r7   r8   r[   f   s    
r[   c                   @   ó$   e Zd Zdd„ Zdd„ Zdd„ ZdS )ÚSecureCookieV1Testc                 C   ó0   t ƒ }|jdddd |  |jdddd¡ d S )NÚfooó   baré   ©Úversion©Úmin_version©r[   Úset_signed_cookieÚassertEqualÚget_signed_cookie©r@   Úhandlerr7   r7   r8   Útest_round_trip}   ó   z"SecureCookieV1Test.test_round_tripc                 C   s  t ƒ }|jdt d¡dd |jd }t d|¡}|  |¡ |d us$J ‚| d¡}| d¡}|  	t
|jjd dd|ƒ|¡ |  	t
|jjd dd	d
| ƒ|¡ tdt|ƒ› dt|ƒ› ƒ|jd< ttdƒ |  |jddd¡ W d   ƒ d S 1 szw   Y  d S )Nrm   s   d76df8e7aefcro   rp   s   12345678\|([0-9]+)\|([0-9a-f]+)é   r]   Ú12345678Ú1234s   5678z	1234|5678ú|zCookie timestamp in futurerr   )r[   ru   ÚbinasciiÚa2b_hexra   ÚreÚmatchÚassertIsNotNoneÚgrouprv   r%   rc   r^   r   r	   r   r   ÚassertIsNonerw   )r@   ry   Úcookierƒ   Ú	timestampÚsigr7   r7   r8   Ú&test_cookie_tampering_future_timestamp‚   s@   




üù
üù

ÿ"ÿz9SecureCookieV1Test.test_cookie_tampering_future_timestampc                 C   rl   )Nrm   ó   éro   rp   rr   rt   rx   r7   r7   r8   Útest_arbitrary_bytes©   s   z'SecureCookieV1Test.test_arbitrary_bytesN)rG   rH   rI   rz   rŠ   rŒ   r7   r7   r7   r8   rk   |   s    'rk   c                   @   s>   e Zd ZdddœZdd„ Zdd„ Zdd	„ Zd
d„ Zdd„ ZdS )ÚSecureCookieV2TestÚajklasdf0ojaisdfÚaslkjasaolwkjsdf)r   ro   c                 C   rl   )Nrm   rn   r|   rp   rr   rt   rx   r7   r7   r8   rz   µ   r{   z"SecureCookieV2Test.test_round_tripc                 C   ó0   t | jdd}| dd¡ |  | d¡d¡ d S )Nr   r_   rm   rn   ©r[   ÚKEY_VERSIONSru   rv   rw   rx   r7   r7   r8   Útest_key_version_roundtripº   ó
   ÿz-SecureCookieV2Test.test_key_version_roundtripc                 C   r   )Nro   r_   rm   rn   r‘   rx   r7   r7   r8   Ú,test_key_version_roundtrip_differing_versionÁ   r”   z?SecureCookieV2Test.test_key_version_roundtrip_differing_versionc                 C   sF   t | jdd}| dd¡ t | jdd}|j|_|  | d¡d¡ d S ©Nr   r_   rm   rn   ro   )r[   r’   ru   ra   rv   rw   )r@   ry   Únew_handlerr7   r7   r8   Ú"test_key_version_increment_versionÈ   s   ÿÿz5SecureCookieV2Test.test_key_version_increment_versionc                 C   sX   t | jdd}| dd¡ | j ¡ }| d¡ t |dd}|j|_|  | d¡d ¡ d S r–   )r[   r’   ru   ÚcopyÚpopra   rv   rw   )r@   ry   Únew_key_versionsr—   r7   r7   r8   Ú#test_key_version_invalidate_versionÓ   s   ÿ

ÿz6SecureCookieV2Test.test_key_version_invalidate_versionN)	rG   rH   rI   r’   rz   r“   r•   r˜   rœ   r7   r7   r7   r8   r   ²   s    
r   c                   @   s0   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ ZdS )
ÚFinalReturnTestNc                    s<   | ‰ G ‡ fdd„dt ƒ}G ‡ fdd„dt ƒ}d|fd|fgS )Nc                       s0   e Zd Zej‡ fdd„ƒZej‡ fdd„ƒZdS )z3FinalReturnTest.get_handlers.<locals>.FinishHandlerc                 3   s    |   ¡ ˆ _ˆ jV  d S r0   )ÚfinishÚfinal_returnr?   ©Útestr7   r8   rW   è   s   €
z7FinalReturnTest.get_handlers.<locals>.FinishHandler.getc                 3   s.    |   d¡ |  ¡ V  |  d¡ˆ _ˆ jV  d S )Nzhello,Úworld)rV   Úflushrž   rŸ   r?   r    r7   r8   Úpostí   s
   €

z8FinalReturnTest.get_handlers.<locals>.FinishHandler.postN)rG   rH   rI   r   Ú	coroutinerW   r¤   r7   r    r7   r8   ÚFinishHandlerç   s
    r¦   c                       s&   e Zd Zdd„ Zej‡ fdd„ƒZdS )z3FinalReturnTest.get_handlers.<locals>.RenderHandlerc                 S   s   t ddiƒS )Núfoo.htmlÚhir   ©r@   r2   r7   r7   r8   Úcreate_template_loaderõ   rO   zJFinalReturnTest.get_handlers.<locals>.RenderHandler.create_template_loaderc                    s   |   d¡ˆ _d S ©Nr§   )ÚrenderrŸ   r?   r    r7   r8   rW   ø   s   z7FinalReturnTest.get_handlers.<locals>.RenderHandler.getN)rG   rH   rI   rª   r   r¥   rW   r7   r    r7   r8   ÚRenderHandlerô   s    r­   ú/finishú/render©r   )r@   r¦   r­   r7   r    r8   r<   ä   s   zFinalReturnTest.get_handlersc                 C   ó
   t ddS )Nr   )Útemplate_path©rb   r?   r7   r7   r8   r=   þ   ó   
zFinalReturnTest.get_app_kwargsc                 C   s‚   |   |  d¡¡}|  |jd¡ |  | jt¡ |  | j ¡ ¡ | j |  d¡ddd}|  |jd¡ |  | jt¡ |  | j ¡ ¡ d S )Nr®   éÈ   ÚPOSTó    ©ÚmethodÚbody)	ÚfetchÚget_urlrv   ÚcodeÚassertIsInstancerŸ   r   Ú
assertTrueÚdone©r@   Úresponser7   r7   r8   Ú test_finish_method_return_future  s   z0FinalReturnTest.test_finish_method_return_futurec                 C   s0   |   |  d¡¡}|  |jd¡ |  | jt¡ d S )Nr¯   rµ   )r»   r¼   rv   r½   r¾   rŸ   r   rÁ   r7   r7   r8   Ú test_render_method_return_future  s   z0FinalReturnTest.test_render_method_return_future)rG   rH   rI   rŸ   r<   r=   rÃ   rÄ   r7   r7   r7   r8   r   á   s    r   c                   @   ód   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ Zdd„ Zdd„ Z	dd„ Z
dd„ Zdd„ Zdd„ ZdS )Ú
CookieTestc                 C   sà   G dd„ dt ƒ}G dd„ dt ƒ}G dd„ dt ƒ}G dd„ dt ƒ}G d	d
„ d
t ƒ}G dd„ dt ƒ}G dd„ dt ƒ}G dd„ dt ƒ}G dd„ dt ƒ}	G dd„ dt ƒ}
d|fd|fd|fd|fd|fd|fd|fd|fd|	fd|
fg
S )Nc                   @   rP   )z1CookieTest.get_handlers.<locals>.SetCookieHandlerc                 S   ó(   |   dd¡ |   dd¡ |   dd¡ d S )NÚstrÚasdfÚunicodeÚqwerÚbytess   zxcv©ri   r?   r7   r7   r8   rW     s   z5CookieTest.get_handlers.<locals>.SetCookieHandler.getNrY   r7   r7   r7   r8   ÚSetCookieHandler  rZ   rÎ   c                   @   rP   )z1CookieTest.get_handlers.<locals>.GetCookieHandlerc                 S   s&   |   dd¡}|d usJ ‚|  |¡ d S )Nrm   Údefault)rf   rV   )r@   r‡   r7   r7   r8   rW     s   z5CookieTest.get_handlers.<locals>.GetCookieHandler.getNrY   r7   r7   r7   r8   ÚGetCookieHandler  rZ   rÐ   c                   @   rP   )z7CookieTest.get_handlers.<locals>.SetCookieDomainHandlerc                 S   ó   | j ddddd d S )NÚunicode_argsÚblahzfoo.comú/foo)Údomainr2   rÍ   r?   r7   r7   r8   rW   #  s   z;CookieTest.get_handlers.<locals>.SetCookieDomainHandler.getNrY   r7   r7   r7   r8   ÚSetCookieDomainHandler"  rZ   rÖ   c                   @   rP   )z<CookieTest.get_handlers.<locals>.SetCookieSpecialCharHandlerc                 S   rÇ   )NÚequalsúa=bÚ	semicolonúa;bÚquoteúa"brÍ   r?   r7   r7   r8   rW   *  s   z@CookieTest.get_handlers.<locals>.SetCookieSpecialCharHandler.getNrY   r7   r7   r7   r8   ÚSetCookieSpecialCharHandler(  ó    rÝ   c                   @   rP   )z>CookieTest.get_handlers.<locals>.SetCookieForbiddenCharHandlerc                 S   sÞ  t tttdƒƒƒtdƒdg D ]Ý}z|  d| d¡ |  d| ¡ W n# tjjyE } zdt	|ƒvr;|  d||f ¡ W Y d }~nd }~ww z| jddd	| d
 d |  d| ¡ W n# tjjy~ } zdt	|ƒvrt|  d||f ¡ W Y d }~nd }~ww z| jddd| d |  d| ¡ W n# tjjyµ } zdt	|ƒvr«|  d||f ¡ W Y d }~nd }~ww z| jddd| d |  d| ¡ W q tjjyì } zdt	|ƒvrâ|  d||f ¡ W Y d }~qd }~ww d S )Né    é   ú;rm   Úbarz2Didn't get expected exception for char %r in name
zInvalid cookie attribute namez-unexpected exception for char %r in name: %s
Úexamplez.com©rÕ   z4Didn't get expected exception for char %r in domain
zInvalid cookie attribute domainz/unexpected exception for char %r in domain: %s
rL   ©r2   z2Didn't get expected exception for char %r in path
zInvalid cookie attribute pathz-unexpected exception for char %r in path: %s
r6   )Úsamesitez6Didn't get expected exception for char %r in samesite
z!Invalid cookie attribute samesitez1unexpected exception for char %r in samesite: %s
)
ÚlistÚmapÚchrÚrangeri   rV   ÚhttpÚcookiesÚCookieErrorrÈ   )r@   ÚcharÚer7   r7   r8   rW   0  s|   "ÿÿÿ€þÿÿÿÿ€þÿÿÿ€þÿÿÿÿ€þÔzBCookieTest.get_handlers.<locals>.SetCookieForbiddenCharHandler.getNrY   r7   r7   r7   r8   ÚSetCookieForbiddenCharHandler/  rZ   rð   c                   @   rP   )z:CookieTest.get_handlers.<locals>.SetCookieOverwriteHandlerc                 S   s0   | j dddd | j dddd |   dd¡ d S )Nr6   Úbzexample.comrä   ÚcÚdrï   rÍ   r?   r7   r7   r8   rW   g  s   z>CookieTest.get_handlers.<locals>.SetCookieOverwriteHandler.getNrY   r7   r7   r7   r8   ÚSetCookieOverwriteHandlerf  rZ   rô   c                   @   rP   )z7CookieTest.get_handlers.<locals>.SetCookieMaxAgeHandlerc                 S   ó   | j dddd d S )Nrm   râ   é
   )Úmax_agerÍ   r?   r7   r7   r8   rW   o  ó   z;CookieTest.get_handlers.<locals>.SetCookieMaxAgeHandler.getNrY   r7   r7   r7   r8   ÚSetCookieMaxAgeHandlern  rZ   rù   c                   @   rP   )z<CookieTest.get_handlers.<locals>.SetCookieExpiresDaysHandlerc                 S   rõ   )Nrm   râ   rö   )rh   rÍ   r?   r7   r7   r8   rW   s  rø   z@CookieTest.get_handlers.<locals>.SetCookieExpiresDaysHandler.getNrY   r7   r7   r7   r8   ÚSetCookieExpiresDaysHandlerr  rZ   rú   c                   @   rP   )z4CookieTest.get_handlers.<locals>.SetCookieFalsyFlagsc                 S   sD   | j dddd | j dddd | j dddd | j d	ddd d S )
Nr6   Ú1T)Úsecurerñ   Frò   )Úhttponlyró   rÍ   r?   r7   r7   r8   rW   w  s   z8CookieTest.get_handlers.<locals>.SetCookieFalsyFlags.getNrY   r7   r7   r7   r8   ÚSetCookieFalsyFlagsv  rZ   rþ   c                   @   rP   )z8CookieTest.get_handlers.<locals>.SetCookieDeprecatedArgsc                 S   rÑ   )Nr6   rñ   TrÔ   )ÚHttpOnlyÚpATHrÍ   r?   r7   r7   r8   rW   ~  s   z<CookieTest.get_handlers.<locals>.SetCookieDeprecatedArgs.getNrY   r7   r7   r7   r8   ÚSetCookieDeprecatedArgs}  rZ   r  ú/setú/getú/set_domainú/special_charú/forbidden_charú/set_overwriteú/set_max_ageú/set_expires_daysú/set_falsy_flagsú/set_deprecatedr°   )r@   rÎ   rÐ   rÖ   rÝ   rð   rô   rù   rú   rþ   r  r7   r7   r8   r<     s*   7özCookieTest.get_handlersc                 C   s*   |   d¡}|  t|j d¡ƒg d¢¡ d S )Nr  ú
Set-Cookie)zbytes=zxcv; Path=/zstr=asdf; Path=/zunicode=qwer; Path=/)r»   rv   ÚsortedÚheadersÚget_listrÁ   r7   r7   r8   Útest_set_cookie  s
   
þzCookieTest.test_set_cookiec                 C   sd   | j dddid}|  |jd¡ | j dddid}|  |jd¡ | j dddid}|  |jd¡ d S )	Nr  ÚCookieúfoo=bar©r  rn   z	foo="bar"z/=exception;ó   default©r»   rv   rº   rÁ   r7   r7   r8   Útest_get_cookie–  s   zCookieTest.test_get_cookiec                 C   s$   |   d¡}|  |j d¡dg¡ d S )Nr  r  z,unicode_args=blah; Domain=foo.com; Path=/foo©r»   rv   r  r  rÁ   r7   r7   r8   Útest_set_cookie_domain   s
   

þz!CookieTest.test_set_cookie_domainc                 C   sª   |   d¡}t|j d¡ƒ}|  t|ƒd¡ |  |d d¡ |  |d d¡ |  |d d	|d ¡ g d
¢}|D ]\}}t d|¡ | j dd|id}|  |j	t
|ƒ¡ q6d S )Nr  r  é   r   zequals="a=b"; Path=/ro   zquote="a\"b"; Path=/r|   )zsemicolon="a;b"; Path=/zsemicolon="a\073b"; Path=/))zfoo=a=brØ   )z	foo="a=b"rØ   )z	foo="a;b"z"a)z
foo=a\073bza\073b)zfoo="a\073b"rÚ   )z
foo="a\"b"rÜ   z	trying %rr  r  r  )r»   r  r  r  rv   ÚlenÚassertInÚloggingÚdebugrº   r   )r@   rÂ   r  ÚdataÚheaderÚexpectedr7   r7   r8   Útest_cookie_special_char§  s    
ýýz#CookieTest.test_cookie_special_charc                 C   s4   |   d¡}|  |jd¡ d| _|  t|jƒd¡ d S )Nr  rµ   i'  Ú )r»   rv   r½   ÚmaxDiffÚassertMultiLineEqualr   rº   rÁ   r7   r7   r8   Útest_set_cookie_forbidden_charÁ  s   
z)CookieTest.test_set_cookie_forbidden_charc                 C   s.   |   d¡}|j d¡}|  t|ƒddg¡ d S )Nr  r  za=e; Path=/zc=d; Domain=example.com; Path=/©r»   r  r  rv   r  ©r@   rÂ   r  r7   r7   r8   Útest_set_cookie_overwriteÇ  s
   
ÿz$CookieTest.test_set_cookie_overwritec                 C   s,   |   d¡}|j d¡}|  t|ƒdg¡ d S )Nr  r  zfoo=bar; Max-Age=10; Path=/r&  r'  r7   r7   r8   Útest_set_cookie_max_ageÎ  s   
z"CookieTest.test_set_cookie_max_agec                 C   sš   |   d¡}|j d¡}|  |¡ |d usJ ‚t d|¡}|  |¡ |d us'J ‚tj tjj	¡tj
dd }tj | ¡ d ¡}|  t||  ¡ ƒd¡ d S )Nr	  r  z(foo=bar; expires=(?P<expires>.+); Path=/rö   ©ÚdaysÚexpires)r»   r  rW   r„   r‚   rƒ   ÚdatetimeÚnowÚtimezoneÚutcÚ	timedeltaÚemailÚutilsÚparsedate_to_datetimeÚ	groupdictÚ
assertLessÚabsÚtotal_seconds©r@   rÂ   r  rƒ   r,  Úheader_expiresr7   r7   r8   Útest_set_cookie_expires_daysÓ  s   


ÿz'CookieTest.test_set_cookie_expires_daysc                 C   s^   |   d¡}t|j d¡ƒ}|  |d d¡ |  |d d¡ |  |d d¡ |  |d	 d
¡ d S )Nr
  r  r   za=1; Path=/; Securero   zb=1; Path=/r|   zc=1; HttpOnly; Path=/r  zd=1; Path=/)r»   r  r  r  rv   r'  r7   r7   r8   Útest_set_cookie_false_flagsâ  s   
z&CookieTest.test_set_cookie_false_flagsc                 C   sL   t ƒ  |  d¡}W d   ƒ n1 sw   Y  |j d¡}|  |d¡ d S )Nr  r  za=b; HttpOnly; Path=/foo)r   r»   r  rW   rv   )r@   rÂ   r  r7   r7   r8   Útest_set_cookie_deprecatedê  s
   ÿz%CookieTest.test_set_cookie_deprecatedN)rG   rH   rI   r<   r  r  r  r!  r%  r(  r)  r;  r<  r=  r7   r7   r7   r8   rÆ     s    |
rÆ   c                   @   s(   e Zd Zdd„ Zdd„ Zedd„ ƒZdS )ÚAuthRedirectRequestHandlerc                 C   ó
   || _ d S r0   ©Ú	login_url)r@   rA  r7   r7   r8   Ú
initializeò  r´   z%AuthRedirectRequestHandler.initializec                 C   ó   | j S r0   r@  r?   r7   r7   r8   Úget_login_urlõ  rE   z(AuthRedirectRequestHandler.get_login_urlc                 C   rR   )Néô  )Ú
send_errorr?   r7   r7   r8   rW   ø  ó   zAuthRedirectRequestHandler.getN)rG   rH   rI   rB  rD  r#   rW   r7   r7   r7   r8   r>  ñ  s
    r>  c                   @   rj   )ÚAuthRedirectTestc                 C   s    dt tddfdt tddfgS )Nú	/relativez/loginr@  ú	/absolutezhttp://example.com/login)r>  rb   r?   r7   r7   r8   r<   ÿ  s   ýþzAuthRedirectTest.get_handlersc                 C   s8   | j |  d¡dd}|  |jd¡ |  |jd d¡ d S )NrI  F©Úfollow_redirectsé.  ÚLocationz/login?next=%2Frelative)r»   r¼   rv   r½   r  rÁ   r7   r7   r8   Útest_relative_auth_redirect	  s   z,AuthRedirectTest.test_relative_auth_redirectc                 C   sF   | j |  d¡dd}|  |jd¡ |  t d|jd ¡|jd ¡ d S )NrJ  FrK  rM  zIhttp://example.com/login\?next=http%3A%2F%2F127.0.0.1%3A[0-9]+%2FabsoluterN  )r»   r¼   rv   r½   r¿   r‚   rƒ   r  rÁ   r7   r7   r8   Útest_absolute_auth_redirect  s   þûz,AuthRedirectTest.test_absolute_auth_redirectN)rG   rH   rI   r<   rO  rP  r7   r7   r7   r8   rH  þ  s    
rH  c                   @   s*   e Zd Zdd„ Zejdd„ ƒZdd„ ZdS )ÚConnectionCloseHandlerc                 C   r?  r0   r    ©r@   r¡   r7   r7   r8   rB    r´   z!ConnectionCloseHandler.initializec                 c   s    | j  ¡  | j j ¡ V  d S r0   )r¡   Úon_handler_waitingÚcleanup_eventÚwaitr?   r7   r7   r8   rW     s   €
zConnectionCloseHandler.getc                 C   s   | j  ¡  d S r0   )r¡   Úon_connection_closer?   r7   r7   r8   rV  #  rX   z*ConnectionCloseHandler.on_connection_closeN)rG   rH   rI   rB  r   r¥   rW   rV  r7   r7   r7   r8   rQ    s
    
rQ  c                   @   ó,   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	S )
ÚConnectionCloseTestc                 C   s   t ƒ | _dtt| dfgS )NrL   r    )r   rT  rQ  rb   r?   r7   r7   r8   r<   (  s   z ConnectionCloseTest.get_handlersc                 C   s`   t   t jt jd¡}| d|  ¡ f¡ t|ƒ| _| j d¡ |  ¡  | j	 
¡  | j dd„ ¡ d S )Nr   ú	127.0.0.1s   GET / HTTP/1.0

c                   S   s
   t  d¡S ©Nr   )r   Úsleepr7   r7   r7   r8   Ú<lambda>4  s   
 z;ConnectionCloseTest.test_connection_close.<locals>.<lambda>)ÚsocketÚAF_INETÚSOCK_STREAMÚconnectÚget_http_portr   ÚstreamrV   rU  rT  ÚsetÚio_loopÚrun_sync)r@   Úsr7   r7   r8   Útest_connection_close,  s   

z)ConnectionCloseTest.test_connection_closec                 C   s   t  d¡ | j ¡  d S )Nzhandler waiting)r  r  rb  Úcloser?   r7   r7   r8   rS  6  ó   
z&ConnectionCloseTest.on_handler_waitingc                 C   s   t  d¡ |  ¡  d S )Nzconnection closed)r  r  Ústopr?   r7   r7   r8   rV  :  ó   
z'ConnectionCloseTest.on_connection_closeN)rG   rH   rI   r<   rg  rS  rV  r7   r7   r7   r8   rX  '  s
    
rX  c                   @   rP   )ÚEchoHandlerc                 G   sÎ   | j jD ]=}t|ƒturtdt|ƒ ƒ‚| j j| D ]}t|ƒtur*tdt|ƒ ƒ‚q|  |¡D ]}t|ƒtur@tdt|ƒ ƒ‚q0q|D ]}t|ƒturTtdt|ƒ ƒ‚qD|  t	| j j
|t| j jƒd¡ d S )Nzincorrect type for key: %rzincorrect type for value: %rzincorrect type for path arg: %r©r2   Ú	path_argsÚargs)ÚrequestÚ	argumentsÚtyperÈ   Ú	ExceptionrÌ   Úget_argumentsr   rV   rb   r2   r   )r@   rn  ÚkeyÚbvalueÚsvalueÚargr7   r7   r8   rW   @  s.   ÿÿÿÿ
ýÿzEchoHandler.getNrY   r7   r7   r7   r8   rl  ?  rZ   rl  c                   @   s<   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ Zdd„ ZdS )ÚRequestEncodingTestc                 C   s   dt fdt fgS )Nz/group/(.*)z/slashes/([^/]*)/([^/]*))rl  r?   r7   r7   r8   r<   [  ó   z RequestEncodingTest.get_handlersc                 C   s   t |  |¡jƒS r0   )r   r»   rº   r©   r7   r7   r8   Ú
fetch_json^  rz  zRequestEncodingTest.fetch_jsonc                 C   sF   |   |  d¡tddgi d¡ |   |  d¡tddgddgid¡ d S )Nz
/group/%3Fú?rm  z/group/%3F?%3F=%3F©rv   r{  rb   r?   r7   r7   r8   Útest_group_question_marka  s   þþz,RequestEncodingTest.test_group_question_markc                 C   s&   |   |  d¡ddgddgidœ¡ d S )Nz/group/%C3%A9?arg=%C3%A9z/group/%C3%A9õ   Ã©rx  rm  ©rv   r{  r?   r7   r7   r8   Útest_group_encodingl  s   ýþz'RequestEncodingTest.test_group_encodingc                 C   sD   |   |  d¡tdddgi d¡ |   |  d¡tdddgi d¡ d S )Nz/slashes/foo/barrm   râ   rm  z/slashes/a%2Fb/c%2Fdza/bzc/dr}  r?   r7   r7   r8   Útest_slashesw  s   þþz RequestEncodingTest.test_slashesc                 C   ó:   t tdƒ |  d¡ W d   ƒ d S 1 sw   Y  d S )Nz.*Invalid unicodez/group/?arg=%25%e9)r   r   r»   r?   r7   r7   r8   Ú
test_errorƒ  ó   "ÿzRequestEncodingTest.test_errorN)	rG   rH   rI   r<   r{  r~  r  r‚  r„  r7   r7   r7   r8   ry  Z  s    ry  c                   @   rW  )
ÚTypeCheckHandlerc                 C   s  i | _ |  d|  ¡ t¡ |  d|  d¡t¡ |  dt| j ¡ ƒd t	¡ |  dt| j 
¡ ƒd jt	¡ t| j ¡ ƒdgkrFtd| j ¡  ƒ‚|  d	|  d¡t¡ |  d
|  d¡t	¡ |  d| jt¡ |  d|  ¡ t	¡ |  d|  dd¡t	¡ |  d|  ¡ t	¡ d S )NÚstatusÚargumentrm   Ú
cookie_keyr   Úcookie_valuerÉ   z%unexpected values for cookie keys: %rrw   rf   Ú
xsrf_tokenÚxsrf_form_htmlÚreverse_urlÚ	typecheckÚrequest_summary)ÚerrorsÚ
check_typeÚ
get_statusÚintÚget_argumentr   rç   rì   ÚkeysrÈ   Úvaluesrg   rs  rw   rÌ   rf   r‹  rŒ  r  Ú_request_summaryr?   r7   r7   r8   Úprepare‹  s   ÿzTypeCheckHandler.preparec                 C   ó   |   d|t¡ |  | j¡ d S ©NÚpath_component©r‘  r   rV   r  ©r@   r›  r7   r7   r8   rW   ¦  s   zTypeCheckHandler.getc                 C   r™  rš  rœ  r  r7   r7   r8   r¤   ¬  s   zTypeCheckHandler.postc                 C   s.   t |ƒ}||krd|› d|› | j|< d S d S )Nz	expected z, got )rr  r  )r@   re   ÚobjÚexpected_typeÚactual_typer7   r7   r8   r‘  °  s   ÿzTypeCheckHandler.check_typeN)rG   rH   rI   r˜  rW   r¤   r‘  r7   r7   r7   r8   r†  Š  s
    r†  c                   @   s   e Zd Zddd„Zdd„ ZdS )ÚDecodeArgHandlerNc                 C   sF   t |ƒturtdt |ƒ ƒ‚d| jjv r!| t| jjd d ƒ¡S |S )Nzunexpected type for value: %rÚencodingr   )rr  rÌ   rs  rp  rq  Údecoder   )r@   rg   re   r7   r7   r8   Údecode_argument·  s
   z DecodeArgHandler.decode_argumentc                 C   s*   dd„ }|   ||ƒ||  d¡ƒdœ¡ d S )Nc                 S   s:   t | ƒtu rdtt | ¡ƒgS t | ƒtu rd| gS tdƒ‚)NrÌ   rÊ   zunknown type)rr  rÌ   r   r€   Úb2a_hexr   rs  )rf  r7   r7   r8   ÚdescribeÁ  s
   z&DecodeArgHandler.get.<locals>.describerm   ©r2   Úquery)rV   r”  )r@   rx  r¦  r7   r7   r8   rW   À  s   "zDecodeArgHandler.getr0   )rG   rH   rI   r¤  rW   r7   r7   r7   r8   r¡  ¶  s    
	r¡  c                   @   rP   )ÚLinkifyHandlerc                 C   s   | j ddd d S )Núlinkify.htmlzhttp://example.com)Úmessage©r¬   r?   r7   r7   r8   rW   Ì  ó   zLinkifyHandler.getNrY   r7   r7   r7   r8   r©  Ë  rZ   r©  c                   @   rP   )ÚUIModuleResourceHandlerc                 C   s   | j dddgd d S )Nú	page.htmlro   r|   )Úentriesr¬  r?   r7   r7   r8   rW   Ñ  ó   zUIModuleResourceHandler.getNrY   r7   r7   r7   r8   r®  Ð  rZ   r®  c                   @   rP   )ÚOptionalPathHandlerc                 C   s   |   d|i¡ d S )Nr2   rU   r©   r7   r7   r8   rW   Ö  r­  zOptionalPathHandler.getNrY   r7   r7   r7   r8   r²  Õ  rZ   r²  c                   @   rP   )ÚMultiHeaderHandlerc                 C   s4   |   dd¡ |   dd¡ |  dd¡ |  dd¡ d S )	Núx-overwriterû   zX-Overwriter|   úx-multir  zX-MultiÚ4)Ú
set_headerÚ
add_headerr?   r7   r7   r8   rW   Û  s   zMultiHeaderHandler.getNrY   r7   r7   r7   r8   r³  Ú  rZ   r³  c                   @   rP   )r   c                 C   sd   |   dd ¡d ur| jdtt|   d¡ƒƒd d S |   dd ¡d ur.| jdt|   d¡ƒd d S tdƒ‚)NÚ	permanentrL   )r¹  r‡  )r‡  z(didn't get permanent or status arguments)r”  ÚredirectÚboolr“  rs  r?   r7   r7   r8   rW   ã  s
    zRedirectHandler.getNrY   r7   r7   r7   r8   r   â  rZ   r   c                   @   ó   e Zd Zejdd„ ƒZdS )ÚEmptyFlushCallbackHandlerc                 c   sB    |   ¡ V  |   ¡ V  |  d¡ |   ¡ V  |   ¡ V  |  d¡ d S )NÚoÚk)r£   rV   rž   r?   r7   r7   r8   rW   í  s   €




zEmptyFlushCallbackHandler.getN)rG   rH   rI   r   r¥   rW   r7   r7   r7   r8   r½  ì  ó    r½  c                   @   rP   )ÚHeaderInjectionHandlerc              
   C   sV   z
|   dd¡ tdƒ‚ ty* } zdt|ƒv r|  d¡ n‚ W Y d }~d S d }~ww )NúX-Foozfoo
X-Bar: bazúDidn't get expected exceptionúUnsafe header valueó   ok)r·  rs  Ú
ValueErrorrÈ   rž   ©r@   rï   r7   r7   r8   rW   û  s   þ€þzHeaderInjectionHandler.getNrY   r7   r7   r7   r8   rÁ  ú  rZ   rÁ  c                   @   rP   )ÚSetHeaderHandlerc                 C   sž   dd„ t ddƒD ƒ}| tdƒ¡ | d¡ |D ])}z|  dd| d	 ¡ td
ƒ‚ tyA } zdt|ƒvr7‚ W Y d }~qd }~ww |  dd¡ |  d¡ d S )Nc                 S   s   g | ]}t |ƒ‘qS r7   )ré   )Ú.0r¾  r7   r7   r8   Ú
<listcomp>	  ó    z(SetHeaderHandler.get.<locals>.<listcomp>r   rß   rà   ú	rÂ  rm   râ   rÃ  rÄ  r"  rÅ  )	rê   Úappendré   Úremover·  rs  rÆ  rÈ   rž   )r@   Úillegal_charsrî   rï   r7   r7   r8   rW     s   
ÿ€ÿzSetHeaderHandler.getNrY   r7   r7   r7   r8   rÈ    rZ   rÈ  c                   @   rP   )ÚGetArgumentHandlerc                 C   sJ   |   dd ¡dkr| j}n|   dd ¡dkr| j}n| j }|  |ddƒ¡ d S )NÚsourcer¨  rº   rm   rÏ   )r”  Úget_query_argumentÚget_body_argumentrž   ©r@   r¹   r7   r7   r8   r˜    s   zGetArgumentHandler.prepareN©rG   rH   rI   r˜  r7   r7   r7   r8   rÐ    rZ   rÐ  c                   @   rP   )ÚGetArgumentsHandlerc                 C   s*   |   t|  d¡|  d¡|  d¡d¡ d S )Nrm   ©rÏ   r¨  rº   )rž   rb   rt  Úget_query_argumentsÚget_body_argumentsr?   r7   r7   r8   r˜  &  s   ýÿzGetArgumentsHandler.prepareNrÕ  r7   r7   r7   r8   rÖ  %  rZ   rÖ  c                       sÈ   e Zd ZdZdd„ Z‡ fdd„Zdd„ Zdd	„ Zd
d„ Zdd„ Z	dd„ Z
dd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zd d!„ Zd"d#„ Zd$d%„ Zd&d'„ Zd(d)„ Zd*d+„ Zd,d-„ Z‡  ZS ).ÚWSGISafeWebTestzWebTest.COOKIE_SECRETc                 C   s    t ddddœƒ}t|d| jdS )Nz{% module linkify(message) %}zv<html><head></head><body>
{% for e in entries %}
{% module Template("entry.html", entry=e) %}
{% end %}
</body></html>aY  {{ set_resources(embedded_css=".entry { margin-bottom: 1em; }",
                 embedded_javascript="js_embed()",
                 css_files=["/base.css", "/foo.css"],
                 javascript_files="/common.js",
                 html_head="<meta>",
                 html_body='<script src="/analytics.js"/>') }}
<div class="entry">...</div>)rª  r¯  z
entry.htmlÚxhtml_escape)Útemplate_loaderÚ
autoescaper]   )r   rb   ÚCOOKIE_SECRET)r@   Úloaderr7   r7   r8   r=   4  s   øÿýzWSGISafeWebTest.get_app_kwargsc                    ó   t ƒ  ¡  tj ¡  d S r0   ©ÚsuperÚtearDownr   Ú_template_loadersÚclearr?   ©Ú	__class__r7   r8   rã  N  ri  zWSGISafeWebTest.tearDownc                 C   sœ   t dtddt dtddt dtƒt dtƒt dtƒt d	tƒt d
tƒt dtƒt dtddiƒt dtdddœƒt dtddiƒt dt	ƒt dt
ƒt dtƒt dtƒg}|S )Nz/typecheck/(.*)rŽ  )re   z/decode_arg/(.*)Ú
decode_argz/decode_arg_kw/(?P<arg>.*)ú/linkifyú/uimodule_resourcesz/optional_path/(.+)?ú/multi_headerz	/redirectú/web_redirect_permanentr$   ú/web_redirect_newpathú/web_redirectF)r$   r¹  ú//web_redirect_double_slashú/header_injectionú/get_argumentz/get_argumentsú/set_header)r$   r†  r¡  r©  r®  r²  r³  r   ÚWebRedirectHandlerrÁ  rÐ  rÖ  rÈ  )r@   Úurlsr7   r7   r8   r<   R  s:   ýýýåzWSGISafeWebTest.get_handlersc                 O   s"   | j |i |¤Ž}| ¡  t|jƒS r0   )r»   Úrethrowr   rº   )r@   ro  ÚkwargsrÂ   r7   r7   r8   r{  r  s   
zWSGISafeWebTest.fetch_jsonc                 C   s\   t t| jddƒƒ}| jddd| id}t|jƒ}|  |i ¡ | jdddd| idd	}d S )
NrÉ   rË   z/typecheck/asdf?foo=barr  zasdf=r  r¶   r  ©r¹   r  rº   )r   r&   rÞ  r»   r   rº   rv   )r@   rŠ  rÂ   r  r7   r7   r8   Ú
test_typesw  s   ÿÿ


üzWSGISafeWebTest.test_typesc                 C   s‚   g d¢}|D ]}|   |¡}| ¡  t|jƒ}|  |ddgddgdœ¡ q|   d¡}| ¡  t|jƒ}|  |ddgddgdœ¡ d S )N)z,/decode_arg/%C3%A9?foo=%C3%A9&encoding=utf-8z'/decode_arg/%E9?foo=%E9&encoding=latin1z*/decode_arg_kw/%E9?foo=%E9&encoding=latin1rÊ   r  r§  z/decode_arg/%C3%A9?foo=%C3%A9rÌ   Úc3a9©r»   rõ  r   rº   rv   ©r@   rô  Úreq_urlrÂ   r  r7   r7   r8   Útest_decode_argumentˆ  s   

þ

z$WSGISafeWebTest.test_decode_argumentc                 C   s`   t tdƒ! |  d¡}|  |jd¡ |  d¡}|  |jd¡ W d   ƒ d S 1 s)w   Y  d S )Nz.*Invalid unicode.*z/typecheck/invalid%FFé  z/typecheck/invalid?foo=%FF©r   r   r»   rv   r½   rÁ   r7   r7   r8   Ú$test_decode_argument_invalid_unicode  s   

"üz4WSGISafeWebTest.test_decode_argument_invalid_unicodec                 C   sL   ddg}|D ]}|   |¡}| ¡  t|jƒ}|  |ddgddgdœ¡ qd S )Nz6/decode_arg/1%20%2B%201?foo=1%20%2B%201&encoding=utf-8z0/decode_arg/1%20+%201?foo=1+%2B+1&encoding=utf-8rÊ   ú1 + 1r§  rú  rû  r7   r7   r8   Útest_decode_argument_plus¥  s   þ

þüz)WSGISafeWebTest.test_decode_argument_plusc                 C   sr   |   | j dd¡d¡ |   | j dd¡d¡ |   | j dd¡d¡ |   | j dd¡d	¡ |   | j dd
¡d¡ d S )Nrè  rm   z/decode_arg/fooé*   z/decode_arg/42r‹   z/decode_arg/%E9r  z/decode_arg/%C3%A9r  z/decode_arg/1%20%2B%201)rv   r>   r  r?   r7   r7   r8   Útest_reverse_url´  s   ÿÿz WSGISafeWebTest.test_reverse_urlc                 C   ó   |   d¡}|  |jd¡ d S )Nré  s3   <a href="http://example.com">http://example.com</a>r  rÁ   r7   r7   r8   Útest_uimodule_unescaped¿  s   
ÿz'WSGISafeWebTest.test_uimodule_unescapedc                 C   r  )Nrê  s¿  <html><head><link href="/base.css" type="text/css" rel="stylesheet"/><link href="/foo.css" type="text/css" rel="stylesheet"/>
<style type="text/css">
.entry { margin-bottom: 1em; }
</style>
<meta>
</head><body>


<div class="entry">...</div>


<div class="entry">...</div>

<script src="/common.js" type="text/javascript"></script>
<script type="text/javascript">
//<![CDATA[
js_embed()
//]]>
</script>
<script src="/analytics.js"/>
</body></html>r  rÁ   r7   r7   r8   Útest_uimodule_resourcesÅ  ó
   
þz'WSGISafeWebTest.test_uimodule_resourcesc                 C   s0   |   |  d¡ddi¡ |   |  d¡dd i¡ d S )Nz/optional_path/foor2   rm   z/optional_path/r€  r?   r7   r7   r8   Útest_optional_pathá  ó   z"WSGISafeWebTest.test_optional_pathc                 C   s8   |   d¡}|  |jd d¡ |  |j d¡ddg¡ d S )Nrë  r´  Ú2rµ  Ú3r¶  r  rÁ   r7   r7   r8   Útest_multi_headerå  s   
z!WSGISafeWebTest.test_multi_headerc                 C   sX   | j ddd}|  |jd¡ | j ddd}|  |jd¡ | j ddd}|  |jd¡ d S )	Nz/redirect?permanent=1FrK  é-  z/redirect?permanent=0rM  z/redirect?status=307i3  ©r»   rv   r½   rÁ   r7   r7   r8   Útest_redirectê  s   zWSGISafeWebTest.test_redirectc                 C   s`   | j ddd}|  |jd¡ |  |jd d¡ | j ddd}|  |jd¡ |  |jd d¡ d S )	Nrì  FrK  r  rN  rí  rî  rM  ©r»   rv   r½   r  rÁ   r7   r7   r8   Útest_web_redirectò  s   z!WSGISafeWebTest.test_web_redirectc                 C   ó2   | j ddd}|  |jd¡ |  |jd d¡ d S )Nrï  FrK  r  rN  rí  r  rÁ   r7   r7   r8   Útest_web_redirect_double_slashú  ó   z.WSGISafeWebTest.test_web_redirect_double_slashc                 C   r  )Nrð  rÅ  r  rÁ   r7   r7   r8   Útest_header_injectionÿ  ó   
z%WSGISafeWebTest.test_header_injectionc                 C   r  )Nrò  rÅ  r  rÁ   r7   r7   r8   Útest_set_header  r  zWSGISafeWebTest.test_set_headerc                 C   s°   |   d¡}|  |jd¡ |   d¡}|  |jd¡ |   d¡}|  |jd¡ tj tdd¡}| j dd	|d
}|  |jd¡ | j dd	|d
}|  t|jƒtddgdgdgd¡ d S )Nz/get_argument?foo=barrn   z/get_argument?foo=r·   rñ  r  rT   ©rm   r¶   r¸   ó   helloz/get_arguments?foo=barrâ   r×  )r»   rv   rº   ÚurllibÚparseÚ	urlencoderb   r   )r@   rÂ   rº   r7   r7   r8   Útest_get_argument  s   


þz!WSGISafeWebTest.test_get_argumentc                 C   sp   t j tdd¡}| jdd|d}|  |jd¡ | jdd|d}|  |jd¡ | jd	d|d}|  |jd
¡ d S )NrT   r  z"/get_argument?source=query&foo=barr¶   r¸   rn   z/get_argument?source=query&foo=r·   z/get_argument?source=queryr  ©r  r  r  rb   r»   rv   rº   ©r@   rº   rÂ   r7   r7   r8   Útest_get_query_arguments  s   ÿÿz(WSGISafeWebTest.test_get_query_argumentsc                 C   s   t j tdd¡}| jdd|d}|  |jd¡ t j tdd¡}| jdd|d}|  |jd¡ t j tƒ ¡}| jdd|d}|  |jd	¡ d S )
Nrâ   r  z#/get_argument?source=body&foo=hellor¶   r¸   rn   r"  r·   r  r  r   r7   r7   r8   Útest_get_body_arguments*  s   ÿÿÿz'WSGISafeWebTest.test_get_body_argumentsc                 C   s:   |   d¡}|  d|j dd¡¡ |  d|j dd¡¡ d S )Nrñ  úAccept-EncodingÚVaryr"  ÚgzipúContent-Encoding)r»   ÚassertNotInr  rW   rÁ   r7   r7   r8   Útest_no_gzip=  s   
zWSGISafeWebTest.test_no_gzip)rG   rH   rI   rÞ  r=   rã  r<   r{  rø  rý  r   r  r  r  r  r	  r  r  r  r  r  r  r  r!  r"  r(  Ú__classcell__r7   r7   ræ  r8   rÚ  1  s0     rÚ  c                   @   ó   e Zd Zdd„ Zdd„ ZdS )ÚNonWSGIWebTestsc                 C   ó
   dt fgS )Nú/empty_flush)r½  r?   r7   r7   r8   r<   D  r´   zNonWSGIWebTests.get_handlersc                 C   r  )Nr-  rÅ  r  rÁ   r7   r7   r8   Útest_empty_flushG  r  z NonWSGIWebTests.test_empty_flushN)rG   rH   rI   r<   r.  r7   r7   r7   r8   r+  C  ó    r+  c                   @   rW  )
ÚErrorResponseTestc                 C   sL   G dd„ dt ƒ}G dd„ dt ƒ}G dd„ dt ƒ}td|ƒtd|ƒtd	|ƒgS )
Nc                   @   rP   )z6ErrorResponseTest.get_handlers.<locals>.DefaultHandlerc                 S   s*   |   dd ¡rtt|   d¡ƒƒ‚dd  d S ©Nr‡  ro   r   )r”  r    r“  r?   r7   r7   r8   rW   O  s   z:ErrorResponseTest.get_handlers.<locals>.DefaultHandler.getNrY   r7   r7   r7   r8   ÚDefaultHandlerN  rZ   r2  c                   @   r*  )z9ErrorResponseTest.get_handlers.<locals>.WriteErrorHandlerc                 S   s0   |   dd ¡r|  t|   d¡ƒ¡ d S dd  d S r1  )r”  rF  r“  r?   r7   r7   r8   rW   U  s   z=ErrorResponseTest.get_handlers.<locals>.WriteErrorHandler.getc                 [   sB   |   dd¡ d|v r|  d|d d j ¡ d S |  d| ¡ d S )NúContent-Typeú
text/plainÚexc_infozException: %sr   z
Status: %d)r·  rV   rG   ©r@   Ústatus_coderö  r7   r7   r8   Úwrite_error[  s   zEErrorResponseTest.get_handlers.<locals>.WriteErrorHandler.write_errorN©rG   rH   rI   rW   r8  r7   r7   r7   r8   ÚWriteErrorHandlerT  s    r:  c                   @   r*  )z?ErrorResponseTest.get_handlers.<locals>.FailedWriteErrorHandlerc                 S   ó   dd  d S ©Nro   r   r7   r?   r7   r7   r8   rW   c  rO   zCErrorResponseTest.get_handlers.<locals>.FailedWriteErrorHandler.getc                 [   ó   t dƒ‚)Nzexception in write_error©rs  r6  r7   r7   r8   r8  f  ó   zKErrorResponseTest.get_handlers.<locals>.FailedWriteErrorHandler.write_errorNr9  r7   r7   r7   r8   ÚFailedWriteErrorHandlerb  r/  r@  ú/defaultú/write_errorú/failed_write_error)r   r$   )r@   r2  r:  r@  r7   r7   r8   r<   M  s   ýzErrorResponseTest.get_handlersc                 C   s¢   t tdƒB |  d¡}|  |jd¡ |  d|j¡ |  d¡}|  |jd¡ |  d|j¡ |  d¡}|  |jd	¡ |  d
|j¡ W d   ƒ d S 1 sJw   Y  d S )NúUncaught exceptionrA  rE  s   500: Internal Server Errorz/default?status=503é÷  s   503: Service Unavailablez/default?status=435i³  s   435: Unknown)r   r   r»   rv   r½   r  rº   rÁ   r7   r7   r8   Útest_defaulto  s   


"õzErrorResponseTest.test_defaultc                 C   s|   t tdƒ/ |  d¡}|  |jd¡ |  d|j¡ |  d¡}|  |jd¡ |  d|j¡ W d   ƒ d S 1 s7w   Y  d S )NrD  rB  rE  s   Exception: ZeroDivisionErrorz/write_error?status=503rE  s   Status: 503©r   r   r»   rv   r½   rº   rÁ   r7   r7   r8   Útest_write_error}  s   

"ùz"ErrorResponseTest.test_write_errorc                 C   sV   t tdƒ |  d¡}|  |jd¡ |  d|j¡ W d   ƒ d S 1 s$w   Y  d S )NrD  rC  rE  r·   rG  rÁ   r7   r7   r8   Útest_failed_write_error‡  s
   
"ýz)ErrorResponseTest.test_failed_write_errorN)rG   rH   rI   r<   rF  rH  rI  r7   r7   r7   r8   r0  L  s
    "
r0  c                   @   sX  e Zd ZdZej ej e¡d¡Z	dd„ Z
dd„ Zdd„ Zd	d
„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd „ Zd!d"„ Zd#d$„ Zd%d&„ Zd'd(„ Zd)d*„ Zd+d,„ Zd-d.„ Zd/d0„ Z d1d2„ Z!d3d4„ Z"d5d6„ Z#d7d8„ Z$d9d:„ Z%d;d<„ Z&d=d>„ Z'd?d@„ Z(dAdB„ Z)dCdD„ Z*dEdF„ Z+dGdH„ Z,e- .ej/dIkdJ¡dKdL„ ƒZ0dMS )NÚStaticFileTests€   63a36e950e134b5217e33c763e88840c10a07d80e6057d92b9ac97508de7fb1fa6f0e9b7531e169657165ea764e8963399cb6d921ffe6078425aaafe54c04563Ústaticc                 C   sT   G dd„ dt ƒ}G dd„ d|ƒ}G dd„ dt ƒ}d|fd|fd	|fd
ttddfgS )Nc                   @   rP   )z5StaticFileTest.get_handlers.<locals>.StaticUrlHandlerc                 S   s(   t |  dd¡ƒ}|  | j||d¡ d S )NÚinclude_versionrû   )rL  )r“  r”  rV   Ú
static_url)r@   r2   Úwith_vr7   r7   r8   rW   ™  s   z9StaticFileTest.get_handlers.<locals>.StaticUrlHandler.getNrY   r7   r7   r7   r8   ÚStaticUrlHandler˜  rZ   rO  c                   @   s   e Zd ZdZdS )z=StaticFileTest.get_handlers.<locals>.AbsoluteStaticUrlHandlerTN)rG   rH   rI   Úinclude_hostr7   r7   r7   r8   ÚAbsoluteStaticUrlHandler  s    rQ  c                   @   rP   )z=StaticFileTest.get_handlers.<locals>.OverrideStaticUrlHandlerc           
      S   s¬   t |  d¡ƒ}| | _|  |¡}| j||d}||kr"|  tdƒ¡S | jjd }t|ƒ}| 	|d|¡}| 	|d|¡}|rE|dkoC|dk}	n|dkoL|dk}	|  t|	ƒ¡ d S )NrP  )rP  Fz://r   éÿÿÿÿ)
r»  r”  rP  rM  rV   rÈ   rp  Úprotocolr  Úfind)
r@   r2   Ú
do_includeÚregular_urlÚoverride_urlrS  Úprotocol_lengthÚcheck_regularÚcheck_overrideÚresultr7   r7   r8   rW   ¡  s   
zAStaticFileTest.get_handlers.<locals>.OverrideStaticUrlHandler.getNrY   r7   r7   r7   r8   ÚOverrideStaticUrlHandler   rZ   r\  ú/static_url/(.*)z/abs_static_url/(.*)z/override_static_url/(.*)z/root_static/(.*)rL   rå   )r   r   rb   )r@   rO  rQ  r\  r7   r7   r8   r<   —  s   üzStaticFileTest.get_handlersc                 C   s   t tdƒdS )NrK  )Ústatic_path©rb   r9   r?   r7   r7   r8   r=   ¼  rX   zStaticFileTest.get_app_kwargsc                 C   sH   |   d¡}|  d|j¡ |   d¡}|  d|j¡ |  |j d¡d¡ d S )Nú/robots.txtó   Disallow: /ú/static/robots.txtr3  r4  )r»   r  rº   rv   r  rW   rÁ   r7   r7   r8   Útest_static_files¿  s
   

z StaticFileTest.test_static_filesc                 C   s8   |   d¡}|  d|j¡ |  d|j¡ |  d|j¡ d S )Nz/robots.txt?v=12345ra  zCache-ControlÚExpires)r»   r  rº   r  rÁ   r7   r7   r8   Útest_static_files_cacheableÇ  s   
z*StaticFileTest.test_static_files_cacheablec                 C   sb   |   d¡}|  |j d¡d¡ |   d¡}|  |j d¡d¡ |   d¡}|  |j d¡ddh¡ d S )	Nz/static/sample.xml.gzr3  zapplication/gzipz/static/sample.xml.bz2zapplication/octet-streamz/static/sample.xmlztext/xmlzapplication/xml)r»   rv   r  rW   r  rÁ   r7   r7   r8   Útest_static_compressed_filesÐ  s   

ÿ
ÿz+StaticFileTest.test_static_compressed_filesc                 C   s"   |   d¡}|  |jd| j ¡ d S )Nz/static_url/robots.txts   /static/robots.txt?v=)r»   rv   rº   Úrobots_txt_hashrÁ   r7   r7   r8   Útest_static_urlÝ  s   
zStaticFileTest.test_static_urlc                 C   s0   |   d¡}|  |jt|  d¡ƒd | j ¡ d S )Nz/abs_static_url/robots.txtrL   s   static/robots.txt?v=)r»   rv   rº   r   r¼   rg  rÁ   r7   r7   r8   Útest_absolute_static_urlá  s
   
þz'StaticFileTest.test_absolute_static_urlc                 C   r  )Nz(/static_url/robots.txt?include_version=0s   /static/robots.txtr  rÁ   r7   r7   r8   Útest_relative_version_exclusionè  r  z.StaticFileTest.test_relative_version_exclusionc                 C   s*   |   d¡}|  |jt|  d¡d ƒ¡ d S )Nz,/abs_static_url/robots.txt?include_version=0rL   ústatic/robots.txt)r»   rv   rº   r   r¼   rÁ   r7   r7   r8   Útest_absolute_version_exclusionì  s   
 z.StaticFileTest.test_absolute_version_exclusionc                 C   s   |   d¡ |   d¡ d S )NFT)Ú_trigger_include_host_checkr?   r7   r7   r8   Útest_include_host_overrideð  ri  z)StaticFileTest.test_include_host_overridec                 C   s0   d}|   |t|ƒ ¡}|  |jttdƒƒ¡ d S )Nz//override_static_url/robots.txt?include_host=%sT)r»   r“  rv   rº   r   rÈ   )r@   rP  r2   rÂ   r7   r7   r8   rm  ô  s   z*StaticFileTest._trigger_include_host_checkc                 O   sž   | j |ddi|¤Ž}| j |ddi|¤Ž}tƒ }t |j|j¡D ]}| d¡r+| |¡ q|D ]}|  |j |¡|j |¡d||j |¡|j |¡f ¡ q.|S )zŸPerforms a GET and HEAD request and returns the GET response.

        Fails if any ``Content-*`` headers returned by the two requests
        differ.
        r¹   ÚHEADÚGETzContent-z)%s differs between GET (%s) and HEAD (%s))	r»   rc  Ú	itertoolsÚchainr  Ú
startswithÚaddrv   rW   )r@   ro  rö  Úhead_responseÚget_responseÚcontent_headersÚhr7   r7   r8   Úget_and_headù  s    

€

ÿýzStaticFileTest.get_and_headc                 C   sB   |   d¡}| j dd|jd id}|  |jd¡ |  d|j¡ d S )Nrb  úIf-Modified-SinceúLast-Modifiedr  é0  úContent-Length)ry  r  rv   r½   r'  ©r@   Ú	response1Ú	response2r7   r7   r8   Ú!test_static_304_if_modified_since  s   
þz0StaticFileTest.test_static_304_if_modified_sincec                 C   s4   |   d¡}| j dd|jd id}|  |jd¡ d S )Nrb  úIf-None-MatchÚEtagr  r|  ©ry  r  rv   r½   r~  r7   r7   r8   Útest_static_304_if_none_match  s
   
ÿz,StaticFileTest.test_static_304_if_none_matchc                 C   s6   |   d¡}| j dd|jd dœd}|  |jd¡ d S )Nrb  z
"MISMATCH"r{  )r‚  rz  r  rµ   r„  r~  r7   r7   r8   Ú!test_static_304_etag_modified_bug  s   
þþz0StaticFileTest.test_static_304_etag_modified_bugc                 C   ó$   | j dddid}|  |jd¡ d S )Nrb  rz  z!nv@l!dr  rµ   ©ry  rv   r½   rÁ   r7   r7   r8   Ú)test_static_304_if_modified_since_invalid)  s
   þz8StaticFileTest.test_static_304_if_modified_since_invalidc                 C   r‡  )Nrb  rz  zFri, 01 Jan 1960 00:00:00 GMTr  rµ   rˆ  rÁ   r7   r7   r8   Ú'test_static_if_modified_since_pre_epoch0  s
   þz6StaticFileTest.test_static_if_modified_since_pre_epochc                 C   sf   t  tdƒ¡}| jddt|jd ƒid}|  |jd¡ | jddt|jd ƒid}|  |jd¡ d S )Nrk  rb  rz  ro   r  rµ   r|  )r1   Ústatr9   ry  r   Úst_mtimerv   r½   )r@   r‹  rÂ   r7   r7   r8   Ú'test_static_if_modified_since_time_zone:  s   þþz6StaticFileTest.test_static_if_modified_since_time_zonec                 C   s0   |   d¡}|  t|j d¡ƒd| j d ¡ d S )Nrb  rƒ  ó   ")ry  rv   r   r  rW   rg  rÁ   r7   r7   r8   Útest_static_etagL  s   
ÿzStaticFileTest.test_static_etagc                 C   s|   | j dddid}|  |jd¡ |  |jd¡ |  t|j d¡ƒd| j d ¡ |  |j d	¡d
¡ |  |j d¡d¡ d S )Nrb  ÚRangez	bytes=0-9r  éÎ   s
   User-agentrƒ  rŽ  r}  Ú10úContent-Rangezbytes 0-9/26)ry  rv   r½   rº   r   r  rW   rg  rÁ   r7   r7   r8   Útest_static_with_rangeR  s   ÿÿz%StaticFileTest.test_static_with_rangec                 C   óœ   | j dddid}|  |jd¡ tj | jd¡}t|dd}|  |jt	| 
¡ ƒ¡ W d   ƒ n1 s4w   Y  |  |j d	¡d
¡ |  |j d¡¡ d S )Nrb  r  zbytes=0-r  rµ   ú
robots.txtúutf-8©r¢  r}  Ú26r“  ©ry  rv   r½   r1   r2   r3   Ú
static_dirÚopenrº   r   Úreadr  rW   r†   ©r@   rÂ   Úrobots_file_pathÚfr7   r7   r8   Ú test_static_with_range_full_file^  s   ÿÿz/StaticFileTest.test_static_with_range_full_filec                 C   r•  )Nrb  r  zbytes=0-10000000r  rµ   r–  r—  r˜  r}  r™  r“  rš  rž  r7   r7   r8   Ú$test_static_with_range_full_past_endk  ó   ÿÿz3StaticFileTest.test_static_with_range_full_past_endc                 C   s¦   | j dddid}|  |jd¡ tj | jd¡}t|dd}|  |jt	| 
¡ d	d … ƒ¡ W d   ƒ n1 s8w   Y  |  |j d
¡d¡ |  |j d¡d¡ d S )Nrb  r  zbytes=1-10000000r  r‘  r–  r—  r˜  ro   r}  Ú25r“  zbytes 1-25/26)ry  rv   r½   r1   r2   r3   r›  rœ  rº   r   r  r  rW   rž  r7   r7   r8   Ú'test_static_with_range_partial_past_endv  s   ÿ ÿz6StaticFileTest.test_static_with_range_partial_past_endc                 C   óL   | j dddid}|  |jd¡ |  |j d¡d¡ |  |j d¡d	¡ d S )
Nrb  r  z	bytes=22-r  ó   : /
r}  r¶  r“  úbytes 22-25/26©ry  rv   rº   r  rW   rÁ   r7   r7   r8   Útest_static_with_range_end_edge  ó   ÿz.StaticFileTest.test_static_with_range_end_edgec                 C   r¦  )
Nrb  r  zbytes=-4r  r§  r}  r¶  r“  r¨  r©  rÁ   r7   r7   r8   Útest_static_with_range_neg_end‰  r«  z-StaticFileTest.test_static_with_range_neg_endc                 C   r•  )Nrb  r  zbytes=-1000000r  rµ   r–  r—  r˜  r}  r™  r“  rš  rž  r7   r7   r8   Ú%test_static_with_range_neg_past_start‘  r£  z4StaticFileTest.test_static_with_range_neg_past_startc                 C   r‡  )Nrb  r  rÉ   r  rµ   rˆ  rÁ   r7   r7   r8   Útest_static_invalid_rangeœ  s   z(StaticFileTest.test_static_invalid_rangec                 C   s8   | j dddid}|  |j d¡d¡ |  |jd¡ d S )Nrb  r  zbytes=-0r  r“  ú
bytes */26é   )ry  rv   r  rW   r½   rÁ   r7   r7   r8   Ú+test_static_unsatisfiable_range_zero_suffix   s
   ÿz:StaticFileTest.test_static_unsatisfiable_range_zero_suffixc                 C   ó8   | j dddid}|  |jd¡ |  |j d¡d¡ d S )Nrb  r  zbytes=26r  r°  r“  r¯  ©ry  rv   r½   r  rW   rÁ   r7   r7   r8   Ú-test_static_unsatisfiable_range_invalid_start§  ó
   ÿz<StaticFileTest.test_static_unsatisfiable_range_invalid_startc                 C   r²  )Nrb  r  z
bytes=10-3r  r°  r“  r¯  r³  rÁ   r7   r7   r8   Ú3test_static_unsatisfiable_range_end_less_than_start®  rµ  zBStaticFileTest.test_static_unsatisfiable_range_end_less_than_startc                 C   s`   | j ddd}|  |jd¡ |  |jd¡ |  |jd d¡ |  t|jd ƒd	| j d	 ¡ d S )
Nrb  ro  ©r¹   rµ   r·   r}  r™  rƒ  rŽ  ©r»   rv   r½   rº   r  r   rg  rÁ   r7   r7   r8   Útest_static_headµ  s   ÿzStaticFileTest.test_static_headc                 C   sf   | j ddddid}|  |jd¡ |  |jd¡ |  |jd d	¡ |  t|jd
 ƒd| j d ¡ d S )Nrb  ro  r  ú	bytes=1-4)r¹   r  r‘  r·   r}  r¶  rƒ  rŽ  r¸  rÁ   r7   r7   r8   Útest_static_head_range¿  s   
ÿÿz%StaticFileTest.test_static_head_rangec                 C   sl   | j ddd| j d dœd}|  |jd¡ |  |jd¡ |  d|j¡ |  t|jd	 ƒd| j d ¡ d S )
Nrb  rº  rŽ  )r  r‚  r  r|  r·   r}  rƒ  )ry  rg  rv   r½   rº   r'  r  r   rÁ   r7   r7   r8   Útest_static_range_if_none_matchÊ  s   þþÿz.StaticFileTest.test_static_range_if_none_matchc                 C   r  )Nz/static/blargé”  rˆ  rÁ   r7   r7   r8   Útest_static_404Ù  r  zStaticFileTest.test_static_404c                 C   sX   | j  ¡  tƒ | _ ttdƒ |  d¡}W d   ƒ n1 sw   Y  |  |jd¡ d S )Nz.*not in root static directoryz/static/../static_foo.txté“  )Úhttp_clientrh  r   r   r   ry  rv   r½   rÁ   r7   r7   r8   Útest_path_traversal_protectionÝ  s   
ÿz-StaticFileTest.test_path_traversal_protectionÚposixznon-posix OSc                 C   sF   t j t j t j t¡¡d¡}|  dtj 	|¡ ¡}|  
|jd¡ d S )Nrk  z/root_staticrµ   )r1   r2   r3   r4   Úabspathr5   ry  r  r  rÛ   rv   r½   )r@   r2   rÂ   r7   r7   r8   Útest_root_static_pathê  s
   ÿz$StaticFileTest.test_root_static_pathN)1rG   rH   rI   rg  r1   r2   r3   r4   r5   r›  r<   r=   rc  re  rf  rh  ri  rj  rl  rn  rm  ry  r  r…  r†  r‰  rŠ  r  r  r”  r¡  r¢  r¥  rª  r¬  r­  r®  r±  r´  r¶  r¹  r»  r¼  r¾  rÁ  ÚunittestÚskipIfre   rÄ  r7   r7   r7   r8   rJ  Ž  sR    ÿ%		

rJ  c                   @   rW  )
ÚStaticDefaultFilenameTestc                 C   ó   t tdƒt dddS ©NrK  ú
index.html©Údefault_filename)r^  Ústatic_handler_argsr_  r?   r7   r7   r8   r=   ø  ó   þz(StaticDefaultFilenameTest.get_app_kwargsc                 C   ó   g S r0   r7   r?   r7   r7   r8   r<   þ  rF   z&StaticDefaultFilenameTest.get_handlersc                 C   s.   | j ddd}|  |jd¡ |  d|j¡ d S )Nú/static/dir/FrK  rµ   s   this is the index
©r»   rv   r½   rº   rÁ   r7   r7   r8   Útest_static_default_filename  s   z6StaticDefaultFilenameTest.test_static_default_filenamec                 C   s6   | j ddd}|  |jd¡ |  |jd  d¡¡ d S )Nú/static/dirFrK  r  rN  rÐ  )r»   rv   r½   r¿   r  ÚendswithrÁ   r7   r7   r8   Útest_static_default_redirect  s   z6StaticDefaultFilenameTest.test_static_default_redirectN)rG   rH   rI   r=   r<   rÒ  rÕ  r7   r7   r7   r8   rÇ  ÷  s
    rÇ  c                   @   rW  )
ÚStaticDefaultFilenameRootTestc                 C   s    t tj tdƒ¡t ddddS )NrK  rÊ  rË  rL   )r^  rÍ  Ústatic_url_prefix)rb   r1   r2   rÃ  r9   r?   r7   r7   r8   r=     s
   ýz,StaticDefaultFilenameRootTest.get_app_kwargsc                 C   rÏ  r0   r7   r?   r7   r7   r8   r<     rF   z*StaticDefaultFilenameRootTest.get_handlersc                 C   ó   t ƒ S r0   r   r?   r7   r7   r8   Úget_http_client  s   z-StaticDefaultFilenameRootTest.get_http_clientc                 C   sŠ   t j t¡}t j |¡\}}t jdkr|  ||¡ n|}ttdƒ | j	d|› ddd}W d   ƒ n1 s7w   Y  |  |j
d¡ d S )NrÂ  z/.*cannot redirect path with two initial slashesz//evil.com/../rÓ  FrK  r¿  )r1   r2   r4   r5   Ú
splitdrivere   rv   r   r   r»   r½   )r@   Útest_dirÚdriveÚtailrÂ   r7   r7   r8   Útest_no_open_redirect  s   

þÿz3StaticDefaultFilenameRootTest.test_no_open_redirectN)rG   rH   rI   r=   r<   rÙ  rÞ  r7   r7   r7   r8   rÖ    s
    rÖ  c                   @   rj   )ÚStaticFileWithPathTestc                 C   rÈ  rÉ  r_  r?   r7   r7   r8   r=   2  rÎ  z%StaticFileWithPathTest.get_app_kwargsc                 C   s   dt dtdƒifgS )Nz	/foo/(.*)r2   z
templates/)r   r9   r?   r7   r7   r8   r<   8  rø   z#StaticFileWithPathTest.get_handlersc                 C   r  )Nz/foo/utf8.htmls   HÃ©llo
r  rÁ   r7   r7   r8   Ú
test_serve;  r  z!StaticFileWithPathTest.test_serveN)rG   rH   rI   r=   r<   rà  r7   r7   r7   r8   rß  1  s    rß  c                   @   rW  )
ÚCustomStaticFileTestc                 C   s0   G dd„ dt ƒ}G dd„ dtƒ}|| _d|fgS )Nc                   @   s^   e Zd Zedd„ ƒZdd„ Zedd„ ƒZdd„ Zedd
d„ƒZdd„ Z	dd„ Z
edd„ ƒZd	S )z>CustomStaticFileTest.get_handlers.<locals>.MyStaticFileHandlerc                 S   s@   |   ||¡}| d¡}|d |… }||d d … }d |||¡S )NÚ.ro   z/static/{}.{}.{})Úget_versionÚrindexÚformat)Úclsr^   r2   Úversion_hashÚextension_indexÚbefore_versionÚafter_versionr7   r7   r8   Úmake_static_urlC  s   
ýzNCustomStaticFileTest.get_handlers.<locals>.MyStaticFileHandler.make_static_urlc                 S   s4   |  d¡}|  dd|¡}|d |… › ||d … › S )Nrâ  r   )rä  )r@   Úurl_pathrè  Úversion_indexr7   r7   r8   Úparse_url_pathO  s   
zMCustomStaticFileTest.get_handlers.<locals>.MyStaticFileHandler.parse_url_pathc                 S   s   d| S )NzCustomStaticFileTest:r7   ©ræ  r^   r2   r7   r7   r8   Úget_absolute_pathT  s   zPCustomStaticFileTest.get_handlers.<locals>.MyStaticFileHandler.get_absolute_pathc                 S   s   |S r0   r7   )r@   ÚrootÚabsolute_pathr7   r7   r8   Úvalidate_absolute_pathX  rF   zUCustomStaticFileTest.get_handlers.<locals>.MyStaticFileHandler.validate_absolute_pathNc                 S   s,   |d u r|d u s
J ‚|dkrdS t d| ƒ‚)NúCustomStaticFileTest:foo.txtrn   úunexpected path %rr>  )r@   r2   ÚstartÚendr7   r7   r8   Úget_content[  s   zJCustomStaticFileTest.get_handlers.<locals>.MyStaticFileHandler.get_contentc                 S   s   | j dkrdS td| j  ƒ‚)Nrô  r  rõ  )rò  rs  r?   r7   r7   r8   Úget_content_sizeb  s   
zOCustomStaticFileTest.get_handlers.<locals>.MyStaticFileHandler.get_content_sizec                 S   ó   d S r0   r7   r?   r7   r7   r8   Úget_modified_timeg  rF   zPCustomStaticFileTest.get_handlers.<locals>.MyStaticFileHandler.get_modified_timec                 S   ó   dS )NÚ42r7   rï  r7   r7   r8   rã  j  ó   zJCustomStaticFileTest.get_handlers.<locals>.MyStaticFileHandler.get_version©NN)rG   rH   rI   Úclassmethodrë  rî  rð  ró  rø  rù  rû  rã  r7   r7   r7   r8   ÚMyStaticFileHandlerB  s    

r  c                   @   rP   )z;CustomStaticFileTest.get_handlers.<locals>.StaticUrlHandlerc                 S   s   |   |  |¡¡ d S r0   )rV   rM  r©   r7   r7   r8   rW   o  rø   z?CustomStaticFileTest.get_handlers.<locals>.StaticUrlHandler.getNrY   r7   r7   r7   r8   rO  n  rZ   rO  r]  )r   r   Ústatic_handler_class)r@   r  rO  r7   r7   r8   r<   A  s   ,
z!CustomStaticFileTest.get_handlersc                 C   s   t d| jdS )NÚdummy)r^  r  )rb   r  r?   r7   r7   r8   r=   v  rX   z#CustomStaticFileTest.get_app_kwargsc                 C   r  )Nz/static/foo.42.txtrn   r  rÁ   r7   r7   r8   rà  y  r  zCustomStaticFileTest.test_servec                 C   sL   t tddd |  d¡}|  |jd¡ W d   ƒ d S 1 sw   Y  d S )NzCould not open static fileF)Úrequiredz/static_url/foo.txts   /static/foo.42.txt)r   r   r»   rv   rº   rÁ   r7   r7   r8   rh  }  s   
"þz$CustomStaticFileTest.test_static_urlN)rG   rH   rI   r<   r=   rà  rh  r7   r7   r7   r8   rá  @  s
    5rá  c                   @   ó,   e Zd ZG dd„ deƒZdd„ Zdd„ ZdS )ÚHostMatchingTestc                   @   r*  )zHostMatchingTest.Handlerc                 C   r?  r0   )Úreply)r@   r  r7   r7   r8   rB  …  r´   z#HostMatchingTest.Handler.initializec                 C   ó   |   | j¡ d S r0   )rV   r  r?   r7   r7   r8   rW   ˆ  rz  zHostMatchingTest.Handler.getN)rG   rH   rI   rB  rW   r7   r7   r7   r8   rN   „  r/  rN   c                 C   s   dt jddifgS )NrÔ   r  Úwildcard)r  rN   r?   r7   r7   r8   r<   ‹  r­  zHostMatchingTest.get_handlersc                 C   s<  | j  ddtjddifg¡ | j  ddtjddifg¡ | j  ddtjdd	ifg¡ | j  d
dtjddifg¡ |  d¡}|  |jd¡ |  d¡}|  |jd¡ |  d¡}|  |jd¡ | jdddid}|  |jd¡ | jdddid}|  |jd¡ | jdddid}|  |jd¡ | jdddid}|  |jd¡ d S )Núwww.example.comrÔ   r  ú[0]úwww\.example\.comú/barú[1]ú/bazú[2]zwww.e.*e.comz[3]s   wildcardr½  ÚHostr  ó   [0]ó   [1]ó   [2]zwww.exe.coms   [3])r>   Úadd_handlersr  rN   r»   rv   rº   r½   rÁ   r7   r7   r8   Útest_host_matchingŽ  s4   ÿÿÿÿ


z#HostMatchingTest.test_host_matchingN)rG   rH   rI   r   rN   r<   r  r7   r7   r7   r8   r  ƒ  s    r  c                   @   rj   )ÚDefaultHostMatchingTestc                 C   rÏ  r0   r7   r?   r7   r7   r8   r<   ®  rF   z$DefaultHostMatchingTest.get_handlersc                 C   s   ddiS )NÚdefault_hostr
  r7   r?   r7   r7   r8   r=   ±  r?  z&DefaultHostMatchingTest.get_app_kwargsc                 C   sà   | j  ddtjddifg¡ | j  ddtjddifg¡ | j  dd	tjdd
ifg¡ |  d¡}|  |jd¡ |  d¡}|  |jd¡ |  d	¡}|  |jd¡ | jdddid}|  |jd¡ d| j _|  d	¡}|  |jd¡ d S )Nr
  rÔ   r  r  r  r  r  zwww.test.comr  r  r  r  r½  z	X-Real-IprY  r  r  )	r>   r  r  rN   r»   rv   rº   r½   r  rÁ   r7   r7   r8   Útest_default_host_matching´  s(   ÿÿÿ



z2DefaultHostMatchingTest.test_default_host_matchingN)rG   rH   rI   r<   r=   r  r7   r7   r7   r8   r  ­  s    r  c                   @   r*  )ÚNamedURLSpecGroupsTestc                 C   s    G dd„ dt ƒ}d|fd|fgS )Nc                   @   rP   )z8NamedURLSpecGroupsTest.get_handlers.<locals>.EchoHandlerc                 S   ó   |   |¡ d S r0   rU   r©   r7   r7   r8   rW   Ò  rX   z<NamedURLSpecGroupsTest.get_handlers.<locals>.EchoHandler.getNrY   r7   r7   r7   r8   rl  Ñ  rZ   rl  z/str/(?P<path>.*)z/unicode/(?P<path>.*)r°   )r@   rl  r7   r7   r8   r<   Ð  s   þz#NamedURLSpecGroupsTest.get_handlersc                 C   s4   |   d¡}|  |jd¡ |   d¡}|  |jd¡ d S )Nz/str/foos   fooz/unicode/barrn   r  rÁ   r7   r7   r8   Útest_named_urlspec_groupsÚ  s   

z0NamedURLSpecGroupsTest.test_named_urlspec_groupsN)rG   rH   rI   r<   r  r7   r7   r7   r8   r  Ï  s    
r  c                   @   ó$   e Zd ZG dd„ deƒZdd„ ZdS )ÚClearHeaderTestc                   @   rP   )zClearHeaderTest.Handlerc                 C   s0   |   dd¡ |   dd¡ |  d¡ |  d¡ d S )NÚh1rm   Úh2râ   Únonexistent)r·  Úclear_headerr?   r7   r7   r8   rW   ä  s   
zClearHeaderTest.Handler.getNrY   r7   r7   r7   r8   rN   ã  rZ   rN   c                 C   s.   |   d¡}|  d|j¡ |  |jd d¡ d S )NrL   r  r   râ   ©r»   r'  r  rv   rÁ   r7   r7   r8   Útest_clear_headerê  s   
z!ClearHeaderTest.test_clear_headerN)rG   rH   rI   r   rN   r$  r7   r7   r7   r8   r  â  ó    r  c                   @   r  )ÚHeader204Testc                   @   rP   )zHeader204Test.Handlerc                 C   s   |   d¡ |  ¡  d S )NéÌ   )Ú
set_statusrž   r?   r7   r7   r8   rW   ò  rk  zHeader204Test.Handler.getNrY   r7   r7   r7   r8   rN   ñ  rZ   rN   c                 C   s8   |   d¡}|  |jd¡ |  d|j¡ |  d|j¡ d S )NrL   r'  r}  úTransfer-Encoding)r»   rv   r½   r'  r  rÁ   r7   r7   r8   Útest_204_headersö  ó   
zHeader204Test.test_204_headersN)rG   rH   rI   r   rN   r*  r7   r7   r7   r8   r&  ð  ó    r&  c                   @   r  )ÚHeader304Testc                   @   rP   )zHeader304Test.Handlerc                 C   s   |   dd¡ |  d¡ d S )NúContent-LanguageÚen_USrT   )r·  rV   r?   r7   r7   r8   rW   ÿ  s   zHeader304Test.Handler.getNrY   r7   r7   r7   r8   rN   þ  rZ   rN   c                 C   s‚   |   d¡}|  |jd d¡ |  |jd d¡ | j dd|jd id}|  |jd	¡ |  d|j¡ |  d|j¡ |  d
|j¡ d S )NrL   r}  Ú5r.  r/  r‚  rƒ  r  r|  r)  )r»   rv   r  r½   r'  r~  r7   r7   r8   Útest_304_headers  s   
ÿzHeader304Test.test_304_headersN)rG   rH   rI   r   rN   r1  r7   r7   r7   r8   r-  ý  r,  r-  c                   @   ó<   e Zd ZG dd„ deƒZdd„ Zdd„ Zdd„ Zd	d
„ ZdS )ÚStatusReasonTestc                   @   rP   )zStatusReasonTest.Handlerc                 C   s:   | j j dg ¡}tt|  d¡ƒ|rt|d ƒd‚d d‚)NÚreasonr½   r   ©r4  )rp  rq  rW   r    r“  r”  r   )r@   r4  r7   r7   r8   rW     s   þþzStatusReasonTest.Handler.getNrY   r7   r7   r7   r8   rN     rZ   rN   c                 C   rØ  r0   r   r?   r7   r7   r8   rÙ    ó   z StatusReasonTest.get_http_clientc                 C   sœ   |   d¡}|  |jd¡ |  |jd¡ |   d¡}|  |jd¡ |  |jd¡ |   d¡}|  |jd¡ |  |jd¡ |   d	¡}|  |jd¡ |  |jd
¡ d S )Nz
/?code=304r|  zNot Modifiedz/?code=304&reason=FooÚFooz/?code=682&reason=Baréª  ÚBarz
/?code=682ÚUnknown)r»   rv   r½   r4  rÁ   r7   r7   r8   Útest_status  s   



zStatusReasonTest.test_statusc                 C   ó8   |   d¡}|  |jd¡ |  |jd¡ |  d|j¡ d S )Nz./?code=200&reason=OK%0D%0AX-Injection:injectedrµ   r:  zX-Injection)r»   rv   r½   r4  r'  r  rÁ   r7   r7   r8   r  -  r+  z&StatusReasonTest.test_header_injectionc                 C   sF   |   d¡}|  |jd¡ |  |jd¡ |  d|j¡ |  d|j¡ d S )Nz+/?code=400&reason=<script>alert(1)</script>rþ  r:  s   scripts   Unknown)r»   rv   r½   r4  r'  rº   r  rÁ   r7   r7   r8   Útest_reason_xss3  s
   
z StatusReasonTest.test_reason_xssN)	rG   rH   rI   r   rN   rÙ  r;  r  r=  r7   r7   r7   r8   r3    s    r3  c                   @   r  )ÚDateHeaderTestc                   @   rP   )zDateHeaderTest.Handlerc                 C   rR   rS   rU   r?   r7   r7   r8   rW   =  rX   zDateHeaderTest.Handler.getNrY   r7   r7   r7   r8   rN   <  rZ   rN   c                 C   sD   |   d¡}tj |jd ¡}|  |tj tjj	¡ tj
dd¡ d S )NrL   ÚDater|   )Úseconds)r»   r2  r3  r4  r  r6  r-  r.  r/  r0  r1  )r@   rÂ   Úheader_dater7   r7   r8   Útest_date_header@  s   

þzDateHeaderTest.test_date_headerN)rG   rH   rI   r   rN   rB  r7   r7   r7   r8   r>  ;  s    r>  c                   @   r2  )ÚRaiseWithReasonTestc                   @   rP   )zRaiseWithReasonTest.Handlerc                 C   s   t ddd‚)Nr8  r7  r5  ©r    r?   r7   r7   r8   rW   K  rO   zRaiseWithReasonTest.Handler.getNrY   r7   r7   r7   r8   rN   J  rZ   rN   c                 C   rØ  r0   r   r?   r7   r7   r8   rÙ  N  r6  z#RaiseWithReasonTest.get_http_clientc                 C   r<  )NrL   r8  r7  s   682: Foo)r»   rv   r½   r4  r  rº   rÁ   r7   r7   r8   Útest_raise_with_reasonR  r+  z*RaiseWithReasonTest.test_raise_with_reasonc                 C   s   |   ttdddƒd¡ d S )Nr8  r7  r5  zHTTP 682: Foo©rv   rÈ   r    r?   r7   r7   r8   Útest_httperror_strX  r:   z&RaiseWithReasonTest.test_httperror_strc                 C   s   |   ttdƒƒd¡ d S )Nr8  zHTTP 682: UnknownrF  r?   r7   r7   r8   Ú test_httperror_str_from_httputil[  s   z4RaiseWithReasonTest.test_httperror_str_from_httputilN)	rG   rH   rI   r   rN   rÙ  rE  rG  rH  r7   r7   r7   r8   rC  I  s    rC  c                   @   rW  )
ÚErrorHandlerXSRFTestc                 C   s   dt tddfgS )Nú/erroré¡  ©r7  )r"   rb   r?   r7   r7   r8   r<   `  s   z!ErrorHandlerXSRFTest.get_handlersc                 C   r±   ©NT)Úxsrf_cookiesr³   r?   r7   r7   r8   r=   f  r´   z#ErrorHandlerXSRFTest.get_app_kwargsc                 C   ó"   | j dddd}|  |jd¡ d S )NrJ  r¶   r"  r¸   rK  r  rÁ   r7   r7   r8   Útest_error_xsrfi  ó   z$ErrorHandlerXSRFTest.test_error_xsrfc                 C   rO  )Nz/404r¶   r"  r¸   r½  r  rÁ   r7   r7   r8   Útest_404_xsrfm  rQ  z"ErrorHandlerXSRFTest.test_404_xsrfN)rG   rH   rI   r<   r=   rP  rR  r7   r7   r7   r8   rI  _  s
    rI  c                   @   sT   e Zd ZG dd„ deƒZdd„ Zdd„ Zdd„ Zd	d
„ Zdd„ Z	dd„ Z
dd„ ZdS )ÚGzipTestCasec                   @   rP   )zGzipTestCase.Handlerc                 C   s4   |   d¡D ]}|  d|¡ q|  ddtj  ¡ d S )NÚvaryr$  zhello worldú!)rt  r¸  rV   r.   Ú
MIN_LENGTH)r@   Úvr7   r7   r8   rW   t  s   zGzipTestCase.Handler.getNrY   r7   r7   r7   r8   rN   s  rZ   rN   c                 C   s   t dtj tj t¡d¡dS )NTrK  )r%  r^  )rb   r1   r2   r3   r4   r5   r?   r7   r7   r8   r=   z  s   ÿzGzipTestCase.get_app_kwargsc                 C   s"   |   |j d|j d¡¡d¡ d S )Nr&  zX-Consumed-Content-Encodingr%  )rv   r  rW   rÁ   r7   r7   r8   Úassert_compressed  s   ÿüzGzipTestCase.assert_compressedc                 C   ó*   |   d¡}|  |¡ |  |jd d¡ d S )NrL   r$  r#  ©r»   rX  rv   r  rÁ   r7   r7   r8   Ú	test_gzip‰  s   

zGzipTestCase.test_gzipc                 C   rY  )Nr`  r$  r#  rZ  rÁ   r7   r7   r8   Útest_gzip_staticŽ  s   

zGzipTestCase.test_gzip_staticc                 C   s2   | j ddd}|  d|j¡ |  |jd d¡ d S )NrL   F)Úuse_gzipr&  r$  r#  r#  rÁ   r7   r7   r8   Útest_gzip_not_requested•  r  z$GzipTestCase.test_gzip_not_requestedc                 C   s>   |   d¡}|  |¡ |  dd„ |jd  d¡D ƒddg¡ d S )Nz/?vary=Accept-Languagec                 S   ó   g | ]}|  ¡ ‘qS r7   ©Ústrip©rÉ  rf  r7   r7   r8   rÊ  ž  rË  z:GzipTestCase.test_vary_already_present.<locals>.<listcomp>r$  ú,úAccept-Languager#  ©r»   rX  rv   r  ÚsplitrÁ   r7   r7   r8   Útest_vary_already_presentš  s   

þz&GzipTestCase.test_vary_already_presentc                 C   s>   |   d¡}|  |¡ |  dd„ |jd  d¡D ƒg d¢¡ d S )Nz"/?vary=Accept-Language&vary=Cookiec                 S   r_  r7   r`  rb  r7   r7   r8   rÊ  §  rË  zCGzipTestCase.test_vary_already_present_multiple.<locals>.<listcomp>r$  rc  )rd  r  r#  re  rÁ   r7   r7   r8   Ú"test_vary_already_present_multiple¢  s   

þz/GzipTestCase.test_vary_already_present_multipleN)rG   rH   rI   r   rN   r=   rX  r[  r\  r^  rg  rh  r7   r7   r7   r8   rS  r  s    
rS  c                   @   ó4   e Zd ZG dd„ deƒZdd„ Zdd„ Zdd„ Zd	S )
ÚPathArgsInPrepareTestc                   @   r*  )zPathArgsInPrepareTest.Handlerc                 C   s   |   t| j| jd¡ d S )N©ro  rö  )rV   rb   rn  Úpath_kwargsr?   r7   r7   r8   r˜  ®  s   z%PathArgsInPrepareTest.Handler.preparec                 C   s   |dksJ ‚|   ¡  d S )Nrm   ©rž   r©   r7   r7   r8   rW   ±  s   z!PathArgsInPrepareTest.Handler.getN©rG   rH   rI   r˜  rW   r7   r7   r7   r8   rN   ­  r/  rN   c                 C   s   d| j fd| j fgS )Nz	/pos/(.*)z/kw/(?P<path>.*)rM   r?   r7   r7   r8   r<   µ  rø   z"PathArgsInPrepareTest.get_handlersc                 C   s4   |   d¡}| ¡  t|jƒ}|  |dgi dœ¡ d S )Nz/pos/foorm   rk  rú  ©r@   rÂ   r  r7   r7   r8   Útest_pos¸  s   

zPathArgsInPrepareTest.test_posc                 C   s6   |   d¡}| ¡  t|jƒ}|  |g ddidœ¡ d S )Nz/kw/foor2   rm   rk  rú  ro  r7   r7   r8   Útest_kw¾  s   

zPathArgsInPrepareTest.test_kwN)rG   rH   rI   r   rN   r<   rp  rq  r7   r7   r7   r8   rj  ¬  s
    rj  c                   @   r  )ÚClearAllCookiesTestc                   @   rP   )zClearAllCookiesTest.Handlerc                 C   s   |   ¡  |  d¡ d S ©NÚok)Úclear_all_cookiesrV   r?   r7   r7   r8   rW   Ç  s   zClearAllCookiesTest.Handler.getNrY   r7   r7   r7   r8   rN   Æ  rZ   rN   c                 C   sN   | j dddid}t|j d¡ƒ}|  |d  d¡¡ |  |d  d	¡¡ d S )
NrL   r  zfoo=bar; baz=xyzzyr  r  r   zbaz="";ro   zfoo="";)r»   r  r  r  r¿   rs  )r@   rÂ   Úset_cookiesr7   r7   r8   Útest_clear_all_cookiesË  s   z*ClearAllCookiesTest.test_clear_all_cookiesN)rG   rH   rI   r   rN   rw  r7   r7   r7   r8   rr  Å  r,  rr  c                   @   ó   e Zd ZdS )ÚPermissionErrorN©rG   rH   rI   r7   r7   r7   r8   ry  Ó  ó    ry  c                   @   ri  )
ÚExceptionHandlerTestc                   @   rj   )zExceptionHandlerTest.Handlerc                 C   sD   |   d¡}|dkrtddƒ‚|dkrdd  d S |dkr td	ƒ‚d S )
NÚexcrë   éš  zno longer hereÚzeroro   r   Ú
permissionznot allowed)r”  r    ry  )r@   r}  r7   r7   r8   rW   Ù  s   

ÿz ExceptionHandlerTest.Handler.getc                 K   sP   d|v r|d \}}}t |tƒr|  d¡ |  d¡ d S tj| |fi |¤Ž d S )Nr5  r¿  ry  )Ú
isinstancery  r(  rV   r   r8  )r@   r7  rö  Útyprg   Útbr7   r7   r8   r8  â  s   


z(ExceptionHandlerTest.Handler.write_errorc                 C   s4   t |tƒrt d|jd ¡ d S t | |||¡ d S )Nz&custom logging for PermissionError: %sr   )r  ry  r   Úwarningro  r   Úlog_exception©r@   r‚  rg   rƒ  r7   r7   r8   r…  ë  s   
z*ExceptionHandlerTest.Handler.log_exceptionN)rG   rH   rI   rW   r8  r…  r7   r7   r7   r8   rN   Ø  s    		rN   c                 C   óH   t tdƒ |  d¡}|  |jd¡ W d   ƒ d S 1 sw   Y  d S )Nz.*no longer herez
/?exc=httpr~  rÿ  rÁ   r7   r7   r8   Útest_http_errorñ  ó   
"þz$ExceptionHandlerTest.test_http_errorc                 C   r‡  )NrD  z
/?exc=zerorE  ©r   r   r»   rv   r½   rÁ   r7   r7   r8   Útest_unknown_errorø  s   
"þz'ExceptionHandlerTest.test_unknown_errorc                 C   r‡  )Nz/custom logging for PermissionError: not allowedz/?exc=permissionr¿  rŠ  rÁ   r7   r7   r8   Útest_known_errorþ  r‰  z%ExceptionHandlerTest.test_known_errorN)rG   rH   rI   r   rN   rˆ  r‹  rŒ  r7   r7   r7   r8   r|  ×  s
    r|  c                   @   r  )ÚBuggyLoggingTestc                   @   r*  )zBuggyLoggingTest.Handlerc                 C   r;  r<  r7   r?   r7   r7   r8   rW     rO   zBuggyLoggingTest.Handler.getc                 C   r;  r<  r7   r†  r7   r7   r8   r…    rO   z&BuggyLoggingTest.Handler.log_exceptionN)rG   rH   rI   rW   r…  r7   r7   r7   r8   rN     r/  rN   c                 C   rƒ  )Nz.*rL   )r   r   r»   r?   r7   r7   r8   Útest_buggy_log_exception  r…  z)BuggyLoggingTest.test_buggy_log_exceptionN)rG   rH   rI   r   rN   rŽ  r7   r7   r7   r8   r    r%  r  c                       s@   e Zd ZdZG dd„ deƒZdd„ Z‡ fdd„Zdd	„ Z‡  Z	S )
ÚUIMethodUIModuleTestz`Test that UI methods and modules are created correctly and
    associated with the handler.
    c                   @   r*  )zUIMethodUIModuleTest.Handlerc                 C   rR   r«   r¬  r?   r7   r7   r8   rW     rX   z UIMethodUIModuleTest.Handler.getc                 C   s
   |   d¡S )Nrg   )r”  r?   r7   r7   r8   rg     r´   z"UIMethodUIModuleTest.Handler.valueN)rG   rH   rI   rW   rg   r7   r7   r7   r8   rN     r/  rN   c                 C   s:   dd„ }G dd„ dt ƒ}tddiƒ}t|d|id|idS )	Nc                 S   s   d|› d|   ¡ › dS )NzIn my_ui_method(z) with handler value râ  )rg   )ry   Úxr7   r7   r8   Úmy_ui_method"  r±  z9UIMethodUIModuleTest.get_app_kwargs.<locals>.my_ui_methodc                   @   rP   )z5UIMethodUIModuleTest.get_app_kwargs.<locals>.MyModulec                 S   s   d  |t tj| j¡ ¡ ¡S )Nz&In MyModule({}) with handler value {}.)rå  ÚtypingÚcastr  rN   ry   rg   )r@   r  r7   r7   r8   r¬   &  s   þz<UIMethodUIModuleTest.get_app_kwargs.<locals>.MyModule.renderN©rG   rH   rI   r¬   r7   r7   r7   r8   ÚMyModule%  rZ   r•  r§   z1{{ my_ui_method(42) }} {% module MyModule(123) %}r‘  )rÜ  Ú
ui_methodsÚ
ui_modules©r)   r   rb   )r@   r‘  r•  rß  r7   r7   r8   r=   !  s   ÿýz#UIMethodUIModuleTest.get_app_kwargsc                    rà  r0   rá  r?   ræ  r7   r8   rã  5  s   
zUIMethodUIModuleTest.tearDownc                 C   r  )Nz/?value=asdfsV   In my_ui_method(42) with handler value asdf. In MyModule(123) with handler value asdf.r  rÁ   r7   r7   r8   Útest_ui_method:  r  z#UIMethodUIModuleTest.test_ui_method)
rG   rH   rI   rJ   r   rN   r=   rã  r™  r)  r7   r7   ræ  r8   r    s    r  c                   @   r  )ÚGetArgumentErrorTestc                   @   rP   )zGetArgumentErrorTest.Handlerc              
   C   sV   z|   d¡ |  i ¡ W d S  ty* } z|  |j|jdœ¡ W Y d }~d S d }~ww )Nrm   ©Úarg_nameÚlog_message)r”  rV   r!   rœ  r  rÇ  r7   r7   r8   rW   E  s   
"€ÿz GetArgumentErrorTest.Handler.getNrY   r7   r7   r7   r8   rN   D  rZ   rN   c                 C   s&   |   d¡}|  t|jƒdddœ¡ d S )NrL   rm   zMissing argument foor›  )r»   rv   r   rº   rÁ   r7   r7   r8   Útest_catch_errorL  s
   
þz%GetArgumentErrorTest.test_catch_errorN)rG   rH   rI   r   rN   rž  r7   r7   r7   r8   rš  C  ó    rš  c                   @   r  )ÚSetLazyPropertiesTestc                   @   rW  )
zSetLazyPropertiesTest.Handlerc                 C   s   d| _ t d¡| _d S )NÚBenr/  )Úcurrent_userr   rW   r?   r7   r7   r8   r˜  V  s   z%SetLazyPropertiesTest.Handler.preparec                 C   rB   r0   rC   r?   r7   r7   r8   Úget_user_localeZ  rE   z-SetLazyPropertiesTest.Handler.get_user_localec                 C   rB   r0   rC   r?   r7   r7   r8   Úget_current_user]  rE   z.SetLazyPropertiesTest.Handler.get_current_userc                 C   s"   |   d| j› d| jj› d¡ d S )NzHello z (ú))rV   r¢  r   r½   r?   r7   r7   r8   rW   `  s   "z!SetLazyPropertiesTest.Handler.getN)rG   rH   rI   r˜  r£  r¤  rW   r7   r7   r7   r8   rN   U  s
    rN   c                 C   r  )NrL   s   Hello Ben (en_US)r  rÁ   r7   r7   r8   Útest_set_propertiesc  ó   
z)SetLazyPropertiesTest.test_set_propertiesN)rG   rH   rI   r   rN   r¦  r7   r7   r7   r8   r   T  ó    r   c                       sV   e Zd Zdd„ Z‡ fdd„Zdd„ Ze d¡dd	„ ƒZd
d„ Z	dd„ Z
dd„ Z‡  ZS )ÚGetCurrentUserTestc                 C   sD   G dd„ dt ƒ}G dd„ dt ƒ}tddddd	œƒ}t|||d
œdS )Nc                   @   rP   )z<GetCurrentUserTest.get_app_kwargs.<locals>.WithoutUserModulec                 S   rü  )Nr"  r7   r?   r7   r7   r8   r¬   m  rF   zCGetCurrentUserTest.get_app_kwargs.<locals>.WithoutUserModule.renderNr”  r7   r7   r7   r8   ÚWithoutUserModulel  rZ   rª  c                   @   rP   )z9GetCurrentUserTest.get_app_kwargs.<locals>.WithUserModulec                 S   s
   t | jƒS r0   )rÈ   r¢  r?   r7   r7   r8   r¬   q  r´   z@GetCurrentUserTest.get_app_kwargs.<locals>.WithUserModule.renderNr”  r7   r7   r7   r8   ÚWithUserModulep  rZ   r«  r"  z{{ current_user }}z {% module WithoutUserModule() %}z{% module WithUserModule() %})úwithout_user.htmlúwith_user.htmlúwithout_user_module.htmlúwith_user_module.html)r«  rª  )rÜ  r—  r˜  )r@   rª  r«  rß  r7   r7   r8   r=   k  s   üÿþþz!GetCurrentUserTest.get_app_kwargsc                    rà  r0   rá  r?   ræ  r7   r8   rã  „  ri  zGetCurrentUserTest.tearDownc                 C   s|   G dd„ dt ƒ}G dd„ d|ƒ}G dd„ d|ƒ}G dd„ d|ƒ}G d	d
„ d
|ƒ}G dd„ d|ƒ}d|fd|fd|fd|fgS )Nc                   @   r*  )z;GetCurrentUserTest.get_handlers.<locals>.CurrentUserHandlerc                 S   s
   d| _ d S )NF©Úhas_loaded_current_userr?   r7   r7   r8   r˜  Š  r´   zCGetCurrentUserTest.get_handlers.<locals>.CurrentUserHandler.preparec                 S   s
   d| _ dS )NTr"  r°  r?   r7   r7   r8   r¤    s   zLGetCurrentUserTest.get_handlers.<locals>.CurrentUserHandler.get_current_userN)rG   rH   rI   r˜  r¤  r7   r7   r7   r8   ÚCurrentUserHandler‰  r/  r²  c                   @   rP   )z;GetCurrentUserTest.get_handlers.<locals>.WithoutUserHandlerc                 S   ó   |   d¡ |  t| jƒ¡ d S )Nr¬  ©Úrender_stringrž   rÈ   r±  r?   r7   r7   r8   rW   ’  ó   
z?GetCurrentUserTest.get_handlers.<locals>.WithoutUserHandler.getNrY   r7   r7   r7   r8   ÚWithoutUserHandler‘  rZ   r·  c                   @   rP   )z8GetCurrentUserTest.get_handlers.<locals>.WithUserHandlerc                 S   r³  )Nr­  r´  r?   r7   r7   r8   rW   —  r¶  z<GetCurrentUserTest.get_handlers.<locals>.WithUserHandler.getNrY   r7   r7   r7   r8   ÚWithUserHandler–  rZ   r¸  c                   @   rP   )zAGetCurrentUserTest.get_handlers.<locals>.CurrentUserModuleHandlerc                 S   rC  r0   )Úuir?   r7   r7   r8   Úget_template_namespaceœ  s   zXGetCurrentUserTest.get_handlers.<locals>.CurrentUserModuleHandler.get_template_namespaceN)rG   rH   rI   rº  r7   r7   r7   r8   ÚCurrentUserModuleHandler›  rZ   r»  c                   @   rP   )zAGetCurrentUserTest.get_handlers.<locals>.WithoutUserModuleHandlerc                 S   r³  )Nr®  r´  r?   r7   r7   r8   rW   £  r¶  zEGetCurrentUserTest.get_handlers.<locals>.WithoutUserModuleHandler.getNrY   r7   r7   r7   r8   ÚWithoutUserModuleHandler¢  rZ   r¼  c                   @   rP   )z>GetCurrentUserTest.get_handlers.<locals>.WithUserModuleHandlerc                 S   r³  )Nr¯  r´  r?   r7   r7   r8   rW   ¨  r¶  zBGetCurrentUserTest.get_handlers.<locals>.WithUserModuleHandler.getNrY   r7   r7   r7   r8   ÚWithUserModuleHandler§  rZ   r½  ú/without_userú
/with_userú/without_user_moduleú/with_user_moduler°   )r@   r²  r·  r¸  r»  r¼  r½  r7   r7   r8   r<   ˆ  s   üzGetCurrentUserTest.get_handlersz	needs fixc                 C   r  )Nr¾  ó   Falser  rÁ   r7   r7   r8   Útest_get_current_user_is_lazy³  r§  z0GetCurrentUserTest.test_get_current_user_is_lazyc                 C   r  )Nr¿  ó   Truer  rÁ   r7   r7   r8   Útest_get_current_user_works¹  r  z.GetCurrentUserTest.test_get_current_user_worksc                 C   r  )NrÀ  rÂ  r  rÁ   r7   r7   r8   Ú,test_get_current_user_from_ui_module_is_lazy½  r  z?GetCurrentUserTest.test_get_current_user_from_ui_module_is_lazyc                 C   r  )NrÁ  rÄ  r  rÁ   r7   r7   r8   Ú*test_get_current_user_from_ui_module_worksÁ  r  z=GetCurrentUserTest.test_get_current_user_from_ui_module_works)rG   rH   rI   r=   rã  r<   rÅ  ÚskiprÃ  rÅ  rÆ  rÇ  r)  r7   r7   ræ  r8   r©  j  s    +
r©  c                   @   r  )ÚUnimplementedHTTPMethodsTestc                   @   rx  )z$UnimplementedHTTPMethodsTest.HandlerNrz  r7   r7   r7   r8   rN   Ç  r{  rN   c                 C   sR   dD ]}| j d|d}|  |jd¡ qdD ]}| j d|dd}|  |jd¡ qd S )N)ro  rp  ÚDELETEÚOPTIONSrL   r·  é•  ©r¶   ÚPUTr·   r¸   r  )r@   r¹   rÂ   r7   r7   r8   Ú#test_unimplemented_standard_methodsÊ  s   þz@UnimplementedHTTPMethodsTest.test_unimplemented_standard_methodsN)rG   rH   rI   r   rN   rÏ  r7   r7   r7   r8   rÉ  Æ  s    rÉ  c                   @   r  )Ú#UnimplementedNonStandardMethodsTestc                   @   rP   )z+UnimplementedNonStandardMethodsTest.Handlerc                 C   rR   ©NÚotherrU   r?   r7   r7   r8   rÒ  Õ  rG  z1UnimplementedNonStandardMethodsTest.Handler.otherN)rG   rH   rI   rÒ  r7   r7   r7   r8   rN   Ô  rZ   rN   c                 C   rO  )NrL   ÚPATCHr·   r¸   rÌ  r  rÁ   r7   r7   r8   Útest_unimplemented_patchÚ  s   z<UnimplementedNonStandardMethodsTest.test_unimplemented_patchc                 C   rO  )NrL   ÚOTHERT©r¹   Úallow_nonstandard_methodsrÌ  r  rÁ   r7   r7   r8   Útest_unimplemented_otherà  rQ  z<UnimplementedNonStandardMethodsTest.test_unimplemented_otherN)rG   rH   rI   r   rN   rÔ  rØ  r7   r7   r7   r8   rÐ  Ó  s    rÐ  c                   @   r  )ÚAllHTTPMethodsTestc                   @   s(   e Zd Zdd„ Ze Z Z Z ZZdS )zAllHTTPMethodsTest.Handlerc                 C   s"   | j jd usJ ‚|  | j j¡ d S r0   )rp  r¹   rV   r?   r7   r7   r8   r¹   ç  rQ  z!AllHTTPMethodsTest.Handler.methodN)	rG   rH   rI   r¹   rW   ÚdeleteÚoptionsr¤   Úputr7   r7   r7   r8   rN   æ  s    rN   c                 C   sv   | j ddd}|  |jd¡ dD ]}| j d|d}|  |jt|ƒ¡ qdD ]}| j d|dd}|  |jt|ƒ¡ q%d S )NrL   ro  r·  r·   )rp  rÊ  rË  rÍ  r¸   )r»   rv   rº   r   )r@   rÂ   r¹   r7   r7   r8   Útest_standard_methodsí  s   þz(AllHTTPMethodsTest.test_standard_methodsN)rG   rH   rI   r   rN   rÝ  r7   r7   r7   r8   rÙ  å  r%  rÙ  c                   @   r  )ÚPatchMethodTestc                   @   s&   e Zd Zejd Zdd„ Zdd„ ZdS )zPatchMethodTest.Handler)rÕ  c                 C   rR   )NÚpatchrU   r?   r7   r7   r8   rß  þ  rX   zPatchMethodTest.Handler.patchc                 C   rR   rÑ  rU   r?   r7   r7   r8   rÒ  	  rX   zPatchMethodTest.Handler.otherN)rG   rH   rI   r   ÚSUPPORTED_METHODSrß  rÒ  r7   r7   r7   r8   rN   ù  s    
rN   c                 C   rO  )NrL   rÓ  r·   r¸   s   patchr  rÁ   r7   r7   r8   Ú
test_patch	  rQ  zPatchMethodTest.test_patchc                 C   rO  )NrL   rÕ  TrÖ  s   otherr  rÁ   r7   r7   r8   Ú
test_other	  rQ  zPatchMethodTest.test_otherN)rG   rH   rI   r   rN   rá  râ  r7   r7   r7   r8   rÞ  ø  s    rÞ  c                   @   r  )ÚFinishInPrepareTestc                   @   r*  )zFinishInPrepareTest.Handlerc                 C   rR   )NrÀ   rm  r?   r7   r7   r8   r˜  	  rX   z#FinishInPrepareTest.Handler.preparec                 C   r=  )Nzshould not reach this methodr>  r?   r7   r7   r8   rW   	  s   zFinishInPrepareTest.Handler.getNrn  r7   r7   r7   r8   rN   	  r/  rN   c                 C   r  )NrL   s   doner  rÁ   r7   r7   r8   Útest_finish_in_prepare	  r  z*FinishInPrepareTest.test_finish_in_prepareN)rG   rH   rI   r   rN   rä  r7   r7   r7   r8   rã  	  ó    
rã  c                   @   r*  )ÚDefault404Testc                 C   r,  ©NrÔ   r°   r?   r7   r7   r8   r<   	  s   
zDefault404Test.get_handlersc                 C   ó*   |   d¡}|  |jd¡ |  |jd¡ d S )NrL   r½  sE   <html><title>404: Not Found</title><body>404: Not Found</body></html>rÑ  rÁ   r7   r7   r8   Útest_404"	  s   
þzDefault404Test.test_404N)rG   rH   rI   r<   ré  r7   r7   r7   r8   ræ  	  s    ræ  c                   @   rj   )ÚCustom404Testc                 C   r,  rç  r°   r?   r7   r7   r8   r<   -	  r´   zCustom404Test.get_handlersc                 C   s   G dd„ dt ƒ}t|dS )Nc                   @   rP   )z6Custom404Test.get_app_kwargs.<locals>.Custom404Handlerc                 S   s   |   d¡ |  d¡ d S )Nr½  zcustom 404 response)r(  rV   r?   r7   r7   r8   rW   2	  ri  z:Custom404Test.get_app_kwargs.<locals>.Custom404Handler.getNrY   r7   r7   r7   r8   ÚCustom404Handler1	  rZ   rë  )Údefault_handler_class)r   rb   )r@   rë  r7   r7   r8   r=   0	  s   
zCustom404Test.get_app_kwargsc                 C   rè  )NrL   r½  s   custom 404 responserÑ  rÁ   r7   r7   r8   ré  8	  s   
zCustom404Test.test_404N)rG   rH   rI   r<   r=   ré  r7   r7   r7   r8   rê  ,	  s    rê  c                   @   rj   )ÚDefaultHandlerArgumentsTestc                 C   r,  rç  r°   r?   r7   r7   r8   r<   ?	  r´   z(DefaultHandlerArgumentsTest.get_handlersc                 C   s   t tt dddS )Nr¿  rL  )rì  Údefault_handler_args)rb   r"   r?   r7   r7   r8   r=   B	  s   þz*DefaultHandlerArgumentsTest.get_app_kwargsc                 C   r  )NrL   r¿  r  rÁ   r7   r7   r8   Útest_403H	  r  z$DefaultHandlerArgumentsTest.test_403N)rG   rH   rI   r<   r=   rï  r7   r7   r7   r8   rí  >	  s    rí  c                   @   r*  )ÚHandlerByNameTestc                 C   s   dt fdtddƒgS )Nú/hello1)ú/hello2ú"tornado.test.web_test.HelloHandlerú/hello3ró  )rQ   r$   r?   r7   r7   r8   r<   N	  s   ýzHandlerByNameTest.get_handlersc                 C   sL   |   d¡}|  |jd¡ |   d¡}|  |jd¡ |   d¡}|  |jd¡ d S )Nrñ  r  rò  rô  r  ©r@   Úrespr7   r7   r8   Útest_handler_by_nameV	  s   


z&HandlerByNameTest.test_handler_by_nameN)rG   rH   rI   r<   r÷  r7   r7   r7   r8   rð  M	  s    rð  c                   @   sL   e Zd Zdd„ Zdd„ Zedd„ ƒZedd„ ƒZed	d
„ ƒZedd„ ƒZ	dS )ÚStreamingRequestBodyTestc                 C   sb   t G dd„ dtƒƒ}t G dd„ dtƒƒ}t G dd„ dtƒƒ}d|t| dfd	|fd
|t| dfgS )Nc                   @   rW  )
zCStreamingRequestBodyTest.get_handlers.<locals>.StreamingBodyHandlerc                 S   r?  r0   r    rR  r7   r7   r8   rB  c	  r´   zNStreamingRequestBodyTest.get_handlers.<locals>.StreamingBodyHandler.initializec                 S   s   | j j d ¡ d S r0   )r¡   ÚpreparedÚ
set_resultr?   r7   r7   r8   r˜  f	  r­  zKStreamingRequestBodyTest.get_handlers.<locals>.StreamingBodyHandler.preparec                 S   s   | j j |¡ d S r0   )r¡   r  rú  ©r@   r  r7   r7   r8   Údata_receivedi	  r­  zQStreamingRequestBodyTest.get_handlers.<locals>.StreamingBodyHandler.data_receivedc                 S   s   | j j d ¡ |  i ¡ d S r0   )r¡   Úfinishedrú  rV   r?   r7   r7   r8   rW   l	  s   zGStreamingRequestBodyTest.get_handlers.<locals>.StreamingBodyHandler.getN)rG   rH   rI   rB  r˜  rü  rW   r7   r7   r7   r8   ÚStreamingBodyHandlera	  s
    rþ  c                   @   rP   )zAStreamingRequestBodyTest.get_handlers.<locals>.EarlyReturnHandlerc                 S   r=  )Né‘  rD  r?   r7   r7   r8   r˜  r	  s   zIStreamingRequestBodyTest.get_handlers.<locals>.EarlyReturnHandler.prepareNrÕ  r7   r7   r7   r8   ÚEarlyReturnHandlerp	  rÞ   r   c                       s$   e Zd Zdd„ Z‡ fdd„Z‡  ZS )zDStreamingRequestBodyTest.get_handlers.<locals>.CloseDetectionHandlerc                 S   r?  r0   r    rR  r7   r7   r8   rB  y	  r´   zOStreamingRequestBodyTest.get_handlers.<locals>.CloseDetectionHandler.initializec                    s   t ƒ  ¡  | jj d ¡ d S r0   )râ  rV  r¡   Úclose_futurerú  r?   ræ  r7   r8   rV  |	  r  zXStreamingRequestBodyTest.get_handlers.<locals>.CloseDetectionHandler.on_connection_close)rG   rH   rI   rB  rV  r)  r7   r7   ræ  r8   ÚCloseDetectionHandlerw	  s    r  z/stream_bodyr    z/early_returnz/close_detection)r+   r   rb   )r@   rþ  r   r  r7   r7   r8   r<   `	  s   	ýz%StreamingRequestBodyTest.get_handlersc                 C   sZ   t   t jt jd¡}| d|  ¡ f¡ t|ƒ}| d| d ¡ |r&| d¡ | d¡ |S )Nr   rY  s   GET s    HTTP/1.1
Host: 127.0.0.1
s   Connection: close
s   Transfer-Encoding: chunked

)r]  r^  r_  r`  ra  r   rV   )r@   r$   Úconnection_closerf  rb  r7   r7   r8   r`  †	  s   

z StreamingRequestBodyTest.connectc                 c   s¬    t ƒ | _t ƒ | _t ƒ | _| jddd}| jV  | d¡ | jV }|  |d¡ t ƒ | _| d¡ | jV }|  |d¡ | d¡ | jV  | ¡ V }|  | 	d	¡¡ | 
¡  d S )
Ns   /stream_bodyT©r  ó	   4
asdf
s   asdfs	   4
qwer
s   qwers   0

s   {})r   rù  r  rý  r`  rV   rv   Úread_until_closer¿   rÔ  rh  ©r@   rb  r  r7   r7   r8   Útest_streaming_body‘	  s$   €



z,StreamingRequestBodyTest.test_streaming_bodyc                 c   s.    | j ddd}| ¡ V }|  | d¡¡ d S )Nó   /early_returnFr  ó   HTTP/1.1 401)r`  r  r¿   rs  r  r7   r7   r8   Útest_early_return¨	  s   €
z*StreamingRequestBodyTest.test_early_returnc                 c   s8    | j ddd}| d¡ | ¡ V }|  | d¡¡ d S )Nr	  Fr  r  r
  )r`  rV   r  r¿   rs  r  r7   r7   r8   Útest_early_return_with_data®	  s
   €

z4StreamingRequestBodyTest.test_early_return_with_datac                 c   s,    t ƒ | _| jddd}| ¡  | jV  d S )Ns   /close_detectionFr  )r   r  r`  rh  )r@   rb  r7   r7   r8   Útest_close_during_uploadµ	  s
   €z1StreamingRequestBodyTest.test_close_during_uploadN)
rG   rH   rI   r<   r`  r   r  r  r  r  r7   r7   r7   r8   rø  _	  s    &


rø  c                   @   s>   e Zd Zdd„ Zejdd„ ƒZejdd„ ƒZ	ejdd„ ƒZ
d	S )
ÚBaseFlowControlHandlerc                 C   s   || _ d | _g | _d S r0   )r¡   r¹   ÚmethodsrR  r7   r7   r8   rB  Ã	  s   
z!BaseFlowControlHandler.initializec                 c   sT    | j d ur| j d|› d| j › ¡ || _ | j |¡ z	d V  W d | _ d S d | _ w )Nzentered method z
 while in )r¹   r¡   Úfailr  rÍ  rÔ  r7   r7   r8   Ú	in_methodÈ	  s   €
z BaseFlowControlHandler.in_methodc                 c   s    | j  d¡ tjV  d S )Nr˜  )r  rÍ  r   Úmomentr?   r7   r7   r8   r˜  Ó	  s   €zBaseFlowControlHandler.preparec                 c   sJ    |   d¡ tjV  W d   ƒ n1 sw   Y  |  t| jd¡ d S )Nr¤   ©r  )r  r   r  rV   rb   r  r?   r7   r7   r8   r¤   Ú	  s
   €
ÿzBaseFlowControlHandler.postN)rG   rH   rI   rB  Ú
contextlibÚcontextmanagerr  r   r¥   r˜  r¤   r7   r7   r7   r8   r  Á	  s    


r  c                   @   sL   e Zd Zdd„ Zdd„ Zdejfdd„Zdejfdd	„Zdejfd
d„Z	dS )Ú#BaseStreamingRequestFlowControlTestc                 C   s   t dddS )Nrö   T)Ú
chunk_sizeÚdecompress_requestr³   r?   r7   r7   r8   Úget_httpserver_optionsâ	  s   z:BaseStreamingRequestFlowControlTest.get_httpserver_optionsc                 C   rØ  r0   r   r?   r7   r7   r8   rÙ  ç	  r6  z3BaseStreamingRequestFlowControlTest.get_http_clientr@   c                 C   s8   | j dddd}| ¡  |  t|jƒtg d¢d¡ d S )NrL   Úabcdefghijklmnopqrstuvwxyzr¶   )rº   r¹   ©r˜  rü  rü  rü  r¤   r  )r»   rõ  rv   r   rº   rb   rÁ   r7   r7   r8   Útest_flow_control_fixed_bodyì	  s   ÿþz@BaseStreamingRequestFlowControlTest.test_flow_control_fixed_bodyc                    sR   g d¢‰ t j‡ fdd„ƒ}| jd|dd}| ¡  |  t|jƒtg d¢d¡ d S )	N)s   abcds   efghs   ijklc                 3   s    ˆ D ]}| |ƒV  qd S r0   r7   )rV   Úi©Úchunksr7   r8   Úbody_producerÿ	  s   €ÿzYBaseStreamingRequestFlowControlTest.test_flow_control_chunked_body.<locals>.body_producerrL   r¶   )r   r¹   r  r  )r   r¥   r»   rõ  rv   r   rº   rb   )r@   r   rÂ   r7   r  r8   Útest_flow_control_chunked_bodyü	  s   ÿþzBBaseStreamingRequestFlowControlTest.test_flow_control_chunked_bodyc                 C   sl   t ƒ }tjd|d}| d¡ | ¡  | ¡ }| jd|dddid}| ¡  |  t	|j
ƒtg d	¢d
¡ d S )NÚw)ÚmodeÚfileobjs   abcdefghijklmnopqrstuvwxyzrL   r¶   r&  r%  )rº   r¹   r  r  r  )r/   r%  ÚGzipFilerV   rh  Úgetvaluer»   rõ  rv   r   rº   rb   )r@   ÚbytesioÚ	gzip_fileÚcompressed_bodyrÂ   r7   r7   r8   Ú!test_flow_control_compressed_body
  s$   
üÿþzEBaseStreamingRequestFlowControlTest.test_flow_control_compressed_bodyN)
rG   rH   rI   r  rÙ  r’  ÚAnyr  r!  r*  r7   r7   r7   r8   r  á	  s    r  c                   @   rP   )Ú(DecoratedStreamingRequestFlowControlTestc                 C   ó"   G dd„ dt ƒ}d|t| dfgS )Nc                   @   r¼  )zZDecoratedStreamingRequestFlowControlTest.get_handlers.<locals>.DecoratedFlowControlHandlerc                 s   s:    |   d¡ tjV  W d   ƒ d S 1 sw   Y  d S )Nrü  )r  r   r  rû  r7   r7   r8   rü  3
  s   €
"ÿzhDecoratedStreamingRequestFlowControlTest.get_handlers.<locals>.DecoratedFlowControlHandler.data_receivedN)rG   rH   rI   r   r¥   rü  r7   r7   r7   r8   ÚDecoratedFlowControlHandler2
  rÀ  r.  rL   r    ©r  rb   )r@   r.  r7   r7   r8   r<   1
  s   z5DecoratedStreamingRequestFlowControlTest.get_handlersN©rG   rH   rI   r<   r7   r7   r7   r8   r,  .
  ó    r,  c                   @   rP   )Ú%NativeStreamingRequestFlowControlTestc                 C   r-  )Nc                   @   rP   )zTNativeStreamingRequestFlowControlTest.get_handlers.<locals>.NativeFlowControlHandlerc                 Ó   sJ   |   d¡ dd l}| d¡I d H  W d   ƒ d S 1 sw   Y  d S )Nrü  r   )r  Úasyncior[  )r@   r  r3  r7   r7   r8   rü  @
  s
   €"ýzbNativeStreamingRequestFlowControlTest.get_handlers.<locals>.NativeFlowControlHandler.data_receivedN)rG   rH   rI   rü  r7   r7   r7   r8   ÚNativeFlowControlHandler?
  rZ   r4  rL   r    r/  )r@   r4  r7   r7   r8   r<   >
  s   z2NativeStreamingRequestFlowControlTest.get_handlersNr0  r7   r7   r7   r8   r2  ;
  r1  r2  c                   @   rj   )ÚIncorrectContentLengthTestc                    sB   | ‰ d | _ G ‡ fdd„dtƒ}G ‡ fdd„dtƒ}d|fd|fgS )Nc                       ó   e Zd Z‡ fdd„ZdS )z8IncorrectContentLengthTest.get_handlers.<locals>.TooHighc              
      ó>   |   dd¡ z|  d¡ W d S  ty } z|ˆ _‚ d }~ww )Nr}  rý  rt  ©r·  rž   rs  Úserver_errorrÇ  r    r7   r8   rW   P
  ó   €þz<IncorrectContentLengthTest.get_handlers.<locals>.TooHigh.getNrY   r7   r    r7   r8   ÚTooHighO
  ó    r;  c                       r6  )z7IncorrectContentLengthTest.get_handlers.<locals>.TooLowc              
      r7  )Nr}  r  rT   r8  rÇ  r    r7   r8   rW   Y
  r:  z;IncorrectContentLengthTest.get_handlers.<locals>.TooLow.getNrY   r7   r    r7   r8   ÚTooLowX
  r<  r=  ú/highú/low)r9  r   )r@   r;  r=  r7   r    r8   r<   J
  s
   		z'IncorrectContentLengthTest.get_handlersc              
   C   ó¢   t tdƒ9 t tdƒ$ |  t¡ | jddd W d   ƒ n1 s#w   Y  W d   ƒ n1 s2w   Y  W d   ƒ n1 sAw   Y  |  t| jƒd¡ d S )Nú*(Uncaught exception|Exception in callback)úS(Cannot send error response after headers written|Failed to flush partial response)r>  T©Úraise_errorz0Tried to write 40 bytes less than Content-Length©	r   r   r   ÚassertRaisesr
   r»   rv   rÈ   r9  r?   r7   r7   r8   Útest_content_length_too_highc
  ó   þÿ€û€ÿ
ÿz7IncorrectContentLengthTest.test_content_length_too_highc              
   C   r@  )NrA  rB  r?  TrC  z,Tried to write more data than Content-LengthrE  r?   r7   r7   r8   Útest_content_length_too_lows
  rH  z6IncorrectContentLengthTest.test_content_length_too_lowN)rG   rH   rI   r<   rG  rI  r7   r7   r7   r8   r5  I
  s    r5  c                   @   r  )ÚClientCloseTestc                   @   rP   )zClientCloseTest.Handlerc                 C   s8   | j j d¡r| j jj ¡  |  d¡ d S |  d¡ d S )NzHTTP/1rT   úrequires HTTP/1.x)rp  rq   rs  Ú
connectionrb  rh  rV   r?   r7   r7   r8   rW   †
  s   zClientCloseTest.Handler.getNrY   r7   r7   r7   r8   rN   …
  rZ   rN   c                 C   sf   |   ttjf¡! | jddd}|jdkr|  d¡ |  |jd¡ W d   ƒ d S 1 s,w   Y  d S )NrL   TrC  s   requires HTTP/1.xrK  iW  )	rF  r
   rÅ  ÚSkipTestr»   rº   ÚskipTestrv   r½   rÁ   r7   r7   r8   Útest_client_close“
  s   

"üz!ClientCloseTest.test_client_closeN)rG   rH   rI   r   rN   rO  r7   r7   r7   r8   rJ  „
  r¨  rJ  c                   @   s|   e Zd ZdZddddœZdd„ Zdd	„ Zd
d„ Zdd„ Zdd„ Z	dd„ Z
dd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ ZdS )ÚSignedValueTestzIt's a secret to everybodyÚ	asdfbasdfÚ12312312Ú2342342)r   ro   r|   c                 C   s   |   ¡ d S )Ni 0* )Úpresentr?   r7   r7   r8   ÚpastŸ
  rO   zSignedValueTest.pastc                 C   rü  )Ni m|Mr7   r?   r7   r7   r8   rT  ¢
  rF   zSignedValueTest.presentc                 C   s¬   t tjddd| jd}|  |d¡ t tjddd| jd}|  |d¡ t tjdd| jd}|  ||¡ ttjd|d| jd	}|  |d
¡ ttjd|d| jd	}|  |d
¡ d S )Nru  rg   ro   )rq   Úclocks<   dmFsdWU=|1300000000|31c934969f53e48164c50768b40cbd7e2daaaa4fr|   se   2|1:0|10:1300000000|3:key|8:dmFsdWU=|3d4e60b996ff9c5d5788e333a0cba6f238a22c6c0f94788870e1a9ecd482e152©rV  )rs   rV  ó   value)r&   rP  ÚSECRETrT  rv   r'   )r@   Ú	signed_v1Ú	signed_v2Úsigned_defaultÚ
decoded_v1Ú
decoded_v2r7   r7   r8   Útest_known_values¥
  s2   ÿÿÿþÿÿÿz!SignedValueTest.test_known_valuesc                 C   sh   t tjdd| jd}t tjdd| jd}ttjd|| jd}|  |¡ ttjd|| jd}|  |¡ d S )NÚkey1rg   rW  Úkey2)r&   rP  rY  rT  r'   r†   )r@   Úsigned1Úsigned2Údecoded1Údecoded2r7   r7   r8   Útest_name_swapÅ
  s   ÿÿÿ
ÿzSignedValueTest.test_name_swapc                 C   sV   t tjdd| jd}ttjd|| jd}|  |d¡ ttjd|| jd}|  |¡ d S )Nr`  rg   rW  rX  )r&   rP  rY  rU  r'   rv   rT  r†   )r@   ÚsignedÚdecoded_pastÚdecoded_presentr7   r7   r8   Útest_expiredÖ
  s   ÿÿÿzSignedValueTest.test_expiredc                    sN   d‰‡ ‡fdd„}ˆ   |dƒ¡ ˆ  |dƒ¡ ˆ  |dƒ¡ ˆ  |dƒ¡ d S )NÚ@3d4e60b996ff9c5d5788e333a0cba6f238a22c6c0f94788870e1a9ecd482e152c                    s   dt tjd| ˆ ˆ jdkS ©NrX  ru  rW  ©r'   rP  rY  rT  )Úprefix©r@   r‰   r7   r8   Úvalidateç
  ó   ÿz8SignedValueTest.test_payload_tampering.<locals>.validateú%2|1:0|10:1300000000|3:key|8:dmFsdWU=|z%2|1:1|10:1300000000|3:key|8:dmFsdWU=|z$2|1:0|10:130000000|3:key|8:dmFsdWU=|z&2|1:0|10:1300000000|3:keey|8:dmFsdWU=|©r¿   ÚassertFalse©r@   rp  r7   ro  r8   Útest_payload_tamperingã
  s   z&SignedValueTest.test_payload_tamperingc                    sj   d‰ ‡ ‡fdd„}ˆ  |dƒ¡ ˆ |dƒ¡ ˆ |dƒ¡ ˆ |dƒ¡ ˆ |dƒ¡ ˆ |d	ƒ¡ d S )
Nrr  c                    s   dt tjdˆ |  ˆjdkS rl  rm  )r‰   ©rn  r@   r7   r8   rp  ÷
  rq  z:SignedValueTest.test_signature_tampering.<locals>.validaterk  Ú 00000000000000000000000000000000Ú@4d4e60b996ff9c5d5788e333a0cba6f238a22c6c0f94788870e1a9ecd482e152Ú@3d4e60b996ff9c5d5788e333a0cba6f238a22c6c0f94788870e1a9ecd482e153Ú?3d4e60b996ff9c5d5788e333a0cba6f238a22c6c0f94788870e1a9ecd482e15ÚA3d4e60b996ff9c5d5788e333a0cba6f238a22c6c0f94788870e1a9ecd482e1538rs  ru  r7   rw  r8   Útest_signature_tamperingô
  s(   ÿÿÿÿÿÿz(SignedValueTest.test_signature_tamperingc                 C   s<   d}t tjd|| jd}ttjd|| jd}|  ||¡ d S )Nr‹   ru  rW  )r&   rP  rY  rT  r'   rv   ©r@   rg   rg  Údecodedr7   r7   r8   Útest_non_ascii  s   ÿÿzSignedValueTest.test_non_asciic                 C   ó>   d}t tjd|| jdd}ttjd|| jd}|  ||¡ d S ©Nr‹   ru  r   ©rV  r`   rW  ©r&   rP  ÚSECRET_DICTrT  r'   rv   r~  r7   r7   r8   Ú*test_key_versioning_read_write_default_key  ó   ÿÿz:SignedValueTest.test_key_versioning_read_write_default_keyc                 C   r  )Nr‹   ru  ro   rƒ  rW  r„  r~  r7   r7   r8   Ú.test_key_versioning_read_write_non_default_key(  r‡  z>SignedValueTest.test_key_versioning_read_write_non_default_keyc                 C   sN   d}t tjd|| jdd}tj ¡ }| d¡ t|d|| jd}|  |¡ d S r‚  )r&   rP  r…  rT  r™   rš   r'   r†   )r@   rg   rg  Únewkeysr  r7   r7   r8   Útest_key_versioning_invalid_key2  s   ÿ

z/SignedValueTest.test_key_versioning_invalid_keyc                 C   s2   d}t tjd|| jdd}t|ƒ}|  d|¡ d S )Nr‹   ru  ro   rƒ  )r&   rP  r…  rT  r(   rv   )r@   rg   rg  r`   r7   r7   r8   Útest_key_version_retrieval<  s   ÿz*SignedValueTest.test_key_version_retrievalN)rG   rH   rI   rY  r…  rU  rT  r_  rf  rj  rv  r}  r€  r†  rˆ  rŠ  r‹  r7   r7   r7   r8   rP  ›
  s      



rP  c                       s¸   e Zd ZG dd„ deƒZdd„ Z‡ fdd„Zd(dd	„Zd)d
d„Zdd„ Z	dd„ Z
dd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zd d!„ Zd"d#„ Zd$d%„ Zd&d'„ Z‡  ZS )*ÚXSRFTestc                   @   r*  )zXSRFTest.Handlerc                 C   s*   t |  dd¡ƒ}|| jd< |  | j¡ d S )Nrq   r  Úxsrf_cookie_version)r“  r”  r^   rV   r‹  )r@   rq   r7   r7   r8   rW   G  s   
zXSRFTest.Handler.getc                 C   rR   rs  rU   r?   r7   r7   r8   r¤   N  rX   zXSRFTest.Handler.postN©rG   rH   rI   rW   r¤   r7   r7   r7   r8   rN   F  s    rN   c                 C   r±   rM  r³   r?   r7   r7   r8   r=   Q  r´   zXSRFTest.get_app_kwargsc                    ó   t ƒ  ¡  |  ¡ | _d S r0   ©râ  ÚsetUpÚ	get_tokenr‹  r?   ræ  r7   r8   r‘  T  ri  zXSRFTest.setUpNc                 C   sH   |d ur
|   |¡}nd }| j|d u rdnd| |d}| ¡  t|jƒS )NrL   z/?version=%dr  ©Úcookie_headersr»   rõ  r   rº   )r@   Ú	old_tokenrq   r  rÂ   r7   r7   r8   r’  X  s   ÿ
zXSRFTest.get_tokenc                 C   ó   |d u r| j }dd| iS )Nr  z_xsrf=©r‹  ©r@   Útokenr7   r7   r8   r”  c  ó   zXSRFTest.cookie_headersc                 C   óL   t tdƒ | jdddd}W d   ƒ n1 sw   Y  |  |jd¡ d S ©Nú.*'_xsrf' argument missingrL   r¶   r·   r¸   r¿  rÿ  rÁ   r7   r7   r8   Útest_xsrf_fail_no_tokenh  ó   ÿz XSRFTest.test_xsrf_fail_no_tokenc              	   C   ó\   t tdƒ | jddtj t| jd¡d}W d   ƒ n1 s w   Y  |  |j	d¡ d S ©Nú!.*XSRF cookie does not match POSTrL   r¶   ©Ú_xsrfr¸   r¿  ©
r   r   r»   r  r  r  rb   r‹  rv   r½   rÁ   r7   r7   r8   Útest_xsrf_fail_body_no_cookiem  ó   ýÿz&XSRFTest.test_xsrf_fail_body_no_cookiec              
   C   s`   t tdƒ | jdd|  ¡ tj tdd¡d}W d   ƒ n1 s"w   Y  |  |j	d¡ d S )Nz%.*'_xsrf' argument has invalid formatrL   r¶   ú3|r£  r÷  r¿  )
r   r   r»   r”  r  r  r  rb   rv   r½   rÁ   r7   r7   r8   Ú&test_xsrf_fail_argument_invalid_formatv  s   üÿz/XSRFTest.test_xsrf_fail_argument_invalid_formatc              
   C   sf   t tdƒ | jdd| jddtj t| jd¡d}W d   ƒ n1 s%w   Y  |  	|j
d¡ d S )	Nr¢  rL   r¶   r¨  ©r™  r£  r÷  r¿  )r   r   r»   r”  r  r  r  rb   r‹  rv   r½   rÁ   r7   r7   r8   Ú$test_xsrf_fail_cookie_invalid_format€  s   
üÿz-XSRFTest.test_xsrf_fail_cookie_invalid_formatc                 C   sR   t tdƒ | jddd|  ¡ d}W d   ƒ n1 sw   Y  |  |jd¡ d S )Nr  rL   r¶   r·   ©r¹   rº   r  r¿  )r   r   r»   r”  rv   r½   rÁ   r7   r7   r8   Útest_xsrf_fail_cookie_no_bodyŠ  s   ÿÿz&XSRFTest.test_xsrf_fail_cookie_no_bodyc                 C   ó:   | j ddtj tdd¡| jddd}|  |jd¡ d S )NrL   r¶   Údeadbeefr£  rª  r¬  rµ   ©r»   r  r  r  rb   r”  rv   r½   rÁ   r7   r7   r8   Útest_xsrf_success_short_token‘  ó   
üz&XSRFTest.test_xsrf_success_short_tokenc                 C   r®  )NrL   r¶   Úxoxor£  rª  r¬  rµ   r°  rÁ   r7   r7   r8   Útest_xsrf_success_non_hex_tokenš  r²  z(XSRFTest.test_xsrf_success_non_hex_tokenc                 C   ó8   | j ddtj t| jd¡|  ¡ d}|  |jd¡ d S ©NrL   r¶   r£  r¬  rµ   ©	r»   r  r  r  rb   r‹  r”  rv   r½   rÁ   r7   r7   r8   Útest_xsrf_success_post_body£  s   üz$XSRFTest.test_xsrf_success_post_bodyc                 C   s<   | j dtj t| jd¡ dd|  ¡ d}|  |jd¡ d S )Nz/?r£  r¶   r·   r¬  rµ   r·  rÁ   r7   r7   r8   Útest_xsrf_success_query_string¬  s   üz'XSRFTest.test_xsrf_success_query_stringc              	   C   s:   | j dddtd| jifi |  ¡ ¤Žd}|  |jd¡ d S )NrL   r¶   r·   zX-Xsrftokenr¬  rµ   )r»   rb   r‹  r”  rv   r½   rÁ   r7   r7   r8   Útest_xsrf_success_headerµ  s   ÿþü	z!XSRFTest.test_xsrf_success_headerc                 C   s:   d}t ƒ }t|ƒD ]	}| |  ¡ ¡ q	|  t|ƒ|¡ d S )Nrö   )rc  rê   rt  r’  rv   r  )r@   Ú
NUM_TOKENSÚtokensr  r7   r7   r8   Útest_distinct_tokensÁ  s
   zXSRFTest.test_distinct_tokensc              
   C   sÌ   |   ¡ }| j|fD ]}| jddtj t|d¡|  |¡d}|  |j	d¡ q	| j|f|| jffD ]3\}}t
tdƒ | jddtj t|d¡|  |¡d}W d   ƒ n1 sWw   Y  |  |j	d¡ q0d S )NrL   r¶   r£  r¬  rµ   r¢  r¿  )r’  r‹  r»   r  r  r  rb   r”  rv   r½   r   r   )r@   Útoken2r™  rÂ   Úcookie_tokenÚ
body_tokenr7   r7   r8   Útest_cross_userÉ  s,   üþüÿõzXSRFTest.test_cross_userc              	   C   sx   | j }|h}tdƒD ]'}|  |¡}| |¡ | jddtj t| j d¡|  	|¡d}|  
|jd¡ q
|  
t|ƒd¡ d S )Né   rL   r¶   r£  r¬  rµ   é   )r‹  rê   r’  rt  r»   r  r  r  rb   r”  rv   r½   r  )r@   r™  Útokens_seenr  rÂ   r7   r7   r8   Útest_refresh_tokenâ  s   

üzXSRFTest.test_refresh_tokenc              	   C   sÆ   |   | jdd| jdd¡ | jdd}tdƒD ]}|  | j|dd|¡ q|  |¡}|   ||¡ |   ||  |¡¡ ||f||ffD ]\}}| jddtj t|d¡|  	|¡d}|  |j
d¡ qBd S )	Nro   rp   rÂ  rL   r¶   r£  r¬  rµ   )ÚassertNotEqualr’  rê   rv   r»   r  r  r  rb   r”  r½   )r@   Úv1_tokenr  Úv2_tokenr¿  rÀ  rÂ   r7   r7   r8   Útest_versioningö  s    
üùzXSRFTest.test_versioningrÿ  r0   )rG   rH   rI   r   rN   r=   r‘  r’  r”  rž  r¦  r©  r«  r­  r±  r´  r¸  r¹  rº  r½  rÁ  rÅ  rÉ  r)  r7   r7   ræ  r8   rŒ  E  s(    

	

				rŒ  c                       s`   e Zd ZG dd„ deƒZdd„ Z‡ fdd„Zddd	„Zdd
d„Zdd„ Z	dd„ Z
dd„ Z‡  ZS )ÚXSRFCookieNameTestc                   @   r*  )zXSRFCookieNameTest.Handlerc                 C   r  r0   ©rV   r‹  r?   r7   r7   r8   rW     rz  zXSRFCookieNameTest.Handler.getc                 C   rR   rs  rU   r?   r7   r7   r8   r¤     rX   zXSRFCookieNameTest.Handler.postNrŽ  r7   r7   r7   r8   rN     r/  rN   c                 C   s   t ddddidS )NTz__Host-xsrfrü   )rN  Úxsrf_cookie_nameÚxsrf_cookie_kwargsr³   r?   r7   r7   r8   r=     s
   ýz!XSRFCookieNameTest.get_app_kwargsc                    r  r0   r  r?   ræ  r7   r8   r‘     ri  zXSRFCookieNameTest.setUpNc                 C   s8   |d ur
|   |¡}nd }| jd|d}| ¡  t|jƒS )NrL   r  r“  )r@   r•  r  rÂ   r7   r7   r8   r’  $  s   
zXSRFCookieNameTest.get_tokenc                 C   r–  )Nr  z__Host-xsrf=r—  r˜  r7   r7   r8   r”  -  rš  z!XSRFCookieNameTest.cookie_headersc                 C   r›  rœ  rÿ  rÁ   r7   r7   r8   rž  2  rŸ  z*XSRFCookieNameTest.test_xsrf_fail_no_tokenc              	   C   r   r¡  r¥  rÁ   r7   r7   r8   r¦  7  r§  z0XSRFCookieNameTest.test_xsrf_fail_body_no_cookiec                 C   rµ  r¶  r·  rÁ   r7   r7   r8   r¸  @  s   ûz.XSRFCookieNameTest.test_xsrf_success_post_bodyr0   )rG   rH   rI   r   rN   r=   r‘  r’  r”  rž  r¦  r¸  r)  r7   r7   ræ  r8   rÊ    s    

		rÊ  c                   @   r  )ÚXSRFCookieKwargsTestc                   @   rP   )zXSRFCookieKwargsTest.Handlerc                 C   r  r0   rË  r?   r7   r7   r8   rW   M  rz  z XSRFCookieKwargsTest.Handler.getNrY   r7   r7   r7   r8   rN   L  rZ   rN   c                 C   s   t dt ddddS )NTr|   )rý   rh   )rN  rÍ  r³   r?   r7   r7   r8   r=   P  s   ÿz#XSRFCookieKwargsTest.get_app_kwargsc                 C   sÎ   |   d¡}|  d|jd  ¡ ¡ |  d|jd  ¡ ¡ |j d¡}|d us'J ‚t d|¡}|d us3J ‚tj tj	j
¡tjdd }tj | ¡ d ¡}|jd u rX|jtj	j
d	}|  t||  ¡ ƒd
k ¡ d S )NrL   z	httponly;r  zexpires=z.*; expires=(?P<expires>.+);.*r|   r*  r,  )Útzinforö   )r»   r  r  ÚlowerrW   r‚   rƒ   r-  r.  r/  r0  r1  r2  r3  r4  r5  rÏ  Úreplacer¿   r7  r8  r9  r7   r7   r8   Útest_xsrf_httponlyU  s   
ÿ
z'XSRFCookieKwargsTest.test_xsrf_httponlyN)rG   rH   rI   r   rN   r=   rÒ  r7   r7   r7   r8   rÎ  K  s    rÎ  c                   @   r  )ÚFinishExceptionTestc                   @   rP   )zFinishExceptionTest.Handlerc                 C   s:   |   d¡ |  dd¡ |  dd¡rtdƒ‚|  d¡ tƒ ‚)Nrÿ  úWWW-AuthenticateúBasic realm="something"Úfinish_valuer"  zauthentication required)r(  r·  r”  r*   rV   r?   r7   r7   r8   rW   i  s   

zFinishExceptionTest.Handler.getNrY   r7   r7   r7   r8   rN   h  rZ   rN   c                 C   sH   dD ]}|   |¡}|  |jd¡ |  d|j d¡¡ |  d|j¡ qd S )N)rL   z/?finish_value=1rÿ  rÕ  rÔ  s   authentication required)r»   rv   r½   r  rW   rº   )r@   ÚurÂ   r7   r7   r8   Útest_finish_exceptionr  s   
ÿúz)FinishExceptionTest.test_finish_exceptionN)rG   rH   rI   r   rN   rØ  r7   r7   r7   r8   rÓ  g  rå  rÓ  c                   @   rj   )ÚDecoratorTestc                 C   s0   G dd„ dt ƒ}G dd„ dt ƒ}d|fd|fgS )Nc                   @   ó   e Zd Zedd„ ƒZdS )z6DecoratorTest.get_handlers.<locals>.RemoveSlashHandlerc                 S   rú  r0   r7   r?   r7   r7   r8   rW     rþ  z:DecoratorTest.get_handlers.<locals>.RemoveSlashHandler.getN)rG   rH   rI   r,   rW   r7   r7   r7   r8   ÚRemoveSlashHandler~  ó    rÛ  c                   @   rÚ  )z3DecoratorTest.get_handlers.<locals>.AddSlashHandlerc                 S   rú  r0   r7   r?   r7   r7   r8   rW   „  rþ  z7DecoratorTest.get_handlers.<locals>.AddSlashHandler.getN)rG   rH   rI   r-   rW   r7   r7   r7   r8   ÚAddSlashHandlerƒ  rÜ  rÝ  ú/removeslash/ú	/addslashr°   )r@   rÛ  rÝ  r7   r7   r8   r<   }  s   zDecoratorTest.get_handlersc                 C   ó`   | j ddd}|  |jd¡ |  |jd d¡ | j ddd}|  |jd¡ |  |jd d¡ d S )	NrÞ  FrK  r  rN  z/removeslashz/removeslash/?foo=barz/removeslash?foo=barr  rÁ   r7   r7   r8   Útest_removeslashŠ  ó   zDecoratorTest.test_removeslashc                 C   rà  )	Nrß  FrK  r  rN  z
/addslash/z/addslash?foo=barz/addslash/?foo=barr  rÁ   r7   r7   r8   Útest_addslash“  râ  zDecoratorTest.test_addslashN)rG   rH   rI   r<   rá  rã  r7   r7   r7   r8   rÙ  |  s    	rÙ  c                   @   rÅ   )Ú	CacheTestc                 C   s   G dd„ dt ƒ}d|fgS )Nc                   @   r*  )z+CacheTest.get_handlers.<locals>.EtagHandlerc                 S   r  r0   rU   )r@   Úcomputed_etagr7   r7   r8   rW      rX   z/CacheTest.get_handlers.<locals>.EtagHandler.getc                 S   s
   | j d S rZ  )Ú_write_bufferr?   r7   r7   r8   Úcompute_etag£  r´   z8CacheTest.get_handlers.<locals>.EtagHandler.compute_etagN)rG   rH   rI   rW   rç  r7   r7   r7   r8   ÚEtagHandlerŸ  r/  rè  z
/etag/(.*)r°   )r@   rè  r7   r7   r8   r<   ž  s   
zCacheTest.get_handlersc                 C   ó   d}d}|   ||d¡ d S )Nú"xyzzy"Ú*r|  ©Ú
_test_etag©r@   rå  Úetagsr7   r7   r8   Útest_wildcard_etag¨  ó   zCacheTest.test_wildcard_etagc                 C   s   d}d}|   ||d¡ d S )Nrê  r|  rì  rî  r7   r7   r8   Útest_strong_etag_match­  rñ  z CacheTest.test_strong_etag_matchc                 C   ré  )Nú"xyzzy1"ú"xyzzy1", "xyzzy2"r|  rì  rî  r7   r7   r8   Útest_multiple_strong_etag_match²  rñ  z)CacheTest.test_multiple_strong_etag_matchc                 C   ré  )Nrê  ró  rµ   rì  rî  r7   r7   r8   Útest_strong_etag_not_match·  rñ  z$CacheTest.test_strong_etag_not_matchc                 C   ré  )Nrê  rô  rµ   rì  rî  r7   r7   r8   Ú#test_multiple_strong_etag_not_match¼  rñ  z-CacheTest.test_multiple_strong_etag_not_matchc                 C   ré  )Nró  ú
W/"xyzzy1"r|  rì  rî  r7   r7   r8   Útest_weak_etag_matchÁ  rñ  zCacheTest.test_weak_etag_matchc                 C   ré  )Nú"xyzzy2"úW/"xyzzy1", W/"xyzzy2"r|  rì  rî  r7   r7   r8   Útest_multiple_weak_etag_matchÆ  rñ  z'CacheTest.test_multiple_weak_etag_matchc                 C   ré  )Nrú  rø  rµ   rì  rî  r7   r7   r8   Útest_weak_etag_not_matchË  rñ  z"CacheTest.test_weak_etag_not_matchc                 C   ré  )Nz"xyzzy3"rû  rµ   rì  rî  r7   r7   r8   Ú!test_multiple_weak_etag_not_matchÐ  rñ  z+CacheTest.test_multiple_weak_etag_not_matchc                 C   s(   | j d| d|id}|  |j|¡ d S )Nz/etag/r‚  r  r  )r@   rå  rï  r7  rÂ   r7   r7   r8   rí  Õ  s   ÿzCacheTest._test_etagN)rG   rH   rI   r<   rð  rò  rõ  rö  r÷  rù  rü  rý  rþ  rí  r7   r7   r7   r8   rä    s    
rä  c                   @   r  )ÚRequestSummaryTestc                   @   rP   )zRequestSummaryTest.Handlerc                 C   s   d | j _|  |  ¡ ¡ d S r0   )rp  Ú	remote_iprž   r—  r?   r7   r7   r8   rW   Þ  s   zRequestSummaryTest.Handler.getNrY   r7   r7   r7   r8   rN   Ý  rZ   rN   c                 C   r  )NrL   s   GET / (None)r  rõ  r7   r7   r8   Útest_missing_remote_ipå  r  z)RequestSummaryTest.test_missing_remote_ipN)rG   rH   rI   r   rN   r  r7   r7   r7   r8   rÿ  Ü  rŸ  rÿ  c                   @   rP   )ÚHTTPErrorTestc                 C   sF   t ddd}t |¡}|  ||¡ |  |j|j¡ |  |j|j¡ d S )Nr¿  zGo awayr5  )r    r™   ÚassertIsNotrv   r7  r4  )r@   rï   Úe2r7   r7   r8   Ú	test_copyë  s
   
zHTTPErrorTest.test_copyN)rG   rH   rI   r  r7   r7   r7   r8   r  ê  rZ   r  c                   @   rP   )ÚApplicationTestc                 C   s"   t g ƒ}|jddd}| ¡  d S )Nr   rY  )Úaddress)r   Úlistenrj  )r@   r>   Úserverr7   r7   r8   Útest_listenô  s   zApplicationTest.test_listenN)rG   rH   rI   r
  r7   r7   r7   r8   r  ó  rZ   r  c                   @   rj   )ÚURLSpecReverseTestc                 C   s0   |   dtdd ƒ ¡ ¡ |   dtdd ƒ ¡ ¡ d S )Nz/favicon.icoz/favicon\.icoz^/favicon\.ico$©rv   r$   Úreverser?   r7   r7   r8   Útest_reverseû  r
  zURLSpecReverseTest.test_reversec              	   C   sN   dg}|D ]}t |d ƒ}z| ¡ }|  d||f ¡ W q ty$   Y qw d S )Nz^/api/v\d+/foo/(\w+)$z<did not get expected exception when reversing %s. result: %s)r$   r  r  rÆ  )r@   Úpathsr2   Úurl_specr[  r7   r7   r8   Útest_non_reversibleÿ  s   
ÿÿÿ÷z&URLSpecReverseTest.test_non_reversiblec                 C   s4   |   dtdd ƒ d¡¡ |   dtdd ƒ d¡¡ d S )Nz/api/v1/foo/barz^/api/v1/foo/(\w+)$râ   z/api.v1/foo/5/icon.pngz/api\.v1/foo/([0-9]+)/icon\.pngrÂ  r  r?   r7   r7   r8   Útest_reverse_arguments  s   ÿþz)URLSpecReverseTest.test_reverse_argumentsN)rG   rH   rI   r  r  r  r7   r7   r7   r8   r  ú  s    r  c                   @   s4   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ ZdS )ÚRedirectHandlerTestc                 C   s(   dt ddifdt ddifdt ddifgS )Nú/srcr$   ú/dstz/src2z/dst2?foo=barz/(.*?)/(.*?)/(.*)z/{1}/{0}/{2})ró  r?   r7   r7   r8   r<     s   ýz RedirectHandlerTest.get_handlersc                 C   r  )Nr  FrK  r  rN  r  r  rÁ   r7   r7   r8   Útest_basic_redirect#  r  z'RedirectHandlerTest.test_basic_redirectc                 C   r  )Nz/src?foo=barFrK  r  rN  z/dst?foo=barr  rÁ   r7   r7   r8   Útest_redirect_with_argument(  r  z/RedirectHandlerTest.test_redirect_with_argumentc                 C   r  )Nz/src2?foo2=bar2FrK  r  rN  z/dst2?foo=bar&foo2=bar2r  rÁ   r7   r7   r8   Ú%test_redirect_with_appending_argument-  r  z9RedirectHandlerTest.test_redirect_with_appending_argumentc                 C   r  )Nz/a/b/cFrK  r  rN  z/b/a/cr  rÁ   r7   r7   r8   Útest_redirect_pattern2  r  z)RedirectHandlerTest.test_redirect_patternN)rG   rH   rI   r<   r  r  r  r  r7   r7   r7   r8   r    s    r  c                   @   s0   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
S )ÚAcceptLanguageTestz)Test evaluation of Accept-Language headerc                 C   s8   t  tj tj t¡d¡d¡ G dd„ dtƒ}d|fgS )NÚgettext_translationsÚtornado_testc                   @   rP   )z>AcceptLanguageTest.get_handlers.<locals>.AcceptLanguageHandlerc                 S   s(   |   d|  ¡ j dd¡¡ |  d¡ d S )Nr.  Ú_ú-r·   )r·  Úget_browser_localer½   rÑ  rž   r?   r7   r7   r8   rW   B  s   ÿzBAcceptLanguageTest.get_handlers.<locals>.AcceptLanguageHandler.getNrY   r7   r7   r7   r8   ÚAcceptLanguageHandlerA  rZ   r   rL   )r   Úload_gettext_translationsr1   r2   r3   r4   r5   r   )r@   r   r7   r7   r8   r<   ;  s   þÿzAcceptLanguageTest.get_handlersc                 C   sL   | j dddid}|  |jd d¡ | j dddid}|  |jd d¡ d S )NrL   rd  zfr-FR;q=0.9r  r.  zfr-FRzfr-FR; q=0.9©r»   rv   r  rÁ   r7   r7   r8   Útest_accept_languageL  s   z'AcceptLanguageTest.test_accept_languagec                 C   ó(   | j dddid}|  |jd d¡ d S )NrL   rd  z	fr-FR;q=0r  r.  úen-USr"  rÁ   r7   r7   r8   Útest_accept_language_ignoreS  ó   z.AcceptLanguageTest.test_accept_language_ignorec                 C   r$  )NrL   rd  z
fr-FR;q=-1r  r.  r%  r"  rÁ   r7   r7   r8   Útest_accept_language_invalidW  r'  z/AcceptLanguageTest.test_accept_language_invalidN)rG   rH   rI   rJ   r<   r#  r&  r(  r7   r7   r7   r8   r  8  s    r  )¢rë   Útornado.concurrentr   Útornador   Útornado.escaper   r   r   r   r   r	   Útornado.httpclientr
   Útornado.httputilr   Útornado.iostreamr   r   Útornado.locksr   Útornado.logr   r   Útornado.simple_httpclientr   Útornado.templater   Útornado.testingr   r   r   r   Útornado.test.utilr   Útornado.utilr   r   Útornado.webr   r   r   r   ró  r    r!   r"   r#   r$   r%   r&   r'   r(   r)   r*   r+   r,   r-   r.   r€   r  r™   r-  Úemail.utilsr2  r%  Úior/   rq  r  r1   r‚   r]  r’  rÅ  Úurllib.parser  r9   r;   rK   rQ   r[   ÚTestCaserk   r   r   rÆ   r>  rH  rQ  rX  rl  ry  r†  r¡  r©  r®  r²  r³  r½  rÁ  rÈ  rÐ  rÖ  rÚ  r+  r0  rJ  rÇ  rÖ  rß  rá  r  r  r  r  r&  r-  r3  r>  rC  rI  rS  rj  rr  rs  ry  r|  r  r  rš  r   r©  rÉ  rÐ  rÙ  rÞ  rã  ræ  rê  rí  rð  rø  r  r  r,  r2  r5  rJ  rP  rŒ  rÊ  rÎ  rÓ  rÙ  rä  rÿ  r  r  r  r  r  r7   r7   r7   r8   Ú<module>   sþ     T6/1 `0,
  	B  k%C*"):/.\b
Mÿ
ÿ; + M:!?	!