
    Yf'                     |   d Z ddlmZ ddlmZ ddlmZmZ ddlm	Z	 ddl
mZ ddlmZ ddlmZ dd	lmZ dd
lmZmZmZmZ ddlmZ ddlmZ 	 ddlmZ eZdZddlmZ ddlm Z  n# e!$ r dZdZY nw xY wdZ" G d dej#                  Z$ G d dej#                  Z% G d dej#                  Z& G d de'          Z( G d dej#                  Z) G d dej#                  Z* G d  d!ej#                  Z+ G d" d#ej#                  Z, G d$ d%ej-                  Z. G d& d'ej#                  Z/ G d( d)ej#                  Z0 G d* d+          Z1 G d, d-ej2                  Z3 G d. d/ej2                  Z4 G d0 d1ej#                  Z5 G d2 d3ej#                  Z6 G d4 d5ej#                  Z7 G d6 d7e          Z8dS )8z8
Tests for L{twisted.words.protocols.jabber.xmlstream}.
    )skipIf)verifyObject)defertask)ConnectionLost)IProtocolFactory)failure)proto_helpers)unittest)errorijabberjid	xmlstream)!GenericXmlStreamFactoryTestsMixin)domish)ssl)F )ClientTLSOptions)CertificateOptionsN)TzSSL not availableurn:ietf:params:xml:ns:xmpp-tlsc                   *    e Zd ZdZd Zd Zd Zd ZdS )HashPasswordTestsz.
    Tests for L{xmlstream.hashPassword}.
    c                 \    t          j        dd          }|                     d|           dS )zS
        The sid and secret are concatenated to calculate sha1 hex digest.
        12345secret(99567ee91b2c7cabf607f10cb9f4a3634fa820e0Nr   hashPasswordassertEqualselfhashs     Y/var/www/html/env/lib/python3.11/site-packages/twisted/words/test/test_jabberxmlstream.py
test_basiczHashPasswordTests.test_basic)   s3     %gx88CTJJJJJ    c                 T    |                      t          t          j        dd           dS )zB
        The session identifier must be a unicode object.
        s   ¹2345r   NassertRaises	TypeErrorr   r   r!   s    r#   test_sidNotUnicodez$HashPasswordTests.test_sidNotUnicode0   s'     	)Y%;_hWWWWWr%   c                 T    |                      t          t          j        dd           dS )z8
        The password must be a unicode object.
        r   s   secrétNr'   r*   s    r#   test_passwordNotUnicodez)HashPasswordTests.test_passwordNotUnicode6   s(     	)Y%;WFVWWWWWr%   c                 \    t          j        dd          }|                     d|           dS )z\
        The concatenated sid and password must be encoded to UTF-8 before hashing.
        r   u   secrét(659bf88d8f8e179081f7f3b4a8e7d224652d2853Nr   r    s     r#   test_unicodeSecretz$HashPasswordTests.test_unicodeSecret<   s3     %g}==CTJJJJJr%   N)__name__
__module____qualname____doc__r$   r+   r-   r0    r%   r#   r   r   $   sh         K K KX X XX X XK K K K Kr%   r   c                   Z    e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zd ZdS )IQTestszG
    Tests both IQ and the associated IIQResponseTracker callback.
    c                    t          j        d          }d|_        t          j        |          | _         t	          j                    | _        | j        j        | j         _        | j         	                    t          j                               | j                             d           t          j        | j         d          | _        d S )N	otherhosttestnszm<stream:stream xmlns:stream='http://etherx.jabber.org/streams' xmlns='testns' from='otherhost' version='1.0'>get)r   ConnectAuthenticator	namespace	XmlStreamr   Clockclock	callLater
_callLatermakeConnectionr
   StringTransportdataReceivedIQiq)r!   authenticators     r#   setUpzIQTests.setUpI   s    !6{CC"*",];;Z\\
$(J$8!%%m&C&E&EFFF##=	
 	
 	
 ,t~u55r%   c                     |                      | j        d         d           |                     | j        d                    d S )Ntyper;   id)r   rG   
assertTruer*   s    r#   	testBasiczIQTests.testBasicV   s<    %000&&&&&r%   c                 4   | j         j                                         | j                                         | j        d                             d          }|                     | j         j                                        d|z   dz   d|z   dz   g           d S )NrL   zutf-8s   <iq type='get' id='s   '/>s   <iq id='s   ' type='get'/>)r   	transportclearrG   sendencodeassertInvalue)r!   idBytess     r#   testSendzIQTests.testSendZ   s     &&((('$-&&w//N$**,,&069g%(99	
 	
 	
 	
 	
r%   c                       fd} j                                         }|                    |            j        }|                    d j         d         z             |S )Nc                 @                         | d         d           d S )NrK   result)r   )rZ   r!   s    r#   cbz&IQTests.testResultResponse.<locals>.cbg   s#    VF^X66666r%   <iq type='result' id='%s'/>rL   )rG   rR   addCallbackr   rE   )r!   r[   dxss   `   r#   testResultResponsezIQTests.testResultResponsef   si    	7 	7 	7 	7 	7 GLLNN	b^
5EFFFr%   c                     | j                                         }|                     |t          j                   | j        }|                    d| j         d         z             |S )Nz<iq type='error' id='%s'/>rL   )rG   rR   assertFailurer   StanzaErrorr   rE   r!   r^   r_   s      r#   testErrorResponsezIQTests.testErrorResponseq   sT    GLLNN1e/000^
4twt}DEEEr%   c                       j         }t          j        |                                |j                    fd}|                    d|d           |                    d           dS )z
        Test that untracked iq responses don't trigger any action.

        Untracked means that the id of the incoming response iq is not
        in the stream's C{iqDeferreds} dictionary.
        c                 P                         t          | dd                     d S )NhandledF)assertFalsegetattr)rG   r!   s    r#   r[   z*IQTests.testNonTrackedResponse.<locals>.cb   s)    WRE::;;;;;r%   z/iqz<iq type='result' id='test'/>N)r   upgradeWithIQResponseTrackerri   iqDeferredsaddObserverrE   )r!   r_   r[   s   `  r#   testNonTrackedResponsezIQTests.testNonTrackedResponsey   s     ^.r222 	(((
	< 	< 	< 	< 	< 	ub"%%% 	788888r%   c                     | j                                         }| j        }|                    d| j         d         z             |                     | j         d         |j                   |S )z
        Test if the deferred associated with an iq request is removed
        from the list kept in the L{XmlStream} object after it has
        been fired.
        r\   rL   )rG   rR   r   rE   assertNotInrm   rd   s      r#   testCleanupzIQTests.testCleanup   s[     GLLNN^
5EFFF777r%   c                     | j                                         }| j        }|                    d           |                     |t
                     |S )z
        Test if deferreds for iq's that haven't yet received a response
        have their errback called on stream disconnect.
        Closed by peer)rG   rR   r   connectionLostrb   r   rd   s      r#   testDisconnectCleanupzIQTests.testDisconnectCleanup   sJ     GLLNN^
*+++1n---r%   c                       fd j                                         }|                                j                            d           |S )z~
        Test to make sure the errbacks cannot cause the iteration of the
        iqDeferreds to blow up in our face.
        c                     t          j        j                                                   }|                               d S N)r   rF   rR   
