
    vgCd                     >   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j)        d01           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 Zd ZdS )HandlerTestsc                 <     |                                  |          S N_getTargetClass)selfsupervisords     W/var/www/pixelcanvas.ch/venv/lib/python3.11/site-packages/supervisor/tests/test_http.py_makeOnezHandlerTests._makeOne   s    %t##%%k222    c                      G d d          }t                      }|                     |          }|                     |                     ||j                            d           d S )Nc                       e Zd Zd ZdS ),HandlerTests.test_match.<locals>.FakeRequestc                     || _         d S 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   s|    	 	 	 	 	 	 	 	 %&&
--
++{{7<'@'@AA4HHHHHr   N)r   r    r!   r   r)   r"   r   r   r   r      s7        3 3 3I I I I Ir   r   c                   &    e Zd Zd Zd Zd Zd ZdS )LogtailHandlerTestsc                     ddl m} |S )Nr   )logtail_handler)supervisor.httpr-   )r   r-   s     r   r   z#LogtailHandlerTests._getTargetClass$       333333r   c                    t                      }t          |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(   requests         r   'test_handle_request_stdout_logfile_nonez;LogtailHandlerTests.test_handle_request_stdout_logfile_none(   s    ..w
Oa.AC C C.w
GLL--,,2D$EEw'''-----r   c                    t                      }t          |ddd          }t          |d|          }|                     |          }t	          dd d d           }|                    |           |                     |j        d           d S )Nfoozit/is/missing/logtail/foor6   r7   r:   s         r   *test_handle_request_stdout_logfile_missingz>LogtailHandlerTests.test_handle_request_stdout_logfile_missing2   s    ..wuoFF.wwGG--,,~tT4@@w'''-----r   c           	      @   t          j                    5 }|j        }t                      }t	          |dd|          }t          |d|          }|                     |          }t          dd d d           }|                    |           | 	                    |j
        d            ddlm} | 	                    |j        d         |                    t          j        |          t           j                                      | 	                    |j        d         d           | 	                    |j        d	         d
           | 	                    t%          |j                  d           | 	                    |j        d           d d d            d S # 1 swxY w Y   d S )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;   s   (** 	2aA"nnG"7E5KKKG27E7KKKmmK00G">4tDDG""7+++W^T222333333W__=))"'!**T]*CDDF F FW_^<>XYYYW_-@A4HHHS!233Q777W]D111	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2s   E2FFFNr   r    r!   r   r>   rB   rX   r"   r   r   r+   r+   #   sP          . . .. . .2 2 2 2 2r   r+   c                   &    e Zd Zd Zd Zd Zd ZdS )MainLogTailHandlerTestsc                     ddl m} |S )Nr   )mainlogtail_handler)r.   r]   )r   r]   s     r   r   z'MainLogTailHandlerTests._getTargetClassN   s    777777""r   c                     t                      }|                     |          }t          dd d d           }|                    |           |                     |j        d           d S )N/mainlogtailr6   )r   r   r   r8   r$   r9   )r   r'   r(   r=   s       r   r>   z?MainLogTailHandlerTests.test_handle_request_stdout_logfile_noneR   sc    $&&
--
++~tT4@@w'''-----r   c                     t                      }d|j        _        t          dd d d           }|                     |          }|                    |           |                     |j        d           d S )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   sn    $&&
%1
"~tT4@@--
++w'''-----r   c           	         t                      }t          j                    5 }|j        }||j        _        |                     |          }t          dd d d           }|                    |           | 	                    |j
        d            ddlm} | 	                    |j        d         |                    t          j        |          t           j                                      | 	                    |j        d         d           | 	                    t%          |j                  d           | 	                    |j        d           d d d            d S # 1 swxY w Y   d S )	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DDG""7+++W^T222333333W__=))"'!**T]*CDDF F FW_^<>XYYYS!233Q777W]D111	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2s   D+EE!ENrY   r"   r   r   r[   r[   M   sP        # # #. . .. . .2 2 2 2 2r   r[   c                   2    e Zd Zd Zd Zd Zd Zd Zd ZdS )TailFProducerTestsc                     ddl m} |S )Nr   )tail_f_producer)r.   rf   )r   rf   s     r   r   z"TailFProducerTests._getTargetClasss   r/   r   c                 @     |                                  |||          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                    }|                    d           |                                 |                     ||j        d          }|	                                }| 
                    |d           |                    t          d                     |                                 |	                                }| 
                    |d           |	                                }| 
                    ||j                   |                    d           |                                 |	                                }| 
                    |d           d S )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   sD   ~tT4@@######'))						==!&"55+++	$$%%%				,,,!2333	

