o
    r¨ÊhCd  ã                   @   sü  d dl Z d dlZd dlZd dl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 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 d dlmZ G dd„ dƒZG dd„ deejƒZG dd„ deejƒZG dd„ dejƒZG dd„ dejƒZG dd„ dejƒZG dd„ dejƒZG dd„ dejƒZG dd„ dejƒZG dd „ d ejƒZd!Z G d"d#„ d#ejƒZ!G d$d%„ d%ejƒZ"G d&d'„ d'ejƒZ#G d(d)„ d)ejƒZ$G d*d+„ d+ƒZ%G d,d-„ d-ƒZ&d.d/„ Z'e(d0krüej)d/d1� dS dS )2é    N)Úas_bytes)Ú	as_string)Úsha1)ÚDummySupervisor)ÚPopulatedDummySupervisor)ÚDummyRPCInterfaceFactory)ÚDummyPConfig)ÚDummyOptions)ÚDummyRequest)ÚDummyLogger)ÚNOT_DONE_YETc                   @   ó   e Zd Zdd„ Zdd„ ZdS )ÚHandlerTestsc                 C   ó   |   ¡ |ƒS ©N©Ú_getTargetClass)ÚselfÚsupervisord© r   úL/var/www/html/env/lib/python3.10/site-packages/supervisor/tests/test_http.pyÚ_makeOne   ó   zHandlerTests._makeOnec                 C   s:   G dd„ dƒ}t ƒ }|  |¡}|  | ||jƒ¡d¡ d S )Nc                   @   s   e Zd Zdd„ ZdS )z,HandlerTests.test_match.<locals>.FakeRequestc                 S   ó
   || _ d S r   )Úuri)r   r   r   r   r   Ú__init__   ó   
z5HandlerTests.test_match.<locals>.FakeRequest.__init__N)Ú__name__Ú
__module__Ú__qualname__r   r   r   r   r   ÚFakeRequest   s    r    T)r   r   ÚassertEqualÚmatchÚpath)r   r    Ú
supervisorÚhandlerr   r   r   Ú
test_match   s   
zHandlerTests.test_matchN)r   r   r   r   r&   r   r   r   r   r      ó    r   c                   @   ó,   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	S )
ÚLogtailHandlerTestsc                 C   ó   ddl m} |S )Nr   )Úlogtail_handler)Úsupervisor.httpr+   )r   r+   r   r   r   r   $   ó   z#LogtailHandlerTests._getTargetClassc                 C   sX   t ƒ }t|ddddd�}t|d|ƒ}|  |¡}tdd d d ƒ}| |¡ |  |jd¡ d S )NÚprocess1z/bin/process1é   z/tmp/process1.log)ÚpriorityÚstdout_logfileú/logtail/process1é”  ©r	   r   r   r   r
   Úhandle_requestr!   Ú_error©r   ÚoptionsÚpconfigr   r%   Úrequestr   r   r   Ú'test_handle_request_stdout_logfile_none(   s   
ÿ

z;LogtailHandlerTests.test_handle_request_stdout_logfile_nonec                 C   sT   t ƒ }t|dddƒ}t|d|ƒ}|  |¡}tdd d d ƒ}| |¡ |  |jd¡ d S )NÚfoozit/is/missingú/logtail/foor3   r4   r7   r   r   r   Ú*test_handle_request_stdout_logfile_missing2   s   

z>LogtailHandlerTests.test_handle_request_stdout_logfile_missingc           	   	   C   sú   t  ¡ �o}|j}tƒ }t|dd|d�}t|d|ƒ}|  |¡}tdd d d ƒ}| |¡ |  	|j
d ¡ ddlm} |  	|jd | t |¡tj ¡¡ |  	|jd d¡ |  	|jd	 d
¡ |  	t|jƒd¡ |  	|jd¡ W d   ƒ d S 1 svw   Y  d S )Nr<   )r1   r=   r   ©Ú	http_dateúLast-ModifiedúContent-Typeútext/plain;charset=utf-8zX-Accel-BufferingÚnor/   T)ÚtempfileÚNamedTemporaryFileÚnamer	   r   r   r   r
   r5   r!   r6   Úsupervisor.medusar@   ÚheadersÚbuild_http_dateÚosÚstatÚST_MTIMEÚlenÚ	producersÚ_done)	r   ÚfÚtr8   r9   r   r%   r:   r@   r   r   r   Útest_handle_request;   s$   