addErrback)r	   r^   ebr!   s     r#   r{   z'IQTests.testNoModifyingDict.<locals>.eb   s8    T^,,1133ALLr%   rt   )rG   rR   rz   r   ru   )r!   r^   r{   s   ` @r#   testNoModifyingDictzIQTests.testNoModifyingDict   sa    	 	 	 	 	 	 GLLNN	R%%&6777r%   c                 D   d| j         _        | j                                         }|                     |t          j                   | j                            ddg           |                     | j        j	                   |                     | j        j
                   |S )zK
        Test that an iq request with a defined timeout times out.
        <      )rG   timeoutrR   rb   r   TimeoutErrorr@   pumpri   callsrm   r!   r^   s     r#   testRequestTimingOutzIQTests.testRequestTimingOut   s     GLLNN1i4555
B   )***3444r%   c                 .   d| j         _        | j                                         }| j                            d| j        j        d| j         d         z             | j                            ddg           |                     | j        j	                   |S )z
        Test that an iq request with a defined timeout does not time out
        when a response was received before the timeout period elapsed.
        r~   r   r\   rL   )
rG   r   rR   r@   rA   r   rE   r   ri   r   r   s     r#   testRequestNotTimingOutzIQTests.testRequestNotTimingOut   s    
 GLLNN
N')DGDM9	
 	
 	

 	
A)***r%   c                     d| j         _        | j                                         }| j        }|                    d           |                     |t                     |                     | j        j	                   |S )z|
        Test if timeouts for iq's that haven't yet received a response
        are cancelled on stream disconnect.
        r~   rt   )
rG   r   rR   r   ru   rb   r   ri   r@   r   rd   s      r#   !testDisconnectTimeoutCancellationz)IQTests.testDisconnectTimeoutCancellation   sl     GLLNN^
*+++1n---)***r%   N)r1   r2   r3   r4   rI   rN   rW   r`   re   ro   rr   rv   r|   r   r   r   r5   r%   r#   r7   r7   D   s         6 6 6' ' '

 

 

	 	 	  9 9 90  
 
 
           r%   r7   c                   n    e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zd Zd Zd Zd ZdS )XmlStreamTestsc                     d| _         d S NT)gotStreamStartr!   objs     r#   onStreamStartzXmlStreamTests.onStreamStart       "r%   c                     d| _         d S r   )gotStreamEndr   s     r#   onStreamEndzXmlStreamTests.onStreamEnd   s     r%   c                     d| _         d S r   )gotStreamErrorr   s     r#   onStreamErrorzXmlStreamTests.onStreamError   r   r%   c                    d| _         d| _        d| _        t          j        t          j                              }|                    d| j                   |                    d| j                   |                    d| j	                   |
                    t          j                               ||j        _        d|_        d|_        || _        dS )z9
        Set up XmlStream and several observers.
        Fz//event/stream/start//event/stream/endz//event/stream/errorr:   r   r   N)r   r   r   r   r>   Authenticatorrn   r   r   r   rC   r
    StringTransportWithDisconnectionrP   protocolr=   versionr!   r_   s     r#   rI   zXmlStreamTests.setUp   s     $!# !8!:!:;;
-t/ABBB
+T-=>>>
-t/ABBB
-HJJKKK "
r%   c                    | j         }|                                 | j         j                                        dd                             d          }|                     d|           |                     d|           |                     d|           |                     d|           |                     |j                   dS )	z>
        Basic test on the header sent by sendHeader.
        r   rk          <stream:stream/   xmlns:stream='http://etherx.jabber.org/streams'   xmlns='testns'   version='1.0'N)r   
sendHeaderrP   rU   splitrT   rM   _headerSentr!   r_   splitHeaders      r#   test_sendHeaderBasicz#XmlStreamTests.test_sendHeaderBasic  s     ^
n.4466qt<BB4HH'555H+VVV'555&444'''''r%   c                    | j         }d|j        d<   |                                 | j         j                                        dd                             d          }|                     d|           |                     d|           |                     d|           |                     d	|           |                     d
|           |                     |j                   dS )z=
        Test for additional namespace declarations.
        dbzjabber:server:dialbackr   rk   r   r   r   s!   xmlns:db='jabber:server:dialback'r   r   N)	r   prefixesr   rP   rU   r   rT   rM   r   r   s      r#   #test_sendHeaderAdditionalNamespacesz2XmlStreamTests.test_sendHeaderAdditionalNamespaces  s     ^04,-
n.4466qt<BB4HH'555H+VVV:KHHH'555&444'''''r%   c                 n   | j         }t          j        d          |_        t          j        d          |_        d|_        |                                 |j                                        dd         	                    d          }| 
                    d|           | 
                    d|           d	S )
z;
        Test addressing when initiating a stream.
        thisHost	otherHostTr   rk   r      to='otherhost'   from='thishost'N)r   r   JID
thisEntityotherEntity
initiatingr   rP   rU   r   rT   r   s      r#   test_sendHeaderInitiatingz(XmlStreamTests.test_sendHeaderInitiating  s     ^
++--
l((**1R4066t<<'555(+66666r%   c                    | j         }t          j        d          |_        t          j        d          |_        d|_        d|_        |                                 |j        	                                dd         
                    d          }|                     d|           |                     d	|           |                     d
|           dS )z:
        Test addressing when receiving a stream.
        r   r   F	session01r   rk   r   r   r   s   id='session01'N)r   r   r   r   r   r   sidr   rP   rU   r   rT   r   s      r#   test_sendHeaderReceivingz'XmlStreamTests.test_sendHeaderReceiving*  s     ^
++--
l((**1R4066t<<'555(+666'55555r%   c                     | j         }|                    d           |                    d           |                     | j                   |                     | j                   dS )z>
        Test events when a stream error is received.
        <stream:stream xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams' from='example.com' id='12345' version='1.0'>z<stream:error/>N)r   rE   rM   r   r   r   s     r#   test_receiveStreamErrorz&XmlStreamTests.test_receiveStreamError9  sk     ^
;	
 	
 	

 	)***+,,,)*****r%   c                 X   | j         }d|_        |                                 |j                                         |                    t          j        d                     |                     d|j        	                                           | 
                    | j                   dS )z
        Test sendStreamError on an initiating xmlstream with a header sent.

        An error should be sent out and the connection lost.
        Tversion-unsupportedr%   Nr   r   r   rP   rQ   sendStreamErrorr   StreamErrorassertNotEqualrU   rM   r   r   s     r#   test_sendStreamErrorInitiatingz-XmlStreamTests.test_sendStreamErrorInitiatingG  s     ^


5,-BCCDDDC!3!3!5!5666)*****r%   c                 d   | j         }d|_        |j                                         |                    t          j        d                     |                     |j                   | 	                    d|j        
                                           |                     | j                   dS )z
        Test sendStreamError on an initiating xmlstream without having sent a
        header.

        In this case, no header should be generated. Also, the error should
        not be sent out on the stream. Just closing the connection.
        Tr   r%   N)r   r   rP   rQ   r   r   r   	assertNotr   r   rU   rM   r   r   s     r#   &test_sendStreamErrorInitiatingNoHeaderz5XmlStreamTests.test_sendStreamErrorInitiatingNoHeaderU  s     ^

5,-BCCDDDr~&&&bl0022333)*****r%   c                 X   | j         }d|_        |                                 |j                                         |                    t          j        d                     |                     d|j        	                                           | 
                    | j                   dS )z
        Test sendStreamError on a receiving xmlstream with a header sent.

        An error should be sent out and the connection lost.
        Fr   r%   Nr   r   s     r#   test_sendStreamErrorReceivingz,XmlStreamTests.test_sendStreamErrorReceivinge  s     ^


5,-BCCDDDC!3!3!5!5666)*****r%   c                 d   | j         }d|_        |j                                         |                    t          j        d                     |                     |j                   | 	                    d|j        
                                           |                     | j                   dS )z
        Test sendStreamError on a receiving xmlstream without having sent a
        header.

        In this case, a header should be generated. Then, the error should
        be sent out on the stream followed by closing the connection.
        Fr   r%   N)r   r   rP   rQ   r   r   r   rM   r   r   rU   r   r   s     r#   %test_sendStreamErrorReceivingNoHeaderz4XmlStreamTests.test_sendStreamErrorReceivingNoHeaders  s     ^

5,-BCCDDD'''C!3!3!5!5666)*****r%   c                     | j         }|                                 |j        }|                                 |                     ||j                   |                     |j                   dS )zE
        Test resetting the XML stream to start a new layer.
        N)r   r   streamresetr   r   r   )r!   r_   r   s      r#   
test_resetzXmlStreamTests.test_reset  s^     ^




FBI...r~&&&&&r%   c                 T   | j         }|                    d           |                     |j                                        d           |j                                         t          j        d          }|                    |           |                     |j                                        d           |j                                         t          j        d          }|                    |           |                     |j                                        d           dS )z:
        Test send with various types of objects.
        <presence/>   <presence/>)r:   presence)z http://etherx.jabber.org/streamsfeaturess   <stream:features/>N)r   rR   r   rP   rU   rQ   r   Element)r!   r_   els      r#   	test_sendzXmlStreamTests.test_send  s     ^
++--~>>>
^233
++--~>>>
^LMM
++--/DEEEEEr%   c                    g g g  G fdd          } |            }t          j        |          }|                     |g           |                                 |                     dg           |                    d           |                     dt                               |                                 |                     dg           dS )zM
        Test that the associated authenticator is correctly called.
        c                   .    e Zd ZfdZfdZ fdZdS )<XmlStreamTests.test_authenticator.<locals>.TestAuthenticatorc                 2                         d            d S ry   append)r!   connectionMadeCallss    r#   connectionMadezKXmlStreamTests.test_authenticator.<locals>.TestAuthenticator.connectionMade  s    #**400000r%   c                 2                         |           d S ry   r   )r!   rootElementstreamStartedCallss     r#   streamStartedzJXmlStreamTests.test_authenticator.<locals>.TestAuthenticator.streamStarted  s    "))+66666r%   c                 2                         |           d S ry   r   )r!   r_   associateWithStreamCallss     r#   associateWithStreamzPXmlStreamTests.test_authenticator.<locals>.TestAuthenticator.associateWithStream  s    (//33333r%   N)r1   r2   r3   r   r   r   )r   r   r   s   r#   TestAuthenticatorr     s`        1 1 1 1 17 7 7 7 74 4 4 4 4 4 4r%   r   Ns<stream:stream xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams' from='example.com' id='12345'>r   )r   r>   r   r   rE   lenr   )r!   r   ar_   r   r   r   s       @@@r#   test_authenticatorz!XmlStreamTests.test_authenticator  s!    !#% 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4  ##"7888
