
    Vh'                        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  dZ" G d dejF                        Z$ G d dejF                        Z% G d dejF                        Z& G d de'      Z( G d dejF                        Z) G d dejF                        Z* G d  d!ejF                        Z+ G d" d#ejF                        Z, G d$ d%ejZ                        Z. G d& d'ejF                        Z/ G d( d)ejF                        Z0 G d* d+      Z1 G d, d-ejd                        Z3 G d. d/ejd                        Z4 G d0 d1ejF                        Z5 G d2 d3ejF                        Z6 G d4 d5ejF                        Z7 G d6 d7e      Z8y# e!$ r dZdZY jw xY w)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y)HashPasswordTestsz.
    Tests for L{xmlstream.hashPassword}.
    c                 T    t        j                  dd      }| j                  d|       y)zS
        The sid and secret are concatenated to calculate sha1 hex digest.
        12345secret(99567ee91b2c7cabf607f10cb9f4a3634fa820e0Nr   hashPasswordassertEqualselfhashs     W/home/dcms/DCMS/lib/python3.12/site-packages/twisted/words/test/test_jabberxmlstream.py
test_basiczHashPasswordTests.test_basic)   s'     %%gx8CTJ    c                 P    | j                  t        t        j                  dd       y)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Wr%   c                 P    | j                  t        t        j                  dd       y)z8
        The password must be a unicode object.
        r   s   secrétNr'   r*   s    r#   test_passwordNotUnicodez)HashPasswordTests.test_passwordNotUnicode6   s     	)Y%;%;WFVWr%   c                 T    t        j                  dd      }| j                  d|       y)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<   s'     %%g}=CTJr%   N)__name__
__module____qualname____doc__r$   r+   r-   r0    r%   r#   r   r   $   s    KXXKr%   r   c                   X    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y)IQTestszG
    Tests both IQ and the associated IIQResponseTracker callback.
    c                    t        j                  d      }d|_        t        j                  |      | _         t	        j
                         | _        | j                  j                  | j                   _        | j                   j                  t        j                                | j                   j                  d       t        j                  | j                   d      | _        y )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6{C"*",,];ZZ\
$(JJ$8$8!%%m&C&C&EF##=	
 ,,t~~u5r%   c                 ~    | j                  | j                  d   d       | j                  | j                  d          y )Ntyper;   id)r   rG   
assertTruer*   s    r#   	testBasiczIQTests.testBasicV   s.    %0&r%   c                 @   | j                   j                  j                          | j                  j	                          | j                  d   j                  d      }| j                  | j                   j                  j                         d|z   dz   d|z   dz   g       y )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/NN$$**,&069g%(99	
r%   c                       fd} j                   j                         }|j                  |        j                  }|j	                  d j                   d   z         |S )Nc                 0    j                  | d   d       y )NrK   result)r   )rZ   r!   s    r#   cbz&IQTests.testResultResponse.<locals>.cbg   s    VF^X6r%   <iq type='result' id='%s'/>rL   )rG   rR   addCallbackr   rE   )r!   r[   dxss   `   r#   testResultResponsezIQTests.testResultResponsef   sM    	7 GGLLN	b^^
5EFr%   c                     | j                   j                         }| j                  |t        j                         | 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   sO    GGLLN1e//0^^
4twwt}DEr%   c                       j                   }t        j                  |        j                  |j                          fd}|j	                  d|d       |j                  d       y)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                 >    j                  t        | dd             y )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   sV     ^^..r2 	(
	< 	ub"% 	78r%   c                     | j                   j                         }| j                  }|j                  d| j                   d   z         | j	                  | 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   sW     GGLLN^^
5EF7r%   c                     | j                   j                         }| j                  }|j                  d       | j	                  |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   s@     GGLLN^^
*+1n-r%   c                       fd j                   j                         }|j                          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                         j                         }|j                         y N)r   rF   rR   
addErrback)r	   r^   ebr!   s     r#   r{   z'IQTests.testNoModifyingDict.<locals>.eb   s*    T^^,113ALLr%   rt   )rG   rR   rz   r   ru   )r!   r^   r{   s   ` @r#   testNoModifyingDictzIQTests.testNoModifyingDict   s=    	 GGLLN	R%%&67r%   c                 j   d| j                   _        | j                   j                         }| j                  |t        j
                         | j                  j                  ddg       | j                  | j                  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}     GGLLN1i445