ÿ"ñz'LogtailHandlerTests.test_handle_requestN©r   r   r   r   r;   r>   rS   r   r   r   r   r)   #   s
    
	r)   c                   @   r(   )
ÚMainLogTailHandlerTestsc                 C   r*   )Nr   )Úmainlogtail_handler)r,   rV   )r   rV   r   r   r   r   N   r-   z'MainLogTailHandlerTests._getTargetClassc                 C   s:   t ƒ }|  |¡}tdd d d ƒ}| |¡ |  |jd¡ d S )Nú/mainlogtailr3   )r   r   r
   r5   r!   r6   )r   r$   r%   r:   r   r   r   r;   R   s
   

z?MainLogTailHandlerTests.test_handle_request_stdout_logfile_nonec                 C   sB   t ƒ }d|j_tdd d d ƒ}|  |¡}| |¡ |  |jd¡ d S )Nz
/not/thererW   r3   )r   r8   Úlogfiler
   r   r5   r!   r6   )r   r$   r:   r%   r   r   r   r>   Y   s   

zBMainLogTailHandlerTests.test_handle_request_stdout_logfile_missingc              	   C   sÔ   t ƒ }t ¡ �Y}|j}||j_|  |¡}tdd d d ƒ}| |¡ |  	|j
d ¡ ddlm} |  	|jd | t |¡tj ¡¡ |  	|jd d¡ |  	t|jƒd¡ |  	|jd¡ W d   ƒ d S 1 scw   Y  d S )	NrW   r   r?   rA   rB   rC   r/   T)r   rE   rF   rG   r8   rX   r   r
   r5   r!   r6   rH   r@   rI   rJ   rK   rL   rM   rN   rO   rP   )r   r$   rQ   rR   r%   r:   r@   r   r   r   rS   a   s    


ÿ"ôz+MainLogTailHandlerTests.test_handle_requestNrT   r   r   r   r   rU   M   s
    rU   c                   @   ó<   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ Zdd„ ZdS )ÚTailFProducerTestsc                 C   r*   )Nr   )Útail_f_producer)r,   r[   )r   r[   r   r   r   r   s   r-   z"TailFProducerTests._getTargetClassc                 C   s   |   ¡ |||ƒS r   r   )r   r:   ÚfilenameÚheadr   r   r   r   w   ó   zTailFProducerTests._makeOnec                 C   sÂ   t dd d d ƒ}ddlm} t ¡ }| d¡ | ¡  |  ||jd¡}| 	¡ }|  
|d¡ | tdƒ¡ | ¡  | 	¡ }|  
|d¡ | 	¡ }|  
||j¡ | d¡ | ¡  | 	¡ }|  
|d¡ d S )Nr=   r   )ÚhttpóP   aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaéP   sd   wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwz==> File truncated <==
)r
   r$   r_   rE   rF   ÚwriteÚflushr   rG   Úmorer!   r   r   Útruncate)r   r:   r_   rQ   ÚproducerÚresultr   r   r   Útest_handle_morez   s$   

z#TailFProducerTests.test_handle_morec                 C   s‚   t dd d d ƒ}t ¡ �$}| tdƒ¡ | ¡  |  ||jd¡}|j 	¡  | 
¡ }W d   ƒ n1 s2w   Y  |  || 
¡ ¡ d S )Nr=   ÚPaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaara   )r
   rE   rF   rb   r   rc   r   rG   ÚfileÚcloserd   r!   )r   r:   rQ   rf   rg   r   r   r   Útest_handle_more_fd_closedŽ   s   


