%PDF- %PDF-
Mini Shell

Mini Shell

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

�

Ϫ�f�@����dZddlmZddlmZddlmZddlmZddlm	Z	m
Z
mZmZddl
mZddlmZ	dd	lmZd
Zd
ZdZdZdezZdZdezZGd�dej4�ZGd�d�ZGd�deej4�ZGd�deej4�ZGd�deej4�ZGd�dej4�Z Gd�d ej4�Z!y#e$rdZdZY��wxYw)!z4
Tests for L{twisted.words.protocols.jabber.client}
�)�sha1)�skipIf)�defer)�unittest)�client�error�jid�	xmlstream)�SASLInitiatingInitializer)�utility)�ssl)F�N)TzSSL not availablez//iq[@type="get"]/query[@xmlns="jabber:iq:auth"]z//iq[@type="set"]/query[@xmlns="jabber:iq:auth"]z urn:ietf:params:xml:ns:xmpp-bindz"/iq[@type="set"]/bind[@xmlns="%s"]z#urn:ietf:params:xml:ns:xmpp-sessionz%/iq[@type="set"]/session[@xmlns="%s"]c��eZdZd�Zd�Zd�Zy)�CheckVersionInitializerTestsc��tj�}tj|�}tj|�|_y�N)r
�
Authenticator�	XmlStreamr�CheckVersionInitializer�init)�self�a�xss   �F/usr/lib/python3/dist-packages/twisted/words/test/test_jabberclient.py�setUpz"CheckVersionInitializerTests.setUp#s2���#�#�%��
�
 �
 ��
#���2�2�2�6��	�c�n�d|jj_|jj�y)z3
        Test supported version number 1.0
        )�rN)rr
�version�
initialize�rs r�
testSupportedz*CheckVersionInitializerTests.testSupported(s&��'-��	�	���#��	�	���rc���d|jj_|jtj
|jj�}|jd|j�y)zK
        Test unsupported version number 0.0, and check exception.
        )rrzunsupported-versionN)	rr
r�assertRaisesr�StreamErrorr �assertEqual�	condition)r�excs  r�testNotSupportedz-CheckVersionInitializerTests.testNotSupported/sM��'-��	�	���#����� 1� 1�4�9�9�3G�3G�H�����.��
�
�>rN)�__name__�
__module__�__qualname__rr"r)�rrrr"s��7�
�?rrc��eZdZdZd�Zd�Zy)�InitiatingInitializerHarnessa�
    Testing harness for interacting with XML stream initializers.

    This sets up an L{utility.XmlPipe} to create a communication channel between
    the initializer and the stubbed receiving entity. It features a sink and
    source side that both act similarly to a real L{xmlstream.XmlStream}. The
    sink is augmented with an authenticator to which initializers can be added.

    The harness also provides some utility methods to work with event observers
    and deferreds.
    c���g|_tj�|_|jj|_tjd�|_|j|j
_y)Nzexample.org)�outputr�XmlPipe�pipe�sinkr
�ConnectAuthenticator�
authenticatorr!s rrz"InitiatingInitializerHarness.setUpEsK������O�O�%��	��������&�;�;�M�J���'+�'9�'9����$rc��tj�}|j|�|jjj||j�|S)a�
        Observe an output event, returning a deferred.

        The returned deferred will be fired when the given event has been
        observed on the source end of the L{XmlPipe} tied to the protocol
        under test. The handler is added as the first callback.

        @param event: The event to be observed. See
            L{utility.EventDispatcher.addOnetimeObserver}.
        @param handler: The handler to be called with the observed event object.
        @rtype: L{defer.Deferred}.
        )r�Deferred�addCallbackr3�source�addOnetimeObserver�callback)r�event�handler�ds    r�waitForz$InitiatingInitializerHarness.waitForLs?��
�N�N���	�
�
�g���	�	���+�+�E�1�:�:�>��rN)r*r+r,�__doc__rr@r-rrr/r/8s��
�:�rr/c�:��eZdZdZ�fd�Zd�Zd�Zd�Zd�Z�xZ	S)�IQAuthInitializerTestsz0
    Tests for L{client.IQAuthInitializer}.
    c����t�|��tj|j�|_t
jd�|j_d|j_	y)N�user@example.com/resource�secret)
�superrr�IQAuthInitializerr
rr	�JIDr6�password�r�	__class__s �rrzIQAuthInitializerTests.setUpdsH���
��
���,�,�T�^�^�<��	�!$���)D�!E�����&.����#rc������fd�}�fd���jt|�}�jj�}t	j
||g�S)z�
        Test plain-text authentication.

        Act as a server supporting plain-text authentication and expect the
        C{password} field to be filled with the password. Then act as if
        authentication succeeds.
        c�n��tj|d�}|jd�|jjd�|jjd�|jjd��j	t
