
    	Pjc                     :   d dl mZ d dlZd dlZd dlZd dlmZ d dlmZ d dl	m
Z
 d dlmZmZ d dlmZmZ 	 d dlZed dlmZ  ej*                  edu d	       G d
 de
j,                               Z G d de      Z G d de      Z G d de      Z ej*                  edu d	       G d de             Z G d de      Z ej*                  edu d	       G d de             Z G d de      Z ej*                  edu d	       G d de             Zy# e$ r dZY w xY w)    )md5N)utf8)ssl_options_to_context)httpclient_test)AsyncHTTPSTestCaseAsyncHTTPTestCase)ApplicationRequestHandler)CurlAsyncHTTPClientzpycurl module not presentc                       e Zd Zd Zy)CurlHTTPClientCommonTestCasec                 p    t        t        d            }| j                  t        |t                      |S )NF
allow_ipv6)defaults)r   dict
assertTrue
isinstance)selfclients     T/root/.hermes/venv/lib/python3.12/site-packages/tornado/test/curl_httpclient_test.pyget_http_clientz,CurlHTTPClientCommonTestCase.get_http_client   s*    $de.DE
6+>?@    N)__name__
__module____qualname__r    r   r   r   r      s    r   r   c                       e Zd Zd Zd Zy)DigestAuthHandlerc                      || _         || _        y Nusernamepassword)r   r#   r$   s      r   
initializezDigestAuthHandler.initialize   s      r   c           
         d}d}d}| j                   j                  j                  dd       }||j                  dd      \  }}|dk(  sJ i }|j                  d      D ]?  }|j	                         j                  d	d      \  }	}
|
d
   dk(  r|
d   dk(  r|
dd }
|
||	<   A |d   |k(  sJ |d   |k(  sJ |d   |k(  sJ |d   | j
                  k(  sJ |d   | j                   j                  k(  sJ t        t        | j
                   d| d| j                               j                         }t        t        | j                   j                   d| j                   j                               j                         }t        t        | d| d|             j                         }||d   k(  r| j                  d       y | j                  d       y | j                  d       | j                  dd| d| d| d       y )Ntestasdf1234Authorization    Digest,=r   "realmopaquenoncer#   uri:responseokfaili  zWWW-AuthenticatezDigest realm="z
", nonce="z", opaque=")requestheadersgetsplitstripr#   pathr   r   r$   	hexdigestmethodwrite
set_status
set_header)r   r2   r3   r4   auth_header	auth_modeparams
param_dictpairkvh1h2digests                 r   r<   zDigestAuthHandler.get#   s   ll**..E" + 1 1#q 9Iv(((JS) "zz|))#q11Q43;1R5C<!BA !
1	"
 g&%///h'6111g&%///j)T]]:::e$(9(9999TT]]O1UG1T]]ODEFPPRBTT\\0014<<3D3D2EFGHRRTBAeWAbT234>>@FJ//

4 

6"OOC OO" z%F81Mr   N)r   r   r   r%   r<   r   r   r   r   r      s    !!r   r   c                       e Zd Zd Zy)CustomReasonHandlerc                 (    | j                  dd       y )N   Custom reasonrC   r   s    r   r<   zCustomReasonHandler.getH       _-r   Nr   r   r   r<   r   r   r   rP   rP   G       .r   rP   c                       e Zd Zd Zy)CustomFailReasonHandlerc                 (    | j                  dd       y )Ni  rS   rT   rU   s    r   r<   zCustomFailReasonHandler.getM   rV   r   NrW   r   r   r   rZ   rZ   L   rX   r   rZ   c                   B     e Zd Z fdZd Zd Zd Zd Zd Zd Z	 xZ
S )CurlHTTPClientTestCasec                 L    t         |           | j                         | _        y r!   )supersetUpcreate_clienthttp_client)r   	__class__s    r   r`   zCurlHTTPClientTestCase.setUpS   s    --/r   c                 `    t        dt        dddfdt        dddfdt        fdt        fg      S )	N/digestfoobarr"   /digest_non_ascii   barユ£/custom_reason/custom_fail_reason)r	   r   rP   rZ   rU   s    r   get_appzCurlHTTPClientTestCase.get_appW   sK    -Eu/UV'%!&J?
 "#67&(?@	
 	
r   c                 2    t        ddt        d      d|S )NTFr   )force_instancer   r   r   r   )r   kwargss     r   ra   z$CurlHTTPClientTestCase.create_cliente   s&    " 
$%*@
DJ
 	