1				!;<<<<<r   c                    t          dd d d           }t          j                    5 }|                    t	          d                     |                                 |                     ||j        d          }|j        	                                 |
                                }d d d            n# 1 swxY w Y   |                     ||
                                           d S )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&&'''GGIII}}Wafb99HM!!!]]__F	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	11111s   B B22B69B6c                    t          dd d d           }t          j                    }|                    t	          d                     |                                 |                     ||j        d          }|                                }| 	                    |d           |
                                 t          |j        d          }	 |                    t	          d                     |
                                 |                                }t          j        |j                   n# t          j        |j                   w xY w| 	                    |d           d S )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5+++				!&$	HHXi(()))HHJJJ]]__FIbgBIbg+++++s   A
D0 0Ec                    t          dd d d           }t          j        d          5 }|j        }|                    d           d d d            n# 1 swxY w Y   	 |                     ||j        d          }t          j        |j                   n# t          j        |j                   w xY w|                                }| 	                    |d           t          |d          5 }|                    t          d                     d d d            n# 1 swxY w Y   	 |                                }| 	                    |d           t          j        |j                   d S # 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66 	!vHGGI	 	 	 	 	 	 	 	 	 	 	 	 	 	 		}}Wafb99HIafBIaf+++(D!! 	)QGGHY''(((	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	)	]]__FVY///YqvRYqvs;   AAAB B.+#DD!D&*E+ +FN)	r   r    r!   r   r   rt   ry   r   r   r"   r   r   rd   rd   r   sn          ? ? ?= = =(2 2 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
dS )DeferringChunkedProducerTestsc                     ddl m} |S )Nr   )deferring_chunked_producer)r.   r   )r   r   s     r   r   z-DeferringChunkedProducerTests._getTargetClass   s    >>>>>>))r   Nc                 >     |                                  ||          S r   r   )r   rr   footerss      r   r   z&DeferringChunkedProducerTests._makeOne   s     %t##%%h888r   c                     t          t                    }|                     |          }|                     |                                t                     d S r   DummyProducerr   r   r$   rp   r   wrappedrr   s      r   test_more_not_done_yetz4DeferringChunkedProducerTests.test_more_not_done_yet   D    --==)),77777r   c                     t          d          }|                     |          }|                     |                                d           d S )N   hellos
   5
hello
r   r   r$   rp   r   s      r   test_more_stringz.DeferringChunkedProducerTests.test_more_string   sE    ))==))*;<<<<<r   c                     t                      }|                     |ddg          }|                     |                                d           d S )N   a   br      0
a
b

r   r   s      r   test_more_nodataz.DeferringChunkedProducerTests.test_more_nodata   sI    //==4,=??*@AAAAAr   c                     t          d          }|                     |ddg          }|                     |                                d           d S )Nr   r   r   r   r   r   r   s      r   test_more_nodata_footersz6DeferringChunkedProducerTests.test_more_nodata_footers   sM    $$==4,=??*@AAAAAr   c                     t          d          }|                     |          }|                     |                                d           d S )Nr   s   0

r   r   s      r   test_more_nodata_nofootersz8DeferringChunkedProducerTests.test_more_nodata_nofooters   sD    $$==)),77777r   c                     |                      d           }|                     |                                d           d S Nr   r   r$   rp   r   rr   s     r   test_more_noproducerz2DeferringChunkedProducerTests.test_more_noproducer   s7    ==&&#.....r   r   )r   r    r!   r   r   r   r   r   r   r   r   r"   r   r   r   r      s        * * *9 9 9 98 8 8
= = =
B B B
B B B
8 8 8
/ / / / /r   r   c                   ,    e Zd Zd Zd Zd Zd Zd ZdS )DeferringCompositeProducerTestsc                     ddl m} |S )Nr   )deferring_composite_producer)r.   r   )r   r   s     r   r   z/DeferringCompositeProducerTests._getTargetClass   s    @@@@@@++r   c                 <     |                                  |          S r   r   )r   rT   s     r   r   z(DeferringCompositeProducerTests._makeOne   s    %t##%%i000r   c                     t          t                    }|                     |g          }|                     |                                t                     d S r   r   r   s      r   r   z6DeferringCompositeProducerTests.test_more_not_done_yet   sF    --=='++,77777r   c                 `   t          d          }t          d          }|                     ||g          }|                     |                                d           |                     |                                d           |                     |                                d           d S )Nhellogoodbyer   r   )r   wrapped1wrapped2rr   s       r   r   z0DeferringCompositeProducerTests.test_more_string   s     )) ++==(H!566'222)444#.....r   c                     t                      }|                     |g          }|                     |                                d           d S r   r   r   s      r   r   z0DeferringCompositeProducerTests.test_more_nodata   sB    //=='++#.....r   Nr   r    r!   r   r   r   r   r   r"   r   r   r   r      s_        , , ,1 1 18 8 8
/ / // / / / /r   r   c                   .    e Zd Zd ZddZd Zd Zd ZdS )	DeferringGlobbingProducerTestsc                     ddl m} |S )Nr   )deferring_globbing_producer)r.   r   )r   r   s     r   r   z.DeferringGlobbingProducerTests._getTargetClass   s    ??????**r      c                 >     |                                  ||          S r   r   )r   rr   buffer_sizes      r   r   z'DeferringGlobbingProducerTests._makeOne  s     %t##%%h<<<r   c                     t          t                    }|                     |          }|                     |                                t                     d S r   r   r   s      r   r   z5DeferringGlobbingProducerTests.test_more_not_done_yet  r   r   c                 F   t          ddd          }|                     |d          }|                     |                                d           t          ddd          }|                     |d          }|                     |                                d           d S )	Nr   thereguyr2   )r   r   2   s   hellothereguyr   r   s      r   r   z/DeferringGlobbingProducerTests.test_more_string	  s    %88==a=88(333%88==b=99*:;;;;;r   c                     t                      }|                     |          }|                     |                                d           d S r   r   r   s      r   r   z/DeferringGlobbingProducerTests.test_more_nodata  s@    //==))#.....r   N)r   r   r"   r   r   r   r      sd        + + += = = =8 8 8
< < </ / / / /r   r   c                   2    e Zd Zd Zd Zd Zd Zd Zd ZdS )DeferringHookedProducerTestsc                     ddl m} |S )Nr   )deferring_hooked_producer)r.   r   )r   r   s     r   r   z,DeferringHookedProducerTests._getTargetClass  s    ======((r   c                 >     |                                  ||          S r   r   )r   rr   functions      r   r   z%DeferringHookedProducerTests._makeOne  s     %t##%%h999r   c                     t          t                    }|                     |d           }|                     |                                t                     d S r   r   r   s      r   r   z3DeferringHookedProducerTests.test_more_not_done_yet  sF    --==$//,77777r   c                 2   t          d          }g fd}|                     ||          }|                     |                                d           |                     g            |                                 |                     dg           d S )Nr   c                 2                         |            d S r   appendbytesLs    r   callbackz?DeferringHookedProducerTests.test_more_string.<locals>.callback'      HHUOOOOOr      r   r   r   r   rr   r   s       @r   r   z-DeferringHookedProducerTests.test_more_string$  s    ((	 	 	 	 	==(33'222BQC     r   c                     t                      }g fd}|                     ||          }|                     |                                d           |                     dg           d S )Nc                 2                         |            d S 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/  sy    //	 	 	 	 	==(33#...QC     r   c                     |                      d d           }|                     |                                d           d S r   r   r   s     r   r   z1DeferringHookedProducerTests.test_more_noproducer8  s9    ==t,,#.....r   N)	r   r    r!   r   r   r   r   r   r   r"   r   r   r   r     sn        ) ) ): : :8 8 8
	! 	! 	!! ! !/ / / / /r   r   c                   d    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dS )DeferringHttpRequestTestsc                     ddl m} |S )Nr   )deferring_http_request)r.   r   )r   r   s     r   r   z)DeferringHttpRequestTests._getTargetClass=      ::::::%%r   NGET / HTTP/1.0GET/1.0r"   c                 F     |                                  ||||||          S r   r   )r   channelreqcommandr   versionheaders          r   r   z"DeferringHttpRequestTests._makeOneA  s1     &t##%%S'3  	r   c                 0     G d d          } |            S )Nc                       e Zd ZdZd Zd ZdS )7DeferringHttpRequestTests._makeChannel.<locals>.ChannelFc                     d| _         d S NT)closedr   s    r   close_when_donezGDeferringHttpRequestTests._makeChannel.<locals>.Channel.close_when_doneQ  s    "r   c                     || _         d S 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  s7        F# # #) ) ) ) )r   r   r"   )r   r   s     r   _makeChannelz&DeferringHttpRequestTests._makeChannelN  s8    	) 	) 	) 	) 	) 	) 	) 	) wyyr   c                     |                                  }|                     |d          }|                                 |                     |j                   d S )Nr   r   r   r   r   done
assertTruer   r   r   insts      r   test_done_http_10_nokeepalivez7DeferringHttpRequestTests.test_done_http_10_nokeepaliveW  sO    ##%%}}We}<<		'''''r   c                     |                                  }|                     |ddg          }|                                 |                     |j                   d S )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]  s`    ##%%}},-    			'''''r   c                    |                                  }|                     |ddg          }d|j        d<   |                                 |                     |d         d           |                     |j                   d S )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  s    ##%%}},-   
 01+,		l+\:::(((((r   c                     |                                  }|                     |ddg          }|                                 |                     |j                   d S )N1.1zConnection: closer   r   r   s      r   "test_done_http_11_connection_closez<DeferringHttpRequestTests.test_done_http_11_connection_closet  s`    ##%%}}'(   
 			'''''r   c                     |                                  }|                     |d          }d|j        d<   |                                 |                     |j                   d S )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~  sh    ##%%}}    3?./		'''''r   c                     |                                  }|                     |d          }d|j        d<   |                                 |                     |j                   d S )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  sj    ##%%}}    3<./		(((((r   c                     |                                  }|                     |d          }d|_        |                                 |                     d|v            |                     |j                   d S )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44(((((r   c                     |                                  }|                     |d          }d|_        |                                 |                     |j                   d S )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  sb    ##%%}}    !		'''''r   c                     |                                  }|                     |d           }|                                 |                     |j                   d S )Nr   r   r   s      r   test_done_http_09z+DeferringHttpRequestTests.test_done_http_09  sZ    ##%%}}    			'''''r   )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   r   c                   8    e Zd Zd Zd Zd Zd Zd Zd Zd Z	dS )	DeferringHttpChannelTestsc                     ddl m} |S )Nr   )deferring_http_channel)r.   r  )r   r  s     r   r   z)DeferringHttpChannelTests._getTargetClass  r   r   c                 B     |                                  d d d           S )N)serverconnaddrr   r   s    r   r   z"DeferringHttpChannelTests._makeOne  s0    %t##%%   	r   c                     |                                  }|                     |j        d           |                     |j        d           d S )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  sF    --//***4a88888r   c                     |                                  }d|_        t          |_        t          dz   }|                     |                    |                     |                     |j        t                     d S )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  sk    --//&*#q))e)445554d;;;;;r   c                    |                                  }d|_        t          |_        t          |j        z   }|                     |                    |                     |                     |j        t                     d S )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  sn    --//&*#w}$))e)445554d;;;;;r   c                     |                                  }d|_        t          |_        t          |j        z   dz   }|                     |                    |                     |                     |j        |           d S )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  sq    --//&*#w}$s*((U(334444e<<<<<r   c                     |                                  }d|_        t          |_        t          dz
  }|                     |                    |                     |                     |j        |           d S )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  si    --//&*#t((U(334444e<<<<<r   N)