��}�jjj|�|S�z�
            Called when the initializer sent a query for authentication methods.

            The response informs the client that plain-text authentication
            is supported.
            �result�zjabber:iq:auth�query�usernamerJ�resource�	r
�
toResponse�
addElementrRr@�IQ_AUTH_SETr3r:�send��iq�responser?�	onAuthSetrs   ��r�	onAuthGetz7IQAuthInitializerTests.testPlainText.<locals>.onAuthGets����!�+�+�B��9�H���� ;�<��N�N�%�%�j�1��N�N�%�%�j�1��N�N�%�%�j�1����[�)�4�A�
�I�I���!�!�(�+��Hrc����jdt|jj���jdt|jj���jdt|jj
��t
j|d�}�jjj|�y)��
            Called when the initializer sent the authentication request.

            The server checks the credentials and responds with an empty result
            signalling success.
            �userrFrTrPN)r&�strrRrSrJrTr
rVr3r:rY�r[r\rs  �rr]z7IQAuthInitializerTests.testPlainText.<locals>.onAuthSet�s����
���V�S����):�):�%;�<����X�s�2�8�8�+<�+<�'=�>����Z��R�X�X�->�->�)?�@�!�+�+�B��9�H��I�I���!�!�(�+r)r@�IQ_AUTH_GETrr r�
gatherResults�rr^�d1�d2r]s`   @r�
testPlainTextz$IQAuthInitializerTests.testPlainTextjsH���	�.
	,� �\�\�+�y�
1���Y�Y�
!�
!�
#���"�"�B��8�,�,rc�������fd�}�fd��d�j_�jt|�}�jj�}t
j||g�S)a"
        Test digest authentication.

        Act as a server supporting digest authentication and expect the
        C{digest} field to be filled with a sha1 digest of the concatenated
        stream session identifier and password. Then act as if authentication
        succeeds.
        c�n��tj|d�}|jd�|jjd�|jjd�|jjd��j	t
��}�jjj|�|S)z�
            Called when the initializer sent a query for authentication methods.

            The response informs the client that digest authentication is
            supported.
            rPrQrS�digestrTrUrZs   ��rr^z4IQAuthInitializerTests.testDigest.<locals>.onAuthGet�s����!�+�+�B��9�H���� ;�<��N�N�%�%�j�1��N�N�%�%�h�/��N�N�%�%�j�1����[�)�4�A�
�I�I���!�!�(�+��Hrc�����jdt|jj���jt	d�j�t|jj���jdt|jj��tj|d�}�jjj|�y)rarbs12345secretrTrPN)
r&rcrRrSr�	hexdigestrmrTr
rVr3r:rYrds  �rr]z4IQAuthInitializerTests.testDigest.<locals>.onAuthSet�s����
���V�S����):�):�%;�<����T�.�1�;�;�=�s�2�8�8�?�?�?S�T����Z��R�X�X�->�->�)?�@�!�+�+�B��9�H��I�I���!�!�(�+r�12345)r
�sidr@rerr rrfrgs`   @r�
testDigestz!IQAuthInitializerTests.testDigest�sV���	�.
	,� %������\�\�+�y�
1���Y�Y�
!�
!�
#���"�"�B��8�,�,rc�����fd�}�jt|�}�jj�}�j	|t
j�tj||g�S)zT
        Test initializer failure of request for fields for authentication.
        c���tjd�j|�}�jjj|�y)z�
            Called when the initializer sent a query for authentication methods.

            The server responds that the client is not authorized to authenticate.
            �not-authorizedN�r�StanzaErrorrVr3r:rYrds  �rr^z?IQAuthInitializerTests.testFailRequestFields.<locals>.onAuthGet�s9����(�(�)9�:�E�E�b�I�H��I�I���!�!�(�+r�	r@rerr �
assertFailurerrwrrf)rr^rhris`   r�testFailRequestFieldsz,IQAuthInitializerTests.testFailRequestFields�s[���
	,��\�\�+�y�
1���Y�Y�
!�
!�
#��	
���2�u�0�0�1��"�"�B��8�,�,rc�������fd�}�fd���jt|�}�jj�}�j	|t
j�tj||g�S)z;
        Test initializer failure to authenticate.
        c�n��tj|d�}|jd�|jjd�|jjd�|jjd��j	t
��}�jjj|�|SrOrUrZs   ��rr^z6IQAuthInitializerTests.testFailAuth.<locals>.onAuthGet�r_rc���tjd�j|�}�jjj|�y)z�
            Called when the initializer sent the authentication request.

            The server checks the credentials and responds with a not-authorized
            stanza error.
            ruNrvrds  �rr]z6IQAuthInitializerTests.testFailAuth.<locals>.onAuthSets9����(�(�)9�:�E�E�b�I�H��I�I���!�!�(�+rrxrgs`   @r�testFailAuthz#IQAuthInitializerTests.testFailAuth�s`���
	�.	,��\�\�+�y�
1���Y�Y�
!�
!�
#��	
���2�u�0�0�1��"�"�B��8�,�,r)
r*r+r,rArrjrrrzr~�
__classcell__�rLs@rrCrC_s#����/�4-�l9-�v-�2/-rrCc�.��eZdZdZ�fd�Zd�Zd�Z�xZS)�BindInitializerTestsz.
    Tests for L{client.BindInitializer}.
    c���t�|��tj|j�|_t
