
    z%ih                     ^   	 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j0                        Z ej*                  e	du d       G d deej,                               Z ej*                  e	du d       ej6                   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)    N)support)socket_helper)mock)log)	protocols)sslproto)utils)
functionalc                  .    t        j                  d        y N)asyncioset_event_loop_policy     S/home/uftp/.pyenv/versions/3.12.0/lib/python3.12/test/test_asyncio/test_sslproto.pytearDownModuler      s    !!$'r   zNo ssl modulec                   t     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 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                  _        |||_        ||_        |j                  |       |S r   )	r   MocksslSSLWantReadErrorreadside_effectr/   _sslobjconnection_made)r   r,   r/   	transportsslobjs        r   r7   z&SslProtoHandshakeTests.connection_made-   sT    IIK	"%"6"6#".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_zero8   si    113
IIK	##J0CD 	:  Iz678:	: 	: 	:   %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_negative@   si    113
IIK	##J0CD 	<  Iz67:<	< 	< 	<rB   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-   r7   r   r1   r2   r3   eof_receivedr"   run_brieflyassertIsInstance	exceptionConnectionResetErrorr   r   r,   s      r   test_eof_received_waiterz/SslProtoHandshakeTests.test_eof_received_waiterH   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NrG   )
r   rH   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_errorS   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 rF   )r   rH   r-   r7   r   r1   r2   r3   connection_lostConnectionAbortedErrorr"   rJ   rK   rL   rN   s      r   test_connection_lostz+SslProtoHandshakeTests.test_connection_lostb   s     ((*%%V%4	s/C/CD 	 	
 	!!"89tyy)f..02HIr   c                    | j                   j                         }| j                  |      }| j                  |t	        j
                  t        j                              }t        j                  | j                          |j                  j                          | j                  |j                  j                         y rF   )r   rH   r-   r7   r   r1   r2   r3   r"   rJ   r'   r*   
assertTrueabortcalled)r   r   r,   r8   s       r   test_close_during_handshakez2SslProtoHandshakeTests.test_close_during_handshakeo   s    ((*%%V%4	((s/C/CD ) 
	 	tyy)  &&(	../r   c                    | j                   j                         }| j                  |      }| j                  |j	                  d             t               }| j                  |j	                  d|      |       | j                  |       | j                  |j	                  d             |j                  d        | j                  |j	                  d             y )NrG   socket)
r   rH   r-   assertIsNone_get_extra_infoobjectr&   r7   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 rQ   )
r   rH   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-   r7   r'   r*   re   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-   r7   r'   r*   re   writers   s      r   test_write_after_closingz/SslProtoHandshakeTests.test_write_after_closing   sK    %%'	Y')) 	&,,w/0r   )__name__
__module____qualname__r   r-   r7   rA   rD   rO   rY   r]   rb   rj   ro   ru   rx   __classcell__)r   s   @r   r   r      sR    '
 &*  :> 	:<	H+J0	?>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mvdata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   r   r   r   )r   nsizes     r   rr   z=BaseStartTLS.test_buf_feed_data.<locals>.Proto.buffer_updated   s:    ::II%0III&5!11Ir   N)ry   rz   r{   r   r   rr   r   r   r   Protor      s    #$2r   r   )FT   s   12345   s   1234   d   r   zempty buffer)r   BufferedProtocolr   _feed_data_to_buffered_protoassertEqualr   r=   RuntimeError)r   r   r   r   s       r   test_buf_feed_datazBaseStartTLS.test_buf_feed_data   s]   	2G,, 	2( # 	H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 H66uhGH H-	H,H Hs   &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_alllenr   	start_tlssendallshutdownrd   	SHUT_RDWRr*   sockr   	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__       &$$%!r   c                 h    | xj                   dz  c_         j                  | j                   d       y Nr   r   r   r   trr   s     r   r7   zSBaseStartTLS.test_start_tls_client_reg_proto_1.<locals>.ClientProto.connection_made   *    ""a'"  !3!3Q7r   c                 :    | j                   j                  |       y r   r   
set_resultr   r   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   rI   zPBaseStartTLS.test_start_tls_client_reg_proto_1.<locals>.ClientProto.eof_received      &&t,r   Nry   rz   r{   r   r7   r   rI   r   s   r   ClientProtor          &
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   <lambda>zPBaseStartTLS.test_start_tls_client_reg_proto_1.<locals>.client.<locals>.<lambda>      GV4 r   r   )	r   sleepr   rH   create_connectionrw   r   r   r*   )
addrr   r   new_trr   r   r   r   client_contextr   s
       @@r   clientz>BaseStartTLS.test_start_tls_client_reg_proto_1.<locals>.client  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   run_until_completewait_forr   r   SHORT_TIMEOUTweakrefref
