
    9bhq                     `   d 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
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 Z ej,                  e
du d       G d dej.                               Z G d dej2                        Z ej,                  e
du d       G d deej.                               Z ej,                  e
du d       ej8                   eed      d       G d deej.                                      Zedk(  r ej@                          yy# e$ r dZ
Y w xY w)zTests for asyncio/sslproto.py.    N)support)socket_helper)mock)log)	protocols)sslproto)utils)
functionalc                  .    t        j                  d        y N)asyncioset_event_loop_policy     I/opt/python-3.12.12/usr/lib/python3.12/test/test_asyncio/test_sslproto.pytearDownModuler      s    !!$'r   zNo ssl modulec                        e Zd Z fdZddddZdddZd Zd Zd	 Zd
 Z	d Z
d Zd Zd Zd Zd Zd Zd Z xZS )SslProtoHandshakeTestsc                     t         |           t        j                         | _        | j                  | j                         y r   )supersetUpr   new_event_looploopset_event_loop)self	__class__s    r   r   zSslProtoHandshakeTests.setUp   s.    **,	DII&r   N)waiterprotoc                @   t        j                         }|t        j                         }t	        j
                  | j                  |||d      }| j                  |j                  j                         |       | j                  |j                  j                         |S )Ng?ssl_handshake_timeout)
test_utilsdummy_ssl_contextr   Protocolr   SSLProtocolr   assertIs_app_transportget_protocol
addCleanupclose)r   r   r   
sslcontext	ssl_protos        r   ssl_protocolz#SslProtoHandshakeTests.ssl_protocol#   s~    113
=$$&E((E:v?BD	i..;;=uE	00667r   do_handshakec                   t        j                         }t        j                         }t        j                  |j                  _        t        j                  |j                  _        |||_        ||_        |j                  |       |S r   )
r   MocksslSSLWantReadErrorreadside_effectwriter/   _sslobjconnection_made)r   r,   r/   	transportsslobjs        r   r8   z&SslProtoHandshakeTests.connection_made-   sf    IIK	"%"6"6#&#7#7 #".F"	!!),r   c                    t        j                         }t        j                         }t        j                         }| j	                  t
        d      5  t        j                  | j                  |||d       d d d        y # 1 sw Y   y xY w)Na positive numberr   r    	r"   r#   r   r1   assertRaisesRegex
ValueErrorr   r%   r   r   r+   	app_protor   s       r   test_handshake_timeout_zeroz2SslProtoHandshakeTests.test_handshake_timeout_zero9   sa    113
IIK	##J0CD  Iz678: EDD   %BB
c                    t        j                         }t        j                         }t        j                         }| j	                  t
        d      5  t        j                  | j                  |||d       d d d        y # 1 sw Y   y xY w)Nr<   ir    r=   r@   s       r   test_handshake_timeout_negativez6SslProtoHandshakeTests.test_handshake_timeout_negativeA   sa    113
IIK	##J0CD  Iz67:< EDDrC   c                 l   | j                   j                         }| j                  |      }| j                  |t	        j
                  t        j                               |j                          t        j                  | j                          | j                  |j                         t               y Nr   r5   r.   )r   create_futurer-   r8   r   r1   r2   r3   eof_receivedr"   run_brieflyassertIsInstance	exceptionConnectionResetErrorr   r   r,   s      r   test_eof_received_waiterz/SslProtoHandshakeTests.test_eof_received_waiterI   s    ((*%%V%4	s/C/CD 	 	
 	 tyy)f..02FGr   c                    | j                   j                         }| j                  |      }t        j                  j                         }t        j                  j                  t        j                         	 |j                  d        t        j                  j                  |       y # t        j                  j                  |       w xY wNrH   )
r   rJ   r-   r   loggergetEffectiveLevelsetLevelloggingFATAL_fatal_error)r   r   r,   	log_levels       r   test_fatal_error_no_name_errorz5SslProtoHandshakeTests.test_fatal_error_no_name_errorT   s     ((*%%V%4	JJ002	

GMM*	+""4( JJ	*CJJ	*s   9B* *!Cc                 v   | j                   j                         }| j                  |      }| j                  |t	        j
                  t        j                               |j                  t               t        j                  | j                          | j                  |j                         t               y rG   )r   rJ   r-   r8   r   r1   r2   r3   connection_lostConnectionAbortedErrorr"   rL   rM   rN   rP   s      r   test_connection_lostz+SslProtoHandshakeTests.test_connection_lostc   s     ((*%%V%4	s/C/CD 	 	
 	!!"89tyy)f..02HIr   c                 r   	
 t        j                         }t        j                  d      |_        t        j                  t              |_        t        j                  d j                        }t        j                  | j                        } j                  |      }t        j                         }t        j                  |j                  _        t        j                  |j                  _        ||_        d	t        j                         }t        j                  	      |_        t!        	      |_        ||_         j                  j'                  ||       |j(                  }t        j*                  ||| j                        
	 
fd	} j                  j-                   |              y )
Ni90  )return_valuerI   i   )limitr   )r   r   s   An interesting messagec                     K   fd}  |         d {    j                  t              5   |         d {    d d d        y 7 27 # 1 sw Y   y xY ww)Nc                  d   K   j                          j                          d {    y 7 wr   )r6   drain)datawriters   r   r6   zRSslProtoHandshakeTests.test_connection_lost_when_busy.<locals>.main.<locals>.write   s"     T"lln$$s   %0.0)assertRaisesrO   )r6   rg   r   rh   s    r   mainzCSslProtoHandshakeTests.test_connection_lost_when_busy.<locals>.main   sM     %
 'MM ""#78g 98   98s5   AAAAA	A
A	AAA)r   r1   filenoBrokenPipeErrorsendr   StreamReaderr   StreamReaderProtocolr-   r2   r3   r4   r5   r6   r7   lenpending	_outgoing_make_socket_transportr'   StreamWriterrun_until_complete)r   sockreaderprotocolr,   r:   outgoingr9   rj   rg   rh   s   `        @@r   test_connection_lost_when_busyz5SslProtoHandshakeTests.test_connection_lost_when_busyp   s6    yy{iiU3II/:	 %%G$))D//TYYG%%H%5	 "%"6"6#&#7#7 "	 )99;		t4t9&	 			((y9,,	%%i6499M	 			$$TV,r   c                    | j                   j                         }| j                  |      }| j                  |t	        j
                  t        j                              }t        j                  | j                          |j                  j                          | j                  |j                  j                         y rG   )r   rJ   r-   r8   r   r1   r2   r3   r"   rL   r'   r*   