ûz-TailFProducerTests.test_handle_more_fd_closedc              	   C   s²   t dd d d ƒ}t ¡ }| tdƒ¡ | ¡  |  ||jd¡}| ¡ }|  	|d¡ | 
¡  t|jdƒ}z| tdƒ¡ | 
¡  | ¡ }W t |j¡ nt |j¡ w |  	|d¡ d S )Nr=   ri   ra   r`   ÚwbóP   bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb)r
   rE   rF   rb   r   rc   r   rG   rd   r!   rk   ÚopenrK   Úunlink)r   r:   rQ   rf   rg   Úf2r   r   r   Ú&test_handle_more_follow_file_recreated˜   s   
z9TailFProducerTests.test_handle_more_follow_file_recreatedc              	   C   sü   t dd d d ƒ}tjdd��}|j}| d¡ W d   ƒ n1 s w   Y  z|  ||jd¡}W t |j¡ nt |j¡ w | ¡ }|  	|d¡ t
|dƒ�}| tdƒ¡ W d   ƒ n1 s^w   Y  z| ¡ }|  	|d¡ W t |j¡ d S t |j¡ w )Nr=   F©Údeleter`   ra   rm   rn   )r
   rE   rF   rG   rb   r   rK   rp   rd   r!   ro   r   )r   r:   rQ   r\   rf   rg   r   r   r   Ú!test_handle_more_follow_file_goneª   s"   þÿz4TailFProducerTests.test_handle_more_follow_file_goneN)	r   r   r   r   r   rh   rl   rr   ru   r   r   r   r   rZ   r   s    
rZ   c                   @   sN   e Zd Z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S )ÚDeferringChunkedProducerTestsc                 C   r*   )Nr   )Údeferring_chunked_producer)r,   rw   )r   rw   r   r   r   r   ¾   r-   z-DeferringChunkedProducerTests._getTargetClassNc                 C   ó   |   ¡ ||ƒS r   r   )r   rf   Úfootersr   r   r   r   Â   ó   z&DeferringChunkedProducerTests._makeOnec                 C   ó&   t tƒ}|  |¡}|  | ¡ t¡ d S r   ©ÚDummyProducerr   r   r!   rd   ©r   Úwrappedrf   r   r   r   Útest_more_not_done_yetÅ   ó   
z4DeferringChunkedProducerTests.test_more_not_done_yetc                 C   ó&   t dƒ}|  |¡}|  | ¡ d¡ d S )Nó   hellos
   5
hello
©r}   r   r!   rd   r~   r   r   r   Útest_more_stringÊ   r�   z.DeferringChunkedProducerTests.test_more_stringc                 C   s,   t ƒ }| j|ddgd�}|  | ¡ d¡ d S )Nó   aó   b©ry   ó   0
a
b

r„   r~   r   r   r   Útest_more_nodataÏ   s   z.DeferringChunkedProducerTests.test_more_nodatac                 C   s.   t dƒ}| j|ddgd�}|  | ¡ d¡ d S )Nó    r†   r‡   rˆ   r‰   r„   r~   r   r   r   Útest_more_nodata_footersÔ   s   z6DeferringChunkedProducerTests.test_more_nodata_footersc                 C   r‚   )Nr‹   s   0

