
    CcCd                     ^   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      Z G d deej,                        Z G d deej,                        Z G d dej,                        Z G d dej,                        Z G d dej,                        Z G d dej,                        Z G d dej,                        Z G d dej,                        Z G d d ej,                        Zd!Z  G d" d#ej,                        Z! G d$ d%ej,                        Z" G d& d'ej,                        Z# G d( d)ej,                        Z$ G d* d+      Z% G d, d-      Z&d. Z'e(d/k(  r ejR                  d01       yy)2    N)as_bytes)	as_string)sha1)DummySupervisor)PopulatedDummySupervisor)DummyRPCInterfaceFactory)DummyPConfig)DummyOptions)DummyRequest)DummyLogger)NOT_DONE_YETc                       e Zd Zd Zd Zy)HandlerTestsc                 .     | j                         |      S N_getTargetClass)selfsupervisords     </usr/lib/python3/dist-packages/supervisor/tests/test_http.py_makeOnezHandlerTests._makeOne   s    %t##%k22    c                      G d d      }t               }| j                  |      }| j                  |j                   ||j                              d       y )Nc                       e Zd Zd Zy),HandlerTests.test_match.<locals>.FakeRequestc                     || _         y r   )uri)r   r   s     r   __init__z5HandlerTests.test_match.<locals>.FakeRequest.__init__   s	    r   N)__name__
__module____qualname__r    r   r   FakeRequestr      s    r   r#   T)r   r   assertEqualmatchpath)r   r#   
supervisorhandlers       r   
test_matchzHandlerTests.test_match   sF    	 	 %&
--
+{7<<'@A4Hr   N)r   r    r!   r   r)   r"   r   r   r   r      s    3Ir   r   c                   $    e Zd Zd Zd Zd Zd Zy)LogtailHandlerTestsc                     ddl m} |S )Nr   )logtail_handler)supervisor.httpr-   )r   r-   s     r   r   z#LogtailHandlerTests._getTargetClass$       3r   c                     t               }t        |dddd      }t        |d|      }| j                  |      }t	        dd d d       }|j                  |       | j                  |j                  d       y )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(   requests         r   'test_handle_request_stdout_logfile_nonez;LogtailHandlerTests.test_handle_request_stdout_logfile_none(   sn    .w
Oa.AC.w
GL--,2D$Ew'-r   c                     t               }t        |ddd      }t        |d|      }| j                  |      }t	        dd d d       }|j                  |       | j                  |j                  d       y )Nfoozit/is/missing/logtail/foor6   r7   r:   s         r   *test_handle_request_stdout_logfile_missingz>LogtailHandlerTests.test_handle_request_stdout_logfile_missing2   sg    .wuoF.wwG--,~tT4@w'-r   c           	          t        j                         5 }|j                  }t               }t	        |dd|      }t        |d|      }| j                  |      }t        dd d d       }|j                  |       | j                  |j                  d        ddlm} | j                  |j                  d   |j                  t        j                   |      t         j"                                  | j                  |j                  d   d       | j                  |j                  d	   d
       | j                  t%        |j&                        d       | j                  |j(                  d       d d d        y # 1 sw Y   y xY w)Nr@   )r4   rA   r   	http_dateLast-ModifiedContent-Typetext/plain;charset=utf-8zX-Accel-Bufferingnor2   T)tempfileNamedTemporaryFilenamer
   r	   r   r   r   r8   r$   r9   supervisor.medusarE   headersbuild_http_dateosstatST_MTIMElen	producers_done)	r   ftr;   r<   r   r(   r=   rE   s	            r   test_handle_requestz'LogtailHandlerTests.test_handle_request;   s2   ((* 	2aA"nG"7E5KG27E7KKmmK0G">4tDG""7+W^^T23W___=))"''!*T]]*CDFW__^<>XYW__-@A4HS!2!23Q7W]]D1	2 	2 	2s   EE44E=Nr   r    r!   r   r>   rB   rX   r"   r   r   r+   r+   #   s    ..2r   r+   c                   $    e Zd Zd Zd Zd Zd Zy)MainLogTailHandlerTestsc                     ddl m} |S )Nr   )mainlogtail_handler)r.   r]   )r   r]   s     r   r   z'MainLogTailHandlerTests._getTargetClassN   s    7""r   c                     t               }| j                  |      }t        dd d d       }|j                  |       | j	                  |j
                  d       y )N/mainlogtailr6   )r   r   r   r8   r$   r9   )r   r'   r(   r=   s       r   r>   z?MainLogTailHandlerTests.test_handle_request_stdout_logfile_noneR   sJ    $&