assertTrue_force_closecalled)r   r   r,   r9   s       r   test_close_during_handshakez2SslProtoHandshakeTests.test_close_during_handshake   s    ((*%%V%4	((s/C/CD ) 
	 	tyy)  &&(	..556r   c                     | j                  | j                               }| j                  |       g | j                  j                  fd       |j                  j                          | j                  g        y )Nrc   c                 &    j                  |      S r   appendr   ctxmessagess     r   <lambda>zGSslProtoHandshakeTests.test_close_during_ssl_over_ssl.<locals>.<lambda>       (//#:Nr   )r-   r8   r   set_exception_handlerr'   r*   assertEqual)r   outerr   s     @r   test_close_during_ssl_over_sslz5SslProtoHandshakeTests.test_close_during_ssl_over_ssl   si     !!(9(9(;!<U#		''(NO""$2&r   c                    | j                   j                         }| j                  |      }| j                  |j	                  d             t               }| j                  |j	                  d|      |       | j                  |       | j                  |j	                  d             |j                  d        | j                  |j	                  d             y )NrH   socket)
r   rJ   r-   assertIsNone_get_extra_infoobjectr&   r8   assertIsNotNoner]   )r   r   r,   defaults       r   (test_get_extra_info_on_closed_connectionz?SslProtoHandshakeTests.test_get_extra_info_on_closed_connection   s    ((*%%V%4	)33H=>(i//'BGLY'Y66x@A!!$')33H=>r   c                 F   | j                   j                         }| j                  |      }t        j                         }|j
                  j                  |       | j                  |j
                  j                         |       | j                  |j                  |       y rS   )
r   rJ   r-   r   r$   r'   set_protocolr&   r(   _app_protocol)r   r   r,   new_app_protos       r   test_set_new_app_protocolz0SslProtoHandshakeTests.test_set_new_app_protocol   sz    ((*%%V%4	((*  --m<i..;;=}Mi--}=r   c                     | j                         }| j                  |       |j                  }|j                          | j	                  |j                  d             y )N   )r-   r8   r'   r*   r   buffer_updatedr   r,   transps      r    test_data_received_after_closingz7SslProtoHandshakeTests.test_data_received_after_closing   sM    %%'	Y')) 	)22156r   c                     | j                         }| j                  |       |j                  }|j                          | j	                  |j                  d             y )Ns   data)r-   r8   r'   r*   r   r6   r   s      r   test_write_after_closingz/SslProtoHandshakeTests.test_write_after_closing   sK    %%'	Y')) 	&,,w/0r   )__name__
__module____qualname__r   r-   r8   rB   rE   rQ   r[   r_   rz   r   r   r   r   r   r   __classcell__)r   s   @r   r   r      s]    '
 &*  :> 