r„   r~   r   r   r   Útest_more_nodata_nofootersÙ   r�   z8DeferringChunkedProducerTests.test_more_nodata_nofootersc                 C   s   |   d ¡}|  | ¡ d¡ d S ©Nr‹   ©r   r!   rd   ©r   rf   r   r   r   Útest_more_noproducerÞ   ó   
z2DeferringChunkedProducerTests.test_more_noproducerr   )r   r   r   r   r   r€   r…   rŠ   rŒ   r�   r‘   r   r   r   r   rv   ½   s    
rv   c                   @   ó4   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ ZdS )ÚDeferringCompositeProducerTestsc                 C   r*   )Nr   )Údeferring_composite_producer)r,   r•   )r   r•   r   r   r   r   ã   r-   z/DeferringCompositeProducerTests._getTargetClassc                 C   r   r   r   )r   rO   r   r   r   r   ç   r   z(DeferringCompositeProducerTests._makeOnec                 C   s(   t tƒ}|  |g¡}|  | ¡ t¡ d S r   r|   r~   r   r   r   r€   ê   ó   z6DeferringCompositeProducerTests.test_more_not_done_yetc                 C   sR   t dƒ}t dƒ}|  ||g¡}|  | ¡ d¡ |  | ¡ d¡ |  | ¡ d¡ d S )NÚhelloÚgoodbyer‹   r„   )r   Úwrapped1Úwrapped2rf   r   r   r   r…   ï   s   z0DeferringCompositeProducerTests.test_more_stringc                 C   s&   t ƒ }|  |g¡}|  | ¡ d¡ d S rŽ   r„   r~   r   r   r   rŠ   ÷   s   z0DeferringCompositeProducerTests.test_more_nodataN©r   r   r   r   r   r€   r…   rŠ   r   r   r   r   r”   â   s    r”   c                   @   s6   e Zd Zdd„ Zddd„Zdd„ Zdd	„ Zd
d„ ZdS )ÚDeferringGlobbingProducerTestsc                 C   r*   )Nr   )Údeferring_globbing_producer)r,   r�   )r   r�   r   r   r   r   ý   r-   z.DeferringGlobbingProducerTests._getTargetClassé   c                 C   rx   r   r   )r   rf   Úbuffer_sizer   r   r   r     rz   z'DeferringGlobbingProducerTests._makeOnec                 C   r{   r   r|   r~   r   r   r   r€     r�   z5DeferringGlobbingProducerTests.test_more_not_done_yetc                 C   sX   t dddƒ}| j|dd�}|  | ¡ d¡ t dddƒ}| j|dd�}|  | ¡ d¡ d S )	Nr—   ÚthereÚguyr/   )rŸ   rƒ   é2   s   hellothereguyr„   r~   r   r   r   r…   	  s   z/DeferringGlobbingProducerTests.test_more_stringc                 C   s$   t ƒ }|  |¡}|  | ¡ d¡ d S rŽ   r„   r~   r   r   r   rŠ     s   
z/DeferringGlobbingProducerTests.test_more_nodataN)rž   r›   r   r   r   r   rœ   ü   s    
	rœ   c                   @   rY   )ÚDeferringHookedProducerTestsc                 C   r*   )Nr   )Údeferring_hooked_producer)r,   r¤   )r   r¤   r   r   r   r     r-   z,DeferringHookedProducerTests._getTargetClassc                 C   rx   r   r   )r   rf   Úfunctionr   r   r   r     rz   z%DeferringHookedProducerTests._makeOnec                 C   s(   t tƒ}|  |d ¡}|  | ¡ t¡ d S r   r|   r~   r   r   r   r€     r–   z3DeferringHookedProducerTests.test_more_not_done_yetc                    sZ   t dƒ}g ‰ ‡ fdd„}|  ||¡}|  | ¡ d¡ |  ˆ g ¡ | ¡  |  ˆ dg¡ d S )Nr—   c                    ó   ˆ   | ¡ d S r   ©Úappend©Úbytes©ÚLr   r   Úcallback'  rz   z?DeferringHookedProducerTests.test_more_string.<locals>.callbacké   r„   ©r   r   r­   rf   r   r«   r   r…   $  s   z-DeferringHookedProducerTests.test_more_stringc                    sD   t ƒ }g ‰ ‡ fdd„}|  ||¡}|  | ¡ d¡ |  ˆ dg¡ d S )Nc                    r¦   r   r§   r©   r«   r   r   r­   2  rz   z?DeferringHookedProducerTests.test_more_nodata.<locals>.callbackr‹   r   r„   r¯   r   r«   r   rŠ   /  s   z-DeferringHookedProducerTests.test_more_nodatac                 C   s    |   d d ¡}|  | ¡ d¡ d S rŽ   r�   r�   r   r   r   r‘   8  s   z1DeferringHookedProducerTests.test_more_noproducerN)	r   r   r   r   r   r€   r…   rŠ   r‘   r   r   r   r   r£     s    	r£   c                   @   sz   e Zd Z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S ) ÚDeferringHttpRequestTestsc                 C   r*   )Nr   )Údeferring_http_request)r,   r±   )r   r±   r   r   r   r   =  r-   z)DeferringHttpRequestTests._getTargetClassNúGET / HTTP/1.0ÚGETú/ú1.0r   c                 C   s   |   ¡ ||||||ƒS r   r   )r   ÚchannelÚreqÚcommandr   ÚversionÚheaderr   r   r   r   A  s   	ÿz"DeferringHttpRequestTests._makeOnec                 C   s   G dd„ dƒ}|ƒ S )Nc                   @   s    e Zd ZdZdd„ Zdd„ ZdS )z7DeferringHttpRequestTests._makeChannel.<locals>.ChannelFc                 S   ó
   d| _ d S ©NT)Úclosed©r   r   r   r   Úclose_when_doneQ  r   zGDeferringHttpRequestTests._makeChannel.<locals>.Channel.close_when_donec                 S   r   r   )rf   r�   r   r   r   Úpush_with_producerS  r   zJDeferringHttpRequestTests._makeChannel.<locals>.Channel.push_with_producerN)r   r   r   r½   r¿   rÀ   r   r   r   r   ÚChannelO  s    rÁ   r   )r   rÁ   r   r   r   Ú_makeChannelN  s   z&DeferringHttpRequestTests._makeChannelc                 C   s.   |   ¡ }| j|dd�}| ¡  |  |j¡ d S )Nrµ   ©r¶   r¹   ©rÂ   r   ÚdoneÚ
