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_jabbersasl.cpython-38.pyc
U


W[�$�@s�ddlmZmZddlmZddlmZddlmZddl	m
Z
ddlmZm
Z
mZmZddlmZdZee
j�Gd	d
�d
e��ZGdd�dej�ZGd
d�de
j�ZGdd�de
j�ZdS)�)�absolute_import�division)�implementer)�defer)�unicode)�unittest)�sasl�sasl_mechanisms�	xmlstream�jid)�domish� urn:ietf:params:xml:ns:xmpp-saslc@s4eZdZdZdZdZdZdd�Zdd�Zd	d
�Z	dS)�DummySASLMechanisma�
    Dummy SASL mechanism.

    This just returns the initialResponse passed on creation, stores any
    challenges and replies with the value of C{response}.

    @ivar challenge: Last received challenge.
    @type challenge: C{unicode}.
    @ivar initialResponse: Initial response to be returned when requested
                           via C{getInitialResponse} or L{None}.
    @type initialResponse: C{unicode}
    N�DUMMY�cCs
||_dS�N��initialResponse)�selfr�r�D/usr/lib/python3/dist-packages/twisted/words/test/test_jabbersasl.py�__init__#szDummySASLMechanism.__init__cCs|jSrr�rrrr�getInitialResponse&sz%DummySASLMechanism.getInitialResponsecCs||_|jSr)�	challenge�response)rrrrr�getResponse)szDummySASLMechanism.getResponse)
�__name__�
__module__�__qualname__�__doc__r�namerrrrrrrrrs
rc@seZdZdZdZdd�ZdS)�DummySASLInitiatingInitializerac
    Dummy SASL Initializer for initiating entities.

    This hardwires the SASL mechanism to L{DummySASLMechanism}, that is
    instantiated with the value of C{initialResponse}.

    @ivar initialResponse: The initial response to be returned by the
                           dummy SASL mechanism or L{None}.
    @type initialResponse: C{unicode}.
    NcCst|j�|_dSr)rr�	mechanismrrrr�setMechanism<sz+DummySASLInitiatingInitializer.setMechanism)rrrr rr$rrrrr".sr"c@sheZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Zdd�Z
dd�ZdS)�SASLInitiatingInitializerTestsz5
    Tests for L{sasl.SASLInitiatingInitializer}
    cCsPg|_t��|_t�|j�|_|jj|j_|j��|j�d�t	|j�|_
dS)Ns�<stream:stream xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams' from='example.com' id='12345' version='1.0'>)�outputr
�
Authenticator�
authenticator�	XmlStream�append�send�connectionMade�dataReceivedr"�initrrrr�setUpFs

z$SASLInitiatingInitializerTests.setUpcs\t�d�}|�d�t���j_�j�|����jjt	j
��jj��fdd���jjS)zL
        Test that the SASL error condition is correctly extracted.
        )r
�failure�not-authorizedcs��d|j�S)Nr1)�assertEqualZ	condition)�errr�<lambda>]s�z?SASLInitiatingInitializerTests.test_onFailure.<locals>.<lambda>)r�Element�
addElementrZDeferredr.Z	_deferredZ	onFailure�
assertFailurerZ
SASLAuthErrorZaddCallback)rr0rrr�test_onFailureSs

z-SASLInitiatingInitializerTests.test_onFailurecCs\d|j_|j��|jd}|�t|j�|�d|j�|�d|d�|�dt|��dS)zH
        Test starting authentication with an initial response.
        sdummyr�authrr#zZHVtbXk=N)	r.r�startr&r2�NS_XMPP_SASL�urir!r�rr9rrr�test_sendAuthInitialResponsecs

z;SASLInitiatingInitializerTests.test_sendAuthInitialResponsecCs0d|j_|j��|jd}|�dt|��dS)zK
        Test starting authentication without an initial response.
        Nr�)r.rr:r&r2�strr=rrr�test_sendAuthNoInitialResponseps

z=SASLInitiatingInitializerTests.test_sendAuthNoInitialResponsecCs0d|j_|j��|jd}|�dt|��dS)zS
        Test starting authentication where the initial response is empty.
        rr�=N)r.rr:r&r2rr=rrr�!test_sendAuthEmptyInitialResponsezs

z@SASLInitiatingInitializerTests.test_sendAuthEmptyInitialResponsecCsP|j��}t�tdf�}|�d�|j�|�|�d|jjj	�|j�
d�|S)z5
        Test receiving a challenge message.
        r�bXkgY2hhbGxlbmdlsmy challengeN)r.r:rr5r;�
addContent�onChallenger2r#r�	onSuccess�r�drrrr�test_onChallenge�s