--
+~tT4@w'-r   c                     t               }d|j                  _        t        dd d d       }| j	                  |      }|j                  |       | j                  |j                  d       y )Nz
/not/therer_   r6   )r   r;   logfiler   r   r8   r$   r9   )r   r'   r=   r(   s       r   rB   zBMainLogTailHandlerTests.test_handle_request_stdout_logfile_missingY   sX    $&
%1
"~tT4@--
+w'-r   c           	         t               }t        j                         5 }|j                  }||j                  _        | j                  |      }t        dd d d       }|j                  |       | j                  |j                  d        ddlm} | j                  |j                  d   |j                  t        j                   |      t         j"                                  | j                  |j                  d   d       | j                  t%        |j&                        d       | j                  |j(                  d       d d d        y # 1 sw Y   y xY w)	Nr_   r   rD   rF   rG   rH   r2   T)r   rJ   rK   rL   r;   ra   r   r   r8   r$   r9   rM   rE   rN   rO   rP   rQ   rR   rS   rT   rU   )r   r'   rV   rW   r(   r=   rE   s          r   rX   z+MainLogTailHandlerTests.test_handle_requesta   s	   $&
((* 	2aA)*J&mmJ/G">4tDG""7+W^^T23W___=))"''!*T]]*CDFW__^<>XYS!2!23Q7W]]D1	2 	2 	2s   D"E

ENrY   r"   r   r   r[   r[   M   s    #..2r   r[   c                   0    e Zd Zd Zd Zd Zd Zd Zd Zy)TailFProducerTestsc                     ddl m} |S )Nr   )tail_f_producer)r.   rf   )r   rf   s     r   r   z"TailFProducerTests._getTargetClasss   r/   r   c                 2     | j                         |||      S r   r   )r   r=   filenameheads       r   r   zTailFProducerTests._makeOnew   s    %t##%gx>>r   c                    t        dd d d       }ddlm} t        j                         }|j                  d       |j                          | j                  ||j                  d      }|j                         }| j                  |d       |j                  t        d             |j                          |j                         }| j                  |d       |j                         }| j                  ||j                         |j                  d       |j                          |j                         }| j                  |d       y )NrA   r   )httpP   aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaP   sd   wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwz==> File truncated <==
)r   r'   rk   rJ   rK   writeflushr   rL   morer$   r   r   truncate)r   r=   rk   rV   producerresults         r   test_handle_morez#TailFProducerTests.test_handle_morez   s    ~tT4@#'')				==!&&"5+	$%		,!2!23	

1		!;<r   c                    t        dd d d       }t        j                         5 }|j                  t	        d             |j                          | j                  ||j                  d      }|j                  j                          |j                         }d d d        | j                  j                                y # 1 sw Y   *xY w)NrA   Paaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaarm   )r   rJ   rK   rn   r   ro   r   rL   filecloserp   r$   )r   r=   rV   rr   rs   s        r   test_handle_more_fd_closedz-TailFProducerTests.test_handle_more_fd_closed   s    ~tT4@((* 	%aGGHX&'GGI}}Waffb9HMM!]]_F	% 	1	% 	%s   A2B>>Cc                    t        dd d d       }t        j                         }|j                  t	        d             |j                          | j                  ||j                  d      }|j                         }| j                  |d       |j                          t        |j                  d      }	 |j                  t	        d             |j                          |j                         }t        j                  |j                         | j                  |d       y # t        j                  |j                         w xY w)NrA   rv   rm   rl   wbP   bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb)r   rJ   rK   rn   r   ro   r   rL   rp   r$   rx   openrP   unlink)r   r=   rV   rr   rs   f2s         r   &test_handle_more_follow_file_recreatedz9TailFProducerTests.test_handle_more_follow_file_recreated   s    ~tT4@'')	"#		==!&&"5+		!&&$	HHXi()HHJ]]_FIIbgg+ IIbggs   3:D !E c                    t        dd d d       }t        j                  d      5 }|j                  }|j	                  d       d d d        	 | j                  |j                  d      }t        j                  |j                         |j                         }| j                  |d       t        d      5 }|j	                  t        d             d d d        	 |j                         }| j                  |d       t        j                  |j                         y # 1 sw Y   xY w# t        j                  j                         w xY w# 1 sw Y   |xY w# t        j                  |j                         w xY w)NrA   Fdeleterl   rm   r{   r|   )r   rJ   rK   rL   rn   r   rP   r~   rp   r$   r}   r   )r   r=   rV   rh   rr   rs   s         r   !test_handle_more_follow_file_gonez4TailFProducerTests.test_handle_more_follow_file_gone   s   ~tT4@((6 	!vvHGGI		}}Waffb9HIIaff+(D! 	)QGGHY'(	)	]]_FVY/YYqvv	 	 IIaff	) 	) YYqvvs/   DD( 6E"E D%(!E	E!E9N)	r   r    r!   r   r   rt   ry   r   r   r"   r   r   rd   rd   r   s     ?=(2,$r   rd   c                   >    e Zd Zd Zd
dZd Zd Zd Zd Zd Z	d	 Z
y)DeferringChunkedProducerTestsc                     ddl m} |S )Nr   )deferring_chunked_producer)r.   r   )r   r   s     r   r   z-DeferringChunkedProducerTests._getTargetClass   s    >))r   Nc                 0     | j                         ||      S r   r   )r   rr   footerss      r   r   z&DeferringChunkedProducerTests._makeOne   s    %t##%h88r   c                     t        t              }| j                  |      }| j                  |j	                         t               y r   DummyProducerr   r   r$   rp   r   wrappedrr   s      r   test_more_not_done_yetz4DeferringChunkedProducerTests.test_more_not_done_yet   0    -==),7r   c                 |    t        d      }| j                  |      }| j                  |j                         d       y )N   hellos
   5