assertTruer½   ©r   r¶   Úinstr   r   r   Útest_done_http_10_nokeepaliveW  s   z7DeferringHttpRequestTests.test_done_http_10_nokeepalivec                 C   ó2   |   ¡ }| j|ddgd�}| ¡  |  |j¡ d S )Nrµ   úConnection: Keep-Alive©r¶   r¹   rº   rÄ   rÇ   r   r   r   Ú-test_done_http_10_keepalive_no_content_length]  s   ýzGDeferringHttpRequestTests.test_done_http_10_keepalive_no_content_lengthc                 C   sL   |   ¡ }| j|ddgd�}d|jd< | ¡  |  |d d¡ |  |j¡ d S )Nrµ   rË   rÌ   r/   zContent-LengthÚ
Connectionz
Keep-Alive)rÂ   r   Úreply_headersrÅ   r!   ÚassertFalser½   rÇ   r   r   r   Ú.test_done_http_10_keepalive_and_content_lengthh  s   ý
zHDeferringHttpRequestTests.test_done_http_10_keepalive_and_content_lengthc                 C   rÊ   )Nú1.1zConnection: closerÌ   rÄ   rÇ   r   r   r   Ú"test_done_http_11_connection_closet  s   ýz<DeferringHttpRequestTests.test_done_http_11_connection_closec                 C   ó8   |   ¡ }| j|dd�}d|jd< | ¡  |  |j¡ d S )NrÒ   rÃ   Ú
notchunkedúTransfer-Encoding)rÂ   r   rÏ   rÅ   rÆ   r½   rÇ   r   r   r   Ú+test_done_http_11_unknown_transfer_encoding~  ó   þ
zEDeferringHttpRequestTests.test_done_http_11_unknown_transfer_encodingc                 C   rÔ   )NrÒ   rÃ   ÚchunkedrÖ   )rÂ   r   rÏ   rÅ   rÐ   r½   rÇ   r   r   r   Ú+test_done_http_11_chunked_transfer_encodingˆ  rØ   zEDeferringHttpRequestTests.test_done_http_11_chunked_transfer_encodingc                 C   sB   |   ¡ }| j|dd�}d|_| ¡  |  d|v ¡ |  |j¡ d S )NrÒ   rÃ   TrÖ   )rÂ   r   Úuse_chunkedrÅ   rÆ   rÐ   r½   rÇ   r   r   r   Útest_done_http_11_use_chunked’  s   þz7DeferringHttpRequestTests.test_done_http_11_use_chunkedc                 C   s4   |   ¡ }| j|dd�}d|_| ¡  |  |j¡ d S )NrÒ   rÃ   F)rÂ   r   rÛ   rÅ   rÆ   r½   rÇ   r   r   r   Ú>test_done_http_11_wo_content_length_no_te_no_use_chunked_close�  s   þzXDeferringHttpRequestTests.test_done_http_11_wo_content_length_no_te_no_use_chunked_closec                 C   s.   |   ¡ }| j|d d�}| ¡  |  |j¡ d S )NrÃ   rÄ   rÇ   r   r   r   Útest_done_http_09§  s   þz+DeferringHttpRequestTests.test_done_http_09)Nr²   r³   r´   rµ   r   )r   r   r   r   r   rÂ   rÉ   rÍ   rÑ   rÓ   r×   rÚ   rÜ   rÝ   rÞ   r   r   r   r   r°   <  s&    
ù	