:<	H+J.-`7
'	?>71r   r   c                       e Zd ZdZej
                  Zd Zd Zd Z	d Z
ej                  d        Zd Zej                  d        Zd	 Zd
 Zd Zd Zd Zy)BaseStartTLSi  c                     t         r   )NotImplementedErrorr   s    r   new_loopzBaseStartTLS.new_loop   s    !!r   c                 ,    G d dt         j                        }dD ]h  } |d|      }t        j                  |d       | j	                  |j
                  d        |d|      }t        j                  |d       | j	                  |j
                  d        |d|      }t        j                  |d       | j	                  |j
                  d        |d|      }t        j                  |d       | j	                  |j
                  d        |d	|      }t        j                  |d       | j	                  |j
                  d        |d
|      }| j                  t        d      5  t        j                  |d       d d d        k y # 1 sw Y   wxY w)Nc                       e Zd Zd Zd Zd Zy).BaseStartTLS.test_buf_feed_data.<locals>.Protoc                 t    t        |      | _        t        | j                        | _        d| _        || _        y Nr   )	bytearraybuf
memoryviewmvrg   usemv)r   bufsizer   s      r   __init__z7BaseStartTLS.test_buf_feed_data.<locals>.Proto.__init__   s,    $W-$TXX.	"
r   c                 J    | j                   r| j                  S | j                  S r   )r   r   r   r   sizehints     r   
get_bufferz9BaseStartTLS.test_buf_feed_data.<locals>.Proto.get_buffer   s    ::77N88Or   c                     | j                   r#| xj                  | j                  d | z  c_        y | xj                  | j                  d | z  c_        y r   )r   rg   r   r   )r   nsizes     r   r   z=BaseStartTLS.test_buf_feed_data.<locals>.Proto.buffer_updated   s:    ::II%0III&5!11Ir   N)r   r   r   r   r   r   r   r   r   Protor      s    #$2r   r   )FT   s   12345   s   1234   d   r   zempty buffer)r   BufferedProtocolr   _feed_data_to_buffered_protor   rg   r>   RuntimeError)r   r   r   r   s       r   test_buf_feed_datazBaseStartTLS.test_buf_feed_data   sJ   	2G,, 	2( #E!UOE225(CUZZ2!UOE225(CUZZ2!UOE225'BUZZ1!UOE225'BUZZ1#u%E225(CUZZ2!UOE''nE66uhG FE- #, FEs   &F		F	c                 N    d j                   z  t        j                         t        j                          fd} G  fddt        j
                         fd} j                  | j                        5 } j                  j                  t	        j                   ||j                        t        j                               d d d        t        j                        t        j                            j#                                 y # 1 sw Y   IxY w)N   1c                    | j                  j                         | j                  t                    }j	                  t        |      t                     | j                  d       | j                  d       | j                  t                    }j	                  t        |      t                     | j                  t        j                         | j                          y NTserver_side   O
settimeoutTIMEOUTrecv_allrp   r   	start_tlssendallshutdownr   	SHUT_RDWRr*   rv   rg   	HELLO_MSGr   server_contexts     r   servez=BaseStartTLS.test_start_tls_client_reg_proto_1.<locals>.serve#  s    OODLL)==Y0DSYI7NN>tN<LL==Y0DSYI7MM&**+JJLr   c                   *    e Zd Zd Z fdZd Zd Zy)CBaseStartTLS.test_start_tls_client_reg_proto_1.<locals>.ClientProtoc                 .    || _         || _        d| _        y Nr   on_dataon_eofcon_made_cntr   r   r   s      r   r   zLBaseStartTLS.test_start_tls_client_reg_proto_1.<locals>.ClientProto.__init__3      &$$%!r   c                 h    | xj                   dz  c_         j                  | j                   d       y Nr   r   r   r   trr   s     r   r8   zSBaseStartTLS.test_start_tls_client_reg_proto_1.<locals>.ClientProto.connection_made8  *    ""a'"  !3!3Q7r   c                 :    | j                   j                  |       y r   r   
set_resultr   rg   s     r   data_receivedzQBaseStartTLS.test_start_tls_client_reg_proto_1.<locals>.ClientProto.data_received=      ''-r   c                 :    | j                   j                  d       y NTr   r   r   s    r   rK   zPBaseStartTLS.test_start_tls_client_reg_proto_1.<locals>.ClientProto.eof_received@      &&t,r   Nr   r   r   r   r8   r   rK   r   s   r   ClientProtor   2      &
8
.-r   r   c                   K   t        j                  d       d {    	j                  j                         	j                  j                          	j                  j                  fdg|   d {   \  }}|j                         	j                  j                  ||       d {   }	j                   d {   d       |j                          d {    |j                          y 7 7 7 N7 ;7 w)N      ?c                              S r   r   r   r   r   s   r   r   zPBaseStartTLS.test_start_tls_client_reg_proto_1.<locals>.client.<locals>.<lambda>J      GV4r   r   )	r   sleepr   rJ   create_connectionr6   r   r   r*   )
addrr   r   new_trr   r   r   r   client_contextr   s
       @@r   clientz>BaseStartTLS.test_start_tls_client_reg_proto_1.<locals>.clientC  s     --$$$ii--/GYY,,.F9dii994=7;= =IB HHY99..r5.IIF7]D1LL#LLLLN %
= J*sX   D
D AD
<D=8D
5D6D

DD
*D+D
D
D
D
D
timeoutPAYLOAD_SIZEr"   simple_server_sslcontextsimple_client_sslcontextr   r$   
tcp_serverr   r   ru   wait_forr   r   SHORT_TIMEOUTweakrefref
gc_collectr   r   r   r  srvr   r   r   r   s   `   @@@@r   !test_start_tls_client_reg_proto_1z.BaseStartTLS.test_start_tls_client_reg_proto_1  s    4,,,	#<<>#<<>		-'** 	-"	$ __UDLL_9SII((  !1)0)>)>@A : !^4.*+ :9   ADD$c                 N    d j                   z  t        j                         t        j                          fd} G  fddt        j
                         fd} j                  | j                        5 } j                  j                  t	        j                   ||j                        t        j                               d d d        t        j                        t        j                            j#                                 y # 1 sw Y   IxY w)Nr   c                 ^   | j                  j                         | j                  d       | j                  d       | j	                  t                    }j                  t        |      t                     | j                  t        j                         | j                          y r   )r   r   r   r   r   rp   r   r   r   r   r*   r   s     r   r   z>BaseStartTLS.test_create_connection_memory_leak.<locals>.servee  st    OODLL)NN>tN<LL==Y0DSYI7MM&**+JJLr   c                   *    e Zd Zd Z fdZd Zd Zy)DBaseStartTLS.test_create_connection_memory_leak.<locals>.ClientProtoc                 .    || _         || _        d| _        y r   r   r   s      r   r   zMBaseStartTLS.test_create_connection_memory_leak.<locals>.ClientProto.__init__r  r   r   c                 v    || _         | xj                  dz  c_        j                  | j                  d       y r   )r   r   r   r   s     r   r8   zTBaseStartTLS.test_create_connection_memory_leak.<locals>.ClientProto.connection_madew  s1    ""a'"  !3!3Q7r   c                 :    | j                   j                  |       y r   r   r   s     r   r   zRBaseStartTLS.test_create_connection_memory_leak.<locals>.ClientProto.data_received~  r   r   c                 :    | j                   j                  d       y r   r   r   s    r   rK   zQBaseStartTLS.test_create_connection_memory_leak.<locals>.ClientProto.eof_received  r   r   Nr   r   s   r   r   r  q  s    &
