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: //usr/lib/python3/dist-packages/twisted/words/test/__pycache__/test_jabberclient.cpython-38.pyc
U

s�@g�A�@sLdZddlmZmZddlmZddlmZddlm	Z	ddl
mZddlm
Z
mZmZmZddlmZdd	lmZzdd
lmZWnek
r�dZdZYnXdZd
ZdZdZdeZdZdeZGdd�dej�ZGdd�de �Z!Gdd�de!ej�Z"Gdd�de!ej�Z#Gdd�de!ej�Z$Gdd�dej�Z%Gdd �d ej�Z&dS)!z4
Tests for L{twisted.words.protocols.jabber.client}
�)�absolute_import�division)�sha1)�defer)�unicode)�unittest)�client�error�jid�	xmlstream)�SASLInitiatingInitializer)�utility)�sslNzSSL 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@s$eZdZdd�Zdd�Zdd�ZdS)�CheckVersionInitializerTestscCs"t��}t�|�}t�|�|_dS�N)rZ
AuthenticatorZ	XmlStreamrZCheckVersionInitializer�init)�self�a�xs�r�F/usr/lib/python3/dist-packages/twisted/words/test/test_jabberclient.py�setUp#s
z"CheckVersionInitializerTests.setUpcCsd|jj_|j��dS)z3
        Test supported version number 1.0
        )�rN)rr�version�
initialize�rrrr�
testSupported)s
z*CheckVersionInitializerTests.testSupportedcCs.d|jj_|�tj|jj�}|�d|j�dS)zK
        Test unsupported version number 0.0, and check exception.
        )rrzunsupported-versionN)	rrrZassertRaisesr	ZStreamErrorr�assertEqualZ	condition)r�excrrr�testNotSupported1s
z-CheckVersionInitializerTests.testNotSupportedN)�__name__�
__module__�__qualname__rrrrrrrr"src@s eZdZdZdd�Zdd�ZdS)�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.
    cCs4g|_t��|_|jj|_t�d�|_|j|j_dS)Nzexample.org)�outputr
ZXmlPipe�pipeZsinkrZConnectAuthenticator�
authenticatorrrrrrHs


z"InitiatingInitializerHarness.setUpcCs(t��}|�|�|jj�||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}.
        )rZDeferred�addCallbackr%�sourceZaddOnetimeObserver�callback)rZeventZhandler�drrr�waitForPs

z$InitiatingInitializerHarness.waitForN)r r!r"�__doc__rr+rrrrr#;sr#cs@eZdZdZ�fdd�Zdd�Zdd�Zdd	�Zd
d�Z�Z	S)�IQAuthInitializerTestsz0
    Tests for L{client.IQAuthInitializer}.
    cs6tt|���t�|j�|_t�d�|j	_d|j	_
dS)N�user@example.com/resource�secret)�superr-rr�IQAuthInitializerrrr
�JIDr&�passwordr��	__class__rrriszIQAuthInitializerTests.setUpcs>��fdd�}�fdd����t|�}�j��}t�||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.
        csXt�|d�}|�d�|j�d�|j�d�|j�d���t��}�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�usernamer3�resource�	r�
toResponse�
addElementr9r+�IQ_AUTH_SETr%r(�send��iq�responser*��	onAuthSetrrr�	onAuthGetys	
z7IQAuthInitializerTests.testPlainText.<locals>.onAuthGetcsZ��dt|jj����dt|jj����dt|jj��t�|d�}�jj	�
|�dS)��
            Called when the initializer sent the authentication request.

            The server checks the credentials and responds with an empty result
            signalling success.
            �userr/r;r7N)rrr9r:r3r;rr=r%r(r@�rBrCrrrrE�s
z7IQAuthInitializerTests.testPlainText.<locals>.onAuthSet)r+�IQ_AUTH_GETrrr�
gatherResults�rrF�d1�d2rrDr�
testPlainTextps
	
z$IQAuthInitializerTests.testPlainTextcsF��fdd�}�fdd��d�j_��t|�}�j��}t�||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.
        csXt�|d�}|�d�|j�d�|j�d�|j�d���t��}�jj�|�|S)z�
            Called when the initializer sent a query for authentication methods.

            The response informs the client that digest authentication is
            supported.
            r7r8r:�digestr;r<rArDrrrF�s	
z4IQAuthInitializerTests.testDigest.<locals>.onAuthGetcsb��dt|jj����td���t|jj����dt|jj��t�	|d�}�j
j�|�dS)rGrHs12345secretr;r7N)
rrr9r:rZ	hexdigestrPr;rr=r%r(r@rIrrrrE�s
�z4IQAuthInitializerTests.testDigest.<locals>.onAuthSetZ12345)rZsidr+rJrrrrKrLrrDr�
testDigest�s

z!IQAuthInitializerTests.testDigestcs>�fdd�}��t|�}�j��}��|tj�t�||g�S)zT
        Test initializer failure of request for fields for authentication.
        cs"t�d��|�}�jj�|�dS)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	�StanzaErrorr=r%r(r@rIrrrrF�sz?IQAuthInitializerTests.testFailRequestFields.<locals>.onAuthGet�	r+rJrr�
assertFailurer	rTrrKrLrrr�testFailRequestFields�s


z,IQAuthInitializerTests.testFailRequestFieldscsL��fdd�}�fdd����t|�}�j��}��|tj�t�||g�S)z;
        Test initializer failure to authenticate.
        csXt�|d�}|�d�|j�d�|j�d�|j�d���t��}�jj�|�|Sr6r<rArDrrrFs	