r°   c                   @   sD   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S )ÚDeferringHttpChannelTestsc                 C   r*   )Nr   )Údeferring_http_channel)r,   rà   )r   rà   r   r   r   r   ±  r-   z)DeferringHttpChannelTests._getTargetClassc                 C   s   |   ¡ d d d d�S )N)ÚserverÚconnÚaddrr   r¾   r   r   r   r   µ  s
   ýz"DeferringHttpChannelTests._makeOnec                 C   s(   |   ¡ }|  |jd¡ |  |jd¡ d S )Nr   )r   r!   ÚdelayÚlast_writable_check)r   r¶   r   r   r   Ú0test_defaults_delay_and_last_writable_check_time¼  s   zJDeferringHttpChannelTests.test_defaults_delay_and_last_writable_check_timec                 C   s@   |   ¡ }d|_t|_td }|  |j|d�¡ |  |jt¡ d S )Né   r/   ©Únow©r   rä   Ú_NOWrå   rÐ   Úwritabler!   ©r   r¶   Úlaterr   r   r   Ú5test_writable_with_delay_is_False_if_elapsed_lt_delayÁ  ó   zODeferringHttpChannelTests.test_writable_with_delay_is_False_if_elapsed_lt_delayc                 C   sB   |   ¡ }d|_t|_t|j }|  |j|d�¡ |  |jt¡ d S )Nrç   rè   rê   rí   r   r   r   Ú5test_writable_with_delay_is_False_if_elapsed_eq_delayÉ  s   
zODeferringHttpChannelTests.test_writable_with_delay_is_False_if_elapsed_eq_delayc                 C   sF   |   ¡ }d|_t|_t|j d }|  |j|d�¡ |  |j|¡ d S )Nrç   gš™™™™™¹?rè   ©r   rä   rë   rå   rÆ   rì   r!   rí   r   r   r   Ú4test_writable_with_delay_is_True_if_elapsed_gt_delayÑ  s   zNDeferringHttpChannelTests.test_writable_with_delay_is_True_if_elapsed_gt_delayc                 C   s@   |   ¡ }d|_t|_td }|  |j|d�¡ |  |j|¡ d S )Nrç   i  rè   rò   rí   r   r   r   Ú>test_writable_with_delay_is_True_if_system_time_goes_backwardsÙ  rð   zXDeferringHttpChannelTests.test_writable_with_delay_is_True_if_system_time_goes_backwardsN)
r   r   r   r   r   ræ   rï   rñ   ró   rô   r   r   r   r   rß   °  s    rß   if»ŸWc                   @   sL   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S )Ú"EncryptedDictionaryAuthorizedTestsc                 C   r*   )Nr   ©Úencrypted_dictionary_authorizer)r,   r÷   )r   r÷   r   r   r   r   ä  r-   z2EncryptedDictionaryAuthorizedTests._getTargetClassc                 C   r   r   r   )r   Údictr   r   r   r   è  r   z+EncryptedDictionaryAuthorizedTests._makeOnec                 C   s   |   i ¡}|  | d¡¡ d S )N©r<   Úbar©r   rÐ   Ú	authorize©r   Ú
authorizerr   r   r   Útest_authorize_baduserë  r’   z9EncryptedDictionaryAuthorizedTests.test_authorize_baduserc                 C   ó"   |   ddi¡}|  | d¡¡ d S )Nr<   Úpasswordrù   rû   rý   r   r   r   Ú#test_authorize_gooduser_badpasswordï  ó   zFEncryptedDictionaryAuthorizedTests.test_authorize_gooduser_badpasswordc                 C   r   )Nr<   r  ©r<   r  ©r   rÆ   rü   rý   r   r   r   Ú$test_authorize_gooduser_goodpasswordó  r  zGEncryptedDictionaryAuthorizedTests.test_authorize_gooduser_goodpasswordc                 C   r   )Nr<   ú	pass:word)r<   r  r  rý   r   r   r   Ú/test_authorize_gooduser_goodpassword_with_colon÷  r  zREncryptedDictionaryAuthorizedTests.test_authorize_gooduser_goodpassword_with_colonc                 C   ó6   dt tdƒƒ ¡  }|  d|i¡}|  | d¡¡ d S )Nú{SHA}r  r<   rù   )r   r   Ú	hexdigestr   rÐ   rü   ©r   r  rþ   r   r   r   Ú'test_authorize_gooduser_badpassword_shaû  ó   zJEncryptedDictionaryAuthorizedTests.test_authorize_gooduser_badpassword_shac                 C   r	  )Nr
  r  r<   r  )r   r   r  r   rÆ   rü   r  r   r   r   Ú(test_authorize_gooduser_goodpassword_sha   r  zKEncryptedDictionaryAuthorizedTests.test_authorize_gooduser_goodpassword_shaN)r   r   r   r   r   rÿ   r  r  r  r  r  r   r   r   r   rõ   ã  s    rõ   c                   @   rY   )ÚSupervisorAuthHandlerTestsc                 C   r*   )Nr   ©Úsupervisor_auth_handler)r,   r  )r   r  r   r   r   r     r-   z*SupervisorAuthHandlerTests._getTargetClassc                 C   rx   r   r   )r   rø   r%   r   r   r   r   
  rz   z#SupervisorAuthHandlerTests._makeOnec                 C   s0   |   ddid ¡}ddlm} |  |jj|¡ d S )NÚar/   r   rö   )r   r,   r÷   r!   rþ   Ú	__class__)r   r%   r÷   r   r   r   Ú	test_ctor  s
   