B ))*334r%   c                 b   d| j                   _        | j                   j                         }| j                  j	                  d| j
                  j                  d| j                   d   z         | j                  j                  ddg       | j                  | 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    
 GGLLN

NN'')DGGDM9	

 	

A))*r%   c                    d| j                   _        | j                   j                         }| j                  }|j	                  d       | j                  |t               | j                  | 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   sc     GGLLN^^
*+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   sC    6'

	90
 r%   r7   c                   l    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y)XmlStreamTestsc                     d| _         y NT)gotStreamStartr!   objs     r#   onStreamStartzXmlStreamTests.onStreamStart   
    "r%   c                     d| _         y r   )gotStreamEndr   s     r#   onStreamEndzXmlStreamTests.onStreamEnd   s
     r%   c                     d| _         y r   )gotStreamErrorr   s     r#   onStreamErrorzXmlStreamTests.onStreamError   r   r%   c                    d| _         d| _        d| _        t        j                  t        j
                               }|j                  d| j                         |j                  d| j                         |j                  d| j                         |j                  t        j                                ||j                  _        d|_        d|_        || _        y)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!8!:;
-t/A/AB
+T-=-=>
-t/A/AB
-HHJK "
r%   c                 n   | j                   }|j                          | j                   j                  j                         dd j	                  d      }| j                  d|       | j                  d|       | j                  d|       | j                  d|       | j                  |j                         y)	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     ^^
nn..446q<BB4H'5H+V'5&4'r%   c                    | j                   }d|j                  d<   |j                          | j                   j                  j	                         dd j                  d      }| j                  d|       | j                  d|       | j                  d|       | j                  d	|       | j                  d
|       | j                  |j                         y)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,-
nn..446q<BB4H'5H+V:KH'5&4'r%   c                 R   | j                   }t        j                  d      |_        t        j                  d      |_        d|_        |j                          |j                  j                         dd j                  d      }| j                  d|       | j                  d|       y	)
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     ^^
+-
ll((*1R066t<'5(+6r%   c                    | j                   }t        j                  d      |_        t        j                  d      |_        d|_        d|_        |j                          |j                  j                         dd j                  d      }| j                  d|       | j                  d	|       | j                  d
|       y)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     ^^
+-
ll((*1R066t<'5(+6'5r%   c                     | j                   }|j                  d       |j                  d       | j                  | j                         | j                  | j                         y)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  sQ     ^^
;	

 	)*++,))*r%   c                 P   | j                   }d|_        |j                          |j                  j	                          |j                  t        j                  d             | j                  d|j                  j                                | j                  | j                         y)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  sv     ^^


5,,-BCDC!3!3!56))*r%   c                 f   | j                   }d|_        |j                  j                          |j	                  t        j                  d             | j                  |j                         | j                  d|j                  j                                | j                  | j                         y)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Dr~~&bll0023))*r%   c                 P   | j                   }d|_        |j                          |j                  j	                          |j                  t        j                  d             | j                  d|j                  j                                | j                  | j                         y)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  sv     ^^


5,,-BCDC!3!3!56))*r%   c                 f   | j                   }d|_        |j                  j                          |j	                  t        j                  d             | j                  |j                         | j                  d|j                  j                                | j                  | j                         y)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D'C!3!3!56))*r%   c                     | j                   }|j                          |j                  }|j                          | j	                  ||j                         | j                  |j                         y)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  sL     ^^


