HEX
Server: Apache
System: Linux scp1.abinfocom.com 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64
User: confeduphaar (1010)
PHP: 8.1.33
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //lib/python3/dist-packages/twisted/words/test/__pycache__/test_jabbercomponent.cpython-38.pyc
U


W[|7�@sdZddlmZddlmZddlmZddlmZddl	m
Z
ddlmZm
Z
mZddlmZdd	lmZdd
lmZGdd�d�ZGd
d�de
j�ZGdd�de
j�ZGdd�de
j�ZGdd�dej�ZGdd�de
j�ZGdd�de
j�ZGdd�de
j�ZGdd�de
j�ZdS)z7
Tests for L{twisted.words.protocols.jabber.component}
�)�sha1)�verifyObject)�failure)�unicode)�unittest)�	component�ijabber�	xmlstream)�JID)�domish)�XmlPipec@seZdZdd�Zdd�ZdS)�DummyTransportcCs
||_dS�N)�list)�selfr�r�I/usr/lib/python3/dist-packages/twisted/words/test/test_jabbercomponent.py�__init__szDummyTransport.__init__cCs|j�|�dSr)r�append)r�bytesrrr�writeszDummyTransport.writeN)�__name__�
__module__�__qualname__rrrrrrr
sr
c@seZdZdd�Zdd�ZdS)�#ComponentInitiatingInitializerTestscCsjg|_t��|_d|j_t�|j�|_d|j_|jj|j_|j�	�|j�
d�d|j_t�
|j�|_dS)N�secret�test:componentz�<stream:stream xmlns='test:component' xmlns:stream='http://etherx.jabber.org/streams' from='example.com' id='12345' version='1.0'>Z12345)�outputr	Z
Authenticator�
authenticator�password�	XmlStream�	namespacer�send�connectionMade�dataReceived�sidrZComponentInitiatingInitializer�init�rrrr�setUps

�z)ComponentInitiatingInitializerTests.setUpcCsb|j��}|jd}|�d|j�|�d|j�|�td���t|��g|_	|j
�|���|S)z?
        Test basic operations of component handshake.
        ����	handshaker�12345secret)
r&Z
initializer�assertEqual�nameZurir�	hexdigestrZchildrenr	r$ZtoXml)r�dr*rrr�
testHandshake+s

�z1ComponentInitiatingInitializerTests.testHandshakeN)rrrr(r0rrrrrsrc@seZdZdd�Zdd�ZdS)�ComponentAuthTestscCs
d|_dS�NT)�authComplete)r�streamrrr�
authPassedBszComponentAuthTests.authPassedcCs�d|_g}t�dd�}t�|�}t|�|_|�tj|j	�|�
�|�d�td��
��d�}|�|dd|d	�|�d
�|�|jd�dS)NFZcjidrsv<stream:stream xmlns='jabber:component:accept' xmlns:stream='http://etherx.jabber.org/streams' from='cjid' id='12345'>r+�ascii�s<handshake>s</handshake>�<handshake/>T)r3rZConnectComponentAuthenticatorr	r r
�	transport�addObserver�STREAM_AUTHD_EVENTr5r#r$rr.�encoder,)rZoutlistZca�xsZhvrrr�testAuthEs

�

zComponentAuthTests.testAuthN)rrrr5r>rrrrr1Asr1c@seZdZdZdd�ZdS)�ServiceTestsz)
    Tests for L{component.Service}.
    cCst��}ttj|�dS)zF
        L{component.Service} implements L{ijabber.IService}.
        N)r�ServicerrZIService)r�servicerrr�test_interfacedszServiceTests.test_interfaceN)rrr�__doc__rBrrrrr?_sr?c@s,eZdZdd�Zdd�Zdd�Zdd�Zd	S)
�JabberServiceHarnesscCsd|_d|_d|_dS)NF)�componentConnectedFlag�componentDisconnectedFlag�transportConnectedFlagr'rrrrnszJabberServiceHarness.__init__cCs
d|_dSr2)rE�rr	rrr�componentConnectedssz'JabberServiceHarness.componentConnectedcCs
d|_dSr2)rFr'rrr�componentDisconnectedvsz*JabberServiceHarness.componentDisconnectedcCs
d|_dSr2)rGrHrrr�transportConnectedysz'JabberServiceHarness.transportConnectedN)rrrrrIrJrKrrrrrDmsrDc@seZdZdd�ZdS)�JabberServiceManagerTestscCs�t�dd�}t�}|�|�g}|���d�}||_|j|j_|�	�|�
d|j�|�|t
j�|�
d|j�|�d�|�
d|j�dS)NZfoorT)rZServiceManagerrDZsetServiceParentZ
getFactory�
buildProtocolr9rrr#r,rG�dispatchr	r;rE�connectionLostrF)rZsmZsvcZwlistr=rrr�testSM~s


