%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /usr/lib/python3/dist-packages/twisted/words/test/__pycache__/
Upload File :
Create Path :
Current File : //usr/lib/python3/dist-packages/twisted/words/test/__pycache__/test_jabbercomponent.cpython-312.pyc

�

Ϫ�fR6����dZddlmZddlmZddlmZddlmZddl	m
Z
mZmZddl
mZddlmZdd	lmZGd
�d�ZGd�d
ej(�ZGd�dej(�ZGd�dej(�ZGd�de
j0�ZGd�dej(�ZGd�dej(�ZGd�dej(�ZGd�dej(�Zy)z7
Tests for L{twisted.words.protocols.jabber.component}
�)�sha1)�verifyObject)�failure)�unittest)�	component�ijabber�	xmlstream)�JID)�domish)�XmlPipec��eZdZd�Zd�Zy)�DummyTransportc��||_y�N)�list)�selfrs  �I/usr/lib/python3/dist-packages/twisted/words/test/test_jabbercomponent.py�__init__zDummyTransport.__init__s	����	�c�:�|jj|�yr)r�append)r�bytess  r�writezDummyTransport.writes���	�	����rN)�__name__�
__module__�__qualname__rr�rrrrs��� rrc��eZdZd�Zd�Zy)�#ComponentInitiatingInitializerTestsc���g|_tj�|_d|j_tj
|j�|_d|j_|jj|j_|jj�|jjd�d|j_tj|j�|_y)N�secret�test:componentz�<stream:stream xmlns='test:component' xmlns:stream='http://etherx.jabber.org/streams' from='example.com' id='12345' version='1.0'>�12345)�outputr	�
Authenticator�
authenticator�password�	XmlStream�	namespacer�send�connectionMade�dataReceived�sidr�ComponentInitiatingInitializer�init�rs r�setUpz)ComponentInitiatingInitializerTests.setUps������&�4�4�6���&.����#�"�,�,�T�-?�-?�@���#3���� �"�k�k�0�0��������%�%�'����#�#�
;�	
�
%������<�<�T�^�^�L��	rc��|jj�}|jd}|jd|j�|jd|j
�|jt
d�j�t|��g|_	|jj|j��|S)z?
        Test basic operations of component handshake.
        ����	handshaker"�12345secret)
r/�
initializer$�assertEqual�name�urir�	hexdigest�str�childrenr	r,�toXml)r�dr4s   r�
testHandshakez1ComponentInitiatingInitializerTests.testHandshake-s���

�I�I� � �"���K�K��O�	�����i�n�n�5����)�9�=�=�9�����2�3�=�=�?��Y��P� �	�����#�#�I�O�O�$5�6��rN)rrrr1r?rrrrrs
��M�"rrc��eZdZd�Zd�Zy)�ComponentAuthTestsc��d|_y�NT)�authComplete)r�streams  r�
authPassedzComponentAuthTests.authPassedDs
�� ��rc��d|_g}tjdd�}tj|�}t|�|_|jtj|j�|j�|jd�td�j�jd�}|j|dd|zd	z�|jd
�|j|jd�y)NF�cjidr!sv<stream:stream xmlns='jabber:component:accept' xmlns:stream='http://etherx.jabber.org/streams' from='cjid' id='12345'>r5�ascii�s<handshake>s</handshake>�<handshake/>T)rDr�ConnectComponentAuthenticatorr	r(r�	transport�addObserver�STREAM_AUTHD_EVENTrFr+r,rr:�encoder7)r�outlist�ca�xs�hvs     r�testAuthzComponentAuthTests.testAuthGs���!�����
�
4�
4�V�X�
F��
�
 �
 ��
$��%�g�.���
���y�3�3�T�_�_�E�	����
���
F�	
�
�&�
'�
1�
1�
3�
:�
:�7�
C��������^�b�%8�?�%J�K�
����'�����*�*�D�1rN)rrrrFrUrrrrArACs��!�2rrAc��eZdZdZd�Zy)�ServiceTestsz)
    Tests for L{component.Service}.
    c�`�tj�}ttj|�y)zF
        L{component.Service} implements L{ijabber.IService}.
        N)r�Servicerr�IService)r�services  r�test_interfacezServiceTests.test_interfacefs"���#�#�%���W�%�%�w�/rN)rrr�__doc__r\rrrrWrWas���0rrWc�$�eZdZd�Zd�Zd�Zd�Zy)�JabberServiceHarnessc�.�d|_d|_d|_y)NF)�componentConnectedFlag�componentDisconnectedFlag�transportConnectedFlagr0s rrzJabberServiceHarness.__init__os��&+��#�).��&�&+��#rc��d|_yrC)ra�rr	s  r�componentConnectedz'JabberServiceHarness.componentConnectedt�
��&*��#rc��d|_yrC)rbr0s r�componentDisconnectedz*JabberServiceHarness.componentDisconnectedws
��)-��&rc��d|_yrC)rcres  r�transportConnectedz'JabberServiceHarness.transportConnectedzrgrN)rrrrrfrirkrrrr_r_ns��,�
+�.�+rr_c��eZdZd�Zy)�JabberServiceManagerTestsc��tjdd�}t�}|j|�g}|j	�jd�}||_|j|j_|j�|jd|j�|j|tj�|jd|j�|j!d�|jd|j"�y)N�foor'T)r�ServiceManagerr_�setServiceParent�
getFactory�
buildProtocolrMrrr+r7rc�dispatchr	rOra�connectionLostrb)r�sm�svc�wlistrSs     r�testSMz JabberServiceManagerTests.testSMs���
�
%�
%�e�Z�
8��"�$�����R� ����]�]�_�
*�
*�4�
0�����"�\�\�����	����	
����s�9�9�:�	���B�	�4�4�5�	
����s�9�9�:�	���$��	
����s�<�<�=rN)rrrryrrrrmrm~s��>rrmc�"�eZdZdZd�Zd�Zd�Zy)�RouterTestsz(
    Tests for L{component.Router}.
    c���tj�}g��fd�|_t�}|j	d|j
�|j
dt|j��|j
|j
|jd�tjd�}|jj|�|j
|g��y)zJ
        Test route registration and routing on incoming stanzas.
        c�&���j|�Sr�r)�element�routeds �r�<lambda>z+RouterTests.test_addRoute.<locals>.<lambda>�s���v�}�}�W�'=�rzexample.orgrJ)�testns�testN)
r�Router�router�addRoute�sinkr7�len�routesr�Element�sourcer*)r�router�piperr�s    @r�
test_addRoutezRouterTests.test_addRoute�s�����!�!�#����=����y�����
�t�y�y�1�����C��
�
�.�/�������F�M�M�-�$@�A��.�.�!3�4��������!����'��F�+rc���t�}t�}tj�}|jd|j�|jd|j�g�|j
j
d�fd��tjd�}d|d<d|d<|j
j|�|j|g��y)	z,
        Test routing of a message.
        �component1.example.orgzcomponent2.example.org�/*c�&���j|�Srr~�r�outgoings �rr�z(RouterTests.test_route.<locals>.<lambda>�s���H�O�O�G�<T�r�N�presence�from�toN�rrr�r�r�r�rNrr�r*r7)r�
component1�
component2r��stanzar�s     @r�
test_routezRouterTests.test_route�s�����Y�
��Y�
��!�!�#�����0�*�/�/�B����0�*�/�/�B������%�%�d�,T�U���� 2�3��1��v��/��t�������v�&����&��8�,rc���t�}t�}tj�}|jd|j�|jd|j�g�|j
j
d�fd��tjd�}d|d<d|d<|j
j|�|j|g��y)	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.
        r�Nr�c�&���j|�Srr~r�s �rr�z/RouterTests.test_routeDefault.<locals>.<lambda>�s���X�_�_�W�5M�rr�r�zexample.comr�r�)rr��s2sr�r�r�s     @r�test_routeDefaultzRouterTests.test_routeDefault�s�����Y�
��i���!�!�#�����0�*�/�/�B�����c�h�h�'����
�
���t�%M�N���� 2�3��1��v��$��t�������v�&����&��8�,rN)rrrr]r�r�r�rrrr{r{�s���,�"-�$-rr{c�F�eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zd
�Zy)�!ListenComponentAuthenticatorTestsz>
    Tests for L{component.ListenComponentAuthenticator}.
    c��g|_tjd�}tj|�|_|jj
|j_y)Nr!)r$r�ListenComponentAuthenticatorr	r(rr*)rr&s  rr1z'ListenComponentAuthenticatorTests.setUp�sA�����!�>�>�x�H�
�"�,�,�]�;���"�k�k�0�0����rc�:�|jjd�y)zA
        Stub loseConnection because we are a transport.
        z	no reasonN)r	rur0s r�loseConnectionz0ListenComponentAuthenticatorTests.loseConnection�s��	
���%�%�k�2rc����g��fd�}|j}||_|j|�|jd|j�|j|j�|jd�|jd|j�|jd|j�|j|j�|jd|jjf�d�y)zK
        The received stream header should set several attributes.
        c�,���j||f�yrr~)�event�
observerfn�	observerss  �r�addOnetimeObserverzPListenComponentAuthenticatorTests.test_streamStarted.<locals>.addOnetimeObserver�s������e�Z�0�1rNzz<stream:stream xmlns='jabber:component:accept' xmlns:stream='http://etherx.jabber.org/streams' to='component.example.org'>)rrr�r3)r	r��makeConnection�assertIdenticalr-�assertFalse�_headerSentr,r7�version�assertNotIdentical�
assertTruer&�	onElement)rr�rSr�s   @r�test_streamStartedz4ListenComponentAuthenticatorTests.test_streamStarted�s�����	�	2��^�^�� 2���
���$�����T�2�6�6�*�������(�
���
*�	
�
	
�������,�����b�f�f�-�������'����$�� 0� 0� :� :�;�Y�r�]�Krc��g}|j}|j|_|j|�|j	d�|jdt
|��|jd|dj�y)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'>rJzinvalid-namespacer3N�r	r�sendStreamErrorr�r,r7r��	condition�r�streamErrorsrSs   r� test_streamStartedWrongNamespacezBListenComponentAuthenticatorTests.test_streamStartedWrongNamespace
sr����
�^�^��)�0�0���
���$��
���
*�	
�
	
����C��-�.����,�l�2�.>�.H�.H�Irc��g}|j}|j|_|j|�|j	d�|jdt
|��|jd|dj�y)zJ
        The received stream header should have a 'to' attribute.
        z_<stream:stream xmlns='jabber:component:accept' xmlns:stream='http://etherx.jabber.org/streams'>rJzimproper-addressingr3Nr�r�s   r�test_streamStartedNoToz8ListenComponentAuthenticatorTests.test_streamStartedNoTosr����
�^�^��)�0�0���
���$��
���
?�	
�	
����C��-�.����.��R�0@�0J�0J�Krc��g}|j}|j|j_t	j
d�}|j
d�|jj|�|jd|d�y)z<
        We expect a handshake element with a hash.
        )�jabber:component:acceptr4�1234r3N)	r	rr&�onHandshakerr��
addContentr�r7)r�
handshakesrSr4s    r�test_onElementz0ListenComponentAuthenticatorTests.test_onElement+sk���
�
�^�^��'1�'8�'8����$��N�N�#K�L�	����V�$�
���"�"�9�-������B��0rc�<�g}g}|j}|j|j_|j|_tjd�}|jj|�|j|�|jd|dj�y)z9
        Reject elements that are not handshakes
        )r��message�not-authorizedr3N)r	rr&r�r�rr�r�r�r7r�)rr�r�rSrs     r�test_onElementNotHandshakez<ListenComponentAuthenticatorTests.test_onElementNotHandshake9s����
���
�^�^��'1�'8�'8����$�)�0�0����.�.�!G�H��
���"�"�7�+�����$����)�<��+;�+E�+E�Frc�(��g��fd�}|j}|jtj|�d|_d}|jj|�|j
d|jd�|j
dt���y)zU
        Receiving a handshake matching the secret authenticates the stream.
        c�(���j|�yrr~�rS�authds �r�
authenticatedzIListenComponentAuthenticatorTests.test_onHandshake.<locals>.authenticatedO�����L�L��rr��(32532c0f7dbf1253c095b18b18e36d38d94c1256rKr3rJN)	r	r�rOr-r&r�r7r$r�)rr�rS�theHashr�s    @r�test_onHandshakez2ListenComponentAuthenticatorTests.test_onHandshakeIs|�����	��^�^��
���i�:�:�M�J����<��
���$�$�W�-��������R��9�����C��J�'rc�N��g}g��fd�}|j}|jtj|�|j|_d|_d}|jj|�|jd|dj�|jdt���y)zH
        Receiving a bad handshake should yield a stream error.
        c�(���j|�yrr~r�s �rr�zRListenComponentAuthenticatorTests.test_onHandshakeWrongHash.<locals>.authenticatedar�rr�r�r3rN)r	r�rOrr�r-r&r�r7r�r�)rr�r�rSr�r�s     @r�test_onHandshakeWrongHashz;ListenComponentAuthenticatorTests.test_onHandshakeWrongHashZs��������	��^�^��
���i�:�:�M�J�)�0�0��������
���$�$�W�-����)�<��+;�+E�+E�F�����C��J�'rN)
rrrr]r1r�r�r�r�r�r�r�r�rrrr�r��s8���1�3�L�4J�"L� 1�G� (�"(rr�c�4�eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z	y)	�XMPPComponentServerFactoryTestsz<
    Tests for L{component.XMPPComponentServerFactory}.
    c���tj�|_tj|jd�|_|jjd�|_td�|j_y)Nr!�component.example.org)	rr�r��XMPPComponentServerFactory�factoryrsr	r
�
thisEntityr0s rr1z%XMPPComponentServerFactoryTests.setUptsR���&�&�(��� �;�;�D�K�K��R������3�3�D�9���$'�(?�$@����!rc��|jj|jtj�|jd|jj�|jd|j
j�|j
d|jj�|j
d|jj�y)zY
        A new connection increases the stream serial count. No logs by default.
        rrJN)	r	rt�STREAM_CONNECTED_EVENTr7�serialr�r��rawDataInFn�rawDataOutFnr0s r�test_makeConnectionz3XMPPComponentServerFactoryTests.test_makeConnectionzs���	
��������	�0P�0P�Q�����D�N�N�1�1�2�����D�L�L�/�/�0����T�4�>�>�#=�#=�>����T�4�>�>�#>�#>�?rc�&�d|j_|jj|jtj�|jd|jj�|jd|jj�y)zD
        Setting logTraffic should set up raw data loggers.
        TN)r��
logTrafficr	rtr�r�r�r�r0s r�test_makeConnectionLogTrafficz=XMPPComponentServerFactoryTests.test_makeConnectionLogTraffic�sb��#'�������������	�0P�0P�Q�����d�n�n�&@�&@�A�����d�n�n�&A�&A�Brc�f�|jj|jtj�Gd�dt�}t	j
|��}|jj|tj�|jdt|j|���y)zQ
        An observer for stream errors should trigger onError to log it.
        c��eZdZy)�?XMPPComponentServerFactoryTests.test_onError.<locals>.TestErrorN)rrrrrr�	TestErrorr��s��rr�rJN)
r	rtr��	Exceptionr�Failure�STREAM_ERROR_EVENTr7r��flushLoggedErrors)rr��reasons   r�test_onErrorz,XMPPComponentServerFactoryTests.test_onError�sz��	
��������	�0P�0P�Q�	�	�	������-��������	�(D�(D�E�����C�� 6� 6�y� A�B�Crc��|jj|jtj�|jd|jj
�|j
|j|jj
d�y)zG
        Make sure a new stream is added to the routing table.
        r�N)r	rtrO�assertInr�r�r�r0s r�test_connectionInitializedz:XMPPComponentServerFactoryTests.test_connectionInitialized�sb��	
��������	�0L�0L�M��
�
�-�t�{�{�/A�/A�B�����N�N�D�K�K�.�.�/F�G�	
rc��|jj|jtj�|jjdtj�|j	d|j
j�y)zU
        Make sure a stream is removed from the routing table on disconnect.
        Nr�)r	rtrO�STREAM_END_EVENT�assertNotInr�r�r0s r�test_connectionLostz3XMPPComponentServerFactoryTests.test_connectionLost�sW��	
��������	�0L�0L�M�������i�&@�&@�A����0�$�+�+�2D�2D�ErN)
rrrr]r1r�r�r�r�r�rrrr�r�os*���A�@�C�D�
�Frr�N)r]�hashlibr�zope.interface.verifyr�twisted.pythonr�
twisted.trialr�twisted.words.protocols.jabberrrr	�"twisted.words.protocols.jabber.jidr
�twisted.words.xishr�twisted.words.xish.utilityrr�TestCaserrArWrYr_rmr{r�r�rrr�<module>rs�����.�"�"�H�H�2�%�.� � �%�(�*;�*;�%�P2��*�*�2�<
0�8�$�$�
0�
+�9�,�,�
+� >�� 1� 1�>�D<-�(�#�#�<-�~M(��(9�(9�M(�`;F�h�&7�&7�;Fr

Zerion Mini Shell 1.0