
[XMc           @   s  d  Z  d d l m Z m Z d d l m Z d d l m Z m Z m	 Z	 d d l
 m Z d d l m Z d d l m Z d d l Z d d l Z d d	 l m Z d
 d j d d  Z d j d d  Z d j d d  Z d j d d  Z d j d d  Z d j d d  Z d j d d  Z d d: d     YZ d e j f d     YZ d e f d     YZ d e j f d     YZ  d e j f d     YZ! d e j f d     YZ" d  e j f d!     YZ# d" d; d#     YZ$ d$ d< d%     YZ% d& e j f d'     YZ& d( e j f d)     YZ' d* e j( f d+     YZ) d, e j f d-     YZ* d. Z+ d/ Z, d0 Z- d1 Z. d2 e j/ f d3     YZ0 d4 e j1 f d5     YZ2 d6 e j f d7     YZ3 d8 e j f d9     YZ4 d S(=   s&   Session Initialization Protocol tests.i(   t   unittestt   util(   t   sip(   t   defert   reactort   utils(   t   Version(   t   proto_helpers(   t   credN(   t
   implementss   


s?   INVITE sip:foo SIP/2.0
From: mo
To: joe
Content-Length: 4

abcds   
s   
s-   INVITE sip:foo SIP/2.0
From: mo
To: joe

1234sH   INVITE sip:foo SIP/2.0
From: mo
To: joe
Content-Length: 4

1234

lalalals   INVITE sip:foo SIP/2.0
From: mo
To: joe
Content-Length: 0

INVITE sip:loop SIP/2.0
From: foo
To: bar
Content-Length: 4

abcdINVITE sip:loop SIP/2.0
From: foo
To: bar
Content-Length: 4

1234s4   SIP/2.0 200 OK
From:  foo
To:bar
Content-Length: 0

s.   INVITE sip:foo SIP/2.0
f: mo
t: joe
l: 4

abcds=   INVITE sip:foo SIP/2.0
Via: SIP/2.0/UDP 10.0.0.1:5060;rport

t	   TestRealmc           B   s   e  Z d    Z RS(   c         G   s   t  j d  d   f S(   Nc           S   s   d  S(   N(   t   None(    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_sip.pyt   <lambda>[   s    (   R   t   IContactR   (   t   selft   avatarIdt   mindt
   interfaces(    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_sip.pyt   requestAvatarZ   s    (   t   __name__t
   __module__R   (    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_sip.pyR
   Y   s   t   MessageParsingTestCasec           B   sY   e  Z d    Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z	 d   Z
 RS(	   c         C   s%   g  |  _  t j |  j  j  |  _ d  S(   N(   t   lR   t   MessagesParsert   appendt   parser(   R   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_sip.pyt   setUp^   s    	c         C   s!   |  j  j |  |  j  j   d  S(   N(   R   t   dataReceivedt   dataDone(   R   t   message(    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_sip.pyt   feedMessageb   s    c         C   si   |  j  | j |  |  j  | j j   |  |  j  | j |  |  j  | j |  |  j  | j d  d S(   s   Validate Requests.i   N(   t   assertEqualst   methodt   urit   toStringt   headerst   bodyt   finished(   R   t   mR    R!   R#   R$   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_sip.pyt   validateMessagef   s
    c         C   sk   |  j  } |  j t  |  j t |  d  |  j | d d d i d g d 6d g d 6d	 g d
 6d  d  S(   Ni   i    t   INVITEs   sip:foot   mot   fromt   joet   tot   4s   content-lengtht   abcd(   R   R   t   request1R   t   lenR'   (   R   R   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_sip.pyt
   testSimplen   s    	!c         C   s   |  j  } |  j t  |  j t  |  j t |  d  |  j | d d d i d g d 6d g d 6d	 g d
 6d  |  j | d d d i d g d 6d g d 6d  d  S(   Ni   i    R(   s   sip:fooR)   R*   R+   R,   R-   s   content-lengthR.   i   t   1234(   R   R   R/   t   request2R   R0   R'   (   R   R   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_sip.pyt   testTwoMessagesw   s    	!c         C   sk   |  j  } |  j t  |  j t |  d  |  j | d d d i d g d 6d g d 6d	 g d
 6d  d  S(   Ni   i    R(   s   sip:fooR)   R*   R+   R,   R-   s   content-lengthR2   (   R   R   t   request3R   R0   R'   (   R   R   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_sip.pyt   testGarbage   s    	!c         C   s   |  j  } |  j t  |  j t |  d  |  j | d d d i d g d 6d g d 6d	 g d
 6d  |  j | d d d i d g d 6d g d 6d g d
 6d  |  j | d d d i d g d 6d g d 6d g d
 6d  d  S(   Ni   i    R(   s   sip:fooR)   R*   R+   R,   t   0s   content-lengtht    i   s   sip:loopt   foot   barR-   R.   i   R2   (   R   R   t   request4R   R0   R'   (   R   R   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_sip.pyt   testThreeInOne   s    	!!!c         C   sk   |  j  } |  j t  |  j t |  d  |  j | d d d i d g d 6d g d 6d	 g d
 6d  d  S(   Ni   i    R(   s   sip:fooR)   R*   R+   R,   R-   s   content-lengthR.   (   R   R   t   request_shortR   R0   R'   (   R   R   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_sip.pyt	   testShort   s    	!c         C   s   |  j  } |  j t  |  j t |  d  | d } |  j | j d  |  j | j d  |  j | j i d g d 6d g d 6d	 g d
 6 |  j | j d  |  j | j	 d  d  S(   Ni   i    i   t   OKR9   R*   R:   R,   R7   s   content-lengthR8   (
   R   R   t	   response1R   R0   t   codet   phraseR#   R$   R%   (   R   R   R&   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_sip.pyt   testSimpleResponse   s    	
%(   R   R   R   R   R'   R1   R4   R6   R<   R>   RC   (    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_sip.pyR   ]   s   											t   MessageParsingTestCase2c           B   s   e  Z d  Z d   Z RS(   s/   Same as base class, but feed data char by char.c         C   s2   x | D] } |  j  j |  q W|  j  j   d  S(   N(   R   R   R   (   R   R   t   c(    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_sip.pyR      s    (   R   R   t   __doc__R   (    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_sip.pyRD      s   t   MakeMessageTestCasec           B   s#   e  Z d    Z d   Z d   Z RS(   c         C   s<   t  j d d  } | j d d  |  j | j   d  d  S(   NR(   s   sip:fooR9   R:   s$   INVITE sip:foo SIP/2.0
Foo: bar

(   R   t   Requestt	   addHeaderR   R"   (   R   t   r(    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_sip.pyt   testRequest   s
    	c         C   sY   t  j d d  } | j d d  | j d d  | j d  |  j | j   d  d  S(	   Ni   R?   R9   R:   s   Content-LengthR-   R2   s3   SIP/2.0 200 OK
Foo: bar
Content-Length: 4

1234(   R   t   ResponseRI   t   bodyDataReceivedR   R"   (   R   RJ   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_sip.pyt   testResponse   s    	c         C   s)   t  j d  } |  j | j   d  d  S(   Ni   s   SIP/2.0 200 OK

(   R   RL   R   R"   (   R   RJ   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_sip.pyt   testStatusCode   s    (   R   R   RK   RN   RO   (    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_sip.pyRG      s   			t   ViaTestCasec           B   sb   e  Z d    Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z	 d   Z
 d	   Z RS(
   c         C   s/   | j    } |  j | t j |  j     d  S(   N(   R"   R   R   t   parseViaHeader(   R   t   vt   s(    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_sip.pyt   checkRoundtrip   s    c         C   sd   t  j d  } t  j d  } |  j | j | j  |  j | j | j  |  j | j | j  d  S(   Ns   SIP/2.0/UDP 192.168.1.1:5060s    SIP/2.0/UDP     192.168.1.1:5060(   R   RQ   R   t	   transportt   hostt   port(   R   t   v1t   v2(    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_sip.pyt   testExtraWhitespace   s
    c         C   s   d } t  j |  } |  j | j d  |  j | j d  |  j | j d  |  j | j d
  |  j | j d
  |  j | j	 t
  |  j | j d  |  j | j d  |  j | j d  |  j | j d  |  j | j   d	  |  j |  d
 S(   sC   
        Test parsing a Via header with one of everything.
        sV   SIP/2.0/UDP first.example.com:4000;ttl=16;maddr=224.2.0.1 ;branch=a7c6a8dlze (Example)t   UDPs   first.example.comi  i   s	   224.2.0.1t
   a7c6a8dlzei    sK   SIP/2.0/UDP first.example.com:4000;ttl=16;branch=a7c6a8dlze;maddr=224.2.0.1N(   R   RQ   R   RU   RV   RW   t   rportR   t
   rportValuet   rportRequestedt   Falset   ttlt   maddrt   brancht   hiddenR"   RT   (   R   RS   RR   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_sip.pyt   test_complex   s    c         C   s   d } t  j |  } |  j | j d  |  j | j d  |  j | j d  |  j | j d  |  j | j d  |  j | j	 t
  |  j | j d  |  j | j d  |  j | j d  |  j | j t  |  j | j   d  |  j |  d S(   s3   
        Test parsing a simple Via header.
        s   SIP/2.0/UDP example.com;hiddenR[   s   example.comi  s#   SIP/2.0/UDP example.com:5060;hiddenN(   R   RQ   R   RU   RV   RW   R]   R   R^   R_   R`   Ra   Rb   Rc   Rd   t   TrueR"   RT   (   R   RS   RR   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_sip.pyt   test_simple   s    c         C   s    t  j d  } |  j |  d  S(   Ns   example.com(   R   t   ViaRT   (   R   RR   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_sip.pyt   testSimpler  s    c         C   s   t  j d d t } |  j d |  j g  } |  j t |  d  |  j | d d d  |  j | d d t  |  j | j   d	  |  j | j	 t  |  j | j
 t  |  j | j d
  d
 S(   s|   
        Setting rport to True is deprecated, but still produces a Via header
        with the expected properties.
        s   foo.barR]   t   offendingFunctionsi   i    R   s+   rport=True is deprecated since Twisted 9.0.t   categorys   SIP/2.0/UDP foo.bar:5060;rportN(   R   Rh   Rf   t   flushWarningst   test_deprecatedRPortt   assertEqualR0   t   DeprecationWarningR"   R]   R_   R^   R   (   R   RR   t   warnings(    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_sip.pyRm     s    	c         C   sU   t  j d d d } |  j | j   d  |  j | j t  |  j | j d  d S(   sU   
        An rport setting of None should insert the parameter with no value.
        s   foo.barR]   s   SIP/2.0/UDP foo.bar:5060;rportN(   R   Rh   R   Rn   R"   R_   Rf   R^   (   R   RR   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_sip.pyt
   test_rport(  s    c         C   sh   t  j d d d } |  j | j   d  |  j | j t  |  j | j d  |  j | j d  d S(   sk   
        An rport numeric setting should insert the parameter with the number
        value given.
        s   foo.barR]   i   s    SIP/2.0/UDP foo.bar:5060;rport=1N(   R   Rh   Rn   R"   R_   R`   R^   R]   (   R   RR   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_sip.pyt   test_rportValue2  s
    c         C   s   d } t  j |  } |  j | j d  |  j | j d  |  j | j d  |  j | j d  |  j | j d  |  j | j	   j
 d  d  d  S(	   Ns8   SIP/2.0/UDP 10.0.0.1:5060;received=22.13.1.5;rport=12345R[   s   10.0.0.1i  s	   22.13.1.5i90  s   rport=12345i(   R   RQ   R   RU   RV   RW   t   receivedR]   t   assertNotEqualsR"   t   find(   R   RS   RR   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_sip.pyt   testNAT>  s    c         C   s/   d } t  j |  } |  j | j   |  d S(   sX   
       Parsing and serializing Via headers with unknown parameters should work.
       s?   SIP/2.0/UDP example.com:5060;branch=a12345b;bogus;pie=deliciousN(   R   RQ   Rn   R"   (   R   RS   RR   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_sip.pyt   test_unknownParamsJ  s    (   R   R   RT   RZ   Re   Rg   Ri   Rm   Rq   Rr   Rv   Rw   (    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_sip.pyRP      s   							
		t   URLTestCasec           B   s   e  Z d    Z d   Z RS(   c         C   s@   x9 d d d d g D]% } |  j  t j |  j   |  q Wd  S(   Ns   sip:j.doe@big.coms&   sip:j.doe:secret@big.com;transport=tcps!   sip:j.doe@big.com?subject=projects   sip:example.com(   R   R   t   parseURLR"   (   R   t   url(    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_sip.pyt   testRoundtripV  s    c         C   s   d } t  j |  } xn d d d d d  d! d" d# d$ d d d g f d i d d 6d d 6f g D]% \ } } |  j t | |  |  q] Wd  S(%   Nse   sip:user:pass@hosta:123;transport=udp;user=phone;method=foo;ttl=12;maddr=1.2.3.4;blah;goo=bar?a=b&c=dt   usernamet   usert   passwordt   passRV   t   hostaRW   i{   RU   t   udpt   usertypet   phoneR    R9   Ra   i   Rb   s   1.2.3.4t   othert   blahs   goo=barR#   t   bt   at   dRE   (   s   usernames   user(   R~   R   (   s   hostR   (   s   porti{   (   s	   transportR   (   R   R   (   s   methods   foo(   s   ttli   (   s   maddrs   1.2.3.4(   R   Ry   R   t   getattr(   R   RS   Rz   t   kRR   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_sip.pyt   testComplex_  s    	'(   R   R   R{   R   (    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_sip.pyRx   T  s   		t   ParseTestCasec           B   s   e  Z d    Z RS(   c      
   C   s   x d d d i  f d d d i  f d d d i  f d d d i  f d d	 d i d
 d 6d d	 6f g D]` \ } } } } t  j |  \ } } } |  j | |  |  j | j   |  |  j | |  q` Wd  S(   Ns"   "A. G. Bell" <sip:foo@example.com>s
   A. G. Bells   sip:foo@example.coms   Anon <sip:foo@example.com>t   AnonR8   s   <sip:foo@example.com>s)   foo <sip:foo@example.com>;tag=bar;foo=bazR9   R:   t   tagt   baz(   R   t   parseAddressR   R"   (   R   t   addresst   namet   urlst   paramst   gnamet   gurlt   gparams(    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_sip.pyt   testParseAddressn  s    -(   R   R   R   (    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_sip.pyR   l  s   t   DummyLocatorc           B   s   e  Z e e j  d    Z RS(   c         C   s   t  j t j d d d  S(   Ns
   server.comRW   i  (   R   t   succeedR   t   URL(   R   t
   logicalURL(    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_sip.pyt
   getAddress  s    (   R   R   R	   R   t   ILocatorR   (    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_sip.pyR   ~  s   t   FailingLocatorc           B   s   e  Z e e j  d    Z RS(   c         C   s   t  j t    S(   N(   R   t   failt   LookupError(   R   R   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_sip.pyR     s    (   R   R   R	   R   R   R   (    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_sip.pyR     s   t   ProxyTestCasec           B   sb   e  Z d    Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z	 d   Z
 d	   Z RS(
   c            sC   t  j d    _ t     j _ g    _   f d     j _ d  S(   Ns	   127.0.0.1c            s     j  j |  | f  S(   N(   t   sentR   (   t   destt   msg(   R   (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_sip.pyR     s    (   R   t   Proxyt   proxyR   t   locatorR   t   sendMessage(   R   (    (   R   s9   /usr/lib/python2.7/dist-packages/twisted/test/test_sip.pyR     s    	c         C   s;  t  j d d  } | j d t  j d  j    | j d t  j d  j    | j d d  | j d d	  | j d
 d  |  j j | j   d  |  j t |  j	  d  |  j	 d \ } } |  j | j
 d  |  j | j d  |  j | j j   d  |  j | j d  |  j | j d d d d g  d  S(   NR(   s   sip:foot   vias   1.2.3.4s   1.2.3.5R9   R:   R,   s   <sip:joe@server.com>t   contacts   <sip:joe@1.2.3.5>i  i   i    s
   server.coms   SIP/2.0/UDP 127.0.0.1:5060s   SIP/2.0/UDP 1.2.3.4:5060s   SIP/2.0/UDP 1.2.3.5:5060(   s   1.2.3.4i  (   R   RH   RI   Rh   R"   R   t   datagramReceivedR   R0   R   RW   RV   R!   R    R#   (   R   RJ   R   R&   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_sip.pyt   testRequestForward  s"    c         C   s   t  j d d  } | j d t  j d  j    | j d d  | j d d  | j d	 d
  |  j j | j   d  |  j d \ } } |  j | j	 d d d g  d  S(   NR(   s   sip:fooR   s   1.2.3.4R9   R:   R,   s   <sip:joe@server.com>R   s   <sip:joe@1.2.3.4>s   1.1.1.1i  i    s   SIP/2.0/UDP 127.0.0.1:5060s)   SIP/2.0/UDP 1.2.3.4:5060;received=1.1.1.1(   s   1.1.1.1i  (
   R   RH   RI   Rh   R"   R   R   R   R   R#   (   R   RJ   R   R&   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_sip.pyt   testReceivedRequestForward  s    c         C   sd   t  j d  } | j d t  j d  j    |  j j | j   d  |  j t |  j	  d  d  S(   Ni   R   s   foo.coms   1.1.1.1i  i    (   s   1.1.1.1i  (
   R   RL   RI   Rh   R"   R   R   R   R0   R   (   R   RJ   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_sip.pyt   testResponseWrongVia  s    c         C   s   t  j d  } | j d t  j d  j    | j d t  j d d d j    |  j j | j   d  |  j t |  j	  d	  |  j	 d
 \ } } |  j | j
 | j f d  |  j | j d  |  j | j d d g  d  S(   Ni   R   s	   127.0.0.1s
   client.comRW   i  s   1.1.1.1i  i   i    s   SIP/2.0/UDP client.com:1234(   s   1.1.1.1i  (   s
   client.comi  (   R   RL   RI   Rh   R"   R   R   R   R0   R   RV   RW   RA   R#   (   R   RJ   R   R&   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_sip.pyt   testResponseForward  s    %c         C   s   t  j d  } | j d t  j d  j    | j d t  j d d d j    |  j j | j   d  |  j t |  j	  d	  |  j	 d
 \ } } |  j | j
 | j f d  d  S(   Ni   R   s	   127.0.0.1s   10.0.0.1Rs   s
   client.coms   1.1.1.1i  i   i    (   s   1.1.1.1i  (   s
   client.comi  (   R   RL   RI   Rh   R"   R   R   R   R0   R   RV   RW   (   R   RJ   R   R&   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_sip.pyt   testReceivedResponseForward  s    c            s   t  j d  } | j d t  j d  j    g      f d   |  j _ |  j j | j   d	  |  j t	    d    d \ } } |  j t	 | j
 j d g    d  |  j | j d  d  S(
   Ni   R   s	   127.0.0.1c             s     j  |   S(   N(   R   (   R   (   R   (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_sip.pyR     s    s   1.1.1.1i  i   i    (   s   1.1.1.1i  (   R   RL   RI   Rh   R"   R   t   gotResponseR   R   R0   R#   t   getRA   (   R   RJ   R&   t   addr(    (   R   s9   /usr/lib/python2.7/dist-packages/twisted/test/test_sip.pyt   testResponseToUs  s    %c         C   s   t  j d d  } | j d t  j d  j    | j d t  j d  j    |  j j | j   d  |  j |  j g   d  S(	   NR(   s   sip:fooR   s   1.2.3.4s	   127.0.0.1s
   client.comi  (   s
   client.comi  (	   R   RH   RI   Rh   R"   R   R   R   R   (   R   RJ   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_sip.pyt   testLoop  s
    c         C   s   t  j d d  } | j d t  j d  j    | j d d  t   |  j _ |  j j | j   d  |  j	 t
 |  j  d  |  j d	 \ } } |  j	 | j | j f d  |  j	 | j d
  |  j	 | j d d g  d  S(   NR(   s   sip:fooR   s   1.2.3.4R,   s   <sip:joe@server.com>i  i   i    i  s   SIP/2.0/UDP 1.2.3.4:5060(   s   1.2.3.4i  (   s   1.2.3.4i  (   R   RH   RI   Rh   R"   R   R   R   R   R   R0   R   RV   RW   RA   R#   (   R   RJ   R   R&   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_sip.pyt   testCantForwardRequest  s    c         C   s   d  S(   N(    (   R   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_sip.pyt   testCantForwardResponse  s    (   R   R   R   R   R   R   R   R   R   R   R   R   (    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_sip.pyR     s   									t   RegistrationTestCasec           B   s   e  Z d    Z e j e e j d e d 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 RS(   c            sb   t  j d d    _ t  j d    _   j   j _   j _ g    _   f d     j _ d  S(   NRV   s	   127.0.0.1s   bell.example.comc            s     j  j |  | f  S(   N(   R   R   (   R   R   (   R   (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_sip.pyR     s    (   R   t   RegisterProxyR   t   InMemoryRegistryt   registryR   R   R   (   R   (    (   R   s9   /usr/lib/python2.7/dist-packages/twisted/test/test_sip.pyR     s
    	Rk   R   s5   twisted.protocols.sip.DigestAuthorizer was deprecatedc         C   s7   x* |  j  j j   D] \ } } | j   q W|  ` d  S(   N(   R   t   userst   valuest   cancelR   (   R   R   R!   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_sip.pyt   tearDown  s    c         C   sn   t  j d d  } | j d d  | j d d  | j d t  j d  j    |  j j | j   d
  d  S(   Nt   REGISTERs   sip:bell.example.comR,   s   sip:joe@bell.example.comR   s   sip:joe@client.com:1234R   s
   client.comi  (   s
   client.comi  (   R   RH   RI   Rh   R"   R   R   (   R   RJ   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_sip.pyt   register  s
    c         C   s~   t  j d d  } | j d d  | j d d  | j d t  j d  j    | j d	 d
  |  j j | j   d  d  S(   NR   s   sip:bell.example.comR,   s   sip:joe@bell.example.comR   t   *R   s
   client.comt   expiresR7   i  (   s
   client.comi  (   R   RH   RI   Rh   R"   R   R   (   R   RJ   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_sip.pyt
   unregister  s    c         C   sT  |  j    |  j d \ } } |  j | j | j f d  |  j | j d  |  j | j d d g  |  j | j d d g  |  j | j d	 d
 g  |  j t | j d d  d k  |  j t	 |  j
 j  d  |  j
 j d \ } } |  j | j   d
  |  j j j t j d d d d   } | j d    | j |  j d  | S(   Ni    s
   client.comi  i   R   s   SIP/2.0/UDP client.com:5060R,   s   sip:joe@bell.example.comR   s   sip:joe@client.com:5060R   i  i  i  i  i   R+   R|   RV   s   bell.example.comc         S   s   |  j  |  j f S(   N(   RV   RW   (   t   desturl(    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_sip.pyR   "  s    (   s
   client.comi  (   i  i  i  i  (   s
   client.comi  (   R   R   R   RV   RW   RA   R#   t
   failUnlesst   intR0   R   R   R"   R   R   R   R   R   t   addCallback(   R   R   R&   t   dcR!   R   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_sip.pyt   testRegister  s"    
c         C   s   |  j    |  j   |  j d \ } } |  j | j | j f d  |  j | j d  |  j | j d d g  |  j | j d d g  |  j | j d	 d
 g  |  j | j d d g  |  j |  j j	 i   d  S(   Ni   s
   client.comi  i   R   s   SIP/2.0/UDP client.com:5060R,   s   sip:joe@bell.example.comR   s   sip:joe@client.com:5060R   R7   (   s
   client.comi  (
   R   R   R   R   RV   RW   RA   R#   R   R   (   R   R   R&   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_sip.pyt   testUnregister&  s    

c         C   sW   t    } t j j |  } t j j   } | j d d  | j |  | |  j _ d  S(   Ns   userXname@127.0.0.1t	   passXword(	   R
   R   t   portalt   Portalt   checkerst'   InMemoryUsernamePasswordDatabaseDontUset   addUsert   registerCheckerR   (   R   RJ   t   pRE   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_sip.pyt	   addPortal3  s    	c         C   ss   |  j    |  j   |  j t |  j j  d  |  j t |  j  d  |  j d \ } } |  j | j d  d  S(   Ni    i   i  (   R   R   R   R0   R   R   R   RA   (   R   R   R&   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_sip.pyt   testFailedAuthentication;  s    

c         C   s|  |  j    |  j j j   |  j _ t j   |  j j d <|  j d |  j g  } |  j t	 |  d  |  j | d d d  |  j | d d t
  t j d d	  } | j d
 d  | j d d  | j d t j d  j    | j d d d j d   |  j j | j   d  |  j t	 |  j j  d  |  j t	 |  j  d  |  j d \ } } |  j | j d  d S(   sK   
        Test that registration with basic authentication suceeds.
        t   basicRj   i   i    R   sE   twisted.protocols.sip.BasicAuthorizer was deprecated in Twisted 9.0.0Rk   R   s   sip:bell.example.comR,   s   sip:joe@bell.example.comR   s   sip:joe@client.com:1234R   s
   client.comt   authorizations   Basic s   userXname:passXwordt   base64i  i   N(   s
   client.comi  (   R   R   t   authorizerst   copyR   t   BasicAuthorizerRl   t   test_basicAuthenticationRn   R0   Ro   RH   RI   Rh   R"   t   encodeR   R   R   R   R   RA   (   R   Rp   RJ   R   R&   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_sip.pyR   E  s.    
		c         C   s|  |  j    |  j j j   |  j _ t j   |  j j d <|  j d |  j g  } |  j t	 |  d  |  j | d d d  |  j | d d t
  t j d d	  } | j d
 d  | j d d  | j d t j d  j    | j d d d j d   |  j j | j   d  |  j t	 |  j j  d  |  j t	 |  j  d  |  j d \ } } |  j | j d  d S(   sr   
        Failed registration with basic authentication results in an
        unauthorized error response.
        R   Rj   i   i    R   sE   twisted.protocols.sip.BasicAuthorizer was deprecated in Twisted 9.0.0Rk   R   s   sip:bell.example.comR,   s   sip:joe@bell.example.comR   s   sip:joe@client.com:1234R   s
   client.comR   s   Basic s   userXname:passwordR   i  i  N(   s
   client.comi  (   R   R   R   R   R   R   Rl   t   test_failedBasicAuthenticationRn   R0   Ro   RH   RI   Rh   R"   R   R   R   R   R   R   RA   (   R   Rp   RJ   R   R&   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_sip.pyR   d  s.    
	c         C   s   t  j d d  } | j d d  | j d d  | j d t  j d  j    |  j j | j   d  |  j t |  j	  d
  d  S(   NR   s   sip:wrong.comR,   s   sip:joe@bell.example.comR   s   sip:joe@client.com:1234R   s
   client.comi  i    (   s
   client.comi  (
   R   RH   RI   Rh   R"   R   R   R   R0   R   (   R   RJ   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_sip.pyt   testWrongDomainRegister  s    c         C   s   t  j d d  } | j d d  | j d d  | j d t  j d  j    |  j j | j   d  |  j t |  j	  d
  d  S(   NR   s   sip:bell.example.comR,   s   sip:joe@foo.comR   s   sip:joe@client.com:1234R   s
   client.comi  i    (   s
   client.comi  (
   R   RH   RI   Rh   R"   R   R   R   R0   R   (   R   RJ   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_sip.pyt   testWrongToDomainRegister  s    c         C   sK   |  j    t j d d d d  } |  j j j |  } |  j | t  | S(   NR|   R+   RV   s   foo.com(   R   R   R   R   R   R   t   assertFailureR   (   R   Rz   R   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_sip.pyt   testWrongDomainLookup  s
    
c         C   sK   |  j    t j d d d d  } |  j j j |  } |  j | t  | S(   NR|   t   janeRV   s   bell.example.com(   R   R   R   R   R   R   R   R   (   R   Rz   R   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_sip.pyt   testNoContactLookup  s
    
(   R   R   R   R   t   suppressWarningsR   t   suppressRo   R   R   R   R   R   R   R   R   R   R   R   R   R   (    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_sip.pyR     s"   									
		 			t   Clientc           B   s   e  Z d    Z d   Z RS(   c         C   s,   t  j j |   g  |  _ t j   |  _ d  S(   N(   R   t   Baset   __init__Rs   R   t   Deferredt   deferred(   R   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_sip.pyR     s    	c         C   s'   |  j  j |  |  j j |  j   d  S(   N(   Rs   R   R   t   callback(   R   t   responseR   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_sip.pyt   handle_response  s    (   R   R   R   R   (    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_sip.pyR     s   	t   LiveTestc           B   sP   e  Z d    Z e j e e j d e d d   Z d   Z d   Z	 d   Z
 RS(   c         C   s   t  j d d  |  _ t  j d  |  _ |  j |  j _ |  j _ t j d |  j d d |  _ t	   |  _
 t j d |  j
 d d |  _ |  j j   j |  j j   j f |  _ d  S(   NRV   s	   127.0.0.1s   bell.example.comi    t	   interface(   R   R   R   R   R   R   R   t	   listenUDPt
   serverPortR   t   clientt
   clientPortt   getHostRV   RW   t   serverAddress(   R   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_sip.pyR     s    Rk   R   s5   twisted.protocols.sip.DigestAuthorizer was deprecatedc         C   sj   x* |  j  j j   D] \ } } | j   q Wt j |  j j  } t j |  j j  } t j	 | | g  S(   N(
   R   R   R   R   R   t   maybeDeferredR   t   stopListeningR   t   gatherResults(   R   R   R!   t   d1t   d2(    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_sip.pyR     s
    c            s     j  j   j } t j d d  } | j d d  | j d d |  | j d t j d d	 | j      j j	 t j
 d
 d d	   j d  |    j j }   f d   } | j |  | S(   NR   s   sip:bell.example.comR,   s   sip:joe@bell.example.comR   s   sip:joe@127.0.0.1:%dR   s	   127.0.0.1RW   RV   i   c            s7     j  t |   d  |  d }   j  | j d  d  S(   Ni   i    i   (   R   R0   RA   (   Rs   RJ   (   R   (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_sip.pyt   check  s    
(   R   R   RW   R   RH   RI   Rh   R"   R   R   R   R   R   R   (   R   R   RJ   R   R   (    (   R   s9   /usr/lib/python2.7/dist-packages/twisted/test/test_sip.pyR     s    %	#c            s)    j  j   j } t j d d  } | j d d  | j d d |  | j d t j d d	 | d
 t j      j	 d   j
 g  }   j t |  d    j | d d d    j | d d t    j j t j d d d	   j d  |    j j }   f d   } | j |  | S(   sp  
        rport is allowed without a value, apparently because server
        implementors might be too stupid to check the received port
        against 5060 and see if they're equal, and because client
        implementors might be too stupid to bind to port 5060, or set a
        value on the rport parameter they send if they bind to another
        port.
        R   s   sip:bell.example.comR,   s   sip:joe@bell.example.comR   s   sip:joe@127.0.0.1:%dR   s	   127.0.0.1RW   R]   Rj   i   i    R   s+   rport=True is deprecated since Twisted 9.0.Rk   RV   c            s7     j  t |   d  |  d }   j  | j d  d  S(   Ni   i    i   (   R   R0   RA   (   Rs   RJ   (   R   (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_sip.pyR     s    
(   R   R   RW   R   RH   RI   Rh   Rf   R"   Rl   t   test_amoralRPortRn   R0   Ro   R   R   R   R   R   R   (   R   R   RJ   Rp   R   R   (    (   R   s9   /usr/lib/python2.7/dist-packages/twisted/test/test_sip.pyR     s*    	+	(   R   R   R   R   R   R   R   Ro   R   R   R   (    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_sip.pyR     s   				sY  
REGISTER sip:intarweb.us SIP/2.0
Via: SIP/2.0/UDP 192.168.1.100:50609
From: <sip:exarkun@intarweb.us:50609>
To: <sip:exarkun@intarweb.us:50609>
Contact: "exarkun" <sip:exarkun@192.168.1.100:50609>
Call-ID: 94E7E5DAF39111D791C6000393764646@intarweb.us
CSeq: 9898 REGISTER
Expires: 500
User-Agent: X-Lite build 1061
Content-Length: 0

s  SIP/2.0 401 Unauthorized
Via: SIP/2.0/UDP 192.168.1.100:50609;received=127.0.0.1;rport=5632
To: <sip:exarkun@intarweb.us:50609>
From: <sip:exarkun@intarweb.us:50609>
Call-ID: 94E7E5DAF39111D791C6000393764646@intarweb.us
CSeq: 9898 REGISTER
WWW-Authenticate: Digest nonce="92956076410767313901322208775",opaque="1674186428",qop-options="auth",algorithm="MD5",realm="intarweb.us"

s   REGISTER sip:intarweb.us SIP/2.0
Via: SIP/2.0/UDP 192.168.1.100:50609
From: <sip:exarkun@intarweb.us:50609>
To: <sip:exarkun@intarweb.us:50609>
Contact: "exarkun" <sip:exarkun@192.168.1.100:50609>
Call-ID: 94E7E5DAF39111D791C6000393764646@intarweb.us
CSeq: 9899 REGISTER
Expires: 500
Authorization: Digest username="exarkun",realm="intarweb.us",nonce="92956076410767313901322208775",response="4a47980eea31694f997369214292374b",uri="sip:intarweb.us",algorithm=MD5,opaque="1674186428"
User-Agent: X-Lite build 1061
Content-Length: 0

s5  SIP/2.0 200 OK
Via: SIP/2.0/UDP 192.168.1.100:50609;received=127.0.0.1;rport=5632
To: <sip:exarkun@intarweb.us:50609>
From: <sip:exarkun@intarweb.us:50609>
Call-ID: 94E7E5DAF39111D791C6000393764646@intarweb.us
CSeq: 9899 REGISTER
Contact: sip:exarkun@127.0.0.1:5632
Expires: 3600
Content-Length: 0

t   FakeDigestAuthorizerc           B   s   e  Z d    Z d   Z RS(   c         C   s   d S(   Nt   92956076410767313901322208775(    (   R   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_sip.pyt   generateNonce1  s    c         C   s   d S(   Nt
   1674186428(    (   R   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_sip.pyt   generateOpaque3  s    (   R   R   R  R  (    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_sip.pyR   0  s   	t   FakeRegistryc           B   s)   e  Z d  Z d   Z d   Z d   Z RS(   si   Make sure expiration is always seen to be 3600.

    Otherwise slow reactors fail tests incorrectly.
    c         C   sA   d | j  k  s | j  d k  r4 t d | j    n  d | _  | S(   Ni  i  s   bad seconds to expire: %s(   t   secondsToExpiryt   RuntimeError(   R   t   reg(    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_sip.pyt   _cbReg=  s
    	c         C   s%   t  j j |  |  } | j |  j  S(   N(   R   R   t   getRegistrationInfoR   R  (   R   R!   R   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_sip.pyR	  D  s    c         C   s+   t  j j |  | | |  } | j |  j  S(   N(   R   R   t   registerAddressR   R  (   R   t	   domainURLR   t   physicalURLR   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_sip.pyR
  H  s    	(   R   R   RF   R  R	  R
  (    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_sip.pyR  7  s   		t   AuthorizationTestCasec           B   s   e  Z d    Z e j e e j d e d d   Z d   Z d   Z	 e j d e d d  e j d e d d  e j d e d d  e j d e d d  g e	 _ RS(	   c         C   s   t  j d d  |  _ |  j j j   |  j _ t   |  j j d <t d  |  _ |  j |  j _ |  j _ t	 j
   |  _ |  j |  j _ t   } t j j |  } t j j   } | j d d  | j |  | |  j _ d  S(   NRV   s   intarweb.ust   digests   exarkun@intarweb.usR~   (   R   R   R   R   R   R   R  R   R   R   t   FakeDatagramTransportRU   R
   R   R   R   R   R   R   R   (   R   RJ   R   RE   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_sip.pyR   N  s    	Rk   R   s5   twisted.protocols.sip.DigestAuthorizer was deprecatedc         C   s7   x* |  j  j j   D] \ } } | j   q W|  ` d  S(   N(   R   R   R   R   R   (   R   R   R!   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_sip.pyR   b  s    c         C   sv   |  j  j t d  |  j |  j j d t d f  g  |  j _ |  j  j t d  |  j |  j j d t d f  d  S(   Ns	   127.0.0.1i   i(   s	   127.0.0.1i   (   s	   127.0.0.1i   (   s	   127.0.0.1i   (   s	   127.0.0.1i   (	   R   R   t   registerRequestR   RU   t   writtent   challengeResponset   authRequestt
   okResponse(   R   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_sip.pyt   testChallengeg  s    s8   twisted.protocols.sip.DigestedCredentials was deprecateds2   twisted.protocols.sip.DigestCalcHA1 was deprecateds7   twisted.protocols.sip.DigestCalcResponse was deprecated(
   R   R   R   R   R   R   R   Ro   R   R  (    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_sip.pyR  M  s$   								t   DeprecationTestsc           B   s;   e  Z d  Z d   Z d   Z d   Z d   Z d   Z RS(   sS   
    Tests for deprecation of obsolete components of L{twisted.protocols.sip}.
    c      	   C   s8   |  j  t d d d d  t j d d d d d d  d S(   s5   
        L{sip.DigestCalcHA1} is deprecated.
        t   Twistedi	   i    R8   N(   t   callDeprecatedR   R   t   DigestCalcHA1(   R   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_sip.pyt   test_deprecatedDigestCalcHA1  s    c         C   s>   |  j  t d d d d  t j d d d d d d d d 
 d S(   s:   
        L{sip.DigestCalcResponse} is deprecated.
        R  i	   i    R8   N(   R  R   R   t   DigestCalcResponse(   R   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_sip.pyt!   test_deprecatedDigestCalcResponse  s    c         C   s&   |  j  t d d d d  t j  d S(   s7   
        L{sip.BasicAuthorizer} is deprecated.
        R  i	   i    N(   R  R   R   R   (   R   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_sip.pyt   test_deprecatedBasicAuthorizer  s    c         C   s&   |  j  t d d d d  t j  d S(   s8   
        L{sip.DigestAuthorizer} is deprecated.
        R  i	   i    N(   R  R   R   t   DigestAuthorizer(   R   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_sip.pyt   test_deprecatedDigestAuthorizer  s    c         C   s/   |  j  t d d d d  t j d i  i   d S(   s;   
        L{sip.DigestedCredentials} is deprecated.
        R  i	   i    R8   N(   R  R   R   t   DigestedCredentials(   R   (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_sip.pyt"   test_deprecatedDigestedCredentials  s    (   R   R   RF   R  R  R  R  R!  (    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_sip.pyR    s   				(    (    (    (5   RF   t   twisted.trialR    R   t   twisted.protocolsR   t   twisted.internetR   R   R   t   twisted.python.versionsR   t   twisted.testR   t   twistedR   t   twisted.cred.portalt   twisted.cred.checkerst   zope.interfaceR	   t   replaceR/   R3   R5   R;   R@   R=   t   request_nattedR
   t   TestCaseR   RD   RG   RP   Rx   R   R   R   R   R   R   R   R   R  R  R  R  R  R   R   R  R  R  (    (    (    s9   /usr/lib/python2.7/dist-packages/twisted/test/test_sip.pyt   <module>   sL   
	X	jX9