hello
r   r   r$   rp   r   s      r   test_more_stringz.DeferringChunkedProducerTests.test_more_string   s1    )==)*;<r   c                     t               }| j                  |ddg      }| j                  |j                         d       y )N   a   br      0
a
b

r   r   s      r   test_more_nodataz.DeferringChunkedProducerTests.test_more_nodata   s6    /==4,=?*@Ar   c                     t        d      }| j                  |ddg      }| j                  |j                         d       y )Nr   r   r   r   r   r   r   s      r   test_more_nodata_footersz6DeferringChunkedProducerTests.test_more_nodata_footers   s9    $==4,=?*@Ar   c                 |    t        d      }| j                  |      }| j                  |j                         d       y )Nr   s   0

r   r   s      r   test_more_nodata_nofootersz8DeferringChunkedProducerTests.test_more_nodata_nofooters   s0    $==),7r   c                 f    | j                  d       }| j                  |j                         d       y Nr   r   r$   rp   r   rr   s     r   test_more_noproducerz2DeferringChunkedProducerTests.test_more_noproducer   s&    ==&#.r   r   )r   r    r!   r   r   r   r   r   r   r   r   r"   r   r   r   r      s,    *98
=
B
B
8
/r   r   c                   *    e Zd Zd Zd Zd Zd Zd Zy)DeferringCompositeProducerTestsc                     ddl m} |S )Nr   )deferring_composite_producer)r.   r   )r   r   s     r   r   z/DeferringCompositeProducerTests._getTargetClass   s    @++r   c                 .     | j                         |      S r   r   )r   rT   s     r   r   z(DeferringCompositeProducerTests._makeOne   s    %t##%i00r   c                     t        t              }| j                  |g      }| j                  |j	                         t               y r   r   r   s      r   r   z6DeferringCompositeProducerTests.test_more_not_done_yet   s2    -=='+,7r   c                    t        d      }t        d      }| j                  ||g      }| j                  |j                         d       | j                  |j                         d       | j                  |j                         d       y )Nhellogoodbyer   r   )r   wrapped1wrapped2rr   s       r   r   z0DeferringCompositeProducerTests.test_more_string   sk     ) +==(H!56'2)4#.r   c                 |    t               }| j                  |g      }| j                  |j                         d       y r   r   r   s      r   r   z0DeferringCompositeProducerTests.test_more_nodata   s/    /=='+#.r   Nr   r    r!   r   r   r   r   r   r"   r   r   r   r      s    ,18
//r   r   c                   ,    e Zd Zd ZddZd Zd Zd Zy)DeferringGlobbingProducerTestsc                     ddl m} |S )Nr   )deferring_globbing_producer)r.   r   )r   r   s     r   r   z.DeferringGlobbingProducerTests._getTargetClass   s    ?**r   c                 0     | j                         ||      S r   r   )r   rr   buffer_sizes      r   r   z'DeferringGlobbingProducerTests._makeOne  s    %t##%h<<r   c                     t        t              }| j                  |      }| j                  |j	                         t               y r   r   r   s      r   r   z5DeferringGlobbingProducerTests.test_more_not_done_yet  r   r   c                    t        ddd      }| j                  |d      }| j                  |j                         d       t        ddd      }| j                  |d      }| j                  |j                         d       y )	Nr   thereguyr2   )r   r   2   s   hellothereguyr   r   s      r   r   z/DeferringGlobbingProducerTests.test_more_string	  so    %8==a=8(3%8==b=9*:;r   c                 z    t               }| j                  |      }| j                  |j                         d       y r   r   r   s      r   r   z/DeferringGlobbingProducerTests.test_more_nodata  s-    /==)#.r   N)i   r   r"   r   r   r   r      s    +=8
</r   r   c                   0    e Zd Zd Zd Zd Zd Zd Zd Zy)DeferringHookedProducerTestsc                     ddl m} |S )Nr   )deferring_hooked_producer)r.   r   )r   r   s     r   r   z,DeferringHookedProducerTests._getTargetClass  s    =((r   c                 0     | j                         ||      S r   r   )r   rr   functions      r   r   z%DeferringHookedProducerTests._makeOne  s    %t##%h99r   c                     t        t              }| j                  |d       }| j                  |j	                         t               y r   r   r   s      r   r   z3DeferringHookedProducerTests.test_more_not_done_yet  s2    -==$/,7r   c                     t        d      }g fd}| j                  ||      }| j                  |j                         d       | j                  g        |j                          | j                  dg       y )Nr   c                 (    j                  |        y r   appendbytesLs    r   callbackz?DeferringHookedProducerTests.test_more_string.<locals>.callback'      HHUOr      r   r   r   r   rr   r   s       @r   r   z-DeferringHookedProducerTests.test_more_string$  sh    (	==(3'2BQC r   c                     t               }g fd}| j                  ||      }| j                  |j                         d       | j                  dg       y )Nc                 (    j                  |        y r   r   r   s    r   r   z?DeferringHookedProducerTests.test_more_nodata.<locals>.callback2  r   r   r   r   r   r   s       @r   r   z-DeferringHookedProducerTests.test_more_nodata/  sL    /	==(3#.QC r   c                 h    | j                  d d       }| j                  |j                         d       y r   r   r   s     r   r   z1DeferringHookedProducerTests.test_more_noproducer8  s(    ==t,#.r   N)	r   r    r!   r   r   r   r   r   r   r"   r   r   r   r     s     ):8
	!!/r   r   c                   b    e Zd Zd Z	 	 	 	 	 	 ddZd Zd Zd Zd Zd Z	d	 Z
d
 Zd Zd Zd Zy)DeferringHttpRequestTestsc                     ddl m} |S )Nr   )deferring_http_request)r.   r   )r   r   s     r   r   z)DeferringHttpRequestTests._getTargetClass=      :%%r   Nc                 8     | j                         ||||||      S r   r   )r   channelreqcommandr   versionheaders          r   r   z"DeferringHttpRequestTests._makeOneA  s)     &t##%S'3 	r   c                 $     G d d      } |       S )Nc                       e Zd ZdZd Zd Zy)7DeferringHttpRequestTests._makeChannel.<locals>.ChannelFc                     d| _         y NT)closedr   s    r   close_when_donezGDeferringHttpRequestTests._makeChannel.<locals>.Channel.close_when_doneQ  s	    "r   c                     || _         y r   )rr   r   s     r   push_with_producerzJDeferringHttpRequestTests._makeChannel.<locals>.Channel.push_with_producerS  s	     (r   N)r   r    r!   r   r   r   r"   r   r   Channelr   O  s    F#)r   r   r"   )r   r   s     r   _makeChannelz&DeferringHttpRequestTests._makeChannelN  s    	) 	) yr   c                     | j                         }| j                  |d      }|j                          | j                  |j                         y )N1.0r   r   r   r   done