$!4555
-	
 	
 	

 	C 233444



$!455555r%   N)r1   r2   r3   r   r   r   rI   r   r   r   r   r   r   r   r   r   r   r   r   r5   r%   r#   r   r      s       # # #! ! !# # #  "( ( (( ( (7 7 76 6 6+ + ++ + ++ + + + + ++ + + 	' 	' 	'F F F$6 6 6 6 6r%   r   c                       e Zd ZdS )	TestErrorN)r1   r2   r3   r5   r%   r#   r   r     s        Dr%   r   c                   ,    e Zd Zd Zd Zd Zd Zd ZdS )AuthenticatorTestsc                 r    t          j                    | _        t          j        | j                  | _         d S ry   )r   r   rH   r>   r*   s    r#   rI   zAuthenticatorTests.setUp  s,    &466",T-?@@r%   c                    | j         }|                    t          j                               |                    d           |                     d|j                   |                     d|j                   |                     d|j	                   |                     d|j
                   |                     d|j                   dS )e
        Test streamStart to fill the appropriate attributes from the
        stream header.
        <stream:stream xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams' from='example.org' to='example.com' id='12345' version='1.0'>r   Ninvalid)r   rC   r
   rD   rE   r   r   assertIdenticalr   r=   r   r   r   s     r#   test_streamStartz#AuthenticatorTests.test_streamStart  s    
 ^
-799:::
	
 	
 	
 	,,,T26***BL111T2>222r}-----r%   c                     | j         }|                    t          j                               |                    d           |                     d|j                   dS )z
        Test streamStart to fill the appropriate attributes from the
        stream header for a pre-XMPP-1.0 header.
        r   r   r   Nr   rC   r
   rD   rE   r   r   r   s     r#   test_streamStartLegacyz)AuthenticatorTests.test_streamStartLegacy  sc    
 ^
-799:::
-	
 	
 	

 	,,,,,r%   c                     | j         }|                    t          j                               |                    d           |                     d|j                   dS )z
        Test streamStart to fill the appropriate attributes from the
        stream header for a version with only one digit.
        z<stream:stream xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams' from='example.com' id='12345' version='1'>r   Nr   r   s     r#   test_streamBadVersionOneDigitz0AuthenticatorTests.test_streamBadVersionOneDigit  sc    
 ^
-799:::
9	
 	
 	

 	,,,,,r%   c                     | j         }|                    t          j                               |                    d           |                     d|j                   dS )z}
        Test streamStart to fill the appropriate attributes from the
        stream header for a malformed version.
        z<stream:stream xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams' from='example.com' id='12345' version='blah'>r   Nr   r   s     r#   test_streamBadVersionNoNumberz0AuthenticatorTests.test_streamBadVersionNoNumber  sc    
 ^
-799:::
<	
 	
 	

 	,,,,,r%   N)r1   r2   r3   rI   r   r   r   r  r5   r%   r#   r   r     sb        A A A. . .&- - -- - -- - - - -r%   r   c                   2    e Zd Zd Zd Zd Zd Zd Zd ZdS )ConnectAuthenticatorTestsc                    d| _         d | _        t          j        d          | _        t          j        | j                  | _        | j                            d| j                   | j                            d| j                   d S )NFr   //event/stream/authd//event/xmpp/initfailed)	gotAuthenticatedinitFailurer   r<   rH   r>   rn   onAuthenticatedonInitFailedr*   s    r#   rI   zConnectAuthenticatorTests.setUp	  sx     %&;KHH",T-?@@""#94;OPPP""#<d>OPPPPPr%   c                     d| _         d S r   )r  r   s     r#   r
  z)ConnectAuthenticatorTests.onAuthenticated  s     $r%   c                     || _         d S ry   )r	  )r!   r	   s     r#   r  z&ConnectAuthenticatorTests.onInitFailed  s    "r%   c                      G d d          } |            }|g| j         _        | j                                         |                     g | j         j                   |                     | j                   dS )zG
        Test successful completion of an initialization step.
        c                       e Zd Zd ZdS )9ConnectAuthenticatorTests.testSucces.<locals>.Initializerc                     d S ry   r5   r*   s    r#   