z/SASLInitiatingInitializerTests.test_onChallengecCsb|j��}t�tdf�}|�d�d|jj_|j�|�|j	d}|�
dt|��|j�d�|S)zS
        A non-empty response gets encoded and included as character data.
        rrDsresponse�zcmVzcG9uc2U=N)
r.r:rr5r;rEr#rrFr&r2rrG)rrIrrrrr�test_onChallengeResponse�s



z7SASLInitiatingInitializerTests.test_onChallengeResponsecCsF|j��}t�tdf�}|j�|�|�d|jjj�|j�	d�|S)z<
        Test receiving an empty challenge message.
        rrN)
r.r:rr5r;rFr2r#rrGrHrrr�test_onChallengeEmpty�s
z4SASLInitiatingInitializerTests.test_onChallengeEmptycCs@|j��}t�tdf�}|�d�|j�|�|�|tj	�|S)zJ
        Test receiving a challenge message with illegal padding.
        rzbXkg=Y2hhbGxlbmdl�
r.r:rr5r;rErFr7rZSASLIncorrectEncodingErrorrHrrr�test_onChallengeIllegalPadding�s

z=SASLInitiatingInitializerTests.test_onChallengeIllegalPaddingcCs@|j��}t�tdf�}|�d�|j�|�|�|tj	�|S)zM
        Test receiving a challenge message with illegal characters.
        rzbXkg*Y2hhbGxlbmdlrNrHrrr�!test_onChallengeIllegalCharacters�s

z@SASLInitiatingInitializerTests.test_onChallengeIllegalCharacterscCs@|j��}t�tdf�}|�d�|j�|�|�|tj	�|S)z?
        Test receiving a malformed challenge message.
        r�arNrHrrr�test_onChallengeMalformed�s

z8SASLInitiatingInitializerTests.test_onChallengeMalformedN)rrrr r/r8r>rArCrJrLrMrOrPrRrrrrr%As




r%c@sHeZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dS)�*SASLInitiatingInitializerSetMechanismTestszB
    Test for L{sasl.SASLInitiatingInitializer.setMechanism}.
    cCsRg|_t��|_t�|j�|_|jj|j_|j��|j�d�t	�
|j�|_dS)Nz�<stream:stream xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams' from='example.com' id='12345' version='1.0'>)r&r
r'r(r)r*r+r,r-r�SASLInitiatingInitializerr.rrrrr/�s

z0SASLInitiatingInitializerSetMechanismTests.setUpcCsDt�tdf�}|jd|d�||jj|j|jf<|j�	�|jj
jS)zX
        Set up the XML Stream to have a SASL feature with the given mechanism.
        Z
mechanismsr#)Zcontent)rr5r;r6r
Zfeaturesr<r!r.r$r#)rr!Zfeaturerrr�
_setMechanism�s

z8SASLInitiatingInitializerSetMechanismTests._setMechanismcCs0t�d�|j_d|j_d}|�||�|��dS)zI
        Test setting ANONYMOUS as the authentication mechanism.
        �example.comNZ	ANONYMOUS�r�JIDr(�passwordr2rU�rr!rrr�test_anonymous�sz9SASLInitiatingInitializerSetMechanismTests.test_anonymouscCs0t�d�|j_d|j_d}|�||�|��dS)zE
        Test setting PLAIN as the authentication mechanism.
        �test@example.com�secretZPLAINNrWrZrrr�
test_plain�sz5SASLInitiatingInitializerSetMechanismTests.test_plaincCs0t�d�|j_d|j_d}|�||�|��dS)zJ
        Test setting DIGEST-MD5 as the authentication mechanism.
        r\r]z
DIGEST-MD5NrWrZrrr�test_digestsz6SASLInitiatingInitializerSetMechanismTests.test_digestcCs,t�d�|j_d|j_|�tj|jd�dS)zK
        Test using an unacceptable SASL authentication mechanism.
        r\r]�SOMETHING_UNACCEPTABLEN�rrXr(rYZassertRaisesrZSASLNoAcceptableMechanismrUrrrr�test_notAcceptables�z=SASLInitiatingInitializerSetMechanismTests.test_notAcceptablecCs,t�d�|j_d|j_|�tj|jd�dS)zW
        Test using an unacceptable SASL authentication mechanism with no JID.
        rVr]r`Nrarrrr�test_notAcceptableWithoutUsers�zHSASLInitiatingInitializerSetMechanismTests.test_notAcceptableWithoutUserN)rrrr r/rUr[r^r_rbrcrrrrrS�srSN)Z
__future__rrZzope.interfacerZtwisted.internetrZtwisted.python.compatrZ
twisted.trialrZtwisted.words.protocols.jabberrr	r
rZtwisted.words.xishrr;ZISASLMechanism�objectrrTr"ZTestCaser%rSrrrr�<module>s