jd�|j_y)NrE)	rGrr�BindInitializerr
rr	rIr6rKs �rrzBindInitializerTests.setUp+s:���
��
���*�*�4�>�>�:��	�!$���)D�!E����rc�����fd�}�fd�}�jt|�}�jj�}|j	|�tj||g�S)zK
        Set up a stream, and act as if resource binding succeeds.
        c����tj|d�}|jtdf�|jjdd���j
jj|�y)NrP�bindr	�user@example.com/other resource)�content)r
rVrW�NS_BINDr�r3r:rYrds  �r�onBindz.BindInitializerTests.testBasic.<locals>.onBind5sX��� �+�+�B��9�H�����&� 1�2��M�M�$�$�U�4U�$�V��I�I���!�!�(�+rc�x���jtjd��jj�y)Nr�)r&r	rIr6)rPrs �r�cbz*BindInitializerTests.testBasic.<locals>.cb;s,���������9�:�D�<N�<N�<R�<R�
r)r@�IQ_BIND_SETr�startr9rrf)rr�r�rhris`    r�	testBasiczBindInitializerTests.testBasic0sP���
	,�	�
�\�\�+�v�
.��
�Y�Y�_�_�
��
���r���"�"�B��8�,�,rc�����fd�}�jt|�}�jj�}�j	|t
j�tj||g�S)zH
        Set up a stream, and act as if resource binding fails.
        c���tjd�j|�}�jjj|�y)N�conflictrvrds  �rr�z0BindInitializerTests.testFailure.<locals>.onBindJs6����(�(��4�?�?��C�H��I�I���!�!�(�+r)	r@r�rr�ryrrwrrf)rr�rhris`   r�testFailurez BindInitializerTests.testFailureEsU���
	,��\�\�+�v�
.��
�Y�Y�_�_�
�����2�u�0�0�1��"�"�B��8�,�,r)r*r+r,rArr�r�rr�s@rr�r�&s����F�
-�*-rr�c�.��eZdZdZ�fd�Zd�Zd�Z�xZS)�SessionInitializerTestsz1
    Tests for L{client.SessionInitializer}.
    c�j��t�|��tj|j�|_yr)rGrr�SessionInitializerr
rrKs �rrzSessionInitializerTests.setUpYs"���
��
���-�-�d�n�n�=��	rc����fd�}�jt|�}�jj�}t	j
||g�S)zP
        Set up a stream, and act as if session establishment succeeds.
        c�|��tj|d�}�jjj	|�y)NrP)r
rVr3r:rYrds  �r�	onSessionz6SessionInitializerTests.testSuccess.<locals>.onSessionbs-��� �+�+�B��9�H��I�I���!�!�(�+r)r@�IQ_SESSION_SETrr�rrf�rr�rhris`   r�testSuccessz#SessionInitializerTests.testSuccess]s?���
	,��\�\�.�)�
4��
�Y�Y�_�_�
���"�"�B��8�,�,rc�����fd�}�jt|�}�jj�}�j	|t
j�tj||g�S)zM
        Set up a stream, and act as if session establishment fails.
        c���tjd�j|�}�jjj|�y)N�	forbiddenrvrds  �rr�z6SessionInitializerTests.testFailure.<locals>.onSessionos6����(�(��5�@�@��D�H��I�I���!�!�(�+r)	r@r�rr�ryrrwrrfr�s`   rr�z#SessionInitializerTests.testFailurejsU���
	,��\�\�.�)�
4��
�Y�Y�_�_�
�����2�u�0�0�1��"�"�B��8�,�,r)r*r+r,rArr�r�rr�s@rr�r�Ts����>�-�-rr�c��eZdZdZd�Zy)�BasicAuthenticatorTestszB
    Test for both BasicAuthenticator and basicClientFactory.
    c�b�tjd�|_tj|jd�jd�}|j