gc_collectre   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_9 	ASII((  !1)0)>)>@A	A !^4.*+	A 	A   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   r   r   r   rd   r   r*   r   s     r   r   z>BaseStartTLS.test_create_connection_memory_leak.<locals>.serve(  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__5  r   r   c                 v    || _         | xj                  dz  c_        j                  | j                  d       y r   )r   r   r   r   s     r   r7   zTBaseStartTLS.test_create_connection_memory_leak.<locals>.ClientProto.connection_made:  s1    ""a'"  !3!3Q7r   c                 :    | j                   j                  |       y r   r   r   s     r   r   zRBaseStartTLS.test_create_connection_memory_leak.<locals>.ClientProto.data_receivedA  r   r   c                 :    | j                   j                  d       y r   r   r   s    r   rI   zQBaseStartTLS.test_create_connection_memory_leak.<locals>.ClientProto.eof_receivedD  r   r   Nr   r   s   r   r   r   4  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>N  r   r   r2   r   )r   r   r   rH   r   r   rw   r*   )	r   r   r   r   r   r   r   r   r   s	      @@r   r   z?BaseStartTLS.test_create_connection_memory_leak.<locals>.clientG  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_9 	ASII((  !1)0)>)>@A	A !^4.*+	A 	Ar   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>.servej  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   r7   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   rr   zWBaseStartTLS.test_start_tls_client_buf_proto_1.<locals>.ClientProtoFirst.buffer_updated  s4      *&&uSWWVe_'=>r   N)ry   rz   r{   r   r7   r   rr   )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   r7   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   rI   zVBaseStartTLS.test_start_tls_client_buf_proto_1.<locals>.ClientProtoSecond.eof_received  r   r   Nr   )r  s   r   ClientProtoSecondr
    s    &
+.-r   r  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    (2 r   r   r   r   )
r   r   r   rH   r   rw   r   r   rl   r*   )r   on_data2r   r   r   r   r  r  r  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   r   r   r   )
r   r   r   r   r  r  r   r  r   r   s
   `   @@@@@@r   !test_start_tls_client_buf_proto_1z.BaseStartTLS.test_start_tls_client_buf_proto_1b  s    4,,,	#<<>#<<> !	&	?w77 	? 	- 0 0 	- 	7 	78 __UDLL_9 	8SII((  !1)-78	8 	8 	8s   &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   r   r   r   call_soon_threadsafer   r\   r*   )r   r   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   r7   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   rI   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   rH   r   rw   assertRaises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    %
=
 , s^   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   rH   r   r$   r   r   r   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_9 	ASII((  !1)0)>)>@A	A 	A 	As   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   r   r   r   r   r*   )r   r   r   ANSWERr   answerr   r   s      r   r   z4BaseStartTLS.test_start_tls_server_1.<locals>.client  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_hellor   r8   )r   r.  r/  r0  s       r   r   zBBaseStartTLS.test_start_tls_server_1.<locals>.ServerProto.__init__  s'    $#. $0!	!%r   c                 H    || _         | j                  j                  |       y r   )r8   r.  r   r   r   s     r   r7   zIBaseStartTLS.test_start_tls_server_1.<locals>.ServerProto.connection_made  s    !#&&r*r   c                     || _         y r   )r8   r2  s     r   replace_transportzKBaseStartTLS.test_start_tls_server_1.<locals>.ServerProto.replace_transport  s	    !#r   c                     | xj                   |z  c_         t        | j                         t              k\  r| j                  j                  d        y y r   )r   r   r0  r   )r   r   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   )r8   r/  r   set_exception)r   excs     r   r[   zIBaseStartTLS.test_start_tls_server_1.<locals>.ServerProto.connection_lost%  s6    !%;$$//5$$2237r   N)ry   rz   r{   r   r7   r4  r   r[   )r   s   r   ServerProtor,    s    &+$7
8r   r9  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!   )rw   r   r   r   r   r   r4  r*   )
r   r.  r/  r0  r   r   r)  r   r   r   s
         r   mainz2BaseStartTLS.test_start_tls_server_1.<locals>.main,  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   )r   s   r   r   zHBaseStartTLS.test_start_tls_server_1.<locals>.run_main.<locals>.<lambda>F  s     r   z	127.0.0.1r   c                      |       S r   r   )r   r   r   s    r   r   zHBaseStartTLS.test_start_tls_server_1.<locals>.run_main.<locals>.<lambda>I  s    fT4.@ r   r   )r   rH   create_serversocketsgetsockname
tcp_clientr   r   r   r*   wait_closedr   )r.  r/  r0  serverr   r   r)  r9  r*  r   r;  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* * ** LLN$$&&&VV,/** * '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   r   )
r   rE  r)  r   r9  r*  r   r   r;  r   s
   ` @@@@@@@@r   test_start_tls_server_1z$BaseStartTLS.test_start_tls_server_1  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   r;  z4BaseStartTLS.test_start_tls_wrong_args.<locals>.mainV  s     ''	3DE <ii))$d;;;<  88:F''	3EF >ii))$f===> > << <
 >> >sV   B=!B#B!B# 2B=2!B1B/B1	B=!B##B,(B=/B11B:6B=)r   r   )r   r;  s   ` r   test_start_tls_wrong_argsz&BaseStartTLS.test_start_tls_wrong_argsU  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   appendr   ctxmessagess     r   r   z5BaseStartTLS.test_handshake_timeout.<locals>.<lambda>f      (//#:N r   Fc                     	 | j                  d       | j                          y # t        $ r dY w xY w# | j                          w xY w)Nr  Tr   r\   r*   )r   server_side_aborteds    r   rD  z3BaseStartTLS.test_handshake_timeout.<locals>.serverj  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>.clients  sb     ""+		++$$AA &$&*1*?*?A   s   AA!AA!r   max_clientsbacklog)r"   r   r   set_exception_handlerr   r#  r   r$  r   r   r_   r   r   r   r   r   re   )r   rD  r   r   r[  rR  rV  s   `   @@@r   test_handshake_timeoutz#BaseStartTLS.test_handshake_timeout`  s     #;;=		''(NO#		 __V)*%&  ( 	?+.""7#7#78 ?		,,VCHH-=>?		? 	+, 	2&  M2-/*? ?		? 	?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   rN  rP  s     r   r   zHBaseStartTLS.test_create_connection_ssl_slow_handshake.<locals>.<lambda>  rS  r   c                     	 | j                  d       | j                          y # t        $ r Y w xY w# | j                          w xY wr  rU  )r   s    r   rD  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)NrX  g      ?rY  )r   open_connectionr   readerwriterr[  s      r   r   zFBaseStartTLS.test_create_connection_ssl_slow_handshake.<locals>.client  s1     #*#:#:! "&)	$+ +NFF +s   )'	)r   r\  zSSL handshake.*is taking longer)
