
    Vh                        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ddlmZ  G d dej0                        Z G d d      Z eej6                         G d de             Z G d deee      Z e       j?                  ejA                                y
# e$ r d
ZY w xY w)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y)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        j                  | |             }|j                          | j	                  g       t               }|j                  |       | j	                  |g       y)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W  ffd	Zy)DBypassTLSTests.test_loseConnectionPassThrough.<locals>.FakeTransportc                 (    j                  |       y N)append)self	_connDoneresults     Q/home/dcms/DCMS/lib/python3.12/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   s    /6 )r   r"   N)objectr   
_BypassTLSr   assertEqual)r   r"   bypass
notDefaultr!   r   s       @@r   test_loseConnectionPassThroughz-BypassTLSTests.test_loseConnectionPassThrough*   s}     (	) 	) ##M=?C 	'+ X
j)':!67r   N)r   r   r    __doc__r   skipr(    r   r   r   r   "   s     M8r   r   c                   "    e Zd ZdZd Zd Zd Zy)FakeProducerz'
    A producer that does nothing.
    c                      y r   r+   r   s    r   pauseProducingzFakeProducer.pauseProducingH       r   c                      y r   r+   r/   s    r   resumeProducingzFakeProducer.resumeProducingK   r1   r   c                      y r   r+   r/   s    r   stopProducingzFakeProducer.stopProducingN   r1   r   N)r   r   r    r)   r0   r3   r5   r+   r   r   r-   r-   C   s    r   r-   c                       e Zd ZdZd Zd Zy)ProducerProtocolzy
    Register a producer, unregister it, and verify the producer hooks up to
    innards of C{TLSMemoryBIOProtocol}.
    c                      || _         || _        y 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                  | j                  d       | j                  j                  | j                  j                  j                  j                         | j                  j                          | j                  j                  | j                  j                  j                         | j                  j                          y )Nz#TLSMemoryBIOProtocol not hooked up.T)
isinstance	transportprotocolr   BufferingTLSTransportRuntimeErrorregisterProducerr9   r   r   	_producerunregisterProducerr   r/   s    r   handshakeCompletedz#ProducerProtocol.handshakeCompleted]   s    $..1133L3LMDEE''t<4>>22<<FFG))+4>>22<<=%%'r   N)r   r   r    r)   r:   rD   r+   r   r   r7   r7   R   s    
(r   r7   c                   6    e Zd ZdZesdZd Zd Zd Zd Z	d Z
y)	ProducerTestsMixinzM
    Test the new TLS code integrates C{TLSMemoryBIOProtocol} correctly.
    z)Could not import twisted.internet._newtlsc                     g }t               }t        | t               t        ||      t	                      | j                  ||dg       y)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.L		
 	(D!12r   c                     g }t               }t        | t               t        ||      t	                      | j                  ||dg       y)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   sH     >!Xv.!#		
 	(D!12r   c                    | j                         | j                         g t                G fddt              } G fddt              }t	        |  |        |       t                      | j                  g       y)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y)MProducerTestsMixin.startTLSAfterRegisterProducer.<locals>.RegisterTLSProtocolc                    | j                   j                         | j                   j                         rij                  | j                   j                  j
                  j
                         j                  | j                   j                  j
                         n|j                  | j                   j                  j
                  j
                  j
                         j                  | j                   j                  j
                  j
                         | j                   j                          | j                   j                          y r   )	r=   rA   startTLSr   r>   rB   r9   rC   r   )r   r9   r   serverContext	streamings    r   connectionMadez\ProducerTestsMixin.startTLSAfterRegisterProducer.<locals>.RegisterTLSProtocol.connectionMade   s    //)D''6 MM$.."9"9"C"C"M"MNMM$.."9"9"C"CD MM$.."9"9"C"C"M"M"W"WXMM$.."9"9"C"C"M"MN113--/r   Nr   r   r    rS   )r9   r   rQ   rR   s   r   RegisterTLSProtocolrN      s    0 0r   rU   c                       e Zd Z fdZy)JProducerTestsMixin.startTLSAfterRegisterProducer.<locals>.StartTLSProtocolc                 <    | j                   j                         y r   )r=   rP   )r   clientContexts    r   rS   zYProducerTestsMixin.startTLSAfterRegisterProducer.<locals>.StartTLSProtocol.connectionMade   s    ''6r   NrT   )rY   s   r   StartTLSProtocolrW      s    7r   rZ   N)getClientContextgetServerContextr-   r   r   r   r%   )r   rR   rU   rZ   rY   r9   r   rQ   s    `  @@@@r   startTLSAfterRegisterProducerz0ProducerTestsMixin.startTLSAfterRegisterProducer   s    
 --/--/>	0 	0"5 	0"	72 	7 	 %')9);Z\	
 	(H!56r   c                 &    | j                  d       y)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0r   c                 &    | j                  d       y)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1r   N)r   r   r    r)   r   r*   rI   rK   r]   r`   rb   r+   r   r   rF   rF   l   s+     :3"3""7H1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  #4% G &8X&& 8B  Z**+(* ( ,(2[23I [2| 	  #779 :_  Gs   B5 5B?>B?