AnonSec Shell
Server IP : 209.38.156.173  /  Your IP : 216.73.216.122   [ Reverse IP ]
Web Server : Apache/2.4.52 (Ubuntu)
System : Linux lakekumayuhotel 5.15.0-136-generic #147-Ubuntu SMP Sat Mar 15 15:53:30 UTC 2025 x86_64
User : root ( 0)
PHP Version : 8.1.2-1ubuntu2.22
Disable Function : NONE
Domains : 2 Domains
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : ON
Directory :  /lib/python3/dist-packages/twisted/words/test/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ HOME ]     [ BACKUP SHELL ]     [ JUMPING ]     [ MASS DEFACE ]     [ SCAN ROOT ]     [ SYMLINK ]     

Current File : /lib/python3/dist-packages/twisted/words/test/__pycache__/test_jabberxmlstream.cpython-310.pyc
o

�b'��@s(dZddlmZddlmZddlmZmZddlm	Z	ddl
mZddlm
Z
ddlmZdd	lmZdd
lmZmZmZmZddlmZddlmZzdd
lmZWn
eyadZdZYnweZdZddlmZddl m!Z!dZ"Gdd�dej#�Z$Gdd�dej#�Z%Gdd�dej#�Z&Gdd�de'�Z(Gdd�dej#�Z)Gdd�dej#�Z*Gd d!�d!ej#�Z+Gd"d#�d#ej#�Z,Gd$d%�d%ej-�Z.Gd&d'�d'ej#�Z/Gd(d)�d)ej#�Z0Gd*d+�d+�Z1Gd,d-�d-ej2�Z3Gd.d/�d/ej2�Z4Gd0d1�d1ej#�Z5Gd2d3�d3ej#�Z6Gd4d5�d5ej#�Z7Gd6d7�d7e�Z8dS)8z8
Tests for L{twisted.words.protocols.jabber.xmlstream}.
�)�skipIf)�verifyObject)�defer�task)�ConnectionLost)�IProtocolFactory)�failure)�
proto_helpers)�unittest)�error�ijabber�jid�	xmlstream)�!GenericXmlStreamFactoryTestsMixin)�domish)�sslN)TzSSL not available)F�)�ClientTLSOptions)�CertificateOptions�urn:ietf:params:xml:ns:xmpp-tlsc@�0eZdZdZdd�Zdd�Zdd�Zdd	�Zd
S)�HashPasswordTestsz.
    Tests for L{xmlstream.hashPassword}.
    cC�t�dd�}|�d|�dS)zS
        The sid and secret are concatenated to calculate sha1 hex digest.
        �12345�secret�(99567ee91b2c7cabf607f10cb9f4a3634fa820e0N�r�hashPassword�assertEqual��self�hash�r"�I/usr/lib/python3/dist-packages/twisted/words/test/test_jabberxmlstream.py�
test_basic)�zHashPasswordTests.test_basiccC�|�ttjdd�dS)zB
        The session identifier must be a unicode object.
        s¹2345rN��assertRaises�	TypeErrorrr�r r"r"r#�test_sidNotUnicode0�z$HashPasswordTests.test_sidNotUnicodecCr&)z8
        The password must be a unicode object.
        rssecrétNr'r*r"r"r#�test_passwordNotUnicode6r,z)HashPasswordTests.test_passwordNotUnicodecCr)z\
        The concatenated sid and password must be encoded to UTF-8 before hashing.
        rusecrét�(659bf88d8f8e179081f7f3b4a8e7d224652d2853Nrrr"r"r#�test_unicodeSecret<r%z$HashPasswordTests.test_unicodeSecretN)�__name__�
__module__�__qualname__�__doc__r$r+r-r/r"r"r"r#r$src@speZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�ZdS)�IQTestszG
    Tests both IQ and the associated IIQResponseTracker callback.
    cCsbt�d�}d|_t�|�|_t��|_|jj|j_|j�	t
���|j�d�t�
|jd�|_dS)N�	otherhost�testnszm<stream:stream xmlns:stream='http://etherx.jabber.org/streams' xmlns='testns' from='otherhost' version='1.0'>�get)r�ConnectAuthenticator�	namespace�	XmlStreamr�Clock�clock�	callLater�
_callLater�makeConnectionr	�StringTransport�dataReceived�IQ�iq)r �
authenticatorr"r"r#�setUpIs

�z
IQTests.setUpcCs&|�|jdd�|�|jd�dS)N�typer7�id)rrC�
assertTruer*r"r"r#�	testBasicVszIQTests.testBasiccCsR|jj��|j��|jd�d�}|�|jj��d|dd|dg�dS)NrGzutf-8s<iq type='get' id='s'/>s<iq id='s' type='get'/>)r�	transport�clearrC�send�encode�assertIn�value)r �idBytesr"r"r#�testSendZs



��zIQTests.testSendcs>�fdd�}�j��}|�|��j}|�d�jd�|S)Ncs��|dd�dS)NrF�result)r)rRr*r"r#�cbgsz&IQTests.testResultResponse.<locals>.cb�<iq type='result' id='%s'/>rG)rCrL�addCallbackrrA)r rS�d�xsr"r*r#�testResultResponsefs

zIQTests.testResultResponsecCs6|j��}|�|tj�|j}|�d|jd�|S)Nz<iq type='error' id='%s'/>rG)rCrL�
assertFailurer�StanzaErrorrrA�r rVrWr"r"r#�testErrorResponseqs