FBII.r~~&r%   c                 :   | j                   }|j                  d       | j                  |j                  j	                         d       |j                  j                          t        j                  d      }|j                  |       | j                  |j                  j	                         d       |j                  j                          t        j                  d      }|j                  |       | j                  |j                  j	                         d       y)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
++-~>
^^LM
++-/DEr%   c                 t   g g g  G fdd      } |       }t        j                  |      }| j                  |g       |j                          | j                  dg       |j	                  d       | j                  dt                     |j                          | j                  dg       y)zM
        Test that the associated authenticator is correctly called.
        c                   ,    e Zd ZfdZfdZ fdZy)<XmlStreamTests.test_authenticator.<locals>.TestAuthenticatorc                 (    j                  d        y ry   append)r!   connectionMadeCallss    r#   connectionMadezKXmlStreamTests.test_authenticator.<locals>.TestAuthenticator.connectionMade  s    #**40r%   c                 (    j                  |       y ry   r   )r!   rootElementstreamStartedCallss     r#   streamStartedzJXmlStreamTests.test_authenticator.<locals>.TestAuthenticator.streamStarted  s    "))+6r%   c                 (    j                  |       y ry   r   )r!   r_   associateWithStreamCallss     r#   associateWithStreamzPXmlStreamTests.test_authenticator.<locals>.TestAuthenticator.associateWithStream  s    (//3r%   N)r1   r2   r3   r   r   r   )r   r   r   s   r#   TestAuthenticatorr     s    17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   #"78
$!45
-	

 	C 234

$!4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      sS    #!#"((76+++ ++ 	'F$6r%   r   c                       e Zd Zy)	TestErrorN)r1   r2   r3   r5   r%   r#   r   r     s    r%   r   c                   *    e Zd Zd Zd Zd Zd Zd Zy)AuthenticatorTestsc                 ~    t        j                         | _        t        j                  | j                        | _         y ry   )r   r   rH   r>   r*   s    r#   rI   zAuthenticatorTests.setUp  s+    &446",,T-?-?@r%   c                    | j                   }|j                  t        j                                |j	                  d       | j                  d|j                         | j                  d|j                         | j                  d|j                         | j                  d|j                         | j                  d|j                         y)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79:
	
 	,T266*BLL1T2>>2r}}-r%   c                     | j                   }|j                  t        j                                |j	                  d       | j                  d|j                         y)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  sK    
 ^^
-779:
-	

 	,r%   c                     | j                   }|j                  t        j                                |j	                  d       | j                  d|j                         y)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  sK    
 ^^
-779:
9	

 	,r%   c                     | j                   }|j                  t        j                                |j	                  d       | j                  d|j                         y)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  sK    
 ^^
-779:
<	

 	,r%   N)r1   r2   r3   rI   r   r   r   r  r5   r%   r#   r   r     s    A.&---r%   r   c                   0    e Zd Zd Zd Zd Zd Zd Zd Zy)ConnectAuthenticatorTestsc                 4   d| _         d | _        t        j                  d      | _        t        j
                  | j                        | _        | j                  j                  d| j                         | j                  j                  d| j                         y )NFr   //event/stream/authd//event/xmpp/initfailed)	gotAuthenticatedinitFailurer   r<   rH   r>   rn   onAuthenticatedonInitFailedr*   s    r#   rI   zConnectAuthenticatorTests.setUp	  ss     %&;;KH",,T-?-?@""#94;O;OP""#<d>O>OPr%   c                     d| _         y r   )r  r   s     r#   r
  z)ConnectAuthenticatorTests.onAuthenticated  s
     $r%   c                     || _         y ry   )r	  )r!   r	   s     r#   r  z&ConnectAuthenticatorTests.onInitFailed  s
    "r%   c                      G d d      } |       }|g| j                   _        | j                  j                          | j	                  g | j                   j                         | j                  | j                         y)zG
        Test successful completion of an initialization step.
        c                       e Zd Zd Zy)9ConnectAuthenticatorTests.testSucces.<locals>.Initializerc                      y 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  sa    
	 	 }'+f#++-T^^889--.r%   c                     G d d      } |       }|g| j                   _        | j                  j                          | j	                  |g| j                   j                         | j                  | j                         | j                  d| j                         | j                  | j                  j                  t                     y)z9
        Test failure of an initialization step.
        c                       e Zd Zd Zy):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&67((..y9:r%   c                    d| j                   _        | j                  }|j                  t	        j
                                |j                  d       | j                  d|j                         | j                  d|j                         | j                  d|j                         | j                  d|j                  j                         | j                  d|j                         | j                  | j                         |j                  d       | j!                  d|j"                         | j%                  | j                         y)	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79:
	
 	,"&&)2<<0(;(;<T2==1t,,-
M	
 	("++6--.r%   N)	r1   r2   r3   rI   r
  r  r  r   r   r5   r%   r#   r  r    s!    Q%#/ ;$/r%   r  c                   "    e Zd ZdZd Zd Zd Zy)ListenAuthenticatorTestsz4
    Tests for L{xmlstream.ListenAuthenticator}
    c                 ~    t        j                         | _        t        j                  | j                        | _         y ry   )r   ListenAuthenticatorrH   r>   r*   s    r#   rI   zListenAuthenticatorTests.setUpY  s+    &::<",,T-?-?@r%   c                     | j                   }|j                  t        j                                | j	                  d|j
                         |j                  d       | j                  d|j                         | j                  d|j
                         | j                  d|j
                         | j                  d|j                         | j	                  d|j                         | j                  d|j                  j                         y)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79:T266*
	
 	,bff-GRVV,",,7T2>>2(:(:;r%   c                     | j                   }|j                  t        j                                |j	                  d       | j                  |j                  t               y)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  sK     ^^
