ϪfdZddlmZddlmZmZddlmZddlm Z ddl m Z m Z m Z mZddlmZ ddlmZdd lmZeZdd lmZGd d ej0ZGddZeej6GddeZGddeee Zej?ejAy #e$rd ZYwxYw)z( Tests for L{twisted.internet._newtls}. ) interfaces)ConnectableProtocolrunProtocolsWithReactor)ReactorBuilder) TCPCreator)ContextGeneratingMixin SSLCreatorStartTLSClientCreatorTLSMixin)unittest)_newtls)tlsN) implementerceZdZdZesdZdZy)BypassTLSTestsz4 Tests for the L{_newtls._BypassTLS} class. z.FakeTransportc(j|yN)append)self _connDoneresults C/usr/lib/python3/dist-packages/twisted/internet/test/test_newtls.pyloseConnectionzSBypassTLSTests.test_loseConnectionPassThrough..FakeTransport.loseConnection4s i(N)__name__ __module__ __qualname__r)defaultrsr FakeTransportr3s /6 )rr"N)objectr _BypassTLSr assertEqual)rr"bypass notDefaultr!rs @@rtest_loseConnectionPassThroughz-BypassTLSTests.test_loseConnectionPassThrough*s} ( ) )##M=?C  '+X j) ':!67rN)rrr __doc__r skipr(rrrr"s M8rrc"eZdZdZdZdZdZy) FakeProducerz' A producer that does nothing. cyrr+rs rpauseProducingzFakeProducer.pauseProducingH rcyrr+r/s rresumeProducingzFakeProducer.resumeProducingKr1rcyrr+r/s r stopProducingzFakeProducer.stopProducingNr1rN)rrr r)r0r3r5r+rrr-r-Cs   rr-ceZdZdZdZdZy)ProducerProtocolzy Register a producer, unregister it, and verify the producer hooks up to innards of C{TLSMemoryBIOProtocol}. c ||_||_yr)producerr)rr9rs r__init__zProducerProtocol.__init__Ys   rc"t|jjtjs t d|jj |jd|jj|jjjj|jj|jj|jjj|jjy)Nz#TLSMemoryBIOProtocol not hooked up.T) isinstance transportprotocolrBufferingTLSTransport RuntimeErrorregisterProducerr9rr _producerunregisterProducerrr/s rhandshakeCompletedz#ProducerProtocol.handshakeCompleted]s$..1133L3LMDE E '' t< 4>>22<<FFG ))+ 4>>22<<= %%'rN)rrr r)r:rDr+rrr7r7Rs  (rr7c6eZdZdZesdZdZdZdZdZ dZ y) ProducerTestsMixinzM Test the new TLS code integrates C{TLSMemoryBIOProtocol} correctly. z)Could not import twisted.internet._newtlscg}t}t|tt||t |j ||dgy)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-rrr7r r%rrr9s rtest_producerSSLFromStartz,ProducerTestsMixin.test_producerSSLFromStarttsG >   ! Xv . L  (D!12rcg}t}t|tt||t |j ||dgy)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-rrr7r r%rHs rtest_producerAfterStartTLSz-ProducerTestsMixin.test_producerAfterStartTLSsH >   ! Xv . ! #  (D!12rc|j|jgtGfddt}Gfddt}t |||t |j gy)z When a producer is registered, and then startTLS is called, the producer is re-registered with the C{TLSMemoryBIOProtocol}. ceZdZfdZy)MProducerTestsMixin.startTLSAfterRegisterProducer..RegisterTLSProtocolc|jj|jjrij|jjj j j|jj j n|j|jjj j j j|jj j j |jj|jjyr) r=rAstartTLSrr>rBr9rCr)rr9r serverContext streamings rconnectionMadez\ProducerTestsMixin.startTLSAfterRegisterProducer..RegisterTLSProtocol.connectionMades//)D'' 6MM$.."9"9"C"C"M"MNMM$.."9"9"C"CDMM$.."9"9"C"C"M"M"W"WXMM$.."9"9"C"C"M"MN113--/rNrrr rS)r9rrQrRsrRegisterTLSProtocolrNs  0 0rrUceZdZfdZy)JProducerTestsMixin.startTLSAfterRegisterProducer..StartTLSProtocolc<|jjyr)r=rP)r clientContexts rrSzYProducerTestsMixin.startTLSAfterRegisterProducer..StartTLSProtocol.connectionMades'' 6rNrT)rYsrStartTLSProtocolrWs 7rrZN)getClientContextgetServerContextr-rrrr%)rrRrUrZrYr9rrQs ` @@@@rstartTLSAfterRegisterProducerz0ProducerTestsMixin.startTLSAfterRegisterProducers --/ --/ > 0 0"5 0" 72 7 %')9);Z\  (H!56rc&|jdy)z When a streaming producer is registered, and then startTLS is called, the producer is re-registered with the C{TLSMemoryBIOProtocol}. TNr]r/s r+test_startTLSAfterRegisterProducerStreamingz>ProducerTestsMixin.test_startTLSAfterRegisterProducerStreamings **40rc&|jdy)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_startTLSAfterRegisterProducerNonStreamings **51rN) rrr r)r r*rIrKr]r`rbr+rrrFrFls+ :3"3""7H12rrF)!r)twisted.internetr&twisted.internet.test.connectionmixinsrr#twisted.internet.test.reactormixinsrtwisted.internet.test.test_tcprtwisted.internet.test.test_tlsrr r r twisted.trialr r __newtlstwisted.protocolsr ImportErrorzope.interfacerTestCaserr-IHandshakeListenerr7rFglobalsupdatemakeTestCaseClassesr+rrrrs (?5 #4%G&8X&&8B    Z * *+(*(,(2[23I[2| #779:_Gs B55B?>B?