r   c                 f    | j                  dddd      }| j                  |j                  d       y )Nre   rN   rf   rg   rF   auth_usernameauth_password   okfetchassertEqualbodyr   r7   s     r   test_digest_authz'CurlHTTPClientTestCase.test_digest_authj   s4    ::e  
 	.r   c                 ^    | j                  d      }| j                  |j                  d       y )Nrj   rS   )rw   rx   reasonrz   s     r   test_custom_reasonz)CurlHTTPClientTestCase.test_custom_reasonp   s%    ::.//:r   c                 p    | j                  d      }| j                  t        |j                        d       y )Nrk   zHTTP 400: Custom reason)rw   rx   strerrorrz   s     r   test_fail_custom_reasonz.CurlHTTPClientTestCase.test_fail_custom_reasont   s+    ::34X^^,.GHr   c                 f    | j                  dddd      }| j                  |j                  d       y )Nrh   rN   rf   ri   rr   ru   rv   rz   s     r   test_digest_auth_non_asciiz1CurlHTTPClientTestCase.test_digest_auth_non_asciix   s7    ::$	  
 	.r   )r   r   r   r`   rl   ra   r{   r~   r   r   __classcell__rc   s   @r   r]   r]   Q   s'    0


/;I/r   r]   c                       e Zd Zd Zy)ProxyAuthEchoHandlerc                     | j                   j                  j                  dd       ,| j                  d| j                   j                  d           y | j                  d       y )NzProxy-Authorizationzproxy auth: zno proxy auth)r:   r;   r<   rB   rU   s    r   r<   zProxyAuthEchoHandler.get   sP    <<##$94@LJJdll&:&:;P&Q%RSTJJ'r   NrW   r   r   r   r   r      s    (r   r   c                       e Zd Zd Zd Zd Zy)$CurlHTTPClientReuseProxyAuthTestCasec                 &    t        dt        fg      S )Nz.*/proxy_auth)r	   r   rU   s    r   rl   z,CurlHTTPClientReuseProxyAuthTestCase.get_app   s     _.BCDEEr   c                 2    t        dt        d      d      S )NTFr   r,   rn   r   max_clientsro   rU   s    r   r   z4CurlHTTPClientReuseProxyAuthTestCase.get_http_client   s$     #  
 	
r   c                     | j                  dd| j                         dd      }| j                  |j                  d       | j                  dd| j                               }| j                  |j                  d       y )	Nz/proxy_authz	127.0.0.1rf   rg   )
proxy_host
proxy_portproxy_usernameproxy_passwords   proxy auth: Basic Zm9vOmJhcg==)r   r   s   no proxy auth)rw   get_http_portrx   ry   rz   s     r   test_reuse_proxy_credentialszACurlHTTPClientReuseProxyAuthTestCase.test_reuse_proxy_credentials   s     ::"))+    
 	(IJ::"))+  

 	(89r   N)r   r   r   rl   r   r   r   r   r   r   r      s    F
	
:r   r   c                       e Zd Zd Zy)ClientCertEchoHandlerc                     | j                   j                         }|*t        |t              sJ | j	                  d|d           y | j	                  d       y )Nzclient cert: subjectzno client cert)r:   get_ssl_certificater   r   rB   )r   certs     r   r<   zClientCertEchoHandler.get   sO    ||//1dD)))JJtI&789JJ'(r   NrW   r   r   r   r   r      s    )r   r   c                   6     e Zd Zd Zd Zd Z fdZd Z xZS ) CurlHTTPClientReuseCertsTestCasec                 &    t        dt        fg      S )Nz.*/client_cert)r	   r   rU   s    r   rl   z(CurlHTTPClientReuseCertsTestCase.get_app   s    -/DEFGGr   c                 4    t        dt        dd      d      S )NTF)r   validate_certr,   r   ro   rU   s    r   r   z0CurlHTTPClientReuseCertsTestCase.get_http_client   s%    " # 
 	
r   c                 z    t        | j                         d      }t        j                  |_        t        |      S )NT)server_side)ssl_options)r   get_ssl_optionssslCERT_OPTIONALverify_moder   )r   ssl_ctxs     r   get_httpserver_optionsz7CurlHTTPClientReuseCertsTestCase.get_httpserver_options   s0    ()=)=)?TR!//((r   c                     t         |          }t        j                  j	                  t        j                  j                  t              d      |d<   |S )Ntest.crtca_certs)r_   r   osr?   joindirname__file__)r   optsrc   s     r   r   z0CurlHTTPClientReuseCertsTestCase.get_ssl_options   s;    w&(77<<(A:NZr   c           	         | j                  | j                  d      t        j                  j	                  t        j                  j                  t              d      t        j                  j	                  t        j                  j                  t              d            }| j                  |j                  d       | j                  | j                  d            }| j                  |j                  d       y )Nz/client_certr   ztest.key)client_cert
client_keys4   client cert: ((('commonName', 'foo.example.com'),),)s   no client cert)	rw   get_urlr   r?   r   r   r   rx   ry   rz   s     r   test_reuse_certsz1CurlHTTPClientReuseCertsTestCase.test_reuse_certs   s     ::LL(RWW__X%>
Kww||BGGOOH$=zJ  

 	MMR	
 ::dll>:;(9:r   )	r   r   r   rl   r   r   r   r   r   r   s   @r   r   r      s    H
)

;r   r   ) hashlibr   r   r   unittesttornado.escaper   tornado.netutilr   tornado.testr   tornado.testingr   r   tornado.webr	   r
   pycurlImportErrortornado.curl_httpclientr   skipIfHTTPClientCommonTestCaser   r   rP   rZ   r]   r   r   r   r   r   r   r   <module>r      sF    	 
   2 ( A 3 
; 4!<=?#K#K  >& &R.. .
.n .
 4!<=-/. -/ >-/`(> ( 4!<=!:+< !: >!:H)N ) 4!<=$;'9 $; >$;Y  Fs   D DD