initializezDConnectAuthenticatorTests.testSucces.<locals>.Initializer.initialize  s    r%   Nr1   r2   r3   r  r5   r%   r#   Initializerr    s#            r%   r  N)r   initializersrH   initializeStreamr   rM   r  r!   r  inits      r#   
testSuccesz$ConnectAuthenticatorTests.testSucces  s    
	 	 	 	 	 	 	 	 {}}'+f#++---T^8999-.....r%   c                     G d d          } |            }|g| j         _        | j                                         |                     |g| j         j                   |                     | j                   |                     d| j                   | 	                    | j        
                    t                               dS )z9
        Test failure of an initialization step.
        c                       e Zd Zd ZdS ):ConnectAuthenticatorTests.testFailure.<locals>.Initializerc                     t           ry   )r   r*   s    r#   r  zEConnectAuthenticatorTests.testFailure.<locals>.Initializer.initialize-  s    r%   Nr  r5   r%   r#   r  r  ,  s#                 r%   r  N)r   r  rH   r  r   ri   r  assertNotIdenticalr	  rM   checkr   r  s      r#   testFailurez%ConnectAuthenticatorTests.testFailure'  s    
	  	  	  	  	  	  	  	  {}}'+f#++---$!<===.///d&6777(..y99:::::r%   c                    d| j         _        | j        }|                    t	          j                               |                    d           |                     d|j                   |                     d|j	                   |                     d|j                   |                     d|j
        j                   |                     d|j                   |                     | j                   |                    d           |                     d|j                   |                     | j                   dS )	r   r:   z<stream:stream xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams' from='example.com' to='example.org' id='12345' version='1.0'>r   r   example.comNz9<stream:features><test xmlns='testns'/></stream:features>r:   test)rH   r=   r   rC   r
   rD   rE   r   r   r   r   hostr   r   r   r  rT   r   rM   r   s     r#   r   z*ConnectAuthenticatorTests.test_streamStart9  s-   
 (0$^
-799:::
	
 	
 	
 	,,,"&)))2<000(;<<<T2=111t,---
M	
 	
 	
 	("+666-.....r%   N)	r1   r2   r3   rI   r
  r  r  r   r   r5   r%   r#   r  r    sq        Q Q Q% % %# # #/ / / ; ; ;$/ / / / /r%   r  c                   $    e Zd ZdZd Zd Zd ZdS )ListenAuthenticatorTestsz4
    Tests for L{xmlstream.ListenAuthenticator}
    c                 r    t          j                    | _        t          j        | j                  | _         d S ry   )r   ListenAuthenticatorrH   r>   r*   s    r#   rI   zListenAuthenticatorTests.setUpY  s,    &:<<",T-?@@r%   c                    | j         }|                    t          j                               |                     d|j                   |                    d           |                     d|j                   | 	                    d|j                   | 
                    d|j                   |                     d|j                   |                     d|j                   |                     d|j        j                   dS )r   Nr   r   r   jabber:clientr"  )r   rC   r
   rD   r   r   rE   r   r   r  r   r=   r   r   r%  r   s     r#   r   z)ListenAuthenticatorTests.test_streamStart]  s    
 ^
-799:::T26***
	
 	
 	
 	,,,bf---GRV,,,",777T2>222(:;;;;;r%   c                     | j         }|                    t          j                               |                    d           |                     |j        t                     dS )zD
        The generated session id must be a unicode object.
        r   N)r   rC   r
   rD   rE   assertIsInstancer   strr   s     r#    test_streamStartUnicodeSessionIDz9ListenAuthenticatorTests.test_streamStartUnicodeSessionIDr  sc     ^
-799:::
	
 	
 	
 	bfc*****r%   N)r1   r2   r3   r4   rI   r   r/  r5   r%   r#   r'  r'  T  sN         A A A< < <*+ + + + +r%   r'  c                       e Zd Zd Zd Zd Z ee d             Z ee d             Z	 ee d             Z