r   r    r!   r   r   r  r&  r(  r+  r-  r"   r   r   r  r    s}        & & &  9 9 9
< < << < <= = == = = = =r   r  ifWc                   >    e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
d	S )
"EncryptedDictionaryAuthorizedTestsc                     ddl m} |S )Nr   encrypted_dictionary_authorizer)r.   r2  )r   r2  s     r   r   z2EncryptedDictionaryAuthorizedTests._getTargetClass  s    CCCCCC..r   c                 <     |                                  |          S r   r   )r   dicts     r   r   z+EncryptedDictionaryAuthorizedTests._makeOne  s    %t##%%d+++r   c                     |                      i           }|                     |                    d                     d S )Nr@   barr   r   	authorizer   
authorizers     r   test_authorize_baduserz9EncryptedDictionaryAuthorizedTests.test_authorize_baduser  s;    ]]2&&
--n==>>>>>r   c                     |                      ddi          }|                     |                    d                     d S )Nr@   passwordr6  r8  r:  s     r   #test_authorize_gooduser_badpasswordzFEncryptedDictionaryAuthorizedTests.test_authorize_gooduser_badpassword  s@    ]]E*#566
--n==>>>>>r   c                     |                      ddi          }|                     |                    d                     d S )Nr@   r>  r@   r>  r   r   r9  r:  s     r   $test_authorize_gooduser_goodpasswordzGEncryptedDictionaryAuthorizedTests.test_authorize_gooduser_goodpassword  s?    ]]E*#566