assertTruer   r   r   insts      r   test_done_http_10_nokeepalivez7DeferringHttpRequestTests.test_done_http_10_nokeepaliveW  s;    ##%}}We}<		'r   c                     | j                         }| j                  |ddg      }|j                          | j                  |j                         y )Nr   Connection: Keep-Aliver   r   r   r   r   s      r   -test_done_http_10_keepalive_no_content_lengthzGDeferringHttpRequestTests.test_done_http_10_keepalive_no_content_length]  sJ    ##%}},-   			'r   c                     | j                         }| j                  |ddg      }d|j                  d<   |j                          | j	                  |d   d       | j                  |j                         y )Nr   r   r   r2   zContent-Length
Connectionz
Keep-Alive)r   r   reply_headersr   r$   assertFalser   r   s      r   .test_done_http_10_keepalive_and_content_lengthzHDeferringHttpRequestTests.test_done_http_10_keepalive_and_content_lengthh  sr    ##%}},-  
 01+,		l+\:(r   c                     | j                         }| j                  |ddg      }|j                          | j                  |j                         y )N1.1zConnection: closer   r   r   s      r   "test_done_http_11_connection_closez<DeferringHttpRequestTests.test_done_http_11_connection_closet  sJ    ##%}}'(  
 			'r   c                     | j                         }| j                  |d      }d|j                  d<   |j                          | j	                  |j
                         y )Nr   r   