d Zd Zd	 Zd
 Zd ZdS )TLSInitiatingInitializerTestsc                    g | _         g | _        t          j        | _        t          j        d          | _        t          j        | j                  | _        | j         j        | j        _	        | j        
                                 | j                            d           t          j        | j                  | _        d S )Nr"  r   )outputdoner   r   savedSSLr<   rH   r>   r   rR   r   rE   TLSInitiatingInitializerr  r*   s    r#   rI   z#TLSInitiatingInitializerTests.setUp  s    	!&;MJJ",T-?@@"k0%%'''##;	
 	
 	

 6t~FF			r%   c                 (    | j         t          _        d S ry   )r5  r   r   r*   s    r#   tearDownz&TLSInitiatingInitializerTests.tearDown  s    	r%   c                     t          j        | j         d          | _        |                     | j        j                   dS )z>
        Passing required sets the instance variable.
        T)requiredN)r   r6  r  rM   r:  r*   s    r#   test_initRequiredz/TLSInitiatingInitializerTests.test_initRequired  s;     6t~PTUUU		*+++++r%   c                     t          j                     j        _         fd j        j        _         fd j        _         fd j        _         j                                        }|	                     j
        t          j                    
                    dt           j                              j        d         } 
                    d|j                    
                    t          |j                    j                            dt          z              
                    g d j                   |S )	zN
        When TLS is wanted and SSL available, StartTLS is initiated.
        c                 8    j                             d          S NTLSr4  r   )ctxr!   s    r#   <lambda>zDTLSInitiatingInitializerTests.test_wantedSupported.<locals>.<lambda>  s    	8H8H8O8O r%   c                  8     j                             d          S Nr   r@  r*   s   r#   rB  zDTLSInitiatingInitializerTests.test_wantedSupported.<locals>.<lambda>      ty'7'7'@'@ r%   c                  8     j                             d          S Nheaderr@  r*   s   r#   rB  zDTLSInitiatingInitializerTests.test_wantedSupported.<locals>.<lambda>      DI,<,<X,F,F r%      r   starttls<proceed xmlns='%s'/>r?  r   rH  )r
   rD   r   rP   startTLSr   r   r  startr]   r   Resetr   r3  nameNS_XMPP_TLSurirE   r4  )r!   r^   rK  s   `  r#   test_wantedSupportedz2TLSInitiatingInitializerTests.test_wantedSupported  s   
 $1#@#B#B ,O,O,O,O )@@@@$F$F$F$F!IOO	d&	888C,,---;q>X]333hl333##$;k$IJJJ333TY???r%   c                 Z     fd}t          j                     j        _        | j        j        _         fd j        _         fd j        _         j                                        } j        	                    dt          z                                  g d j                   |S )z:
        The server certificate will be verified.
        c                                          | t                                         | j        d           j                            d           d S )Nr"  r?  )r-  r   r   	_hostnamer4  r   )contextFactoryr!   s    r#   fakeStartTLSzJTLSInitiatingInitializerTests.test_certificateVerify.<locals>.fakeStartTLS  sO    !!.2BCCC^5}EEEIU#####r%   c                  8     j                             d          S rD  r@  r*   s   r#   rB  zFTLSInitiatingInitializerTests.test_certificateVerify.<locals>.<lambda>  rE  r%   c                  8     j                             d          S rG  r@  r*   s   r#   rB  zFTLSInitiatingInitializerTests.test_certificateVerify.<locals>.<lambda>  rI  r%   rL  rM  )r
   rD   r   rP   rN  r   r   r  rO  rE   rR  r   r4  )r!   rY  r^   s   `  r#   test_certificateVerifyz4TLSInitiatingInitializerTests.test_certificateVerify  s    	$ 	$ 	$ 	$ 	$
 $1#@#B#B ,8 )@@@@$F$F$F$F!IOO##$;k$IJJJ333TY???r%   c                     t                      t          j         j                   _         j        _         fd}t          j                     j        _        | j        j        _         fd j        _	         fd j        _
         j                                        } j                            dt          z                                  g d j                   |S )zH
        A custom contextFactory is passed through to startTLS.
        )configurationForTLSc                 h                         |            j                            d           d S r>  )assertIsr4  r   )rX  rA  r!   s    r#   rY  zQTLSInitiatingInitializerTests.test_certificateVerifyContext.<locals>.fakeStartTLS  s3    MM#~...IU#####r%   c                  8     j                             d          S rD  r@  r*   s   r#   rB  zMTLSInitiatingInitializerTests.test_certificateVerifyContext.<locals>.<lambda>  rE  r%   c                  8     j                             d          S rG  r@  r*   s   r#   rB  zMTLSInitiatingInitializerTests.test_certificateVerifyContext.<locals>.<lambda>  rI  r%   rL  rM  )r   r   r6  r  rX  r
   rD   rP   rN  r   r   rO  rE   rR  r   r4  )r!   rY  r^   rA  s   `  @r#   test_certificateVerifyContextz;TLSInitiatingInitializerTests.test_certificateVerifyContext  s    
 !""6N
 
 
	 $'	 	$ 	$ 	$ 	$ 	$ 	$ $1#@#B#B ,8 )@@@@$F$F$F$F!IOO##$;k$IJJJ333TY???r%   c                     dt           _        d| j        _        | j                                        }|                    | j        d           |                     dt          | j                             |S )zX
        No StartTLS is initiated when wanted, not required, SSL not available.
        NFr   )	r   r   r  r:  rO  r]   r   r   r3  r   s     r#   "test_wantedNotSupportedNotRequiredz@TLSInitiatingInitializerTests.test_wantedNotSupportedNotRequired  sb     	"	IOO	d&---C,,---r%   c                     dt           _        d| j        _        | j                                        }|                     |t           j                   |                     dt          | j	                             |S )zS
        TLSNotSupported is raised when TLS is required but not available.
        NTr   )
r   r   r  r:  rO  rb   TLSNotSupportedr   r   r3  r   s     r#   test_wantedNotSupportedRequiredz=TLSInitiatingInitializerTests.test_wantedNotSupportedRequired  sd     	!	IOO1i7888C,,---r%   c                 f   t          j        d          }|                    d           |j        |j        f|i| j        _        d| j        _        | j        	                                }| 
                    dt          | j                             |                     |t
          j                   |S )zW
        TLSRequired is raised when TLS is not wanted, but required by server.
        r   rK  r:  Fr   )r   r   
addElementrS  rQ  r   r   r  wantedrO  r   r   r3  rb   TLSRequiredr!   tlsr^   s      r#   test_notWantedRequiredz4TLSInitiatingInitializerTests.test_notWantedRequired  s     nLMMz"""$'GSX#6"< 	IOOC,,---1i3444r%   c                 J   t          j        d          }|j        |j        f|i| j        _        d| j        _        d| j        _        | j        	                                }|
                    | j        d           |                     dt          | j                             |S )zL
        No StartTLS is initiated when not wanted and not required.
        rj  FNr   )r   r   rS  rQ  r   r   r  rl  r:  rO  r]   r   r   r3  rn  s      r#   test_notWantedNotRequiredz7TLSInitiatingInitializerTests.test_notWantedNotRequired
  s     nLMM$'GSX#6"< 	"	IOO	d&---C,,---r%   c                     dt           _        | j                                        }|                     |t           j                   | j                             dt          z             |S )zN
        TLSFailed is raised when the server responds with a failure.
        r   z<failure xmlns='%s'/>)r   r   r  rO  rb   	TLSFailedrE   rR  r   s     r#   test_failedz)TLSInitiatingInitializerTests.test_failed  sV     	IOO1i1222##$;k$IJJJr%   N)r1   r2   r3   rI   r8  r;  r   skipWhenNoSSLrT  r\  rc  re  rh  rp  rr  ru  r5   r%   r#   r1  r1    s        G G G"& & &, , , V]  ( V]  ( V]  2            r%   r1  c                       e Zd ZdZd ZdS )TestFeatureInitializerr#  c                 *    t          j        d           S ry   )r   succeedr*   s    r#   rO  zTestFeatureInitializer.start*  s    }T"""r%   N)r1   r2   r3   featurerO  r5   r%   r#   rx  rx  '  s(         G# # # # #r%   rx  c                   &    e Zd Zd Zd Zd Zd ZdS )%BaseFeatureInitiatingInitializerTestsc                     t          j        t          j                              | _         t          | j                   | _        d S ry   )r   r>   r   rx  r  r*   s    r#   rI   z+BaseFeatureInitiatingInitializerTests.setUp/  s2    ",Y-D-F-FGG*4>::			r%   c                     | j         j        t          j        | j         j                  i| j        _        | j                                         S )zW
        Test that an advertized feature results in successful initialization.
        )r  r{  r   r   r   r   r  r*   s    r#   testAdvertizedz4BaseFeatureInitiatingInitializerTests.testAdvertized3  s;     $(9#4fnTYEV6W6W"Xy##%%%r%   c                 r    d| j         _        |                     t          j        | j         j                   dS )z
        Test that when the feature is not advertized, but required by the
        initializer, an exception is raised.
        TN)r  r:  r(   r   FeatureNotAdvertizedr  r*   s    r#   testNotAdvertizedRequiredz?BaseFeatureInitiatingInitializerTests.testNotAdvertizedRequired:  s2    
 "	)8$):NOOOOOr%   c                 x    d| j         _        |                     d| j                                                    dS )z
        Test that when the feature is not advertized, and not required by the
        initializer, the initializer silently succeeds.
        FN)r  r:  r   r  r*   s    r#   testNotAdvertizedNotRequiredzBBaseFeatureInitiatingInitializerTests.testNotAdvertizedNotRequiredB  s8    
 #	T49#7#7#9#9:::::r%   N)r1   r2   r3   rI   r  r  r  r5   r%   r#   r}  r}  .  sS        ; ; ;& & &P P P; ; ; ; ;r%   r}  c                   2    e Zd Zd Zd Zd Zd Zd Zd ZdS )ToResponseTestsc                    t          j        d          }d|d<   d|d<   d|d<   d|d	<   t          j        |d
          }|                     ||           |                     |d         d           |                     |d         d           |                     |d         d
           |                     |d	         d           dS )zS
        Test that a response stanza is generated with addressing swapped.
        r+  rG   r;   rK   user1@example.comtouser2@example.com/resourcefromstanza1rL   rZ   N)r   r   r   
toResponser  r   r!   stanzaresponses      r#   test_toResponsezToResponseTests.test_toResponseL  s      788v*t5v t'99111&)+>???$)EFFF&)8444$33333r%   c                     t          j        d          }d|d<   d|d<   t          j        |          }|                     |d         d           |                     |                    d                     dS )zY
        Test that a response is generated from a stanza without a from address.
        r  r;   rK   r  r  r  N)r   r   r   r  r   ri   hasAttributer  s      r#   test_toResponseNoFromz%ToResponseTests.test_toResponseNoFrom\  sz      788v*t'//&)+>???..t4455555r%   c                     t          j        d          }d|d<   d|d<   t          j        |          }|                     |                    d                     |                     |d         d           dS )zW
        Test that a response is generated from a stanza without a to address.
        r  r;   rK   r  r  r  N)r   r   r   r  ri   r  r   r  s      r#   test_toResponseNoToz#ToResponseTests.test_toResponseNoTog  sy      788v5v'//..v66777$)EFFFFFr%   c                     t          j        d          }d|d<   t          j        |          }|                     |                    d                     |                     |                    d                     dS )zY
        Test that a response is generated from a stanza without any addressing.
        r+  messagechatrK   r  r  Nr   r   r   r  ri   r  r  s      r#   test_toResponseNoAddressingz+ToResponseTests.test_toResponseNoAddressingr  sw      <==v'//..t44555..v6677777r%   c                     t          j        d          }t          j        |          }|                     |                    d                     dS )zP
        Test that a proper response is generated without id attribute.
        r  rL   Nr  r  s      r#   	test_noIDzToResponseTests.test_noID|  sL      <=='//..t4455555r%   c                     t          j        d          }t          j        |          }|                     |                    d                     dS )zR
        Test that a proper response is generated without type attribute.
        r  rK   Nr  r  s      r#   test_noTypezToResponseTests.test_noType  sL      <=='//..v6677777r%   N)	r1   r2   r3   r  r  r  r  r  r  r5   r%   r#   r  r  K  sq        4 4 4 	6 	6 	6	G 	G 	G8 8 86 6 68 8 8 8 8r%   r  c                       e Zd ZdZd Zd ZdS )DummyFactoryzJ
    Dummy XmlStream factory that only registers bootstrap observers.
    c                     i | _         d S ry   	callbacksr*   s    r#   __init__zDummyFactory.__init__  s    r%   c                     || j         |<   d S ry   r  )r!   eventcallbacks      r#   addBootstrapzDummyFactory.addBootstrap  s     (ur%   N)r1   r2   r3   r4   r  r  r5   r%   r#   r  r    s<           ) ) ) ) )r%   r  c                   0    e Zd ZdZd Zd Zd Zd Zd ZdS )DummyXMPPHandlerzO
    Dummy XMPP subprotocol handler to count the methods are called on it.
    c                 0    d| _         d| _        d| _        d S )Nr   )doneMadedoneInitializeddoneLostr*   s    r#   r  zDummyXMPPHandler.__init__  s     r%   c                 .    |                                   d S ry   )r   r   s     r#   rC   zDummyXMPPHandler.makeConnection  s    r%   c                 &    | xj         dz  c_         d S Nr   r  r*   s    r#   r   zDummyXMPPHandler.connectionMade      r%   c                 &    | xj         dz  c_         d S r  )r  r*   s    r#   connectionInitializedz&DummyXMPPHandler.connectionInitialized  s    !r%   c                 &    | xj         dz  c_         d S r  )r  r!   reasons     r#   ru   zDummyXMPPHandler.connectionLost  r  r%   N)	r1   r2   r3   r4   r  rC   r   r  ru   r5   r%   r#   r  r    si           
    " " "    r%   r  c                       e Zd ZdZd Zd ZdS )FailureReasonXMPPHandlerz>
    Dummy handler specifically for failure Reason tests.
    c                     d| _         d S )NF)gotFailureReasonr*   s    r#   r  z!FailureReasonXMPPHandler.__init__  s     %r%   c                 L    t          |t          j                  r	d| _        d S d S r   )
isinstancer	   Failurer  r  s     r#   ru   z'FailureReasonXMPPHandler.connectionLost  s.    fgo.. 	)$(D!!!	) 	)r%   N)r1   r2   r3   r4   r  ru   r5   r%   r#   r  r    s<         & & &) ) ) ) )r%   r  c                   *    e Zd ZdZd Zd Zd Zd ZdS )XMPPHandlerTestsz-
    Tests for L{xmlstream.XMPPHandler}.
    c                 \    t          t          j        t          j                               dS )zN
        L{xmlstream.XMPPHandler} implements L{ijabber.IXMPPHandler}.
        N)r   r   IXMPPHandlerr   XMPPHandlerr*   s    r#   test_interfacezXMPPHandlerTests.test_interface  s&     	W)9+@+B+BCCCCCr%   c                      G d d          }t          j                    } |            |_        |                    d           |                     dg|j        j                   dS )zP
        Test that data is passed on for sending by the stream manager.
        c                       e Zd Zd Zd ZdS )6XMPPHandlerTests.test_send.<locals>.DummyStreamManagerc                     g | _         d S ry   )outlistr*   s    r#   r  z?XMPPHandlerTests.test_send.<locals>.DummyStreamManager.__init__  s    !r%   c                 :    | j                             |           d S ry   )r  r   )r!   datas     r#   rR   z;XMPPHandlerTests.test_send.<locals>.DummyStreamManager.send  s    ##D)))))r%   N)r1   r2   r3   r  rR   r5   r%   r#   DummyStreamManagerr    s2        " " "* * * * *r%   r  r   N)r   r  parentrR   r   r  )r!   r  handlers      r#   r   zXMPPHandlerTests.test_send  s    
	* 	* 	* 	* 	* 	* 	* 	* '))++--]###-'.*@AAAAAr%   c                 (    G d dt           j                  } |            }t          j        t          j                              }|                    |           |                     |j                   |                     ||j                    dS )zY
        Test that makeConnection saves the XML stream and calls connectionMade.
        c                       e Zd Zd ZdS )=XMPPHandlerTests.test_makeConnection.<locals>.TestXMPPHandlerc                     d| _         d S r   r  r*   s    r#   r   zLXMPPHandlerTests.test_makeConnection.<locals>.TestXMPPHandler.connectionMade  s     $r%   N)r1   r2   r3   r   r5   r%   r#   TestXMPPHandlerr    s#        % % % % %r%   r  N)r   r  r>   r   rC   rM   r  r   )r!   r  r  r_   s       r#   test_makeConnectionz$XMPPHandlerTests.test_makeConnection  s    
	% 	% 	% 	% 	%i3 	% 	% 	% "/## !8!:!:;;r"""()))R!233333r%   c                    t          j                    }t          j        t          j                              }|                    |           |                    t                                 |                     d|j                    dS )zB
        Test that connectionLost forgets the XML stream.
        N)r   r  r>   r   rC   ru   	Exceptionr   )r!   r  r_   s      r#   test_connectionLostz$XMPPHandlerTests.test_connectionLost  sv     ')) !8!:!:;;r"""y{{+++T7#455555r%   N)r1   r2   r3   r4   r  r   r  r  r5   r%   r#   r  r    s`         D D DB B B"4 4 46 6 6 6 6r%   r  c                   *    e Zd ZdZd Zd Zd Zd ZdS )XMPPHandlerCollectionTestsz7
    Tests for L{xmlstream.XMPPHandlerCollection}.
    c                 6    t          j                    | _        d S ry   )r   XMPPHandlerCollection
