
    Yf                        d Z ddlmZ ddlmZmZ ddlmZ ddlm	Z	 ddl
mZmZmZmZ ddlmZ 	 ddlmZ dd	lmZ eZn# e$ r d
ZY nw xY wddlmZ  G d dej                  Z G d d          Z eej                   G d de                      Z G d deee          Z e                                e                                            d
S )z(
Tests for L{twisted.internet._newtls}.
    )
interfaces)ConnectableProtocolrunProtocolsWithReactor)ReactorBuilder)
TCPCreator)ContextGeneratingMixin
SSLCreatorStartTLSClientCreatorTLSMixin)unittest)_newtls)tlsN)implementerc                        e Zd ZdZesdZd ZdS )BypassTLSTestsz4
    Tests for the L{_newtls._BypassTLS} class.
    z<Couldn't import _newtls, perhaps pyOpenSSL is old or missingc                 \   t                      g  G fdd          }t                              | |                      }|                                 |                     g           t                      }|                    |           |                     |g           dS )z
        C{_BypassTLS.loseConnection} calls C{loseConnection} on the base
        class, while preserving any default argument in the base class'
        C{loseConnection} implementation.
        c                       e Zd Z ffd	ZdS )DBypassTLSTests.test_loseConnectionPassThrough.<locals>.FakeTransportc                 2                         |           d S N)append)self	_connDoneresults     S/var/www/html/env/lib/python3.11/site-packages/twisted/internet/test/test_newtls.pyloseConnectionzSBypassTLSTests.test_loseConnectionPassThrough.<locals>.FakeTransport.loseConnection4   s    i(((((    N)__name__
__module____qualname__r   )defaultr   s   r   FakeTransportr   3   s6        /6 ) ) ) ) ) ) ) )r   r"   N)objectr   
_BypassTLSr   assertEqual)r   r"   bypass
notDefaultr!   r   s       @@r   test_loseConnectionPassThroughz-BypassTLSTests.test_loseConnectionPassThrough*   s     ((	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) ##M==??CC 	'+++ XX
j)))':!677777r   N)r   r   r    __doc__r   skipr(    r   r   r   r   "   s=           NM8 8 8 8 8r   r   c                   $    e Zd ZdZd Zd Zd ZdS )FakeProducerz'
    A producer that does nothing.
    c                     d S r   r+   r   s    r   pauseProducingzFakeProducer.pauseProducingH       r   c                     d S r   r+   r/   s    r   resumeProducingzFakeProducer.resumeProducingK   r1   r   c                     d S r   r+   r/   s    r   stopProducingzFakeProducer.stopProducingN   r1   r   N)r   r   r    r)   r0   r3   r5   r+   r   r   r-   r-   C   sK                 r   r-   c                       e Zd ZdZd Zd ZdS )ProducerProtocolzy
    Register a producer, unregister it, and verify the producer hooks up to
    innards of C{TLSMemoryBIOProtocol}.
    c                 "    || _         || _        d S r   )producerr   )r   r9   r   s      r   __init__zProducerProtocol.__init__Y   s     r   c                    t          | j        j        t          j                  st          d          | j                            | j        d           | j        	                    | j        j        j
        j
                   | j                                         | j        	                    | j        j        j
                   | j                                         d S )Nz#TLSMemoryBIOProtocol not hooked up.T)