z JabberServiceManagerTests.testSMN)rrrrPrrrrrL}srLc@s(eZdZdZdd�Zdd�Zdd�ZdS)	�RouterTestsz(
    Tests for L{component.Router}.
    cs|t��}g��fdd�|_t�}|�d|j�|�dt|j��|�|j|jd�t	�
d�}|j�|�|�|g��dS)zJ
        Test route registration and routing on incoming stanzas.
        cs
��|�Sr�r��element�Zroutedrr�<lambda>��z+RouterTests.test_addRoute.<locals>.<lambda>zexample.orgr7)ZtestnsZtestN)
r�RouterZrouter�addRoute�sinkr,�len�routesr�Element�sourcer")r�router�piperTrrUr�
test_addRoute�s
zRouterTests.test_addRoutecs�t�}t�}t��}|�d|j�|�d|j�g�|j�d�fdd��t�d�}d|d<d|d<|j�	|�|�
|g��d	S)
z,
        Test routing of a message.
        �component1.example.orgzcomponent2.example.org�/*cs
��|�SrrRrS�ZoutgoingrrrV�rWz(RouterTests.test_route.<locals>.<lambda>�NZpresence�from�toN�rrrXrYrZr^r:rr]r"r,)r�
component1Z
component2r_�stanzarrdr�
test_route�s
�
zRouterTests.test_routecs�t�}t�}t��}|�d|j�|�d|j�g�|j�d�fdd��t�d�}d|d<d|d	<|j�	|�|�
|g��dS)
a
        Test routing of a message using the default route.

        The default route is the one with L{None} as its key in the
        routing table. It is taken when there is no more specific route
        in the routing table that matches the stanza's destination.
        rbNrccs
��|�SrrRrSrdrrrV�rWz/RouterTests.test_routeDefault.<locals>.<lambda>rerfzexample.comrgrh)rriZs2sr_rjrrdr�test_routeDefault�s
zRouterTests.test_routeDefaultN)rrrrCrarkrlrrrrrQ�srQc@sXeZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�ZdS)�!ListenComponentAuthenticatorTestsz>
    Tests for L{component.ListenComponentAuthenticator}.
    cCs,g|_t�d�}t�|�|_|jj|j_dS)Nr)rrZListenComponentAuthenticatorr	r rr")rrrrrr(�s
z'ListenComponentAuthenticatorTests.setUpcCs|j�d�dS)zA
        Stub loseConnection because we are a transport.
        z	no reasonN)r	rOr'rrr�loseConnection�sz0ListenComponentAuthenticatorTests.loseConnectioncs�g��fdd�}|j}||_|�|�|�d|j�|�|j�|�d�|�d|j	�|�
d|j�|�|j�|�d|jj
f�d�dS)zK
        The received stream header should set several attributes.
        cs��||f�dSrrR)ZeventZ
observerfn�Z	observersrr�addOnetimeObserver�szPListenComponentAuthenticatorTests.test_streamStarted.<locals>.addOnetimeObserverNzz<stream:stream xmlns='jabber:component:accept' xmlns:stream='http://etherx.jabber.org/streams' to='component.example.org'>)rrrcr))r	rp�makeConnection�assertIdenticalr%�assertFalseZ_headerSentr$r,�version�assertNotIdenticalZ
assertTruer�	onElement)rrpr=rror�test_streamStarted�s

z4ListenComponentAuthenticatorTests.test_streamStartedcCsLg}|j}|j|_|�|�|�d�|�dt|��|�d|dj�dS)zM
        The received stream header should have a correct namespace.
        zp<stream:stream xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams' to='component.example.org'>r7zinvalid-namespacer)N�r	r�sendStreamErrorrqr$r,r[�	condition�r�streamErrorsr=rrr� test_streamStartedWrongNamespaces

zBListenComponentAuthenticatorTests.test_streamStartedWrongNamespacecCsLg}|j}|j|_|�|�|�d�|�dt|��|�d|dj�dS)zJ
        The received stream header should have a 'to' attribute.
        z_<stream:stream xmlns='jabber:component:accept' xmlns:stream='http://etherx.jabber.org/streams'>r7zimproper-addressingr)Nrxr{rrr�test_streamStartedNoTos

z8ListenComponentAuthenticatorTests.test_streamStartedNoTocCsHg}|j}|j|j_t�d�}|�d�|j�|�|�d|d�dS)z<
        We expect a handshake element with a hash.
        )�jabber:component:acceptr*�1234r)N)	r	rr�onHandshakerr]Z
addContentrvr,)r�
handshakesr=r*rrr�test_onElement.s


z0ListenComponentAuthenticatorTests.test_onElementcCsVg}g}|j}|j|j_|j|_t�d�}|j�|�|�|�|�	d|dj
�dS)z9
        Reject elements that are not handshakes
        )r�message�not-authorizedr)N)r	rrr�ryrr]rvrsr,rz)rr�r|r=rTrrr�test_onElementNotHandshake<s


z<ListenComponentAuthenticatorTests.test_onElementNotHandshakecs`g��fdd�}|j}|�tj|�d|_d}|j�|�|�d|jd�|�dt���dS)	zU
        Receiving a handshake matching the secret authenticates the stream.
        cs��|�dSrrR�r=�Zauthdrr�
authenticatedSszIListenComponentAuthenticatorTests.test_onHandshake.<locals>.authenticatedr�Z(32532c0f7dbf1253c095b18b18e36d38d94c1256r8r)r7N)	r	rpr;r%rr�r,rr[)rr�r=�theHashrr�r�test_onHandshakeMsz2ListenComponentAuthenticatorTests.test_onHandshakecslg}g��fdd�}|j}|�tj|�|j|_d|_d}|j�|�|�d|dj	�|�dt
���dS)zH
        Receiving a bad handshake should yield a stream error.
        cs��|�dSrrRr�r�rrr�fszRListenComponentAuthenticatorTests.test_onHandshakeWrongHash.<locals>.authenticatedr�r�r)rN)r	rpr;rryr%rr�r,rzr[)rr|r�r=r�rr�r�test_onHandshakeWrongHash_sz;ListenComponentAuthenticatorTests.test_onHandshakeWrongHashN)
rrrrCr(rnrwr}r~r�r�r�r�rrrrrm�srmc@s@eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dS)�XMPPComponentServerFactoryTestsz<
    Tests for L{component.XMPPComponentServerFactory}.
    cCs8t��|_t�|jd�|_|j�d�|_td�|j_dS)Nr�component.example.org)	rrXr_ZXMPPComponentServerFactory�factoryrMr	r
Z
thisEntityr'rrrr(zs
�z%XMPPComponentServerFactoryTests.setUpcCsV|j�|jtj�|�d|jj�|�d|jj�|�d|jj�|�d|jj�dS)zY
        A new connection increases the stream serial count. No logs by default.
        rr7N)	r	rN�STREAM_CONNECTED_EVENTr,�serialr�rr�rawDataInFn�rawDataOutFnr'rrr�test_makeConnection�s
�z3XMPPComponentServerFactoryTests.test_makeConnectioncCs>d|j_|j�|jtj�|�d|jj�|�d|jj�dS)zD
        Setting logTraffic should set up raw data loggers.
        TN)r�Z
logTrafficr	rNr�rur�r�r'rrr�test_makeConnectionLogTraffic�s
�z=XMPPComponentServerFactoryTests.test_makeConnectionLogTrafficcCsX|j�|jtj�Gdd�dt�}t�|��}|j�|tj�|�dt|�	|���dS)zQ
        An observer for stream errors should trigger onError to log it.
        c@seZdZdS)z?XMPPComponentServerFactoryTests.test_onError.<locals>.TestErrorN)rrrrrrr�	TestError�sr�r7N)
r	rNr��	ExceptionrZFailureZSTREAM_ERROR_EVENTr,r[ZflushLoggedErrors)rr��reasonrrr�test_onError�s
�z,XMPPComponentServerFactoryTests.test_onErrorcCs<|j�|jtj�|�d|jj�|�|j|jjd�dS)zG
        Make sure a new stream is added to the routing table.
        r�N)r	rNr;ZassertInr_r\rrr'rrr�test_connectionInitialized�s

�z:XMPPComponentServerFactoryTests.test_connectionInitializedcCs6|j�|jtj�|j�dtj�|�d|jj�dS)zU
        Make sure a stream is removed from the routing table on disconnect.
        Nr�)r	rNr;ZSTREAM_END_EVENTZassertNotInr_r\r'rrr�test_connectionLost�sz3XMPPComponentServerFactoryTests.test_connectionLostN)
rrrrCr(r�r�r�r�r�rrrrr�us
r�N) rCZhashlibrZzope.interface.verifyrZtwisted.pythonrZtwisted.python.compatrZ
twisted.trialrZtwisted.words.protocols.jabberrrr	Z"twisted.words.protocols.jabber.jidr
Ztwisted.words.xishrZtwisted.words.xish.utilityrr
ZTestCaserr1r?r@rDrLrQrmr�rrrr�<module>s&'#C