ÿz$SupervisorAuthHandlerTests.test_ctorc                 C   ó\   t dd d d ƒ}t tdƒ¡}dt|ƒ g|_tƒ }|  ddi|¡}| |¡ |  	|j
¡ d S )Nr2   zuser:passwordúAuthorization: Basic %sÚuserr  ©r
   Úbase64Ú	b64encoder   r   rº   ÚDummyHandlerr   r5   rÆ   Úhandled_request©r   r:   Úencodedr%   Úauth_handlerr   r   r   Ú/test_handle_request_authorizes_good_credentials  ó   
zJSupervisorAuthHandlerTests.test_handle_request_authorizes_good_credentialsc                 C   r  )Nr2   zuser:pass:wordr  r  r  r  r  r   r   r   Ú7test_handle_request_authorizes_good_password_with_colon  s   
zRSupervisorAuthHandlerTests.test_handle_request_authorizes_good_password_with_colonc                 C   r  )Nr2   zwrong:wrongr  r  r  )r
   r  r  r   r   rº   r  r   r5   rÐ   r  r  r   r   r   Ú6test_handle_request_does_not_authorize_bad_credentials&  r"  zQSupervisorAuthHandlerTests.test_handle_request_does_not_authorize_bad_credentialsN)	r   r   r   r   r   r  r!  r#  r$  r   r   r   r   r    s    	
r  c                   @   r“   )ÚLogWrapperTestsc                 C   r*   )Nr   )Ú
LogWrapper)r,   r&  )r   r&  r   r   r   r   0  r-   zLogWrapperTests._getTargetClassc                 C   r   r   r   )r   Úloggerr   r   r   r   4  r   zLogWrapperTests._makeOnec                 C   sD   t ƒ }|  |¡}| d¡ |j}|  t|ƒd¡ |  |d d¡ d S )Nzfoo
r/   r   r<   )r   r   ÚlogÚdatar!   rN   )r   r'  Úlog_wrapperÚlogdatar   r   r   Ú'test_strips_trailing_newlines_from_msgs7  s   

z7LogWrapperTests.test_strips_trailing_newlines_from_msgsc                 C   óJ   t ƒ }|  |¡}g }|j|_| d¡ |  t|ƒd¡ |  |d d¡ d S )NzServer Errorr/   r   )r   r   r¨   Úerrorr(  r!   rN   )r   r'  r*  Úerrorsr   r   r   Ú(test_logs_msgs_with_error_at_error_level?  ó   

z8LogWrapperTests.test_logs_msgs_with_error_at_error_levelc                 C   r-  )NzGET /r/   r   )r   r   r¨   Útracer(  r!   rN   )r   r'  r*  Útracesr   r   r   Ú'test_logs_other_messages_at_trace_levelH  r1  z7LogWrapperTests.test_logs_other_messages_at_trace_levelN)r   r   r   r   r   r,  r0  r4  r   r   r   r   r%  /  s    	r%  c                   @   r(   )
ÚTopLevelFunctionTestsc           
      C   sš   t ƒ }||_dti fg|_tƒ }ddlm} |||ƒ}z&|D ]\}}| ¡  | d¡}|d ur4t	 
|¡ qW ddlm}	 |	 ¡  |S ddlm}	 |	 ¡  w )NÚdummyr   )Úmake_http_serversrj   )Ú
socket_map)r	   Úserver_configsr   Úrpcinterface_factoriesr   r,   r7  rk   ÚgetrK   rp   Úsupervisor.medusa.asyncore_25r8  Úclear)
r   Úsconfigsr8   r   r7  ÚserversÚconfigÚsÚ
socketfiler8  r   r   r   Ú_make_http_serversR  s&   


