o
    Ͱic                     @   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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S ).    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   N/home/ubuntu/.local/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_missing1   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   M   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;   Q   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>   X   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   `   s    


"z+MainLogTailHandlerTests.test_handle_requestNrT   r   r   r   r   rU   L   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   r   r-   z"TailFProducerTests._getTargetClassc                 C   s   |   |||S r   r   )r   r:   filenameheadr   r   r   r   v   s   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   )httpP   aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaP   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_morey   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=   Paaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaar`   )r
   rE   rF   ra   r   rb   r   rG   filecloserc   r!   )r   r:   rQ   re   rf   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=   rh   r`   r_   wbP   bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb)r
   rE   rF   ra   r   rb   r   rG   rc   r!   rj   openrK   unlink)r   r:   rQ   re   rf   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_   r`   rl   rm   )r
   rE   rF   rG   ra   r   rK   ro   rc   r!   rn   r   )r   r:   rQ   r\   re   rf   r   r   r   !test_handle_more_follow_file_gone   s"   z4TailFProducerTests.test_handle_more_follow_file_goneN)	r   r   r   r   r   rg   rk   rq   rt   r   r   r   r   rZ   q   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,   rv   )r   rv   r   r   r   r      r-   z-DeferringChunkedProducerTests._getTargetClassNc                 C      |   ||S r   r   )r   re   footersr   r   r   r         z&DeferringChunkedProducerTests._makeOnec                 C   &   t t}| |}| | t d S r   DummyProducerr   r   r!   rc   r   wrappedre   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!   rc   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rx      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!   rc   r   re   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   ru      s    
ru   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wrapped2re   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   rw   r   r   )r   re   buffer_sizer   r   r   r      ry   z'DeferringGlobbingProducerTests._makeOnec                 C   rz   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   rw   r   r   )r   re   functionr   r   r   r     ry   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&  ry   z?DeferringHookedProducerTests.test_more_string.<locals>.callback   r   r   r~   r   re   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   1  ry   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   7  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   @  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_doneP  r   zGDeferringHttpRequestTests._makeChannel.<locals>.Channel.close_when_donec                 S   r   r   )re   r   r   r   r   push_with_producerR  r   zJDeferringHttpRequestTests._makeChannel.<locals>.Channel.push_with_producerN)r   r   r   r   r   r   r   r   r   r   ChannelN  s    r   r   )r   r   r   r   r   _makeChannelM  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_nokeepaliveV  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_lengthg  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_closes  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   ifWc                   @   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   rw   r   r   )r   r   r%   r   r   r   r   	  ry   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   /  r-   zLogWrapperTests._getTargetClassc                 C   r   r   r   )r   loggerr   r   r   r   3  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_msgs6  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_levelG  r0  z7LogWrapperTests.test_logs_other_messages_at_trace_levelN)r   r   r   r   r   r+  r/  r3  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_serversri   )
socket_map)r	   server_configsr   rpcinterface_factoriesr   r,   r6  rj   getrK   ro   supervisor.medusa.asyncore_25r7  clear)
r   sconfigsr8   r   r6  serversconfigs
socketfiler7  r   r   r   _make_http_serversQ  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  	localhostGE  inet_http_serverfamilyhostportusernamer   sectionznothing raisedr   z Cannot determine socket type 999)rB  fail
ValueErrorr!   args)r   r?  excr   r   r   (test_make_http_servers_socket_type_errorc  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 )NTrr   rC  rD  rE  rF    rS  unix_http_serverrG  ri   chmodchownrJ  r   rK  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   rX  r   rY  r[  r   r   r   r^    r_  )rE   rF   rG   r   rK   r#   existssocketAF_INETAF_UNIXrB  r!   rN   handlers)
r   rQ   rA  inetunixr>  inetdatar   identsunixdatar   r   r   test_make_http_servers_noauthm  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 )NTrr   rC  iHE  rJ  r   rE  rF  rQ  rR  rT  rU  r   r   r  )rE   rF   rG   r   rK   r#   r`  ra  rb  rc  rB  r!   rN   r,   r  rd  r   
isinstance)
r   rQ   rA  re  rf  r>  r  r?  r   r%   r   r   r   test_make_http_servers_withauth  s,   
z5TopLevelFunctionTests.test_make_http_servers_withauthN)r   r   r   rB  rP  rj  rl  r   r   r   r   r4  P  s
    
r4  c                   @   r   )r  c                 C   r   )NFr  r   r   r   r   r     r   zDummyHandler.__init__c                 C   r   r   rm  )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     ry   zDummyProducer.__init__c                 C   s   | j r	| j dS dS )Nr   r   )r(  popr   r   r   r   rc     s   zDummyProducer.moreN)r   r   r   r   rc   r   r   r   r   r|     r'   r|   )&r  rK   rL   ra  rE   unittestsupervisor.compatr   r   r   supervisor.tests.baser   r   r   r   r	   r
   r   r,   r   r   TestCaser)   rU   rZ   ru   r   r   r   r   r   r   r   r  r$  r4  r  r|   r   r   r   r   <module>   sD    *%K%%t1"*"N