collectionr*   s    r#   rI   z XMPPHandlerCollectionTests.setUp  s    #9;;r%   c                 D    t          t          j        | j                   dS )zZ
        L{xmlstream.StreamManager} implements L{ijabber.IXMPPHandlerCollection}.
        N)r   r   IXMPPHandlerCollectionr  r*   s    r#   r  z)XMPPHandlerCollectionTests.test_interface  s     	W3T_EEEEEr%   c                     t                      }|                    | j                   |                     || j                   |                     | j        |j                   dS )z:
        Test the addition of a protocol handler.
        N)r  setHandlerParentr  rT   r   r  r!   r  s     r#   test_addHandlerz*XMPPHandlerCollectionTests.test_addHandler  s[     #$$  111gt///T_gn=====r%   c                     t                      }|                    | j                   |                    | j                   |                     || j                   |                     d|j                   dS )z5
        Test removal of a protocol handler.
        N)r  r  r  disownHandlerParentrq   r   r  r  s     r#   test_removeHandlerz-XMPPHandlerCollectionTests.test_removeHandler
  sq     #$$  111##DO444$/222T7>22222r%   N)r1   r2   r3   r4   rI   r  r  r  r5   r%   r#   r  r    s]         < < <F F F> > >3 3 3 3 3r%   r  c                   f    e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zd Zd Zd ZdS )StreamManagerTestsz/
    Tests for L{xmlstream.StreamManager}.
    c                 T    t                      }t          j        |          | _        d S ry   )r  r   StreamManagerstreamManager)r!   factorys     r#   rI   zStreamManagerTests.setUp  s$    ..&4W==r%   c                    | j         }|                     d|j                   |                     g |j                   |                     |j        |j        j        d                    |                     |j        |j        j        d                    |                     |j	        |j        j        d                    |                     |j
        |j        j        d                    dS )zM
        Test correct initialization and setup of factory observers.
        Nz//event/stream/connectedr  r   r  )r  r   r   r   handlers