r"   r   r   r_  r   r=   r\   r   r   r   )r   rD  r   r   r[  rR  s       @@r   )test_create_connection_ssl_slow_handshakez6BaseStartTLS.test_create_connection_ssl_slow_handshake  s    ";;=		''(NO		+ __V)*%&  ( 	?+.''*68 ? 		,,VCHH-=>	?		? 	2&? ?		? 	?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   rQ  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*   )r   rJ  s    r   rD  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)NrX  rY  )r   re  r   LOOPBACK_TIMEOUTrf  s      r   r   zJBaseStartTLS.test_create_connection_ssl_failed_certificate.<locals>.client  s:     #*#:#:! "&-&>&>	$@ @NFF @s   )75	7r   r\  )r   r_  r"   r   r   r   r#  r2   SSLCertVerificationErrorr   r   )r   rD  r   r   r[  rJ  s       @@r   -test_create_connection_ssl_failed_certificatez:BaseStartTLS.test_create_connection_ssl_failed_certificate  s    		''(>?446";; "
		@ __V)*%&  ( 	?+.""3#?#?@ ?		,,VCHH-=>?		? 	?? ?		? 	?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   rl  s     r   r   zBBaseStartTLS.test_start_tls_client_corrupted_ssl.<locals>.<lambda>  rm  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   sendr2   rp  r*   )r   	orig_sockrJ  s     r   rD  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)NrX  )r2   rZ  ry     BOK)	r   re  r   readlinerw   r#  r2   rp  r*   )r   rg  rh  r[  r   s      r   r   z@BaseStartTLS.test_start_tls_client_corrupted_ssl.<locals>.client  s     #*#:#:! "$$ $NFF
 6??#44f=LL""3<<0 (oo'''( LLN$
 5 (( (sK   CB/%CB19C=B5B3B5C1C3B55B>:Cr   r\  r  )	r   r_  r"   r   r   r   r   r   r   )r   rD  r   r   resr[  rJ  s   `    @@r   #test_start_tls_client_corrupted_sslz0BaseStartTLS.test_start_tls_client_corrupted_ssl  s    		''(>?446";;=		 __V)*%&  ( 	A+.))..vchh/?@C		A 	d#	A 	As   ',B..B7N)ry   rz   r{   r   r   LONG_TIMEOUTr   r   r   r   r   r   skip_if_tcp_blackholer  r%  rF  rK  r`  ri  ru  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ry   rz   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_loop	  r  r   Nr  r   r   r   r  r    s    +r   r  __main__) rU   rd   unittestr   testr   test.supportr   r   r2   ImportErrorr   r   r   r   test.test_asyncior	   r"   r
   
func_testsr   skipIfTestCaser   FunctionalTestCaseMixinr~   r  
skipUnlesshasattrr  ry   r;  r   r   r   <module>r     sB   $      &      1 6( o.E1Z00 E1 /E1ZR	$:55 R	$j o.+L(*;*; + /+ o.WW&9:NK+L(*;*; + L /+ zHMMO C  
Cs   D! !D,+D,