€üþ
z(TopLevelFunctionTests._make_http_serversc              
   C   sh   dddd d ddœ}z|   |g¡ |  d¡ W d S  ty3 } z|  |jd d¡ W Y d }~d S d }~ww )	Niç  Ú	localhostéGE  Úinet_http_server©ÚfamilyÚhostÚportÚusernamer  Úsectionznothing raisedr   z Cannot determine socket type 999)rC  ÚfailÚ
ValueErrorr!   Úargs)r   r@  Úexcr   r   r   Ú(test_make_http_servers_socket_type_errord  s   þ €ÿz>TopLevelFunctionTests.test_make_http_servers_socket_type_errorc           
      C   s  t jdd��}|j}W d   ƒ n1 sw   Y  |  tj |¡¡ tjddd d ddœ}tj	|ddd d d	d
œ}|  
||g¡}|  t|ƒd¡ |d }|  |d |¡ |d }g d¢}|  dd„ |jD ƒ|¡ |d }	|  |	d |¡ |	d }|  dd„ |jD ƒ|¡ d S )NTrs   rD  rE  rF  rG  éÀ  ©éÿÿÿÿrT  Úunix_http_server©rH  rj   ÚchmodÚchownrK  r  rL  rç   r   r/   )zSupervisor XML-RPC HandlerzLogtail HTTP Request Handlerz!Main Logtail HTTP Request Handlerz&Supervisor Web UI HTTP Request HandlerzDefault HTTP Request Handlerc                 S   ó   g | ]}|j ‘qS r   ©ÚIDENT©Ú.0Úxr   r   r   Ú
<listcomp>…  ó    zGTopLevelFunctionTests.test_make_http_servers_noauth.<locals>.<listcomp>c                 S   rY  r   rZ  r\  r   r   r   r_  Š  r`  )rE   rF   rG   rÐ   rK   r#   ÚexistsÚsocketÚAF_INETÚAF_UNIXrC  r!   rN   Úhandlers)
r   rQ   rB  ÚinetÚunixr?  Úinetdatará   ÚidentsÚunixdatar   r   r   Útest_make_http_servers_noauthn  s,   ÿÿþz3TopLevelFunctionTests.test_make_http_servers_noauthc           
      C   sÈ   t jdd��}|j}W d   ƒ n1 sw   Y  |  tj |¡¡ tjddddddœ}tj	|d	d
ddddœ}|  
||g¡}|  t|ƒd¡ ddlm} |D ]\}}|jD ]}	|  t|	|ƒ|	¡ qUqNd S )NTrs   rD  iHE  rK  r  rF  rG  rR  rS  rU  rV  rç   r   r  )rE   rF   rG   rÐ   rK   r#   ra  rb  rc  rd  rC  r!   rN   r,   r  re  rÆ   Ú
isinstance)
r   rQ   rB  rf  rg  r?  r  r@  rá   r%   r   r   r   Útest_make_http_servers_withauthŒ  s,   ÿþþ
ÿÿÿz5TopLevelFunctionTests.test_make_http_servers_withauthN)r   r   r   rC  rQ  rk  rm  r   r   r   r   r5  Q  s
    
r5  c                   @   r   )r  c                 C   r»   )NF©r  r¾   r   r   r   r      r   zDummyHandler.__init__c                 C   r»   r¼   rn  )r   r:   r   r   r   r5   £  r   zDummyHandler.handle_requestN)r   r   r   r   r5   r   r   r   r   r  Ÿ  r'   r  c                   @   r   )r}   c                 G   s   t |ƒ| _d S r   )Úlistr)  )r   r)  r   r   r   r   §  rz   zDummyProducer.__init__c                 C   s   | j r	| j  d¡S dS )Nr   r‹   )r)  Úpopr¾   r   r   r   rd   ª  s   zDummyProducer.moreN)r   r   r   r   rd   r   r   r   r   r}   ¦  r'   r}   c                   C   s   t  tjt ¡S r   )ÚunittestÚfindTestCasesÚsysÚmodulesr   r   r   r   r   Ú
test_suite°  r^   ru  Ú__main__)ÚdefaultTest)*r  rK   rL   rs  rb  rE   rq  Úsupervisor.compatr   r   r   Úsupervisor.tests.baser   r   r   r   r	   r
   r   r,   r   r   ÚTestCaser)   rU   rZ   rv   r”   rœ   r£   r°   rß   rë   rõ   r  r%  r5  r  r}   ru  r   Úmainr   r   r   r   Ú<module>   sN    *%K%%t1"*"N
ÿ