z6IQAuthInitializerTests.testFailAuth.<locals>.onAuthGetcs"t�d��|�}�jj�|�dS)z�
            Called when the initializer sent the authentication request.

            The server checks the credentials and responds with a not-authorized
            stanza error.
            rRNrSrIrrrrEsz6IQAuthInitializerTests.testFailAuth.<locals>.onAuthSetrUrLrrDr�testFailAuth�s
z#IQAuthInitializerTests.testFailAuth)
r r!r"r,rrOrQrWrX�
__classcell__rrr4rr-ds7=r-cs0eZdZdZ�fdd�Zdd�Zdd�Z�ZS)�BindInitializerTestsz.
    Tests for L{client.BindInitializer}.
    cs.tt|���t�|j�|_t�d�|j	_dS)Nr.)
r0rZrr�BindInitializerrrr
r2r&rr4rrr5szBindInitializerTests.setUpcsF�fdd�}�fdd�}��t|�}�j��}|�|�t�||g�S)zK
        Set up a stream, and act as if resource binding succeeds.
        cs<t�|d�}|�tdf�|jjddd��jj�|�dS)Nr7�bindr
�user@example.com/other resource)Zcontent)rr=r>�NS_BINDr\r%r(r@rIrrr�onBind?s�z.BindInitializerTests.testBasic.<locals>.onBindcs��t�d��jj�dS)Nr])rr
r2r&)r7rrr�cbFs�z*BindInitializerTests.testBasic.<locals>.cb)r+�IQ_BIND_SETr�startr'rrK)rr_r`rMrNrrr�	testBasic;s

zBindInitializerTests.testBasiccs>�fdd�}��t|�}�j��}��|tj�t�||g�S)zH
        Set up a stream, and act as if resource binding fails.
        cs"t�d��|�}�jj�|�dS)NZconflictrSrIrrrr_Tsz0BindInitializerTests.testFailure.<locals>.onBind)	r+rarrbrVr	rTrrK)rr_rMrNrrr�testFailurePs

z BindInitializerTests.testFailure)r r!r"r,rrcrdrYrrr4rrZ0srZcs0eZdZdZ�fdd�Zdd�Zdd�Z�ZS)�SessionInitializerTestsz1
    Tests for L{client.SessionInitializer}.
    cs tt|���t�|j�|_dSr)r0rerr�SessionInitializerrrrr4rrrdszSessionInitializerTests.setUpcs0�fdd�}��t|�}�j��}t�||g�S)zP
        Set up a stream, and act as if session establishment succeeds.
        cst�|d�}�jj�|�dS)Nr7)rr=r%r(r@rIrrr�	onSessionnsz6SessionInitializerTests.testSuccess.<locals>.onSession)r+�IQ_SESSION_SETrrbrrK�rrgrMrNrrr�testSuccessis
z#SessionInitializerTests.testSuccesscs>�fdd�}��t|�}�j��}��|tj�t�||g�S)zM
        Set up a stream, and act as if session establishment fails.
        cs"t�d��|�}�jj�|�dS)NZ	forbiddenrSrIrrrrg{sz6SessionInitializerTests.testFailure.<locals>.onSession)	r+rhrrbrVr	rTrrKrirrrrdws

z#SessionInitializerTests.testFailure)r r!r"r,rrjrdrYrrr4rre_srec@seZdZdZdd�ZdS)�BasicAuthenticatorTestszB
    Test for both BasicAuthenticator and basicClientFactory.
    cCs�t�d�|_t�|jd��d�}|�d|jj�|�|j|jj�|�d|jj	�|j
\}}|�|tj
�|�|tj�|�|j�dS)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}.
        r.r/N�example.com)r
r2�
client_jidrZbasicClientFactory�
buildProtocolrr&�	otherHostr3�initializers�assertIsInstancer�TLSInitiatingInitializerr1�assertFalse�required)rr�tlsZauthrrr�
test_basic�s��
z"BasicAuthenticatorTests.test_basicN)r r!r"r,rvrrrrrk�srkc@s&eZdZdZdd�Zdd�Zee_dS)�XMPPAuthenticatorTestsz@
    Test for both XMPPAuthenticator and XMPPClientFactory.
    cCs�t�d�|_t�|jd��d�}|�d|jj�|�|j|jj�|�d|jj	�|j
\}}}}}|�|tj
�|�|t�|�|tj�|�|tj�|�|j�|�|j�|�|j�|�|j�dS)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.
        r.r/Nrl)r
r2rmr�XMPPClientFactoryrnrr&ror3rprqrrrrr[rfZ
assertTruertrs)rrrru�saslr\�sessionrrrrv�s$��z!XMPPAuthenticatorTests.test_basicc
s�g�d
�fdd�	}t�d�|_t��}tj|jd|d�}|�tj	d|�|�
d�}|j\}}}}}	|�|tj	�|�
|�d	�dS)zG
        A TLS configuration is passed to the TLS initializer.
        TNcs��|�dSr)�append)rrrt�configurationForTLS�Zconfigsrrr�sz:XMPPAuthenticatorTests.test_tlsConfiguration.<locals>.initr.r/)r|�__init__r)TN)r
r2rmrZCertificateOptionsrrxZpatchrrrrnrprqZassertIs)
rrr|�factoryrrruryr\rzrr}r�test_tlsConfiguration�s�
z,XMPPAuthenticatorTests.test_tlsConfigurationN)r r!r"r,rvr��
skipWhenNoSSL�skiprrrrrw�s#rw)'r,Z
__future__rrZhashlibrZtwisted.internetrZtwisted.python.compatrZ
twisted.trialrZtwisted.words.protocols.jabberrr	r
rZ#twisted.words.protocols.jabber.saslrZtwisted.words.xishr
r�ImportErrorr�rJr?r^raZ
NS_SESSIONrhZTestCaser�objectr#r-rZrerkrwrrrr�<module>s8
)M/''