-779:
	
 	bffc*r%   N)r1   r2   r3   r4   rI   r   r/  r5   r%   r#   r'  r'  T  s    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y)TLSInitiatingInitializerTestsc                    g | _         g | _        t        j                  | _        t        j
                  d      | _        t        j                  | j                        | _        | j                   j                  | j                  _	        | j                  j                          | j                  j                  d       t        j                  | j                        | _        y )Nr"  r   )outputdoner   r   savedSSLr<   rH   r>   r   rR   r   rE   TLSInitiatingInitializerr  r*   s    r#   rI   z#TLSInitiatingInitializerTests.setUp  s    	!&;;MJ",,T-?-?@"kk00%%'##;	

 66t~~F	r%   c                 .    | j                   t        _        y ry   )r5  r   r   r*   s    r#   tearDownz&TLSInitiatingInitializerTests.tearDown  s    	r%   c                     t        j                  | j                   d      | _        | j                  | j                  j                         y)z>
        Passing required sets the instance variable.
        T)requiredN)r   r6  r  rM   r:  r*   s    r#   test_initRequiredz/TLSInitiatingInitializerTests.test_initRequired  s3     66t~~PTU			**+r%   c                     t        j                          j                  _         fd j                  j                  _         fd j                  _         fd j                  _         j                  j                         }|j                   j                  t        j                          j                  dt         j                                j                  d   } j                  d|j                          j                  t        |j                           j                  j#                  dt        z          j                  g d j$                         |S )	zN
        When TLS is wanted and SSL available, StartTLS is initiated.
        c                 :    j                   j                  d      S NTLSr4  r   )ctxr!   s    r#   <lambda>zDTLSInitiatingInitializerTests.test_wantedSupported.<locals>.<lambda>  s    		8H8H8O r%   c                  :     j                   j                  d      S Nr   r@  r*   s   r#   rB  zDTLSInitiatingInitializerTests.test_wantedSupported.<locals>.<lambda>      tyy'7'7'@ r%   c                  :     j                   j                  d      S Nheaderr@  r*   s   r#   rB  zDTLSInitiatingInitializerTests.test_wantedSupported.<locals>.<lambda>      DII,<,<X,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 ,O  )@$F!IIOO	d&&	8C,-;;q>X]]3hll3##$;k$IJ3TYY?r%   c                      fd}t        j                          j                  _        | j                  j                  _         fd j                  _         fd j                  _         j                  j                         } j                  j                  dt        z          j                  g d j                         |S )z:
        The server certificate will be verified.
        c                     j                  | t               j                  | j                  d       j                  j                  d       y )Nr"  r?  )r-  r   r   	_hostnamer4  r   )contextFactoryr!   s    r#   fakeStartTLSzJTLSInitiatingInitializerTests.test_certificateVerify.<locals>.fakeStartTLS  s<    !!.2BC^55}EIIU#r%   c                  :     j                   j                  d      S rD  r@  r*   s   r#   rB  zFTLSInitiatingInitializerTests.test_certificateVerify.<locals>.<lambda>  rE  r%   c                  :     j                   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 ,8  )@$F!IIOO##$;k$IJ3TYY?r%   c                     t               t        j                   j                         _         j                  _         fd}t        j                          j                  _        | j                  j                  _         fd j                  _	         fd j                  _
         j                  j                         } j                  j                  dt        z          j                  g d j                         |S )zH
        A custom contextFactory is passed through to startTLS.
        )configurationForTLSc                 `    j                  |        j                  j                  d       y r>  )assertIsr4  r   )rX  rA  r!   s    r#   rY  zQTLSInitiatingInitializerTests.test_certificateVerifyContext.<locals>.fakeStartTLS  s#    MM#~.IIU#r%   c                  :     j                   j                  d      S rD  r@  r*   s   r#   rB  zMTLSInitiatingInitializerTests.test_certificateVerifyContext.<locals>.<lambda>  rE  r%   c                  :     j                   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6NN
	 $'		 	$ $1#@#@#B ,8  )@$F!IIOO##$;k$IJ3TYY?r%   c                     dt         _        d| j                  _        | j                  j	                         }|j                  | j                  d       | j                  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  sY     	"		IIOO	d&&-C,-r%   c                     dt         _        d| j                  _        | j                  j	                         }| j                  |t         j                         | 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  s[     	!		IIOO1i778C,-r%   c                    t        j                  d      }|j                  d       |j                  |j                  f|i| j
                  _        d| j                  _        | j                  j                         }| j                  dt        | j                               | 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     nnLMz"$'GGSXX#6"< 		IIOOC,-1i334r%   c                 |   t        j                  d      }|j                  |j                  f|i| j                  _        d| j                  _        d| j                  _        | j                  j                         }|j                  | j                  d       | j                  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     nnLM$'GGSXX#6"< 		"		IIOO	d&&-C,-r%   c                     dt         _        | j                  j                         }| j	                  |t         j
                         | 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  sN     	IIOO1i112##$;k$IJr%   N)r1   r2   r3   rI   r8  r;  r   skipWhenNoSSLrT  r\  rc  re  rh  rp  rr  ru  r5   r%   r#   r1  r1    sv    G"&, ] ( ] ( ] 2r%   r1  c                       e Zd ZdZd Zy)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y)%BaseFeatureInitiatingInitializerTestsc                     t        j                  t        j                               | _         t        | j                         | _        y ry   )r   r>   r   rx  r  r*   s    r#   rI   z+BaseFeatureInitiatingInitializerTests.setUp/  s-    ",,Y-D-D-FG*4>>:	r%   c                     | j                   j                  t        j                  | j                   j                        i| j                  _        | 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  sE     $(99#4#4fnnTYYEVEV6W"Xyy##%%r%   c                     d| j                   _        | j                  t        j                  | j                   j
                         y)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:  s0    
 "		)88$)):N:NOr%   c                 z    d| j                   _        | j                  d| j                   j                                y)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  s-    
 #		T499#7#7#9:r%   N)r1   r2   r3   rI   r  r  r  r5   r%   r#   r}  r}  .  s    ;&P;r%   r}  c                   0    e Zd Zd Zd Zd Zd Zd Zd Zy)ToResponseTestsc                 N   t        j                  d      }d|d<   d|d<   d|d<   d|d	<   t        j                  |d
      }| j	                  ||       | j                  |d   d       | j                  |d   d       | j                  |d   d
       | j                  |d	   d       y)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v*t5v t''91&)+>?$)EF&)84$3r%   c                     t        j                  d      }d|d<   d|d<   t        j                  |      }| j	                  |d   d       | j                  |j                  d             y)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\  sd      78v*t''/&)+>?..t45r%   c                     t        j                  d      }d|d<   d|d<   t        j                  |      }| j	                  |j                  d             | j                  |d   d       y)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  sc      78v5v''/..v67$)EFr%   c                     t        j                  d      }d|d<   t        j                  |      }| j	                  |j                  d             | j	                  |j                  d             y)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  s^      <=v''/..t45..v67r%   c                     t        j                  d      }t        j                  |      }| j	                  |j                  d             y)zP
        Test that a proper response is generated without id attribute.
        r  rL   Nr  r  s      r#   	test_noIDzToResponseTests.test_noID|  s<      <=''/..t45r%   c                     t        j                  d      }t        j                  |      }| j	                  |j                  d             y)zR
        Test that a proper response is generated without type attribute.
        r  rK   Nr  r  s      r#   test_noTypezToResponseTests.test_noType  s<      <=''/..v67r%   N)	r1   r2   r3   r  r  r  r  r  r  r5   r%   r#   r  r  K  s!    4 	6	G868r%   r  c                       e Zd ZdZd Zd Zy)DummyFactoryzJ
    Dummy XmlStream factory that only registers bootstrap observers.
    c                     i | _         y ry   	callbacksr*   s    r#   __init__zDummyFactory.__init__  s	    r%   c                 "    || j                   |<   y 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                   .    e Zd ZdZd Zd Zd Zd Zd Zy)DummyXMPPHandlerzO
    Dummy XMPP subprotocol handler to count the methods are called on it.
    c                 .    d| _         d| _        d| _        y )Nr   )doneMadedoneInitializeddoneLostr*   s    r#   r  zDummyXMPPHandler.__init__  s     r%   c                 $    | j                          y ry   )r   r   s     r#   rC   zDummyXMPPHandler.makeConnection  s    r%   c                 .    | xj                   dz  c_         y Nr   r  r*   s    r#   r   zDummyXMPPHandler.connectionMade      r%   c                 .    | xj                   dz  c_         y r  )r  r*   s    r#   connectionInitializedz&DummyXMPPHandler.connectionInitialized  s    !r%   c                 .    | xj                   dz  c_         y 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    s     
"r%   r  c                       e Zd ZdZd Zd Zy)FailureReasonXMPPHandlerz>
    Dummy handler specifically for failure Reason tests.
    c                     d| _         y )NF)gotFailureReasonr*   s    r#   r  z!FailureReasonXMPPHandler.__init__  s
     %r%   c                 H    t        |t        j                        rd| _        y y r   )
isinstancer	   Failurer  r  s     r#   ru   z'FailureReasonXMPPHandler.connectionLost  s    fgoo.$(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y)XMPPHandlerTestsz-
    Tests for L{xmlstream.XMPPHandler}.
    c                 \    t        t        j                  t        j                                y)zN
        L{xmlstream.XMPPHandler} implements L{ijabber.IXMPPHandler}.
        N)r   r   IXMPPHandlerr   XMPPHandlerr*   s    r#   test_interfacezXMPPHandlerTests.test_interface  s     	W))9+@+@+BCr%   c                      G d d      }t        j                         } |       |_        |j                  d       | j	                  dg|j                  j
                         y)zP
        Test that data is passed on for sending by the stream manager.
        c                       e Zd Zd Zd Zy)6XMPPHandlerTests.test_send.<locals>.DummyStreamManagerc                     g | _         y ry   )outlistr*   s    r#   r  z?XMPPHandlerTests.test_send.<locals>.DummyStreamManager.__init__  s	    !r%   c                 :    | j                   j                  |       y 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    s    "*r%   r  r   N)r   r  parentrR   r   r  )r!   r  handlers      r#   r   zXMPPHandlerTests.test_send  sN    
	* 	* '')+-]#-'..*@*@Ar%   c                 "    G d dt         j                        } |       }t        j                  t        j                               }|j	                  |       | j                  |j                         | j                  ||j                          y)zY
        Test that makeConnection saves the XML stream and calls connectionMade.
        c                       e Zd Zd Zy)=XMPPHandlerTests.test_makeConnection.<locals>.TestXMPPHandlerc                     d| _         y 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  sm    
	%i33 	% "#  !8!8!:;r"(()R!2!23r%   c                    t        j                         }t        j                  t        j                               }|j	                  |       |j                  t                      | j                  d|j                          y)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  s_     '')  !8!8!:;r"y{+T7#4#45r%   N)r1   r2   r3   r4   r  r   r  r  r5   r%   r#   r  r    s    DB"46r%   r  c                   (    e Zd ZdZd Zd Zd Zd Zy)XMPPHandlerCollectionTestsz7
    Tests for L{xmlstream.XMPPHandlerCollection}.
    c                 6    t        j                         | _        y ry   )r   XMPPHandlerCollection
collectionr*   s    r#   rI   z XMPPHandlerCollectionTests.setUp  s    #99;r%   c                 L    t        t        j                  | j                         y)zZ
        L{xmlstream.StreamManager} implements L{ijabber.IXMPPHandlerCollection}.
        N)r   r   IXMPPHandlerCollectionr  r*   s    r#   r  z)XMPPHandlerCollectionTests.test_interface  s     	W33T__Er%   c                     t               }|j                  | j                         | j                  || j                         | j	                  | j                  |j
                         y)z:
        Test the addition of a protocol handler.
        N)r  setHandlerParentr  rT   r   r  r!   r  s     r#   test_addHandlerz*XMPPHandlerCollectionTests.test_addHandler  sH     #$  1gt/T__gnn=r%   c                     t               }|j                  | j                         |j                  | j                         | j	                  || j                         | j                  d|j                         y)z5
        Test removal of a protocol handler.
        N)r  r  r  disownHandlerParentrq   r   r  r  s     r#   test_removeHandlerz-XMPPHandlerCollectionTests.test_removeHandler
  sX     #$  1##DOO4$//2T7>>2r%   N)r1   r2   r3   r4   rI   r  r  r  r5   r%   r#   r  r    s    <F>3r%   r  c                   d    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y)StreamManagerTestsz/
    Tests for L{xmlstream.StreamManager}.
    c                 L    t               }t        j                  |      | _        y ry   )r  r   StreamManagerstreamManager)r!   factorys     r#   rI   zStreamManagerTests.setUp  s    .&44W=r%   c                 $   | j                   }| j                  d|j                         | j                  g |j                         | j                  |j
                  |j                  j                  d          | j                  |j                  |j                  j                  d          | j                  |j                  |j                  j                  d          | j                  |j                  |j                  j                  d          y)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R[[)MM2:://0JK	
 	BJJ$8$89O$PQ))2::+?+?@T+UV##RZZ%9%9:S%T	
r%   c                 j   | j                   }t               }|j                  |       t        j                  t        j
                               }|j                  |       | j                  d|j                         | j                  d|j                         | j                  d|j                         y)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!8!:;
bG,,-G334G,,-r%   c                 2   | j                   }t               }|j                  |       t        j                  t        j
                               }|j                  |       | j                  d|j                         | j                  d|j                         y)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<  sr     "$  $  !8!8!:;
bT2>>2T2??3r%   c                 @   | j                   }d|_        t               }|j                  |       t	        j
                  t	        j                               }|j                  |       | j                  d|j                         | j                  d|j                         y)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  sy     "$  $  !8!8!:;
bbnn5boo6r%   c                 j   | j                   }t               }|j                  |       t        j                  t        j
                               }|j                  |       | j                  d|j                         | j                  d|j                         | j                  d|j                         y)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!8!:;
		"G,,-G334G,,-r%   c                 j   | j                   }t               }|j                  |       t        j                  t        j
                               }|j                  |       | j                  d|j                         | j                  d|j                         | j                  d|j                         y)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!8!:;
G,,-G334G,,-r%   c                     | j                   }t               }|j                  |       |j                  t	        j
                  t        d                   | j                  d|j                         y)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  sW    
 *,  $
;)?@Aw778r%   c                     | j                   }t               }|j                  |       | j                  d|j                         | j                  d|j
                         | j                  d|j                         y)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|  sg     "$  $G,,-G334G,,-r%   c                    | j                   }t        j                  t        j                               }|j	                  |       |j                  |       t               }|j                  |       | j                  d|j                         | j                  d|j                         | j                  d|j                         y)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!8!:;
b
		""$  $G,,-G334G,,-r%   c                    t        j                  t        j                               }t        j                  |      }|j	                  d      }t        j                         |_        |j                          |j                  d       |j                  |d       |j                  d       | j                  d|j                  j                                y)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-D-FG$$W-""4($446

-	

 	B./
););)=>r%   c                 <   t        j                  t        j                               }t        j                  |      }t	               }|j                  |       |j                  d      }t        j                         |_	        |j                  d       | j                  d|j                  j                                | j                  d|j                  d          |j                          | j                  d|j                  j                                | j                  d|j                  d          |j                  d       |j!                  |d       | j                  d|j                  j                                | j#                  |j                         y)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  s6    ,,Y-D-D-FG$$W-"$
g""4($446
bll0023(:;
bll0023(:;
-	

 	B./););)=>)r%   c                    t        j                  t        j                               }t        j                  |      }|j	                  d      }t        j                         |_        |j                          |j                  d       |j                  d       | j                  d|j                  j                                | j                  d|j                  d          y)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-D-FG$$W-""4($446

-	

 	bll0023(:;r%   c                    t        j                  t        j                               }t        j                  |      }t	               }|j                  |       |j                  d      }|j                          t        j                         |_
        |j                  d       |j                  d       | j                  d|j                  j                                | j                  d|j                  d          y)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-D-FG$$W-"$
g""4(
$446
$
bll002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    sN    >
 .
47..	9
..(?(*@<(<r%   r  c                   .    e Zd ZdZd Zd Zd Zd Zd Zy)XmlStreamServerFactoryTestsz8
    Tests for L{xmlstream.XmlStreamServerFactory}.
    c                 X     G d d      fd}t        j                  |      | _        y)zQ
        Set up a server factory with an authenticator factory function.
        c                       e Zd Zd Zd Zy)<XmlStreamServerFactoryTests.setUp.<locals>.TestAuthenticatorc                     g | _         y ry   )
xmlstreamsr*   s    r#   r  zEXmlStreamServerFactoryTests.setUp.<locals>.TestAuthenticator.__init__  s	    "$r%   c                 :    | j                   j                  |       y 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    s    %+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'    
	+ 	+	' !778LMr%   c                 8    t        t        | j                         y)z<
        L{XmlStreamServerFactory} is a L{Factory}.
        N)r   r   r  r*   s    r#   r  z*XmlStreamServerFactoryTests.test_interface  s     	%t||4r%   c                     | j                   j                  d      }| j                  |g|j                  j                         y)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  s6     \\''-"r//::;r%   c                 z    | j                   j                  d      }| j                  |t        j                         y)zV
        The protocol factory creates Jabber XML Stream protocols by default.
        N)r  r  r-  r   r>   r   s     r#   test_buildProtocolXmlStreamz7XmlStreamServerFactoryTests.test_buildProtocolXmlStream#  s.     \\''-b)"5"56r%   c                     | j                   j                  d      }| j                   j                  d      }| j                  ||       | j                  |j                  |j                         y)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*  sX    
 ll((.ll((.S) 1 133D3DEr%   N)	r1   r2   r3   r4   rI   r  r(  r*  r.  r5   r%   r#   r  r    s"    N"5<7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 8 " & " I I O %	8,
 CM<7/K)) K@_h _DX6X&& X6v		 	@-** @-FI/ 1 1 I/X*+x00 *+ZcH$5$5 cL#YGG #;H,=,= ;:?8h'' ?8D	) 	)y,, .
)y44 
)36x(( 36l3!2!2 3Db<** b<J8F"C 8FE'  0
C/M0s   G 	GG