8.-r   r   c                   K   t        j                  d       d {    j                  j                         j                  j                          j                  j                  fdg| di d {   \  }}j                   d {   d       |j                          d {    |j                          y 7 7 O7 97 w)Nr   c                              S r   r   r   s   r   r   zQBaseStartTLS.test_create_connection_memory_leak.<locals>.client.<locals>.<lambda>  r   r   r2   r   )r   r   r   rJ   r   r   r6   r*   )	r   r   r   r   r   r   r   r   r   s	      @@r   r  z?BaseStartTLS.test_create_connection_memory_leak.<locals>.client  s     --$$$ii--/GYY,,.F9dii994$7;$"$ $IB 7]D1HHYLLHHJ %
$ +sF   CCA C?C CCC7C8CCCCr  r  r  s   `   @@@@r   "test_create_connection_memory_leakz/BaseStartTLS.test_create_connection_memory_leak_  s    4,,,	#<<>#<<>
		-'** 	-&	  __UDLL_9SII((  !1)0)>)>@A : !^4.*+ :9r  c                    	 d j                   z  t        j                         	t        j                         d 	fd} G  fddt        j
                         G fddt        j                         fd} j                  | j                  	      5 } j                  j                  t	        j                   ||j                         j                  	             d d d        y # 1 sw Y   y xY w)
Nr   r   c                 x   | j                  j                         | j                  t                    }j	                  t        |      t                     | j                  d       | j                  d       | j                  t                    }j	                  t        |      t                     | j                  d       | j                  t                    }j	                  t        |      t                     | j                  t        j                         | j                          y )NTr   r      2r   r   s     r   r   z=BaseStartTLS.test_start_tls_client_buf_proto_1.<locals>.serve  s    OODLL)==Y0DSYI7NN>tN<LL==Y0DSYI7LL==Y0DSYI7MM&**+JJLr   c                   .    e Zd Zd Z fdZd ZfdZy)HBaseStartTLS.test_start_tls_client_buf_proto_1.<locals>.ClientProtoFirstc                 2    || _         t        d      | _        y r   )r   r   r   )r   r   s     r   r   zQBaseStartTLS.test_start_tls_client_buf_proto_1.<locals>.ClientProtoFirst.__init__  s    &$Q<r   c                     dz  y r   r   r   r   client_con_made_callss     r   r8   zXBaseStartTLS.test_start_tls_client_buf_proto_1.<locals>.ClientProtoFirst.connection_made      %*%r   c                     | j                   S r   )r   r   s     r   r   zSBaseStartTLS.test_start_tls_client_buf_proto_1.<locals>.ClientProtoFirst.get_buffer  s    xxr   c                     j                  |d       | j                  j                  t        | j                  d |              y r   )r   r   r   bytesr   )slfr   r   s     r   r   zWBaseStartTLS.test_start_tls_client_buf_proto_1.<locals>.ClientProtoFirst.buffer_updated  s4      *&&uSWWVe_'=>r   N)r   r   r   r   r8   r   r   )r%  r   s   r   ClientProtoFirstr!    s    (+ ?r   r+  c                   *    e Zd Zd Z fdZd Zd Zy)IBaseStartTLS.test_start_tls_client_buf_proto_1.<locals>.ClientProtoSecondc                 .    || _         || _        d| _        y r   r   r   s      r   r   zRBaseStartTLS.test_start_tls_client_buf_proto_1.<locals>.ClientProtoSecond.__init__  r   r   c                     dz  y r   r   r$  s     r   r8   zYBaseStartTLS.test_start_tls_client_buf_proto_1.<locals>.ClientProtoSecond.connection_made  r&  r   c                 :    | j                   j                  |       y r   r   r   s     r   r   zWBaseStartTLS.test_start_tls_client_buf_proto_1.<locals>.ClientProtoSecond.data_received  r   r   c                 :    | j                   j                  d       y r   r   r   s    r   rK   zVBaseStartTLS.test_start_tls_client_buf_proto_1.<locals>.ClientProtoSecond.eof_received  r   r   Nr   )r%  s   r   ClientProtoSecondr-    s    &
+.-r   r2  c                   K   t        j                  d       d {    j                  j                         j                  j                         }j                  j                         } j                  j                  fdg|   d {   \  }}|j                  	       j                  j                  ||       d {   }j                   d {   d       |j                  	       |j                   ||             j                  | d {   d       |j                  	       | d {    |j                          j                  
d       y 7 P7 7 7 7 P7 2w)Nr   c                              S r   r   )r+  on_data1s   r   r   zPBaseStartTLS.test_start_tls_client_buf_proto_1.<locals>.client.<locals>.<lambda>  s    (2r   r   r  r   )
r   r   r   rJ   r   r6   r   r   r   r*   )r   on_data2r   r   r   r   r5  r+  r2  r   r%  r   r   s         @r   r  z>BaseStartTLS.test_start_tls_client_buf_proto_1.<locals>.client  s7    --$$$yy..0Hyy..0HYY,,.F9dii992;59; ;IB HHY99..r5.IIF8^T2LL# 1(F CD8^T2LL#LLLLN
 2A63 %; J+ ,sk   E:E-A6E:E08E:E2E:"E4#AE:%E6&E:E8(E:0E:2E:4E:6E:8E:r  )r  r"   r  r  r   r   r$   r  r   r   ru   r	  r   )
r   r   r  r  r+  r2  r   r%  r   r   s
   `   @@@@@@r   !test_start_tls_client_buf_proto_1z.BaseStartTLS.test_start_tls_client_buf_proto_1  s    4,,,	#<<>#<<> !	&	?w77 	? 	- 0 0 	- 	7 	78 __UDLL_9SII((  !1)-78 :99s   &AC::Dc                     d j                   z  t        j                          j                  j	                          fd} G  fddt
        j                         fd} j                  | j                        5 } j                  j                  t        j                   ||j                        t        j                               d d d        y # 1 sw Y   y xY w)Nr   c                    | j                  j                         | j                  t                    }j	                  t        |      t                     	 j
                  j                  j                  d        | j                  d      }| j                          y # t        $ r Y w xY w# | j                          w xY wN   )
