Ë
    oj…  ã                   ó„  — 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     €úC/usr/lib/python3/dist-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Ñ1´3×3LÑ3LÔ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   € ð ˆÜ“>ˆäØÜÓ!Ü˜X vÓ.Ü‹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   € ð ˆÜ“>ˆäØÜÓ!Ü˜X vÓ.Ü!Ó#ô		
ð 	×Ñ˜ (¨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ñ à—M‘M $§.¡.×"9Ñ"9×"CÑ"C×"MÑ"MÔNØ—M‘M $§.¡.×"9Ñ"9×"CÑ"CÕDð —M‘M $§.¡.×"9Ñ"9×"CÑ"C×"MÑ"M×"WÑ"WÔXØ—M‘M $§.¡.×"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ò""7òH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Ý &ô8�X×&Ñ&ô 8÷Bñ ñ ˆZ×*Ñ*Ó+ô(Ð*ó (ó ,ð(ô2[2˜¨Ð3Iô [2ñ| ƒ	× Ñ Ð#×7Ñ7Ó9Õ :øð_ ò Ø‚Gðús   °B5 Â5B?Â>B?