,,-@AABBBBBr   c                     |                      ddi          }|                     |                    d                     d S )Nr@   	pass:word)r@   rE  rB  r:  s     r   /test_authorize_gooduser_goodpassword_with_colonzREncryptedDictionaryAuthorizedTests.test_authorize_gooduser_goodpassword_with_colon  s?    ]]E+#677

,,-ABBCCCCCr   c                     dt          t          d                                                    z   }|                     d|i          }|                     |                    d                     d S )N{SHA}r>  r@   r6  )r   r   	hexdigestr   r   r9  r   r>  r;  s      r   'test_authorize_gooduser_badpassword_shazJEncryptedDictionaryAuthorizedTests.test_authorize_gooduser_badpassword_sha  sf    T(:"6"677AACCC]]E(#344
--n==>>>>>r   c                     dt          t          d                                                    z   }|                     d|i          }|                     |                    d                     d S )NrH  r>  r@   rA  )r   r   rI  r   r   r9  rJ  s      r   (test_authorize_gooduser_goodpassword_shazKEncryptedDictionaryAuthorizedTests.test_authorize_gooduser_goodpassword_sha   se    T(:"6"677AACCC]]E(#344

,,-@AABBBBBr   N)r   r    r!   r   r   r<  r?  rC  rF  rK  rM  r"   r   r   r/  r/    s        / / /, , ,? ? ?? ? ?C C CD D D? ? ?
C C C C Cr   r/  c                   2    e Zd Zd Zd Zd Zd Zd Zd ZdS )SupervisorAuthHandlerTestsc                     ddl m} |S )Nr   supervisor_auth_handler)r.   rR  )r   rR  s     r   r   z*SupervisorAuthHandlerTests._getTargetClass  s    ;;;;;;&&r   c                 >     |                                  ||          S r   r   )r   r4  r(   s      r   r   z#SupervisorAuthHandlerTests._makeOne
  s     %t##%%dG444r   c                     |                      ddid           }ddlm} |                     |j        j        |           d S )Nar2   r   r1  )r   r.   r2  r$   r;  	__class__)r   r(   r2  s      r   	test_ctorz$SupervisorAuthHandlerTests.test_ctor  sX    --Q..CCCCCC+58	: 	: 	: 	: 	:r   c                 F   t          dd d d           }t          j        t          d                    }dt	          |          z  g|_        t                      }|                     ddi|          }|                    |           | 	                    |j
                   d S )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  s    2D$EE"8O#<#<==3i6H6HHI..}}fZ%8'BB##G,,,/00000r   c                 F   t          dd d d           }t          j        t          d                    }dt	          |          z  g|_        t                      }|                     ddi|          }|                    |           | 	                    |j
                   d S )Nr5   zuser:pass:wordrY  rZ  rE  r[  r`  s        r   7test_handle_request_authorizes_good_password_with_colonzRSupervisorAuthHandlerTests.test_handle_request_authorizes_good_password_with_colon  s    2D$EE"8,<#=#=>>3i6H6HHI..}}f[%97CC##G,,,/00000r   c                 F   t          dd d d           }t          j        t          d                    }dt	          |          z  g|_        t                      }|                     ddi|          }|                    |           | 	                    |j
                   d S )Nr5   zwrong:wrongrY  rZ  r>  )r   r\  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&  s    2D$EE"8M#:#:;;3i6H6HHI..}}fZ%8'BB##G,,,011111r   N)	r   r    r!   r   r   rW  rc  re  rg  r"   r   r   rO  rO    sn        ' ' '5 5 5: : :1 1 11 1 12 2 2 2 2r   rO  c                   ,    e Zd Zd Zd Zd Zd Zd ZdS )LogWrapperTestsc                     ddl m} |S )Nr   )
LogWrapper)r.   rk  )r   rk  s     r   r   zLogWrapperTests._getTargetClass0  s    ......r   c                 <     |                                  |          S r   r   )r   loggers     r   r   zLogWrapperTests._makeOne4  s    %t##%%f---r   c                    t                      }|                     |          }|                    d           |j        }|                     t          |          d           |                     |d         d           d S )Nzfoo
r2   r   r@   )r   r   logdatar$   rS   )r   rm  log_wrapperlogdatas       r   'test_strips_trailing_newlines_from_msgsz7LogWrapperTests.test_strips_trailing_newlines_from_msgs7  sq    mmF++   +Wq)))U+++++r   c                    t                      }|                     |          }g }|j        |_        |                    d           |                     t          |          d           |                     |d         d           d S )NzServer Errorr2   r   )r   r   r   errorro  r$   rS   )r   rm  rq  errorss       r   (test_logs_msgs_with_error_at_error_levelz8LogWrapperTests.test_logs_msgs_with_error_at_error_level?  sx    mmF++}'''Va(((N33333r   c                    t                      }|                     |          }g }|j        |_        |                    d           |                     t          |          d           |                     |d         d           d S )NzGET /r2   r   )r   r   r   tracero  r$   rS   )r   rm  rq  tracess       r   'test_logs_other_messages_at_trace_levelz7LogWrapperTests.test_logs_other_messages_at_trace_levelH  sx    mmF++}   Va(((G,,,,,r   N)r   r    r!   r   r   rs  rw  r{  r"   r   r   ri  ri  /  s_          . . ., , ,4 4 4- - - - -r   ri  c                   &    e Zd Zd Zd Zd Zd ZdS )TopLevelFunctionTestsc                    t                      }||_        dt          i fg|_        t	                      }ddlm}  |||          }	 |D ]D\  }}|                                 |                    d          }|t          j
        |           E	 ddlm}	 |	                                 n# ddlm}	 |	                                 w xY w|S )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55555##G[99	$ * *				#ZZ//
)Ij)))	* A@@@@@ A@@@@@s   AB* *Cc                     dddd d dd}	 |                      |g           |                     d           d S # t          $ r,}|                     |j        d         d           Y d }~d S 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  s    {5!d.0 0	N##VH---II&''''' 	N 	N 	NSXa[*LMMMMMMMMM	Ns   +8 
A.!A))A.c                    t          j        d          5 }|j        }d d d            n# 1 swxY 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 |j        D             |           |d         }	|                     |	d         |           |	d         }|                     d |j        D             |           d S )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 Handlerc                     g | ]	}|j         
S r"   IDENT.0xs     r   
<listcomp>zGTopLevelFunctionTests.test_make_http_servers_noauth.<locals>.<listcomp>      ;;;a!';;;r   c                     g | ]	}|j         
S r"   r  r  s     r   r  zGTopLevelFunctionTests.test_make_http_servers_noauth.<locals>.<listcomp>  r  r   )rJ   rK   rL   r   rP   r&   existssocketAF_INETAF_UNIXr  r$   rS   handlers)
r   rV   r  inetunixr  inetdatar  identsunixdatas
             r   test_make_http_servers_noauthz3TopLevelFunctionTests.test_make_http_servers_noauthn  s   (555 	 J	  	  	  	  	  	  	  	  	  	  	  	  	  	  	 
33444ED<NP P
E Td,. . ))4,77Wq)))1:!d+++!   	;;6?;;;VDDD1:!d+++!;;6?;;;VDDDDD   *..c                    t          j        d          5 }|j        }d d d            n# 1 swxY 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 ]3\  }}|j        D ]&}	|                     t#          |	|          |	           '4d S )NTr   r  iHE  r  r>  r  r  r  r  r  r  r  r   rQ  )rJ   rK   rL   r   rP   r&   r  r  r  r  r  r$   rS   r.   rR  r  r   
isinstance)
r   rV   r  r  r  r  rR  r  r  r(   s
             r   test_make_http_servers_withauthz5TopLevelFunctionTests.test_make_http_servers_withauth  st   (555 	 J	  	  	  	  	  	  	  	  	  	  	  	  	  	  	 
33444E%*,. .  
E ZJ,. . ))4,77Wq)));;;;;;% 	) 	)NFF!? ) )
74K L L ') ) ) ))	) 	)r  N)r   r    r!   r  r  r  r  r"   r   r   r}  r}  Q  sV          $N N NE E E<) ) ) ) )r   r}  c                       e Zd Zd Zd ZdS )r^  c                     d| _         d S )NFr_  r   s    r   r   zDummyHandler.__init__  s    $r   c                     d| _         d S r   r  )r   r=   s     r   r8   zDummyHandler.handle_request  s    #r   N)r   r    r!   r   r8   r"   r   r   r^  r^    s2        % % %$ $ $ $ $r   r^  c                       e Zd Zd Zd ZdS )r   c                 .    t          |          | _        d S r   )listrp  )r   rp  s     r   r   zDummyProducer.__init__  s    JJ			r   c                 H    | j         r| j                             d          S dS )Nr   r   )rp  popr   s    r   rp   zDummyProducer.more  s%    9 	9==###3r   N)r   r    r!   r   rp   r"   r   r   r   r     s2              r   r   c                  T    t          j        t          j        t                             S r   )unittestfindTestCasessysmodulesr   r"   r   r   
test_suiter    s    !#+h"7888r   __main__r  )defaultTest)*r\  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/  rO  ri  r}  r^  r   r  r   mainr"   r   r   <module>r     sH    				  



    & & & & & & ' ' ' ' ' ' " " " " " " 1 1 1 1 1 1 : : : : : : : : : : : : . . . . . . . . . . . . . . . . . . - - - - - - ( ( ( ( ( (
I 
I 
I 
I 
I 
I 
I 
I(2 (2 (2 (2 (2,(9 (2 (2 (2T"2 "2 "2 "2 "2lH,= "2 "2 "2JI I I I I* I I IV#/ #/ #/ #/ #/H$5 #/ #/ #/J/ / / / /h&7 / / /4/ / / / /X%6 / / /6#/ #/ #/ #/ #/8#4 #/ #/ #/Jr( r( r( r( r( 1 r( r( r(h/= /= /= /= /= 1 /= /= /=b  C  C  C  C  C):  C  C  CD(2 (2 (2 (2 (2!2 (2 (2 (2T -  -  -  -  -h'  -  -  -DL) L) L) L) L)H- L) L) L)\$ $ $ $ $ $ $ $       9 9 9 zHMl++++++ r   