r   r   r   rp   r   r   call_soon_threadsafer   r^   r*   )rv   rg   r   r   server_waits_on_handshakes     r   r   z=BaseStartTLS.test_start_tls_slow_client_cancel.<locals>.serve  s    OODLL)==Y0DSYI7		..-88$@}}[1 

 *  

s$   7B$ $	B0-B3 /B00B3 3Cc                   *    e Zd Zd Z fdZd Zd Zy)CBaseStartTLS.test_start_tls_slow_client_cancel.<locals>.ClientProtoc                 .    || _         || _        d| _        y r   r   r   s      r   r   zLBaseStartTLS.test_start_tls_slow_client_cancel.<locals>.ClientProto.__init__  r   r   c                 h    | xj                   dz  c_         j                  | j                   d       y r   r   r   s     r   r8   zSBaseStartTLS.test_start_tls_slow_client_cancel.<locals>.ClientProto.connection_made  r   r   c                 :    | j                   j                  |       y r   r   r   s     r   r   zQBaseStartTLS.test_start_tls_slow_client_cancel.<locals>.ClientProto.data_received  r   r   c                 :    | j                   j                  d       y r   r   r   s    r   rK   zPBaseStartTLS.test_start_tls_slow_client_cancel.<locals>.ClientProto.eof_received  r   r   Nr   r   s   r   r   r?    r   r   r   c                 .  K   t        j                  d       d {    j                  j                         j                  j                          j                  j                  fdg|   d {   \  }}|j                         	 d {    j                  t         j                        5  t        j                  j                  j                  ||      d       d {    d d d        y 7 7 7 j7 # 1 sw Y   y xY ww)Nr   c                              S r   r   r   s   r   r   zPBaseStartTLS.test_start_tls_slow_client_cancel.<locals>.client.<locals>.<lambda>(  r   r   )
r   r   r   rJ   r   r6   ri   TimeoutErrorr	  r   )
r   r   r   r   r   r   r   r   r   r=  s
      @@r   r  z>BaseStartTLS.test_start_tls_slow_client_cancel.<locals>.client!  s     --$$$ii--/GYY,,.F9dii994=7;= =IB HHY+++""7#7#78&&II''E>B   98 %
=
 , 98s^   DDAD<D=DD#D>5D	3D4D	8
DDDD		DDr  )r  r"   r  r   rJ   r   r$   r  r   ru   r	  r   r   r
  )r   r   r  r  r   r   r   r=  s   `   @@@@r   !test_start_tls_slow_client_cancelz.BaseStartTLS.test_start_tls_slow_client_cancel  s    4,,,	#<<>$(II$;$;$=!		-'** 	-"	 	$ __UDLL_9SII((  !1)0)>)>@A :99s   AC##C,c                 8   	 d j                   z  dt        j                         	t        j                         d  fd G fddt        j
                         	fd fd} j                  j                   |              y )Nr   s   answerc                 r   | j                  j                         | j                  |       | j                  t	                    }j                  t	        |      t	                     | j                         | j                         | j                  t	                    | j                          y r   )	r   r   connectr   rp   r   r   r   r*   )rv   r   rg   ANSWERr   answerr   r   s      r   r  z4BaseStartTLS.test_start_tls_server_1.<locals>.clientA  s|    OODLL)LL==Y0DSYI7NN>*LL#]]3v;/FJJLr   c                   0    e Zd Zd Zd Zd Z fdZd Zy)9BaseStartTLS.test_start_tls_server_1.<locals>.ServerProtoc                 J    || _         || _        || _        d| _        d | _        y r   )on_conon_con_loston_got_hellorg   r9   )r   rP  rQ  rR  s       r   r   zBBaseStartTLS.test_start_tls_server_1.<locals>.ServerProto.__init__O  s'    $#. $0!	!%r   c                 H    || _         | j                  j                  |       y r   )r9   rP  r   r   r   s     r   r8   zIBaseStartTLS.test_start_tls_server_1.<locals>.ServerProto.connection_madeV  s    !#&&r*r   c                     || _         y r   )r9   rT  s     r   replace_transportzKBaseStartTLS.test_start_tls_server_1.<locals>.ServerProto.replace_transportZ  s	    !#r   c                     | xj                   |z  c_         t        | j                         t              k\  r| j                  j                  d        y y r   )rg   rp   rR  r   )r   rg   r   s     r   r   zGBaseStartTLS.test_start_tls_server_1.<locals>.ServerProto.data_received]  s>    		T!	tyy>S^3%%006 4r   c                     d | _         || j                  j                  d        y | j                  j                  |       y r   )r9   rQ  r   set_exception)r   excs     r   r]   zIBaseStartTLS.test_start_tls_server_1.<locals>.ServerProto.connection_lostb  s6    !%;$$//5$$2237r   N)r   r   r   r   r8   rV  r   r]   )r   s   r   ServerProtorN  N  s    &+$7
8r   r[  c                   K   | d {   }|j                         j                  | j                  d       j                  j	                  || 	dj
                         d {   }| j                  |       | d {    |j                         | d {    j                  | j                         |j                          y 7 7 i7 P7 7w)Nr   T)r   r!   )r6   r   rg   r   r   r   rV  r*   )
r   rP  rQ  rR  r   r   rK  r   r   r   s
         r   rj   z2BaseStartTLS.test_start_tls_server_1.<locals>.maini  s     BHHYUZZ-99..E> &*ll / 4 4F ##F+LL UZZ3LLN! 
4  sF   CCAC(C)CCCC2CCCCc            	        K   j                   j                         } j                   j                         }j                   j                         } | ||      j                   j                  fddd       d {   }|j                  d   j	                         j                  	fdj                        5  t        j                   
| ||      j                         d {    d d d        |j                          |j                          d {    j                         y 7 7 I# 1 sw Y   HxY w7 'w)Nc                       S r   r   rc   s   r   r   zHBaseStartTLS.test_start_tls_server_1.<locals>.run_main.<locals>.<lambda>  s    r   z	127.0.0.1r   c                      |       S r   r   )rv   r   r  s    r   r   zHBaseStartTLS.test_start_tls_server_1.<locals>.run_main.<locals>.<lambda>  s    fT4.@r   r  )r   rJ   create_serversocketsgetsockname
tcp_clientr   r   r	  r*   wait_closedr   )rP  rQ  rR  serverr   r   rK  r[  rL  r  rj   r   s       @@r   run_mainz6BaseStartTLS.test_start_tls_server_1.<locals>.run_main|  s    YY,,.F))113K99224L\BE9922{A/ /F>>!$002D!@)- ! 7&&\B LL* * *7 LLN$$&&&VV,/*7 7 'sI   A<ED:AE.D>2D<3D>7+E"E
#E<D>>EE)r  r"   r  r  r   r$   r   ru   )
r   rf  rK  r   r[  rL  r  r   rj   r   s
   ` @@@@@@@@r   test_start_tls_server_1z$BaseStartTLS.test_start_tls_server_18  s{    4,,,	#<<>#<<>	 		8'** 	86	&	- 	-( 			$$XZ0r   c                 P      fd} j                   j                   |              y )Nc                  ~  K   j                  t        d      5  j                  j                  d d d        d {    d d d        t	        j
                         } j                  t        d      5  j                  j                  d d |        d {    d d d        y 7 e# 1 sw Y   dxY w7 # 1 sw Y   y xY ww)NzSSLContext, gotzis not supported)r>   	TypeErrorr   r   r"   r  )sslctxr   s    r   rj   z4BaseStartTLS.test_start_tls_wrong_args.<locals>.main  s     ''	3DEii))$d;;; F  88:F''	3EFii))$f=== GF < FE
 > GFsV   B=!B#B!B# 2B=2!B1B/B1	B=!B##B,(B=/B11B:6B=)r   ru   )r   rj   s   ` r   test_start_tls_wrong_argsz&BaseStartTLS.test_start_tls_wrong_args  s    	> 			$$TV,r   c                 b    t        j                         g  j                  j                  fd       dfd} fd} j	                  |dd      5 } j                  t        j                        5   j                  j                   ||j                               d d d        d d d         j                          j                  g        t        j                        t        j                           j!                                 y # 1 sw Y   txY w# 1 sw Y   xxY w)Nc                 &    j                  |      S r   r   r   s     r   r   z5BaseStartTLS.test_handshake_timeout.<locals>.<lambda>  r   r   Fc                     	 | j                  d       | j                          y # t        $ r dY w xY w# | j                          w xY w)Nr;  Tr   r^   r*   )rv   server_side_aborteds    r   re  z3BaseStartTLS.test_handshake_timeout.<locals>.server  sB    k* 

 * +&*#+ 

s   % 36 36 Ac           	         K   t        j                   j                  j                  t         j                  g| dt
        j                  dd       d {    y 7 w)N r2   server_hostnamer!   r   )r   r	  r   r   r$   r   r
  )r   client_sslctxr   s    r   r  z3BaseStartTLS.test_handshake_timeout.<locals>.client  sb     ""+		++$$AA &$&*1*?*?A   s   AA!AA!r   max_clientsbacklog)r"   r  r   r   r  ri   r   rF  ru   r   r|   r   r  r  r   r  r   )r   re  r  r  rv  r   rq  s   `   @@@r   test_handshake_timeoutz#BaseStartTLS.test_handshake_timeout  s     #;;=		''(NO#		 __V)*%&  (+.""7#7#78		,,VCHH-=> 9	( 	+, 	2&  M2-/* 98	( (s$    D%:,D&D%D"	D%%D.c                    t        j                         g | j                  j                  fd       d }fd}| j	                  |dd      5 }| j                  t        d      5  | j                  j                   ||j                               d d d        d d d        | j                  g        y # 1 sw Y   $xY w# 1 sw Y   (xY w)Nc                 &    j                  |      S r   r   r   s     r   r   zHBaseStartTLS.test_create_connection_ssl_slow_handshake.<locals>.<lambda>  r   r   c                     	 | j                  d       | j                          y # t        $ r Y w xY w# | j                          w xY wr:  rp  )rv   s    r   re  zFBaseStartTLS.test_create_connection_ssl_slow_handshake.<locals>.server  s>    k* 

 *  