notchunkedTransfer-Encoding)r   r   r   r   r   r   r   s      r   +test_done_http_11_unknown_transfer_encodingzEDeferringHttpRequestTests.test_done_http_11_unknown_transfer_encoding~  sU    ##%}}   3?./		'r   c                     | j                         }| j                  |d      }d|j                  d<   |j                          | j	                  |j
                         y )Nr   r   chunkedr  )r   r   r   r   r   r   r   s      r   +test_done_http_11_chunked_transfer_encodingzEDeferringHttpRequestTests.test_done_http_11_chunked_transfer_encoding  sW    ##%}}   3<./		(r   c                     | j                         }| j                  |d      }d|_        |j                          | j	                  d|v        | j                  |j                         y )Nr   r   Tr  )r   r   use_chunkedr   r   r   r   r   s      r   test_done_http_11_use_chunkedz7DeferringHttpRequestTests.test_done_http_11_use_chunked  s`    ##%}}    		+t34(r   c                     | j                         }| j                  |d      }d|_        |j                          | j	                  |j
                         y )Nr   r   F)r   r   r  r   r   r   r   s      r   >test_done_http_11_wo_content_length_no_te_no_use_chunked_closezXDeferringHttpRequestTests.test_done_http_11_wo_content_length_no_te_no_use_chunked_close  sL    ##%}}   !		'r   c                     | j                         }| j                  |d       }|j                          | j                  |j                         y )Nr   r   r   s      r   test_done_http_09z+DeferringHttpRequestTests.test_done_http_09  sD    ##%}}   			'r   )NzGET / HTTP/1.0GET/r   r"   )r   r    r!   r   r   r   r   r   r   r   r  r  r  r
  r  r"   r   r   r   r   <  sR    & (	(
)(()	)((r   r   c                   6    e Zd Zd Zd Zd Zd Zd Zd Zd Z	y)	DeferringHttpChannelTestsc                     ddl m} |S )Nr   )deferring_http_channel)r.   r  )r   r  s     r   r   z)DeferringHttpChannelTests._getTargetClass  r   r   c                 4     | j                         d d d       S )N)serverconnaddrr   r   s    r   r   z"DeferringHttpChannelTests._makeOne  s#    %t##% 	r   c                     | j                         }| j                  |j                  d       | j                  |j                  d       y )Nr   )r   r$   delaylast_writable_check)r   r   s     r   0test_defaults_delay_and_last_writable_check_timezJDeferringHttpChannelTests.test_defaults_delay_and_last_writable_check_time  s7    --/*44a8r   c                     | j                         }d|_        t        |_        t        dz   }| j	                  |j                  |             | j                  |j                  t               y )N   r2   nowr   r  _NOWr  r   writabler$   r   r   laters      r   5test_writable_with_delay_is_False_if_elapsed_lt_delayzODeferringHttpChannelTests.test_writable_with_delay_is_False_if_elapsed_lt_delay  sW    --/&*#q))e)4544d;r   c                     | j                         }d|_        t        |_        t        |j                  z   }| j	                  |j                  |             | j                  |j                  t               y )Nr  r  r  r"  s      r   5test_writable_with_delay_is_False_if_elapsed_eq_delayzODeferringHttpChannelTests.test_writable_with_delay_is_False_if_elapsed_eq_delay  s\    --/&*#w}}$))e)4544d;r   c                     | j                         }d|_        t        |_        t        |j                  z   dz   }| j	                  |j                  |             | j                  |j                  |       y )Nr  g?r  r   r  r   r  r   r!  r$   r"  s      r   4test_writable_with_delay_is_True_if_elapsed_gt_delayzNDeferringHttpChannelTests.test_writable_with_delay_is_True_if_elapsed_gt_delay  s_    --/&*#w}}$s*((U(3444e<r   c                     | j                         }d|_        t        |_        t        dz
  }| j	                  |j                  |             | j                  |j                  |       y )Nr  i  r  r(  r"  s      r   >test_writable_with_delay_is_True_if_system_time_goes_backwardszXDeferringHttpChannelTests.test_writable_with_delay_is_True_if_system_time_goes_backwards  sU    --/&*#t((U(3444e<r   N)
r   r    r!   r   r   r  r$  r&  r)  r+  r"   r   r   r  r    s%    &9
<<==r   r  ifWc                   <    e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
y	)
"EncryptedDictionaryAuthorizedTestsc                     ddl m} |S )Nr   encrypted_dictionary_authorizer)r.   r0  )r   r0  s     r   r   z2EncryptedDictionaryAuthorizedTests._getTargetClass  s    C..r   c                 .     | j                         |      S r   r   )r   dicts     r   r   z+EncryptedDictionaryAuthorizedTests._makeOne  s    %t##%d++r   c                 f    | j                  i       }| j                  |j                  d             y )Nr@   barr   r   	authorizer   
authorizers     r   test_authorize_baduserz9EncryptedDictionaryAuthorizedTests.test_authorize_baduser  s)    ]]2&
--n=>r   c                 j    | j                  ddi      }| j                  |j                  d             y )Nr@   passwordr4  r6  r8  s     r   #test_authorize_gooduser_badpasswordzFEncryptedDictionaryAuthorizedTests.test_authorize_gooduser_badpassword  s.    ]]E*#56
--n=>r   c                 j    | j                  ddi      }| j                  |j                  d             y )Nr@   r<  r@   r<  r   r   r7  r8  s     r   $test_authorize_gooduser_goodpasswordzGEncryptedDictionaryAuthorizedTests.test_authorize_gooduser_goodpassword  s-    ]]E*#56

