o
    )Zh                     @   s   d dl m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 zd dlZW n ey5   dZY nw edur@d dlmZ eedu dG d	d
 d
ejZG dd deZG dd deZG dd deZeedu dG dd deZdS )    )md5N)utf8)AsyncHTTPTestCase)httpclient_test)ApplicationRequestHandler)CurlAsyncHTTPClientzpycurl module not presentc                   @      e Zd Zdd ZdS )CurlHTTPClientCommonTestCasec                 C   s$   t tddd}| t|t  |S )NFZ
allow_ipv6)defaults)r   dictZ
assertTrue
isinstance)selfclient r   X/var/www/html/lang_env/lib/python3.10/site-packages/tornado/test/curl_httpclient_test.pyget_http_client   s   z,CurlHTTPClientCommonTestCase.get_http_clientN)__name__
__module____qualname__r   r   r   r   r   r
      s    r
   c                   @   s   e Zd Zdd Zdd ZdS )DigestAuthHandlerc                 C   s   || _ || _d S Nusernamepassword)r   r   r   r   r   r   
initialize   s   
zDigestAuthHandler.initializec                 C   s  d}d}d}| j jdd }|d ur|dd\}}|dks J i }|dD ]"}| d	d\}	}
|
d
 dkrE|
d dkrE|
dd }
|
||	< q'|d |ksRJ |d |ksZJ |d |ksbJ |d | jkskJ |d | j jksuJ ttd| j|| j	f 
 }ttd| j j| j jf 
 }ttd|||f 
 }||d kr| d d S | d d S | d | dd|||f  d S )NtestZasdf1234Authorization    Digest,=r   "realmopaquenoncer   uriz%s:%s:%sz%s:%sresponseokZfaili  zWWW-Authenticatez*Digest realm="%s", nonce="%s", opaque="%s")requestheadersgetsplitstripr   pathr   r   r   	hexdigestmethodwrite
set_statusZ
set_header)r   r'   r(   r)   auth_header	auth_modeparamsZ
param_dictpairkvZh1Zh2digestr   r   r   r/   !   sJ   

zDigestAuthHandler.getN)r   r   r   r   r/   r   r   r   r   r      s    r   c                   @   r	   )CustomReasonHandlerc                 C      |  dd d S )N   Custom reasonr6   r   r   r   r   r/   J      zCustomReasonHandler.getNr   r   r   r/   r   r   r   r   r>   I       r>   c                   @   r	   )CustomFailReasonHandlerc                 C   r?   )Ni  rA   rB   rC   r   r   r   r/   O   rD   zCustomFailReasonHandler.getNrE   r   r   r   r   rG   N   rF   rG   c                       sL   e Zd Z fddZdd Zdd Zdd Zd	d
 Zdd Zdd Z	  Z
S )CurlHTTPClientTestCasec                    s   t    |  | _d S r   )supersetUpcreate_clienthttp_clientrC   	__class__r   r   rJ   U   s   
zCurlHTTPClientTestCase.setUpc                 C   s0   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   r>   rG   rC   r   r   r   get_appY   s   zCurlHTTPClientTestCase.get_appc                 K   s   t ddtddd|S )NTFr   )Zforce_instancer   r   )r   r   )r   kwargsr   r   r   rK   g   s
   
z$CurlHTTPClientTestCase.create_clientc                 C   $   | j ddddd}| |jd d S )NrO   r=   rP   rQ   r8   Zauth_usernameZauth_password   okfetchassertEqualbodyr   r+   r   r   r   test_digest_authl   s   z'CurlHTTPClientTestCase.test_digest_authc                 C   s   |  d}| |jd d S )NrT   rA   )r\   r]   reasonr_   r   r   r   test_custom_reasonr   s   
z)CurlHTTPClientTestCase.test_custom_reasonc                 C   s    |  d}| t|jd d S )NrU   zHTTP 400: Custom reason)r\   r]   strerrorr_   r   r   r   test_fail_custom_reasonv   s   
z.CurlHTTPClientTestCase.test_fail_custom_reasonc                 C   rX   )NrR   r=   rP   rS   rY   rZ   r[   r_   r   r   r   test_digest_auth_non_asciiz   s   z1CurlHTTPClientTestCase.test_digest_auth_non_ascii)r   r   r   rJ   rV   rK   r`   rb   re   rf   __classcell__r   r   rM   r   rH   S   s    rH   )hashlibr   ZunittestZtornado.escaper   Ztornado.testingr   Ztornado.testr   Ztornado.webr   r   ZpycurlImportErrorZtornado.curl_httpclientr   ZskipIfZHTTPClientCommonTestCaser
   r   r>   rG   rH   r   r   r   r   <module>   s(    -