s   $ 	03 03 Ac                 V   K   t        j                  | ddd d {   \  }}y 7 w)Nrs  g      ?rt  )r   open_connectionr   rw   rh   rv  s      r   r  zFBaseStartTLS.test_create_connection_ssl_slow_handshake.<locals>.client  s1     #*#:#:! "&)	$+ +NFF +s   )'	)r   rw  zSSL handshake.*is taking longer)
r"   r  r   r   r  r>   r^   ru   r   r   )r   re  r  r  rv  r   s       @@r   )test_create_connection_ssl_slow_handshakez6BaseStartTLS.test_create_connection_ssl_slow_handshake  s    ";;=		''(NO		+ __V)*%&  (+.''*68 		,,VCHH-=>	8	( 	2&8 8	( (s$   C*,B9C9C	>CCc                    | j                   j                  d        t        j                         t        j                  d      fd}fd}| j                  |dd      5 }| j                  t        j                        5  | j                   j                   ||j                               d d d        d d d        y # 1 sw Y   xY w# 1 sw Y   y xY w)Nc                      y r   r   r   r   s     r   r   zLBaseStartTLS.test_create_connection_ssl_failed_certificate.<locals>.<lambda>      $r   F)disable_verifyc                     	 | j                  d       | j	                          y # t        j                  $ r Y &t        $ r Y 0w xY w# | j	                          w xY w)NTr   )r   r2   SSLErrorOSErrorr*   )rv   rk  s    r   re  zJBaseStartTLS.test_create_connection_ssl_failed_certificate.<locals>.server  sY    	 $  & 

 <<   

s+   ' AA
 AA
 AA
 
Ac                 r   K   t        j                  | dt        j                  d d {   \  }}y 7 w)Nrs  rt  )r   r  r   LOOPBACK_TIMEOUTr  s      r   r  zJBaseStartTLS.test_create_connection_ssl_failed_certificate.<locals>.client  s:     #*#:#:! "&-&>&>	$@ @NFF @s   )75	7r   rw  )r   r   r"   r  r  r  ri   r2   SSLCertVerificationErrorru   r   )r   re  r  r  rv  rk  s       @@r   -test_create_connection_ssl_failed_certificatez:BaseStartTLS.test_create_connection_ssl_failed_certificate  s    		''(>?446";; "
		@ __V)*%&  (+.""3#?#?@		,,VCHH-=> A	( ( A@	( (s$   ' C,C3CC		CCc                 t     j                   j                  d        t        j                         t        j                         fd} fd} j                  |dd      5 } j                   j                   ||j                              }d d d         j                  d       y # 1 sw Y   xY w)Nc                      y r   r   r  s     r   r   zBBaseStartTLS.test_start_tls_client_corrupted_ssl.<locals>.<lambda>  r  r   c                 p   | j                         }	 | j                  d       | j                  d       | j                  d       |j	                  d       |j                          | j                          y # t
        j                  $ r Y 6w xY w# |j                          | j                          w xY w)NTr      A
r   s!   please corrupt the SSL connection)dupr   r   r   rm   r2   r  r*   )rv   	orig_sockrk  s     r   re  z@BaseStartTLS.test_start_tls_client_corrupted_ssl.<locals>.server  s    
I $  & V$a CD !

	 <<  !