,,-@ABr   c                 j    | j                  ddi      }| j                  |j                  d             y )Nr@   	pass:word)r@   rC  r@  r8  s     r   /test_authorize_gooduser_goodpassword_with_colonzREncryptedDictionaryAuthorizedTests.test_authorize_gooduser_goodpassword_with_colon  s-    ]]E+#67

,,-ABCr   c                     dt        t        d            j                         z   }| j                  d|i      }| j	                  |j                  d             y )N{SHA}r<  r@   r4  )r   r   	hexdigestr   r   r7  r   r<  r9  s      r   'test_authorize_gooduser_badpassword_shazJEncryptedDictionaryAuthorizedTests.test_authorize_gooduser_badpassword_sha  sK    T(:"67AACC]]E(#34
--n=>r   c                     dt        t        d            j                         z   }| j                  d|i      }| j	                  |j                  d             y )NrF  r<  r@   r?  )r   r   rG  r   r   r7  rH  s      r   (test_authorize_gooduser_goodpassword_shazKEncryptedDictionaryAuthorizedTests.test_authorize_gooduser_goodpassword_sha   sJ    T(:"67AACC]]E(#34

,,-@ABr   N)r   r    r!   r   r   r:  r=  rA  rD  rI  rK  r"   r   r   r-  r-    s-    /,??CD?
Cr   r-  c                   0    e Zd Zd Zd Zd Zd Zd Zd Zy)SupervisorAuthHandlerTestsc                     ddl m} |S )Nr   supervisor_auth_handler)r.   rP  )r   rP  s     r   r   z*SupervisorAuthHandlerTests._getTargetClass  s    ;&&r   c                 0     | j                         ||      S r   r   )r   r2  r(   s      r   r   z#SupervisorAuthHandlerTests._makeOne
  s    %t##%dG44r   c                     | j                  ddid       }ddlm} | j                  |j                  j
                  |       y )Nar2   r   r/  )r   r.   r0  r$   r9  	__class__)r   r(   r0  s      r   	test_ctorz$SupervisorAuthHandlerTests.test_ctor  s8    --Q.C++558	:r   c                    t        dd d d       }t        j                  t        d            }dt	        |      z  g|_        t               }| j                  ddi|      }|j                  |       | j                  |j                         y )Nr5   zuser:passwordAuthorization: Basic %suserr<  r   base64	b64encoder   r   r   DummyHandlerr   r8   r   handled_requestr   r=   encodedr(   auth_handlers        r   /test_handle_request_authorizes_good_credentialszJSupervisorAuthHandlerTests.test_handle_request_authorizes_good_credentials  sx    2D$E""8O#<=3i6HHI.}}fZ%8'B##G,//0r   c                    t        dd d d       }t        j                  t        d            }dt	        |      z  g|_        t               }| j                  ddi|      }|j                  |       | j                  |j                         y )Nr5   zuser:pass:wordrW  rX  rC  rY  r^  s        r   7test_handle_request_authorizes_good_password_with_colonzRSupervisorAuthHandlerTests.test_handle_request_authorizes_good_password_with_colon  sy    2D$E""8,<#=>3i6HHI.}}f[%97C##G,//0r   c                    t        dd d d       }t        j                  t        d            }dt	        |      z  g|_        t               }| j                  ddi|      }|j                  |       | j                  |j                         y )Nr5   zwrong:wrongrW  rX  r<  )r   rZ  r[  r   r   r   r\  r   r8   r   r]  r^  s        r   6test_handle_request_does_not_authorize_bad_credentialszQSupervisorAuthHandlerTests.test_handle_request_does_not_authorize_bad_credentials&  sz    2D$E""8M#:;3i6HHI.}}fZ%8'B##G,001r   N)	r   r    r!   r   r   rU  ra  rc  re  r"   r   r   rM  rM    s     '5:112r   rM  c                   *    e Zd Zd Zd Zd Zd Zd Zy)LogWrapperTestsc                     ddl m} |S )Nr   )
LogWrapper)r.   ri  )r   ri  s     r   r   zLogWrapperTests._getTargetClass0  s    .r   c                 .     | j                         |      S r   r   )r   loggers     r   r   zLogWrapperTests._makeOne4  s    %t##%f--r   c                     t               }| j                  |      }|j                  d       |j                  }| j	                  t        |      d       | j	                  |d   d       y )Nzfoo
r2   r   r@   )r   r   logdatar$   rS   )r   rk  log_wrapperlogdatas       r   'test_strips_trailing_newlines_from_msgsz7LogWrapperTests.test_strips_trailing_newlines_from_msgs7  sT    mmF+ ++Wq)U+r   c                     t               }| j                  |      }g }|j                  |_        |j	                  d       | j                  t        |      d       | j                  |d   d       y )NzServer Errorr2   r   )r   r   r   errorrm  r$   rS   )r   rk  ro  errorss       r   (test_logs_msgs_with_error_at_error_levelz8LogWrapperTests.test_logs_msgs_with_error_at_error_level?  s[    mmF+}}'Va(N3r   c                     t               }| j                  |      }g }|j                  |_        |j	                  d       | j                  t        |      d       | j                  |d   d       y )NzGET /r2   r   )r   r   r   tracerm  r$   rS   )r   rk  ro  tracess       r   'test_logs_other_messages_at_trace_levelz7LogWrapperTests.test_logs_other_messages_at_trace_levelH  s[    mmF+}} Va(G,r   N)r   r    r!   r   r   rq  ru  ry  r"   r   r   rg  rg  /  s    .,4-r   rg  c                   $    e Zd Zd Zd Zd Zd Zy)TopLevelFunctionTestsc                 d   t               }||_        dt        i fg|_        t	               }ddlm}  |||      }	 |D ]>  \  }}|j                          |j                  d      }|*t        j                  |       @ 	 ddlm}	 |	j                          |S # ddlm}	 |	j                          w xY w)Ndummyr   )make_http_serversrw   )
socket_map)r
   server_configsr   rpcinterface_factoriesr   r.   r~  rx   getrP   r~   supervisor.medusa.asyncore_25r  clear)