_connectedr  r  _authd_disconnectedinitializationFailed)r!   sms     r#   r$   zStreamManagerTests.test_basic  s     T2<000R[)))M2:/0JK	
 	
 	
 	BJ$89O$PQQQ)2:+?@T+UVVV#RZ%9:S%T	
 	
 	
 	
 	
r%   c                 p   | j         }t                      }|                    |           t          j        t          j                              }|                    |           |                     d|j                   |                     d|j	                   |                     d|j
                   dS )z
        Test that protocol handlers have their connectionMade method called
        when the XML stream is connected.
        r   r   N)r  r  r  r   r>   r   r  r   r  r  r  r!   r  r  r_   s       r#   test_connectedz!StreamManagerTests.test_connected.  s    
 "$$  $$$ !8!:!:;;
bG,---G3444G,-----r%   c                 :   | j         }t                      }|                    |           t          j        t          j                              }|                    |           |                     d|j                   |                     d|j	                   dS )zP
        Test raw data functions unset when logTraffic is set to False.
        N)
r  r  r  r   r>   r   r  r   rawDataInFnrawDataOutFnr  s       r#   test_connectedLogTrafficFalsez0StreamManagerTests.test_connectedLogTrafficFalse<  s     "$$  $$$ !8!:!:;;
bT2>222T2?33333r%   c                 H   | j         }d|_        t                      }|                    |           t	          j        t	          j                              }|                    |           |                     d|j	                   |                     d|j
                   dS )zM
        Test raw data functions set when logTraffic is set to True.
        TN)r  
logTrafficr  r  r   r>   r   r  r  r  r  r  s       r#   test_connectedLogTrafficTruez/StreamManagerTests.test_connectedLogTrafficTrueH  s     "$$  $$$ !8!:!:;;
bbn555bo66666r%   c                 p   | j         }t                      }|                    |           t          j        t          j                              }|                    |           |                     d|j                   |                     d|j	                   |                     d|j
                   dS )z
        Test that protocol handlers have their connectionInitialized method
        called when the XML stream is initialized.
        r   r   N)r  r  r  r   r>   r   r  r   r  r  r  r  s       r#   
test_authdzStreamManagerTests.test_authdU  s    
 "$$  $$$ !8!:!:;;
		"G,---G3444G,-----r%   c                 p   | j         }t                      }|                    |           t          j        t          j                              }|                    |           |                     d|j                   |                     d|j	                   |                     d|j
                   dS )z
        Test that protocol handlers have their connectionLost method
        called when the XML stream is disconnected.
        r   r   N)r  r  r  r   r>   r   r  r   r  r  r  r  s       r#   test_disconnectedz$StreamManagerTests.test_disconnectedc  s    
 "$$  $$$ !8!:!:;;
G,---G3444G,-----r%   c                     | j         }t                      }|                    |           |                    t	          j        t          d                               |                     d|j                   dS )z
        A L{STREAM_END_EVENT} results in L{StreamManager} firing the handlers
        L{connectionLost} methods, passing a L{failure.Failure} reason.
        z	no reasonTN)	r  r  r  r  r	   r  r  r   r  r!   r  r  s      r#   test_disconnectedReasonz*StreamManagerTests.test_disconnectedReasonq  sp    
 *,,  $$$
;)?)?@@AAAw788888r%   c                     | j         }t                      }|                    |           |                     d|j                   |                     d|j                   |                     d|j                   dS )zN
        Test the addition of a protocol handler while not connected.
        r   N)r  r  r  r   r  r  r  r  s      r#   r  z"StreamManagerTests.test_addHandler|  s|     "$$  $$$G,---G3444G,-----r%   c                    | j         }t          j        t          j                              }|                    |           |                    |           t                      }|                    |           |                     d|j	                   |                     d|j
                   |                     d|j                   dS )a  
        Test the addition of a protocol handler after the stream
        have been initialized.

        Make sure that the handler will have the connected stream
        passed via C{makeConnection} and have C{connectionInitialized}
        called.
        r   r   N)r  r   r>   r   r  r  r  r  r   r  r  r  )r!   r  r_   r  s       r#   test_addHandlerInitializedz-StreamManagerTests.test_addHandlerInitialized  s      !8!:!:;;
b
		""$$  $$$G,---G3444G,-----r%   c                    t          j        t          j                              }t          j        |          }|                    d          }t          j                    |_        |                                 |	                    d           |
                    |d           |                    d           |                     d|j                                                   dS )z
        Test send when the stream has been initialized.

        The data should be sent directly over the XML stream.
        Nr   r  r   r   )r   XmlStreamFactoryr   r  buildProtocolr
   rD   rP   r   rE   dispatchrR   r   rU   r!   r  r  r_   s       r#   test_sendInitializedz'StreamManagerTests.test_sendInitialized  s     ,Y-D-F-FGG$W--""4(($466