zIQTests.testErrorResponsecsD�j}t�|���|j��fdd�}|�d|d�|�d�dS)z�
        Test that untracked iq responses don't trigger any action.

        Untracked means that the id of the incoming response iq is not
        in the stream's C{iqDeferreds} dictionary.
        cs��t|dd��dS)N�handledF)�assertFalse�getattr)rCr*r"r#rS�sz*IQTests.testNonTrackedResponse.<locals>.cbz/iq���z<iq type='result' id='test'/>N)r�upgradeWithIQResponseTrackerr^�iqDeferreds�addObserverrA)r rWrSr"r*r#�testNonTrackedResponseys
zIQTests.testNonTrackedResponsecCs<|j��}|j}|�d|jd�|�|jd|j�|S)z�
        Test if the deferred associated with an iq request is removed
        from the list kept in the L{XmlStream} object after it has
        been fired.
        rTrG)rCrLrrA�assertNotInrbr[r"r"r#�testCleanup�s

zIQTests.testCleanupcCs*|j��}|j}|�d�|�|t�|S)z�
        Test if deferreds for iq's that haven't yet received a response
        have their errback called on stream disconnect.
        �Closed by peer)rCrLr�connectionLostrYrr[r"r"r#�testDisconnectCleanup�s


zIQTests.testDisconnectCleanupcs2��fdd���j��}|����j�d�|S)z~
        Test to make sure the errbacks cannot cause the iteration of the
        iqDeferreds to blow up in our face.
        cst��j���}|���dS�N)rrBrL�
addErrback)rrV��ebr r"r#rm�sz'IQTests.testNoModifyingDict.<locals>.ebrg)rCrLrkrrh�r rVr"rlr#�testNoModifyingDict�s


zIQTests.testNoModifyingDictcCsPd|j_|j��}|�|tj�|j�ddg�|�|jj	�|�|jj
�|S)zK
        Test that an iq request with a defined timeout times out.
        �<�)rC�timeoutrLrYr�TimeoutErrorr<�pumpr^�callsrbrnr"r"r#�testRequestTimingOut�s
zIQTests.testRequestTimingOutcCsRd|j_|j��}|j�d|jjd|jd�|j�ddg�|�|jj	�|S)z�
        Test that an iq request with a defined timeout does not time out
        when a response was received before the timeout period elapsed.
        rprqrTrG)
rCrrrLr<r=rrArtr^rurnr"r"r#�testRequestNotTimingOut�s
�zIQTests.testRequestNotTimingOutcCs@d|j_|j��}|j}|�d�|�|t�|�|jj	�|S)z|
        Test if timeouts for iq's that haven't yet received a response
        are cancelled on stream disconnect.
        rprg)
rCrrrLrrhrYrr^r<rur[r"r"r#�!testDisconnectTimeoutCancellation�s

z)IQTests.testDisconnectTimeoutCancellationN)r0r1r2r3rErIrQrXr\rdrfrirorvrwrxr"r"r"r#r4Ds


r4c@s�eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd �Zd!S)"�XmlStreamTestscC�
d|_dS�NT)�gotStreamStart�r �objr"r"r#�
onStreamStart��
zXmlStreamTests.onStreamStartcCrzr{)�gotStreamEndr}r"r"r#�onStreamEnd�r�zXmlStreamTests.onStreamEndcCrzr{)�gotStreamErrorr}r"r"r#�
onStreamError�r�zXmlStreamTests.onStreamErrorcCsvd|_d|_d|_t�t���}|�d|j�|�d|j�|�d|j	�|�
t���||j
_d|_d|_||_dS)z9
        Set up XmlStream and several observers.
        Fz//event/stream/start�//event/stream/endz//event/stream/errorr6�rqrN)r|r�r�rr:�
Authenticatorrcrr�r�r?r	� StringTransportWithDisconnectionrJ�protocolr9�version�r rWr"r"r#rE�s
zXmlStreamTests.setUpcCsh|j}|��|jj��dd��d�}|�d|�|�d|�|�d|�|�d|�|�|j�dS)	z>
        Basic test on the header sent by sendHeader.
        rr`� �<stream:stream�/xmlns:stream='http://etherx.jabber.org/streams'�xmlns='testns'�
version='1.0'N)r�
sendHeaderrJrO�splitrNrH�_headerSent�r rW�splitHeaderr"r"r#�test_sendHeaderBasicsz#XmlStreamTests.test_sendHeaderBasiccCs~|j}d|jd<|��|jj��dd��d�}|�d|�|�d|�|�d|�|�d	|�|�d
|�|�|j�dS)z=
        Test for additional namespace declarations.
        �dbzjabber:server:dialbackrr`r�r�r�s!xmlns:db='jabber:server:dialback'r�r�N)	r�prefixesr�rJrOr�rNrHr�r�r"r"r#�#test_sendHeaderAdditionalNamespacess
z2XmlStreamTests.test_sendHeaderAdditionalNamespacescCs`|j}t�d�|_t�d�|_d|_|��|j��dd��	d�}|�
d|�|�
d|�d	S)
z;
        Test addressing when initiating a stream.
        �thisHost�	otherHostTrr`r��to='otherhost'�from='thishost'N)rr