r   sconfigsr;   r   r~  serversconfigs
socketfiler  s
             r   _make_http_serversz(TopLevelFunctionTests._make_http_serversR  s    .!)+23KB*O)P&%'5#G[9	$ *		#ZZ/
)IIj)	* A As   +B 'B B/c                     dddd d dd}	 | j                  |g       | j                  d       y # t        $ r)}| j                  |j                  d   d       Y d }~y d }~ww xY w)	Ni  	localhostGE  inet_http_serverfamilyhostportusernamer<  sectionznothing raisedr   z Cannot determine socket type 999)r  fail
ValueErrorr$   args)r   r  excs      r   (test_make_http_servers_socket_type_errorz>TopLevelFunctionTests.test_make_http_servers_socket_type_errord  si    {5!d.0	N##VH-II&' 	NSXXa[*LMM	Ns   #/ 	A!AA!c                    t        j                  d      5 }|j                  }d d d        | j                  t        j
                  j                               t        j                  ddd d dd}t        j                  |ddd d d	d
}| j                  ||g      }| j                  t        |      d       |d   }| j                  |d   |       |d   }g d}| j                  |j                  D 	cg c]  }	|	j                   c}	|       |d   }
| j                  |
d   |       |
d   }| j                  |j                  D 	cg c]  }	|	j                   c}	|       y # 1 sw Y   @xY wc c}	w c c}	w )NTr   r  r  r  r    r  unix_http_serverr  rw   chmodchownr  r<  r  r  r   r2   )zSupervisor XML-RPC HandlerzLogtail HTTP Request Handlerz!Main Logtail HTTP Request Handlerz&Supervisor Web UI HTTP Request HandlerzDefault HTTP Request Handler)rJ   rK   rL   r   rP   r&   existssocketAF_INETAF_UNIXr  r$   rS   handlersIDENT)r   rV   r  inetunixr  inetdatar  identsxunixdatas              r   test_make_http_servers_noauthz3TopLevelFunctionTests.test_make_http_servers_noauthn  sP   ((5 	 J	 
34ED<NP
E Td,. ))4,7Wq)1:!d+! 	6??;a!'';VD1:!d+!6??;a!'';VD7	  	 , <
 <s   E"3E/E4"E,c                    t        j                  d      5 }|j                  }d d d        | j                  t        j
                  j                               t        j                  dddddd}t        j                  |d	d