-	
 	
 	

 	B.///
););)=)=>>>>>r%   c                    t          j        t          j                              }t          j        |          }t	                      }|                    |           |                    d          }t          j                    |_	        |
                    d           |                     d|j	                                                   |                     d|j        d                    |                                 |                     d|j	                                                   |                     d|j        d                    |                    d           |                    |d           |                     d|j	                                                   |                     |j                   dS )z
        Test send when there is no established XML stream.

        The data should be cached until an XML stream has been established and
        initialized.
        Nr   r%   r   r   r  r   )r   r  r   r  r  
addHandlerr  r
   rD   rP   rR   r   rU   _packetQueuer   rE   r  ri   r!   r  r  r  r_   s        r#   test_sendNotConnectedz(StreamManagerTests.test_sendNotConnected  s    ,Y-D-F-FGG$W--"$$
g""4(($466
bl0022333(:;;;
bl0022333(:;;;
-	
 	
 	

 	B.///););)=)=>>>)))))r%   c                    t          j        t          j                              }t          j        |          }|                    d          }t          j                    |_        |                                 |	                    d           |
                    d           |                     d|j                                                   |                     d|j        d                    dS )z
        Test send when the stream is connected but not yet initialized.

        The data should be cached until the XML stream has been initialized.
        Nr   r   r%   r   )r   r  r   r  r  r
   rD   rP   r   rE   rR   r   rU   r  r  s       r#   test_sendNotInitializedz*StreamManagerTests.test_sendNotInitialized  s     ,Y-D-F-FGG$W--""4(($466

-	
 	
 	

 	bl0022333(:;;;;;r%   c                 0   t          j        t          j                              }t          j        |          }t	                      }|                    |           |                    d          }|                                 t          j	                    |_
        |                    d           |                    d           |                     d|j
                                                   |                     d|j        d                    dS )z
        Test send after XML stream disconnection.

        The data should be cached until a new XML stream has been established
        and initialized.
        Nr   r%   r   )r   r  r   r  r  r  r  r   r
   rD   rP   ru   rR   r   rU   r  r  s        r#   test_sendDisconnectedz(StreamManagerTests.test_sendDisconnected  s     ,Y-D-F-FGG$W--"$$
g""4((
$466
$
bl0022333(:;;;;;r%   N)r1   r2   r3   r4   rI   r$   r  r  r  r  r  r  r  r  r  r  r  r  r5   r%   r#   r  r    s         > > >
 
 
 . . .
4 
4 
47 7 7. . .. . .	9 	9 	9
. 
. 
.. . .(? ? ?(* * *@< < <(< < < < <r%   r  c                   0    e Zd ZdZd Zd Zd Zd Zd ZdS )XmlStreamServerFactoryTestsz8
    Tests for L{xmlstream.XmlStreamServerFactory}.
    c                 ^     G d d          fd}t          j        |          | _        dS )zQ
        Set up a server factory with an authenticator factory function.
        c                       e Zd Zd Zd ZdS )<XmlStreamServerFactoryTests.setUp.<locals>.TestAuthenticatorc                     g | _         d S ry   )
xmlstreamsr*   s    r#   r  zEXmlStreamServerFactoryTests.setUp.<locals>.TestAuthenticator.__init__  s    "$r%   c                 :    | j                             |           d S ry   )r!  r   r   s     r#   r   zPXmlStreamServerFactoryTests.setUp.<locals>.TestAuthenticator.associateWithStream  s    &&r*****r%   N)r1   r2   r3   r  r   r5   r%   r#   r   r    s2        % % %+ + + + +r%   r   c                                    S ry   r5   )r   s   r#   authenticatorFactoryz?XmlStreamServerFactoryTests.setUp.<locals>.authenticatorFactory  s    $$&&&r%   N)r   XmlStreamServerFactoryr  )r!   r$  r   s     @r#   rI   z!XmlStreamServerFactoryTests.setUp  s]    
	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+	' 	' 	' 	' 	' !78LMMr%   c                 :    t          t          | j                   dS )z<
        L{XmlStreamServerFactory} is a L{Factory}.
        N)r   r   r  r*   s    r#   r  z*XmlStreamServerFactoryTests.test_interface  s     	%t|44444r%   c                 |    | j                             d          }|                     |g|j        j                   dS )a  
        The authenticator factory should be used to instantiate the
        authenticator and pass it to the protocol.

        The default protocol, L{XmlStream} stores the authenticator it is
        passed, and calls its C{associateWithStream} method. so we use that to
        check whether our authenticator factory is used and the protocol
        instance gets an authenticator.
        N)r  r  r   rH   r!  r   s     r#   ,test_buildProtocolAuthenticatorInstantiationzHXmlStreamServerFactoryTests.test_buildProtocolAuthenticatorInstantiation  s=     \''--"r/:;;;;;r%   c                 z    | j                             d          }|                     |t          j                   dS )zV
        The protocol factory creates Jabber XML Stream protocols by default.
        N)r  r  r-  r   r>   r   s     r#   test_buildProtocolXmlStreamz7XmlStreamServerFactoryTests.test_buildProtocolXmlStream#  s8     \''--b)"566666r%   c                     | j                             d          }| j                             d          }|                     ||           |                     |j        |j                   dS )z
        Subsequent calls to buildProtocol should result in different instances
        of the protocol, as well as their authenticators.
        N)r  r  r  rH   )r!   xs1xs2s      r#   test_buildProtocolTwicez3XmlStreamServerFactoryTests.test_buildProtocolTwice*  sf    
 l((..l((..S))) 133DEEEEEr%   N)	r1   r2   r3   r4   rI   r  r(  r*  r.  r5   r%   r#   r  r    sq         N N N"5 5 5< < <7 7 7F F F F Fr%   r  )9r4   r   r   zope.interface.verifyr   twisted.internetr   r   twisted.internet.errorr   twisted.internet.interfacesr   twisted.pythonr	   twisted.testr
   twisted.trialtwisted.words.protocols.jabberr   r   r   r   !twisted.words.test.test_xmlstreamr   twisted.words.xishr   r   _sslrv  twisted.internet._sslverifyr   twisted.internet.sslr   ImportErrorrR  TestCaser   r7   r   r  r   r   r  r'  r1   BaseFeatureInitiatingInitializerrx  r}  r  r  r  r  r  r  r  r  r  r5   r%   r#   <module>r?     s          . . . . . . ( ( ( ( ( ( ( ( 1 1 1 1 1 1 8 8 8 8 8 8 " " " " " " & & & & & & " " " " " " I I I I I I I I I I I I O O O O O O % % % % % %	8,,,,,,
 CM<<<<<<7777777  0 0 0
C/MMM0 0K K K K K) K K K@_ _ _ _ _h _ _ _DX6 X6 X6 X6 X6X& X6 X6 X6v	 	 	 	 		 	 	 	@- @- @- @- @-* @- @- @-FI/ I/ I/ I/ I/ 1 I/ I/ I/X*+ *+ *+ *+ *+x0 *+ *+ *+Zc c c c cH$5 c c cL# # # # #YG # # #; ; ; ; ;H,= ; ; ;:?8 ?8 ?8 ?8 ?8h' ?8 ?8 ?8D	) 	) 	) 	) 	) 	) 	) 	)    y,   .
) 
) 
) 
) 
)y4 
) 
) 
)36 36 36 36 36x( 36 36 36l3 3 3 3 3!2 3 3 3Db< b< b< b< b<* b< b< b<J8F 8F 8F 8F 8F"C 8F 8F 8F 8F 8Fs   A% %	A10A1