d|jj�|j
|j|jj�|j
d|jj�|j\}}|j|tj�|j|tj�|j|j �y)a
        Authenticator and stream are properly constructed by the factory.

        The L{xmlstream.XmlStream} protocol created by the factory has the new
        L{client.BasicAuthenticator} instance in its C{authenticator}
        attribute.  It is set up with C{jid} and C{password} as passed to the
        factory, C{otherHost} taken from the client JID. The stream futher has
        two initializers, for TLS and authentication, of which the first has
        its C{required} attribute set to C{True}.
        rErFN�example.com)r	rI�
client_jidr�basicClientFactory�
buildProtocolr&r6�	otherHostrJ�initializers�assertIsInstancer
�TLSInitiatingInitializerrH�assertFalse�required)rr�tls�auths    r�
test_basicz"BasicAuthenticatorTests.test_basic~s����'�'�"=�>���
�
&�
&�t����
A�
O�
O�PT�
U��	
�����(8�(8�(B�(B�C�������"�*:�*:�*>�*>�?�����2�#3�#3�#<�#<�=��O�O�	��T����c�9�#E�#E�F����d�F�$<�$<�=�������&rN)r*r+r,rAr�r-rrr�r�ys���'rr�c�,�eZdZdZd�Zee�d��Zy)�XMPPAuthenticatorTestsz@
    Test for both XMPPAuthenticator and XMPPClientFactory.
    c�v�tjd�|_tj|jd�jd�}|j
d|jj�|j
|j|jj�|j
d|jj�|j\}}}}}|j|tj�|j|t�|j|tj�|j|tj �|j#|j$�|j#|j$�|j#|j$�|j'|j$�y)z�
        Test basic operations.

        Setup an XMPPClientFactory, which sets up an XMPPAuthenticator, and let
        it produce a protocol instance. Then inspect the instance variables of
        the authenticator and XML stream objects.
        rErFNr�)r	rIr�r�XMPPClientFactoryr�r&r6r�rJr�r�r
r�rr�r��
assertTruer�r�)rrrr��saslr��sessions       rr�z!XMPPAuthenticatorTests.test_basic�s?���'�'�"=�>���
�
%�
%�d�o�o�x�
@�
N�
N�t�
T��	
�����(8�(8�(B�(B�C�������"�*:�*:�*>�*>�?�����2�#3�#3�#<�#<�=�-/�O�O�)���d�D�'����c�9�#E�#E�F����d�$=�>����d�F�$:�$:�;����g�v�'@�'@�A�������%�����
�
�&�����
�
�&�����)�)�*rc��
�g�
d�
fd�	}tjd�|_tj�}tj|jd|��}|jtjd|�|jd�}|j\}}}}}	|j|tj�|j|�
d�y)	zG
        A TLS configuration is passed to the TLS initializer.
        Nc�(���j|�yr)�append)rrr��configurationForTLS�configss    �rrz:XMPPAuthenticatorTests.test_tlsConfiguration.<locals>.init�s����N�N�.�/rrErF)r��__init__r)TN)r	rIr�r
�CertificateOptionsrr��patchr
r�r�r�r��assertIs)rrr��factoryrrr�r�r�r�r�s          @r�test_tlsConfigurationz,XMPPAuthenticatorTests.test_tlsConfiguration�s����
��	0��'�'�"=�>���
"�4�4�6���*�*��O�O�X�;N�
��	
�
�
�9�5�5�z�4�H�
�
"�
"�4�
(��-/�O�O�)���d�D�'����c�9�#E�#E�F��
�
�)�7�1�:�6rN)r*r+r,rAr�r�
skipWhenNoSSLr�r-rrr�r��s&���+�B�]��7��7rr�)"rA�hashlibrrr�twisted.internetr�
twisted.trial�twisted.words.protocols.jabberrrr	r
�#twisted.words.protocols.jabber.saslr�twisted.words.xishrr
r��ImportErrorrerXr�r��
NS_SESSIONr��TestCaserr/rCr�r�r�r�r-rr�<module>r�s����
��"�"�H�H�I�&� �$�
 �M�?��?��
,��2�W�<��
2�
�8�:�E��?�8�#4�#4�?�,$�$�ND-�9�8�;L�;L�D-�N+-�7��9J�9J�+-�\"-�:�H�<M�<M�"-�J"'�h�/�/�"'�J@7�X�.�.�@7��U�0�
�C�/�M�0�s�C�	C&�%C&

Zerion Mini Shell 1.0