dddd}| j                  ||g      }| j                  t        |      d       ddlm} |D ]2  \  }}|j                  D ]  }	| j!                  t#        |	|      |	         4 y # 1 sw Y   xY w)NTr   r  iHE  r  r<  r  r  r  r  r  r  r  r   rO  )rJ   rK   rL   r   rP   r&   r  r  r  r  r  r$   rS   r.   rP  r  r   
isinstance)
r   rV   r  r  r  r  rP  r  r  r(   s
             r   test_make_http_servers_withauthz5TopLevelFunctionTests.test_make_http_servers_withauth  s    ((5 	 J	 
34E%*,.  
E ZJ,. ))4,7Wq);% 	)NFF!?? )
74K L '))	)	  	 s   C55C>N)r   r    r!   r  r  r  r  r"   r   r   r{  r{  Q  s    $NE<)r   r{  c                       e Zd Zd Zd Zy)r\  c                     d| _         y )NFr]  r   s    r   r   zDummyHandler.__init__  s
    $r   c                     d| _         y r   r  )r   r=   s     r   r8   zDummyHandler.handle_request  s
    #r   N)r   r    r!   r   r8   r"   r   r   r\  r\    s    %$r   r\  c                       e Zd Zd Zd Zy)r   c                 $    t        |      | _        y r   )listrn  )r   rn  s     r   r   zDummyProducer.__init__  s    J	r   c                 R    | j                   r| j                   j                  d      S y)Nr   r   )rn  popr   s    r   rp   zDummyProducer.more  s    9999==##r   N)r   r    r!   r   rp   r"   r   r   r   r     s    r   r   c                  V    t        j                  t        j                  t                 S r   )unittestfindTestCasessysmodulesr   r"   r   r   
test_suiter    s    !!#++h"788r   __main__r  )defaultTest)*rZ  rP   rQ   r  r  rJ   r  supervisor.compatr   r   r   supervisor.tests.baser   r   r   r	   r
   r   r   r.   r   r   TestCaser+   r[   rd   r   r   r   r   r   r  r   r-  rM  rg  r{  r\  r   r  r   mainr"   r   r   <module>r     s    	  
    & ' " 1 : : . . . - (
I 
I(2,(9(9 (2T"2lH,=,= "2JI** IV#/H$5$5 #/J/h&7&7 /4/X%6%6 /6#/8#4#4 #/Jr( 1 1 r(h/= 1 1 /=b  C):):  CD(2!2!2 (2T -h''  -DL)H-- L)\$ $ 9 zHMMl+ r   