s$   AA: :BB BB "B5c                   K   t        j                  | dd d {   \  }}j                  |j                          d {   d       |j	                  d       j                  t        j                        5  |j                          d {    d d d        |j                          y7 7 m7 !# 1 sw Y    xY ww)Nrs  )r2   ru  r     BOK)	r   r  r   readliner6   ri   r2   r  r*   )r   rw   rh   rv  r   s      r   r  z@BaseStartTLS.test_start_tls_client_corrupted_ssl.<locals>.client$  s     #*#:#:! "$$ $NFF
 6??#44f=LL""3<<0oo''' 1 LLN$
 5 ( 10sK   CB/%CB19C=B5B3B5C1C3B55B>:Cr   rw  r  )	r   r   r"   r  r  r  ru   r   r   )r   re  r  r  resrv  rk  s   `    @@r   #test_start_tls_client_corrupted_sslz0BaseStartTLS.test_start_tls_client_corrupted_ssl  s    		''(>?446";;=		 __V)*%&  (+.))..vchh/?@C	( 	d#( (s   ',B..B7N)r   r   r   r  r   LONG_TIMEOUTr   r   r   r  r  r   skip_if_tcp_blackholer7  rG  rg  rl  rz  r  r  r  r   r   r   r   r      s    L""G"-H^@,D>,@ ((Y8 )Y8v;Az ((W1 )W1r	-.+`'B?B)$r   r   c                       e Zd Zd Zy)SelectorStartTLSTestsc                 *    t        j                         S r   )r   SelectorEventLoopr   s    r   r   zSelectorStartTLSTests.new_loop>      ((**r   Nr   r   r   r   r   r   r   r  r  ;  s    +r   r  ProactorEventLoopzWindows onlyc                       e Zd Zd Zy)ProactorStartTLSTestsc                 *    t        j                         S r   )r   r  r   s    r   r   zProactorStartTLSTests.new_loopF  r  r   Nr  r   r   r   r  r  B  s    +r   r  __main__)!__doc__rW   r   unittestr  testr   test.supportr   r   r2   ImportErrorr   r   r   r   test.test_asyncior	   r"   r
   
func_testsr   skipIfTestCaser   FunctionalTestCaseMixinr   r  
skipUnlesshasattrr  r   rj   r   r   r   <module>r     sB   $      &      1 6( o.B1Z00 B1 /B1TR	$:55 R	$j o.+L(*;*; + /+ o.WW&9:NK+L(*;*; + L /+ zHMMO }  
Cs   D" "D-,D-