�JID�
thisEntity�otherEntity�
initiatingr�rJrOr�rNr�r"r"r#�test_sendHeaderInitiatingsz(XmlStreamTests.test_sendHeaderInitiatingcCsr|j}t�d�|_t�d�|_d|_d|_|��|j�	�dd��
d�}|�d|�|�d	|�|�d
|�dS)z:
        Test addressing when receiving a stream.
        r�r�F�	session01rr`r�r�r�sid='session01'N)rr
r�r�r�r��sidr�rJrOr�rNr�r"r"r#�test_sendHeaderReceiving*sz'XmlStreamTests.test_sendHeaderReceivingcCs6|j}|�d�|�d�|�|j�|�|j�dS)z>
        Test events when a stream error is received.
        ��<stream:stream xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams' from='example.com' id='12345' version='1.0'>z<stream:error/>N)rrArHr�r�r�r"r"r#�test_receiveStreamError9s�
z&XmlStreamTests.test_receiveStreamErrorcC�P|j}d|_|��|j��|�t�d��|�d|j�	��|�
|j�dS)z�
        Test sendStreamError on an initiating xmlstream with a header sent.

        An error should be sent out and the connection lost.
        T�version-unsupported�N�rr�r�rJrK�sendStreamErrorr�StreamError�assertNotEqualrOrHr�r�r"r"r#�test_sendStreamErrorInitiatingG�
z-XmlStreamTests.test_sendStreamErrorInitiatingcCsT|j}d|_|j��|�t�d��|�|j�|�	d|j�
��|�|j�dS)z�
        Test sendStreamError on an initiating xmlstream without having sent a
        header.

        In this case, no header should be generated. Also, the error should
        not be sent out on the stream. Just closing the connection.
        Tr�r�N)
rr�rJrKr�rr��	assertNotr�rrOrHr�r�r"r"r#�&test_sendStreamErrorInitiatingNoHeaderU�
z5XmlStreamTests.test_sendStreamErrorInitiatingNoHeadercCr�)z�
        Test sendStreamError on a receiving xmlstream with a header sent.

        An error should be sent out and the connection lost.
        Fr�r�Nr�r�r"r"r#�test_sendStreamErrorReceivinger�z,XmlStreamTests.test_sendStreamErrorReceivingcCsT|j}d|_|j��|�t�d��|�|j�|�	d|j�
��|�|j�dS)z�
        Test sendStreamError on a receiving xmlstream without having sent a
        header.

        In this case, a header should be generated. Then, the error should
        be sent out on the stream followed by closing the connection.
        Fr�r�N)rr�rJrKr�rr�rHr�r�rOr�r�r"r"r#�%test_sendStreamErrorReceivingNoHeadersr�z4XmlStreamTests.test_sendStreamErrorReceivingNoHeadercCs:|j}|��|j}|��|�||j�|�|j�dS)zE
        Test resetting the XML stream to start a new layer.
        N)rr��stream�resetr�r�r�)r rWr�r"r"r#�
test_reset�szXmlStreamTests.test_resetcCs�|j}|�d�|�|j��d�|j��t�d�}|�|�|�|j��d�|j��t�d�}|�|�|�|j��d�dS)z:
        Test send with various types of objects.
        �<presence/>�<presence/>)r6�presence)z http://etherx.jabber.org/streams�featuress<stream:features/>N)rrLrrJrOrKr�Element)r rW�elr"r"r#�	test_send�s






zXmlStreamTests.test_sendcs�g�g�g�G���fdd�d�}|�}t�|�}|�|g��|��|�dg��|�d�|�dt���|��|�dg��dS)zM
        Test that the associated authenticator is correctly called.
        cs0eZdZ�fdd�Z�fdd�Z�fdd�ZdS)z<XmlStreamTests.test_authenticator.<locals>.TestAuthenticatorcs��d�dSrj��appendr*)�connectionMadeCallsr"r#�connectionMade��zKXmlStreamTests.test_authenticator.<locals>.TestAuthenticator.connectionMadec���|�dSrjr�)r �rootElement)�streamStartedCallsr"r#�
streamStarted�r�zJXmlStreamTests.test_authenticator.<locals>.TestAuthenticator.streamStartedcr�rjr�r�)�associateWithStreamCallsr"r#�associateWithStream�r�zPXmlStreamTests.test_authenticator.<locals>.TestAuthenticator.associateWithStreamN)r0r1r2r�r�r�r"�r�r�r�r"r#�TestAuthenticator�sr�N�s<stream:stream xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams' from='example.com' id='12345'>rq)rr:rr�rA�lenr�)r r��arWr"r�r#�test_authenticator�s

�z!XmlStreamTests.test_authenticatorN)r0r1r2rr�r�rEr�r�r�r�r�r�r�r�r�r�r�r�r"r"r"r#ry�s"

ryc@seZdZdS)�	TestErrorN)r0r1r2r"r"r"r#r��sr�c@s4eZdZdd�Zdd�Zdd�Zdd�Zd	d
�ZdS)�AuthenticatorTestscC�t��|_t�|j�|_dSrj)rr�rDr:r*r"r"r#rE��
zAuthenticatorTests.setUpcCsh|j}|�t���|�d�|�d|j�|�d|j�|�d|j	�|�d|j
�|�d|j�dS)�e
        Test streamStart to fill the appropriate attributes from the
        stream header.
        ��<stream:stream xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams' from='example.org' to='example.com' id='12345' version='1.0'>r�N�invalid)rr?r	r@rArr��assertIdenticalr�r9r�r�r�r"r"r#�test_streamStart�s�z#AuthenticatorTests.test_streamStartcC�0|j}|�t���|�d�|�d|j�dS)z
        Test streamStart to fill the appropriate attributes from the
        stream header for a pre-XMPP-1.0 header.
        r��rrN�rr?r	r@rArr�r�r"r"r#�test_streamStartLegacy���z)AuthenticatorTests.test_streamStartLegacycCr�)z�
        Test streamStart to fill the appropriate attributes from the
        stream header for a version with only one digit.
        z<stream:stream xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams' from='example.com' id='12345' version='1'>r�Nr�r�r"r"r#�test_streamBadVersionOneDigit�r�z0AuthenticatorTests.test_streamBadVersionOneDigitcCr�)z}
        Test streamStart to fill the appropriate attributes from the
        stream header for a malformed version.
        z�<stream:stream xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams' from='example.com' id='12345' version='blah'>r�Nr�r�r"r"r#�test_streamBadVersionNoNumber�r�z0AuthenticatorTests.test_streamBadVersionNoNumberN)r0r1r2rEr�r�r�r�r"r"r"r#r��sr�c@�<eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
S)�ConnectAuthenticatorTestscCsJd|_d|_t�d�|_t�|j�|_|j�d|j�|j�d|j�dS)NFr��//event/stream/authd�//event/xmpp/initfailed)	�gotAuthenticated�initFailurerr8rDr:rc�onAuthenticated�onInitFailedr*r"r"r#rE	szConnectAuthenticatorTests.setUpcCrzr{)r�r}r"r"r#r�r�z)ConnectAuthenticatorTests.onAuthenticatedcCs
||_dSrj)r�)r rr"r"r#r�r�z&ConnectAuthenticatorTests.onInitFailedcCsHGdd�d�}|�}|g|j_|j��|�g|jj�|�|j�dS)zG
        Test successful completion of an initialization step.
        c@�eZdZdd�ZdS)z9ConnectAuthenticatorTests.testSucces.<locals>.InitializercSsdSrjr"r*r"r"r#�
initialize�zDConnectAuthenticatorTests.testSucces.<locals>.Initializer.initializeN�r0r1r2r�r"r"r"r#�Initializer�r�N)r�initializersrD�initializeStreamrrHr��r r��initr"r"r#�
testSuccess

z$ConnectAuthenticatorTests.testSuccescCsjGdd�d�}|�}|g|j_|j��|�|g|jj�|�|j�|�d|j�|�	|j�
t��dS)z9
        Test failure of an initialization step.
        c@r�)z:ConnectAuthenticatorTests.testFailure.<locals>.InitializercSst�rj)r�r*r"r"r#r�-r�zEConnectAuthenticatorTests.testFailure.<locals>.Initializer.initializeNr�r"r"r"r#r�,r�r�N)rr�rDr�rr^r��assertNotIdenticalr�rH�checkr�r�r"r"r#�testFailure's

z%ConnectAuthenticatorTests.testFailurecCs�d|j_|j}|�t���|�d�|�d|j�|�d|j	�|�d|j�|�d|j
j�|�d|j
�|�|j�|�d�|�d|j�|�|j�dS)	r�r6z�<stream:stream xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams' from='example.com' to='example.org' id='12345' version='1.0'>r�r�example.comNz9<stream:features><test xmlns='testns'/></stream:features>�r6�test)rDr9rr?r	r@rArr�r�r��hostr�r�r�r�rNr�rHr�r"r"r#r�9s"��z*ConnectAuthenticatorTests.test_streamStartN)	r0r1r2rEr�r�r�r�r�r"r"r"r#r�sr�c@s(eZdZdZdd�Zdd�Zdd�ZdS)	�ListenAuthenticatorTestsz4
    Tests for L{xmlstream.ListenAuthenticator}
    cCr�rj)r�ListenAuthenticatorrDr:r*r"r"r#rEYr�zListenAuthenticatorTests.setUpcCs�|j}|�t���|�d|j�|�d�|�d|j�|�	d|j�|�
d|j�|�d|j�|�d|j�|�d|j
j�dS)r�Nr�r�r�
jabber:clientr�)rr?r	r@r�r�rArr�r�r�r9r�r�r�r�r"r"r#r�]s�z)ListenAuthenticatorTests.test_streamStartcCs0|j}|�t���|�d�|�|jt�dS)zD
        The generated session id must be a unicode object.
        r�N)rr?r	r@rA�assertIsInstancer��strr�r"r"r#� test_streamStartUnicodeSessionIDrs�z9ListenAuthenticatorTests.test_streamStartUnicodeSessionIDN)r0r1r2r3rEr�rr"r"r"r#r�Ts
r�c@s|eZdZdd�Zdd�Zdd�Zee�dd��Zee�d	d
��Z	ee�dd��Z
d
d�Zdd�Zdd�Z
dd�Zdd�ZdS)�TLSInitiatingInitializerTestscCsbg|_g|_tj|_t�d�|_t�|j�|_|jj|j_	|j�
�|j�d�t�|j�|_
dS)Nr�r�)�output�donerr�savedSSLr8rDr:r�rLr�rA�TLSInitiatingInitializerr�r*r"r"r#rE�s
�z#TLSInitiatingInitializerTests.setUpcCs|jt_dSrj)rrrr*r"r"r#�tearDown��z&TLSInitiatingInitializerTests.tearDowncCs$tj|jdd�|_|�|jj�dS)z>
        Passing required sets the instance variable.
        T)�requiredN)rrr�rHrr*r"r"r#�test_initRequired�sz/TLSInitiatingInitializerTests.test_initRequiredcs�t���j_�fdd��jj_�fdd��j_�fdd��j_�j��}|�	�j
tj���
dt�j
���j
d}��
d|j���
t|j��j�dt���
gd	��j�|S)
zN
        When TLS is wanted and SSL available, StartTLS is initiated.
        c��j�d�S�N�TLS�rr�)�ctxr*r"r#�<lambda>��zDTLSInitiatingInitializerTests.test_wantedSupported.<locals>.<lambda>cr
�Nr�r
r"r*r"r#r�rcr
�N�headerr
r"r*r"r#r�r�rq�starttls�<proceed xmlns='%s'/>�rr�r)r	r@rrJ�startTLSr�r�r��startrUr�Resetr�r�name�NS_XMPP_TLS�urirAr)r rVrr"r*r#�test_wantedSupported�s

z2TLSInitiatingInitializerTests.test_wantedSupportedcsr�fdd�}t���j_|�jj_�fdd��j_�fdd��j_�j��}�j�	dt
���gd��j�|S)z:
        The server certificate will be verified.
        cs*��|t���|jd��j�d�dS)Nr�r)r�rr�	_hostnamerr���contextFactoryr*r"r#�fakeStartTLS�szJTLSInitiatingInitializerTests.test_certificateVerify.<locals>.fakeStartTLScr
rr
r"r*r"r#r�rzFTLSInitiatingInitializerTests.test_certificateVerify.<locals>.<lambda>cr
rr
r"r*r"r#r�rrr)
r	r@rrJrr�r�r�rrArrr�r r"rVr"r*r#�test_certificateVerify�s

z4TLSInitiatingInitializerTests.test_certificateVerifycs�t��tj�j�d��_��j_��fdd�}t���j_|�jj_�fdd��j_	�fdd��j_
�j��}�j�dt
���gd��j�|S)	zH
        A custom contextFactory is passed through to startTLS.
        )�configurationForTLScs���|��j�d�dSr)�assertIsrr�r �rr r"r#r"�szQTLSInitiatingInitializerTests.test_certificateVerifyContext.<locals>.fakeStartTLScr
rr
r"r*r"r#r�rzMTLSInitiatingInitializerTests.test_certificateVerifyContext.<locals>.<lambda>cr
rr
r"r*r"r#r�rrr)rrrr�r!r	r@rJrr�r�rrArrrr#r"r'r#�test_certificateVerifyContext�s�

z;TLSInitiatingInitializerTests.test_certificateVerifyContextcCs<dt_d|j_|j��}|�|jd�|�dt|j��|S)zX
        No StartTLS is initiated when wanted, not required, SSL not available.
        NFrq)	rrr�rrrUrr�rrnr"r"r#�"test_wantedNotSupportedNotRequired��
z@TLSInitiatingInitializerTests.test_wantedNotSupportedNotRequiredcCs<dt_d|j_|j��}|�|tj�|�dt|j	��|S)zS
        TLSNotSupported is raised when TLS is required but not available.
        NTrq)
rrr�rrrY�TLSNotSupportedrr�rrnr"r"r#�test_wantedNotSupportedRequired�r*z=TLSInitiatingInitializerTests.test_wantedNotSupportedRequiredcCs^t�d�}|�d�|j|jf|i|j_d|j_|j�	�}|�
dt|j��|�
|tj�|S)zW
        TLSRequired is raised when TLS is not wanted, but required by server.
        �rrrFrq)rr��
addElementrrrr�r��wantedrrr�rrY�TLSRequired�r �tlsrVr"r"r#�test_notWantedRequired�s


z4TLSInitiatingInitializerTests.test_notWantedRequiredcCs\t�d�}|j|jf|i|j_d|j_d|j_|j�	�}|�
|jd�|�dt|j
��|S)zL
        No StartTLS is initiated when not wanted and not required.
        r-FNrq)rr�rrrr�r�r/rrrUrr�rr1r"r"r#�test_notWantedNotRequired
s

z7TLSInitiatingInitializerTests.test_notWantedNotRequiredcCs2dt_|j��}|�|tj�|j�dt�|S)zN
        TLSFailed is raised when the server responds with a failure.
        rqz<failure xmlns='%s'/>)rrr�rrY�	TLSFailedrArrnr"r"r#�test_faileds

z)TLSInitiatingInitializerTests.test_failedN)r0r1r2rErr	r�
skipWhenNoSSLrr$r(r)r,r3r4r6r"r"r"r#r�s




rc@seZdZdZdd�ZdS)�TestFeatureInitializerr�cCs
t�d�Srj)r�succeedr*r"r"r#r*r�zTestFeatureInitializer.startN)r0r1r2�featurerr"r"r"r#r8'sr8c@s,eZdZdd�Zdd�Zdd�Zdd�Zd	S)
�%BaseFeatureInitiatingInitializerTestscCs t�t���|_t|j�|_dSrj)rr:r�r8r�r*r"r"r#rE/sz+BaseFeatureInitiatingInitializerTests.setUpcCs$|jjt�|jj�i|j_|j��S)zW
        Test that an advertized feature results in successful initialization.
        )r�r:rr�rr�r�r*r"r"r#�testAdvertized3s
z4BaseFeatureInitiatingInitializerTests.testAdvertizedcCsd|j_|�tj|jj�dS)z�
        Test that when the feature is not advertized, but required by the
        initializer, an exception is raised.
        TN)r�rr(r�FeatureNotAdvertizedr�r*r"r"r#�testNotAdvertizedRequired:�z?BaseFeatureInitiatingInitializerTests.testNotAdvertizedRequiredcCsd|j_|�d|j���dS)z�
        Test that when the feature is not advertized, and not required by the
        initializer, the initializer silently succeeds.
        FN)r�rr�r�r*r"r"r#�testNotAdvertizedNotRequiredBr?zBBaseFeatureInitiatingInitializerTests.testNotAdvertizedNotRequiredN)r0r1r2rEr<r>r@r"r"r"r#r;.s
r;c@r�)�ToResponseTestscCs�t�d�}d|d<d|d<d|d<d|d	<t�|d
�}|�||�|�|dd�|�|dd�|�|dd
�|�|d	d�dS)zS
        Test that a response stanza is generated with addressing swapped.
        �r�rCr7rF�user1@example.com�to�user2@example.com/resource�from�stanza1rGrRN)rr�r�
toResponser�r�r �stanza�responser"r"r#�test_toResponseLs
zToResponseTests.test_toResponsecCsHt�d�}d|d<d|d<t�|�}|�|dd�|�|�d��dS)zY
        Test that a response is generated from a stanza without a from address.
        rBr7rFrCrDrFN)rr�rrHrr^�hasAttributerIr"r"r#�test_toResponseNoFrom\�

z%ToResponseTests.test_toResponseNoFromcCsHt�d�}d|d<d|d<t�|�}|�|�d��|�|dd�dS)zW
        Test that a response is generated from a stanza without a to address.
        rBr7rFrErFrDN)rr�rrHr^rMrrIr"r"r#�test_toResponseNoTogrOz#ToResponseTests.test_toResponseNoTocCs@t�d�}d|d<t�|�}|�|�d��|�|�d��dS)zY
        Test that a response is generated from a stanza without any addressing.
        �r��message�chatrFrDrFN�rr�rrHr^rMrIr"r"r#�test_toResponseNoAddressingrs


z+ToResponseTests.test_toResponseNoAddressingcC�(t�d�}t�|�}|�|�d��dS)zP
        Test that a proper response is generated without id attribute.
        rQrGNrTrIr"r"r#�	test_noID|�

zToResponseTests.test_noIDcCrV)zR
        Test that a proper response is generated without type attribute.
        rQrFNrTrIr"r"r#�test_noType�rXzToResponseTests.test_noTypeN)	r0r1r2rLrNrPrUrWrYr"r"r"r#rAKs
rAc@� eZdZdZdd�Zdd�ZdS)�DummyFactoryzJ
    Dummy XmlStream factory that only registers bootstrap observers.
    cCs
i|_dSrj��	callbacksr*r"r"r#�__init__�r�zDummyFactory.__init__cCs||j|<dSrjr\)r �event�callbackr"r"r#�addBootstrap�r�zDummyFactory.addBootstrapN)r0r1r2r3r^rar"r"r"r#r[��r[c@�8eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�ZdS)
�DummyXMPPHandlerzO
    Dummy XMPP subprotocol handler to count the methods are called on it.
    cCsd|_d|_d|_dS)Nr)�doneMade�doneInitialized�doneLostr*r"r"r#r^�s
zDummyXMPPHandler.__init__cCs|��dSrj)r�r�r"r"r#r?�rzDummyXMPPHandler.makeConnectioncC�|jd7_dS�Nrq�rer*r"r"r#r���zDummyXMPPHandler.connectionMadecCrhri)rfr*r"r"r#�connectionInitialized�rkz&DummyXMPPHandler.connectionInitializedcCrhri)rg�r �reasonr"r"r#rh�rkzDummyXMPPHandler.connectionLostN)	r0r1r2r3r^r?r�rlrhr"r"r"r#rd�srdc@rZ)�FailureReasonXMPPHandlerz>
    Dummy handler specifically for failure Reason tests.
    cCrz)NF)�gotFailureReasonr*r"r"r#r^�r�z!FailureReasonXMPPHandler.__init__cCst|tj�rd|_dSdSr{)�
isinstancer�Failurerprmr"r"r#rh�s
�z'FailureReasonXMPPHandler.connectionLostN)r0r1r2r3r^rhr"r"r"r#ro�rbroc@r)�XMPPHandlerTestsz-
    Tests for L{xmlstream.XMPPHandler}.
    cCsttjt���dS)zN
        L{xmlstream.XMPPHandler} implements L{ijabber.IXMPPHandler}.
        N)rr�IXMPPHandlerr�XMPPHandlerr*r"r"r#�test_interface�szXMPPHandlerTests.test_interfacecCs>Gdd�d�}t��}|�|_|�d�|�dg|jj�dS)zP
        Test that data is passed on for sending by the stream manager.
        c@�eZdZdd�Zdd�ZdS)z6XMPPHandlerTests.test_send.<locals>.DummyStreamManagercS�
g|_dSrj)�outlistr*r"r"r#r^�r�z?XMPPHandlerTests.test_send.<locals>.DummyStreamManager.__init__cS�|j�|�dSrj)ryr�)r �datar"r"r#rL��z;XMPPHandlerTests.test_send.<locals>.DummyStreamManager.sendN)r0r1r2r^rLr"r"r"r#�DummyStreamManager��r}r�N)rru�parentrLrry)r r}�handlerr"r"r#r��s

zXMPPHandlerTests.test_sendcCsNGdd�dtj�}|�}t�t���}|�|�|�|j�|�||j�dS)zY
        Test that makeConnection saves the XML stream and calls connectionMade.
        c@r�)z=XMPPHandlerTests.test_makeConnection.<locals>.TestXMPPHandlercSrzr{rjr*r"r"r#r��r�zLXMPPHandlerTests.test_makeConnection.<locals>.TestXMPPHandler.connectionMadeN)r0r1r2r�r"r"r"r#�TestXMPPHandler�r�r�N)rrur:r�r?rHrer�)r r�r�rWr"r"r#�test_makeConnection�s
z$XMPPHandlerTests.test_makeConnectioncCs>t��}t�t���}|�|�|�t��|�d|j�dS)zB
        Test that connectionLost forgets the XML stream.
        N)rrur:r�r?rh�	Exceptionr�)r r�rWr"r"r#�test_connectionLost�s

z$XMPPHandlerTests.test_connectionLostN)r0r1r2r3rvr�r�r�r"r"r"r#rs�srsc@r)�XMPPHandlerCollectionTestsz7
    Tests for L{xmlstream.XMPPHandlerCollection}.
    cCst��|_dSrj)r�XMPPHandlerCollection�
collectionr*r"r"r#rE�r�z XMPPHandlerCollectionTests.setUpcCsttj|j�dS)zZ
        L{xmlstream.StreamManager} implements L{ijabber.IXMPPHandlerCollection}.
        N)rr�IXMPPHandlerCollectionr�r*r"r"r#rv�sz)XMPPHandlerCollectionTests.test_interfacecCs4t�}|�|j�|�||j�|�|j|j�dS)z:
        Test the addition of a protocol handler.
        N)rd�setHandlerParentr�rNr�r�r r�r"r"r#�test_addHandlersz*XMPPHandlerCollectionTests.test_addHandlercCs>t�}|�|j�|�|j�|�||j�|�d|j�dS)z5
        Test removal of a protocol handler.
        N)rdr�r��disownHandlerParentrer�rr�r"r"r#�test_removeHandler
s
z-XMPPHandlerCollectionTests.test_removeHandlerN)r0r1r2r3rErvr�r�r"r"r"r#r��s	r�c@s�eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�ZdS)�StreamManagerTestsz/
    Tests for L{xmlstream.StreamManager}.
    cCst�}t�|�|_dSrj)r[r�
StreamManager�
streamManager)r �factoryr"r"r#rEszStreamManagerTests.setUpcCs~|j}|�d|j�|�g|j�|�|j|jjd�|�|j|jjd�|�|j	|jjd�|�|j
|jjd�dS)zM
        Test correct initialization and setup of factory observers.
        Nz//event/stream/connectedr�r�r�)r�r�rr�handlers�
_connectedr�r]�_authd�
_disconnected�initializationFailed)r �smr"r"r#r$s��zStreamManagerTests.test_basiccCs\|j}t�}|�|�t�t���}|�|�|�d|j�|�d|j	�|�d|j
�dS)z
        Test that protocol handlers have their connectionMade method called
        when the XML stream is connected.
        rqrN)r�rdr�rr:r�r�rrerfrg�r r�r�rWr"r"r#�test_connected.�

z!StreamManagerTests.test_connectedcCsN|j}t�}|�|�t�t���}|�|�|�d|j�|�d|j	�dS)zP
        Test raw data functions unset when logTraffic is set to False.
        N)
r�rdr�rr:r�r�r��rawDataInFn�rawDataOutFnr�r"r"r#�test_connectedLogTrafficFalse<s

z0StreamManagerTests.test_connectedLogTrafficFalsecCsT|j}d|_t�}|�|�t�t���}|�|�|�d|j	�|�d|j
�dS)zM
        Test raw data functions set when logTraffic is set to True.
        TN)r��
logTrafficrdr�rr:r�r�r�r�r�r�r"r"r#�test_connectedLogTrafficTrueHs

z/StreamManagerTests.test_connectedLogTrafficTruecCs\|j}t�}|�|�t�t���}|�|�|�d|j�|�d|j	�|�d|j
�dS)z�
        Test that protocol handlers have their connectionInitialized method
        called when the XML stream is initialized.
        rrqN)r�rdr�rr:r�r�rrerfrgr�r"r"r#�
test_authdUr�zStreamManagerTests.test_authdcCs\|j}t�}|�|�t�t���}|�|�|�d|j�|�d|j	�|�d|j
�dS)z�
        Test that protocol handlers have their connectionLost method
        called when the XML stream is disconnected.
        rrqN)r�rdr�rr:r�r�rrerfrgr�r"r"r#�test_disconnectedcr�z$StreamManagerTests.test_disconnectedcCs<|j}t�}|�|�|�t�td���|�d|j�dS)z�
        A L{STREAM_END_EVENT} results in L{StreamManager} firing the handlers
        L{connectionLost} methods, passing a L{failure.Failure} reason.
        z	no reasonTN)	r�ror�r�rrrr�rrp�r r�r�r"r"r#�test_disconnectedReasonqs

z*StreamManagerTests.test_disconnectedReasoncCsD|j}t�}|�|�|�d|j�|�d|j�|�d|j�dS)zN
        Test the addition of a protocol handler while not connected.
        rN)r�rdr�rrerfrgr�r"r"r#r�|s
z"StreamManagerTests.test_addHandlercCsf|j}t�t���}|�|�|�|�t�}|�|�|�d|j	�|�d|j
�|�d|j�dS)a
        Test the addition of a protocol handler after the stream
        have been initialized.

        Make sure that the handler will have the connected stream
        passed via C{makeConnection} and have C{connectionInitialized}
        called.
        rqrN)r�rr:r�r�r�rdr�rrerfrg)r r�rWr�r"r"r#�test_addHandlerInitialized�s	


z-StreamManagerTests.test_addHandlerInitializedcCsjt�t���}t�|�}|�d�}t��|_|��|�	d�|�
|d�|�d�|�d|j�
��dS)z�
        Test send when the stream has been initialized.

        The data should be sent directly over the XML stream.
        Nr�r�r�r�)r�XmlStreamFactoryr�r��
buildProtocolr	r@rJr�rA�dispatchrLrrO�r r�r�rWr"r"r#�test_sendInitialized�s


�
z'StreamManagerTests.test_sendInitializedcCs�t�t���}t�|�}t�}|�|�|�d�}t��|_	|�
d�|�d|j	���|�d|j
d�|��|�d|j	���|�d|j
d�|�d�|�|d�|�d|j	���|�|j
�dS)z�
        Test send when there is no established XML stream.

        The data should be cached until an XML stream has been established and
        initialized.
        Nr�r�rr�r�r�)rr�r�r�rd�
addHandlerr�r	r@rJrLrrO�_packetQueuer�rAr�r^�r r�r�r�rWr"r"r#�test_sendNotConnected�s$




�z(StreamManagerTests.test_sendNotConnectedcCspt�t���}t�|�}|�d�}t��|_|��|�	d�|�
d�|�d|j���|�d|j
d�dS)z�
        Test send when the stream is connected but not yet initialized.

        The data should be cached until the XML stream has been initialized.
        Nr�r�r�r)rr�r�r�r�r	r@rJr�rArLrrOr�r�r"r"r#�test_sendNotInitialized�s


�
z*StreamManagerTests.test_sendNotInitializedcCs�t�t���}t�|�}t�}|�|�|�d�}|��t�	�|_
|�d�|�d�|�
d|j
���|�
d|jd�dS)z�
        Test send after XML stream disconnection.

        The data should be cached until a new XML stream has been established
        and initialized.
        Nr�r�r)rr�r�r�rdr�r�r�r	r@rJrhrLrrOr�r�r"r"r#�test_sendDisconnected�s





z(StreamManagerTests.test_sendDisconnectedN)r0r1r2r3rEr$r�r�r�r�r�r�r�r�r�r�r�r�r"r"r"r#r�s 
 r�c@rc)
�XmlStreamServerFactoryTestsz8
    Tests for L{xmlstream.XmlStreamServerFactory}.
    cs*Gdd�d���fdd�}t�|�|_dS)zQ
        Set up a server factory with an authenticator factory function.
        c@rw)z<XmlStreamServerFactoryTests.setUp.<locals>.TestAuthenticatorcSrxrj)�
xmlstreamsr*r"r"r#r^r�zEXmlStreamServerFactoryTests.setUp.<locals>.TestAuthenticator.__init__cSrzrj)r�r�r�r"r"r#r�r|zPXmlStreamServerFactoryTests.setUp.<locals>.TestAuthenticator.associateWithStreamN)r0r1r2r^r�r"r"r"r#r�r~r�cs��Srjr"r"�r�r"r#�authenticatorFactorysz?XmlStreamServerFactoryTests.setUp.<locals>.authenticatorFactoryN)r�XmlStreamServerFactoryr�)r r�r"r�r#rE�sz!XmlStreamServerFactoryTests.setUpcCstt|j�dS)z<
        L{XmlStreamServerFactory} is a L{Factory}.
        N)rrr�r*r"r"r#rvsz*XmlStreamServerFactoryTests.test_interfacecCs"|j�d�}|�|g|jj�dS)a�
        The authenticator factory should be used to instantiate the
        authenticator and pass it to the protocol.

        The default protocol, L{XmlStream} stores the authenticator it is
        passed, and calls its C{associateWithStream} method. so we use that to
        check whether our authenticator factory is used and the protocol
        instance gets an authenticator.
        N)r�r�rrDr�r�r"r"r#�,test_buildProtocolAuthenticatorInstantiations
zHXmlStreamServerFactoryTests.test_buildProtocolAuthenticatorInstantiationcCs|j�d�}|�|tj�dS)zV
        The protocol factory creates Jabber XML Stream protocols by default.
        N)r�r�r�rr:r�r"r"r#�test_buildProtocolXmlStream#sz7XmlStreamServerFactoryTests.test_buildProtocolXmlStreamcCs8|j�d�}|j�d�}|�||�|�|j|j�dS)z�
        Subsequent calls to buildProtocol should result in different instances
        of the protocol, as well as their authenticators.
        N)r�r�r�rD)r �xs1�xs2r"r"r#�test_buildProtocolTwice*sz3XmlStreamServerFactoryTests.test_buildProtocolTwiceN)	r0r1r2r3rErvr�r�r�r"r"r"r#r��s
r�)9r3r
r�zope.interface.verifyr�twisted.internetrr�twisted.internet.errorr�twisted.internet.interfacesr�twisted.pythonr�twisted.testr	�
twisted.trial�twisted.words.protocols.jabberrrr
r�!twisted.words.test.test_xmlstreamr�twisted.words.xishrr�_ssl�ImportErrorr7�twisted.internet._sslverifyr�twisted.internet.sslrr�TestCaserr4ryr�r�r�r�r�r� BaseFeatureInitiatingInitializerr8r;rAr[rurdrorsr�r�r�r"r"r"r#�<module>sZ� #\CL-'B
6"f

Anon7 - 2022
AnonSec Team