isinstance	transportprotocolr   BufferingTLSTransportRuntimeErrorregisterProducerr9   r   r   	_producerunregisterProducerr   r/   s    r   handshakeCompletedz#ProducerProtocol.handshakeCompleted]   s    $.133LMM 	FDEEE''t<<<4>2<FGGG))+++4>2<===%%'''''r   N)r   r   r    r)   r:   rD   r+   r   r   r7   r7   R   s<         
  ( ( ( ( (r   r7   c                   8    e Zd ZdZesdZd Zd Zd Zd Z	d Z
dS )	ProducerTestsMixinzM
    Test the new TLS code integrates C{TLSMemoryBIOProtocol} correctly.
    z)Could not import twisted.internet._newtlsc                     g }t                      }t          | t                      t          ||          t	                                 |                     ||dg           dS )z
        C{registerProducer} and C{unregisterProducer} on TLS transports
        created as SSL from the get go are passed to the
        C{TLSMemoryBIOProtocol}, not the underlying transport directly.
        N)r-   r   r   r7   r	   r%   r   r   r9   s      r   test_producerSSLFromStartz,ProducerTestsMixin.test_producerSSLFromStartt   sg     >>!!Xv..LL		
 	
 	
 	(D!122222r   c                     g }t                      }t          | t                      t          ||          t	                                 |                     ||dg           dS )z
        C{registerProducer} and C{unregisterProducer} on TLS transports
        created by C{startTLS} are passed to the C{TLSMemoryBIOProtocol}, not
        the underlying transport directly.
        N)r-   r   r   r7   r
   r%   rH   s      r   test_producerAfterStartTLSz-ProducerTestsMixin.test_producerAfterStartTLS   si     >>!!Xv..!##		
 	
 	
 	(D!122222r   c                 f   |                                  |                                 g t                       G fddt                    } G fddt                    }t	          |  |             |            t                                 |                     g           dS )z
        When a producer is registered, and then startTLS is called,
        the producer is re-registered with the C{TLSMemoryBIOProtocol}.
        c                        e Zd Z fdZdS )MProducerTestsMixin.startTLSAfterRegisterProducer.<locals>.RegisterTLSProtocolc                 $   | j                                        | j                                        rN                    | j         j        j        j                                       | j         j        j                   nW                    | j         j        j        j        j                                       | j         j        j        j                   | j                                          | j                                          d S r   )	r=   rA   startTLSr   r>   rB   r9   rC   r   )r   r9   r   serverContext	streamings    r   connectionMadez\ProducerTestsMixin.startTLSAfterRegisterProducer.<locals>.RegisterTLSProtocol.connectionMade   s    //)DDD''666  OMM$."9"C"MNNNMM$."9"CDDDD MM$."9"C"M"WXXXMM$."9"C"MNNN11333--/////r   Nr   r   r    rS   )r9   r   rQ   rR   s   r   RegisterTLSProtocolrN      s=        0 0 0 0 0 0 0 0 0 0r   rU   c                       e Zd Z fdZdS )JProducerTestsMixin.startTLSAfterRegisterProducer.<locals>.StartTLSProtocolc                 <    | j                                        d S r   )r=   rP   )r   clientContexts    r   rS   zYProducerTestsMixin.startTLSAfterRegisterProducer.<locals>.StartTLSProtocol.connectionMade   s    ''66666r   NrT   )rY   s   r   StartTLSProtocolrW      s.        7 7 7 7 7 7 7r   rZ   N)getClientContextgetServerContextr-   r   r   r   r%   )r   rR   rU   rZ   rY   r9   r   rQ   s    `  @@@@r   startTLSAfterRegisterProducerz0ProducerTestsMixin.startTLSAfterRegisterProducer   s
   
 --//--//>>	0 	0 	0 	0 	0 	0 	0 	0 	0 	0"5 	0 	0 	0"	7 	7 	7 	7 	7 	7 	72 	7 	7 	7 	 %%'')9)9););Z\\	
 	
 	
 	(H!566666r   c                 0    |                      d           dS )z
        When a streaming producer is registered, and then startTLS is called,
        the producer is re-registered with the C{TLSMemoryBIOProtocol}.
        TNr]   r/   s    r   +test_startTLSAfterRegisterProducerStreamingz>ProducerTestsMixin.test_startTLSAfterRegisterProducerStreaming   s    
 	**400000r   c                 0    |                      d           dS )z
        When a non-streaming producer is registered, and then startTLS is
        called, the producer is re-registered with the
        C{TLSMemoryBIOProtocol}.
        FNr_   r/   s    r   .test_startTLSAfterRegisterProducerNonStreamingzAProducerTestsMixin.test_startTLSAfterRegisterProducerNonStreaming   s     	**511111r   N)r   r   r    r)   r   r*   rI   rK   r]   r`   rb   r+   r   r   rF   rF   l   sy           ;:3 3 3"3 3 3""7 "7 "7H1 1 12 2 2 2 2r   rF   )!r)   twisted.internetr   &twisted.internet.test.connectionmixinsr   r   #twisted.internet.test.reactormixinsr   twisted.internet.test.test_tcpr   twisted.internet.test.test_tlsr   r	   r
   r   twisted.trialr   r   __newtlstwisted.protocolsr   ImportErrorzope.interfacer   TestCaser   r-   IHandshakeListenerr7   rF   globalsupdatemakeTestCaseClassesr+   r   r   <module>rr      s/   
 ( ' ' ' ' '        ? > > > > > 5 5 5 5 5 5            # " " " " "444444%%%%%% GG    GGG ' & & & & &8 8 8 8 8X& 8 8 8B        Z*++( ( ( ( (* ( ( ,+(2[2 [2 [2 [2 [23I [2 [2 [2| 		  #7799 : : : : :s   ? A	A	