
    Vh                         d 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 ddlmZ dd	lmZ dd
lmZmZmZ  G d de      Z G d de      Z G d de      Zy)z!
Tests for L{twisted.web.vhost}.
    )gatherResults)TestCase)	NOT_FOUND)
NoResource)Site)Data)_render)DummyRequest)NameVirtualHostVHostMonsterResource_HostResourcec                       e Zd ZdZd Zy)HostResourceTestsz%
    Tests for L{_HostResource}.
    c                 &   t        dd      }t        dd      }t        dd      }|j                  d|       |j                  d|       t               }t               }t        dd      |_        |j                  d|       t        ddg      }g d	|_        t        |      |_	        d
 |_
        d|_        |j                  d|      }| j                  |t                t        ddg      }|j                  d|      }| j                  |t               y)z
        L{_HostResource.getChild} returns the proper I{Resource} for the vhost
        embedded in the URL.  Verify that returning the proper I{Resource}
        required changing the I{Host} in the header.
        s	   root data s   uri datas	   test datas   tests   uris   default data   baz.com)s   bar   httpr   c                       y)NF r       K/home/dcms/DCMS/lib/python3.12/site-packages/twisted/web/test/test_vhost.py<lambda>z1HostResourceTests.test_getChild.<locals>.<lambda>-   s    r   r   N)r   putChildr   r   defaultaddHostr
   prepathr   siteisSecurehostgetChildassertIsInstancer   )selfbazrootbazuribaztesthrrootrequeststeps           r   test_getChildzHostResourceTests.test_getChild   s     |R(k2&|R()(_ OR0Z)017Dz({{:w/dD)01}}VW-dJ/r   N__name__
__module____qualname____doc__r*   r   r   r   r   r      s    0r   r   c                   :    e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
y	)
NameVirtualHostTestsz'
    Tests for L{NameVirtualHost}.
    c                     t               }t        dd      |_        t        dg      }| j	                  |j                  |      d       y)z
        L{NameVirtualHost.render} returns the result of rendering the
        instance's C{default} if it is not L{None} and there is no I{Host}
        header in the request.
        s   correct resultr   r   N)r   r   r   r
   assertEqualrenderr"   virtualHostResourcer(   s      r   test_renderWithoutHostz+NameVirtualHostTests.test_renderWithoutHost=   sG     ./&*+<b&A#u%,33G<>OPr   c                 |     t               }t        dg      t        |      } fd}|j                  |       |S )z
        L{NameVirtualHost.render} returns a response with a status of I{NOT
        FOUND} if the instance's C{default} is L{None} and there is no I{Host}
        header in the request.
        r   c                 F    j                  j                  t               y Nr3   responseCoder   ignoredr(   r"   s    r   
cbRenderedzHNameVirtualHostTests.test_renderWithoutHostNoDefault.<locals>.cbRenderedR       W119=r   )r   r
   r	   addCallbackr"   r6   dr?   r(   s   `   @r   test_renderWithoutHostNoDefaultz4NameVirtualHostTests.test_renderWithoutHostNoDefaultH   s?     ./u%'1	> 	
j!r   c                     t               }|j                  dt        dd             t        dg      }|j                  j                  dd       t        ||      } fd}|j                  ||       t        dg      }|j                  j                  dd       t        ||      } fd}|j                  ||       t        ||g      S )	z
        L{NameVirtualHost.render} returns the result of rendering the resource
        which is the value in the instance's C{host} dictionary corresponding
        to the key indicated by the value of the I{Host} header in the request.
        s   example.org   winnerr   r      hostc                 \    j                  dj                  |j                        d       y Nr   rF   r3   joinwrittenr=   s     r   r?   z<NameVirtualHostTests.test_renderWithHost.<locals>.cbRenderede   s     SXXgoo6	Br   s   example.org:8000c                 \    j                  dj                  |j                        d       y rI   rJ   )r>   requestWithPortr"   s     r   r?   z<NameVirtualHostTests.test_renderWithHost.<locals>.cbRenderedo   s"    SXXo&=&=>	Jr   )	r   r   r   r
   requestHeadersaddRawHeaderr	   rA   r   )r"   r6   r(   rC   r?   rN   	dWithPorts   `      r   test_renderWithHostz(NameVirtualHostTests.test_renderWithHostX   s     ./##NDB4GHu%++G^D'1	C 	
j'* 'u-&&33G=PQ/A		K 	j/:a^,,r   c                      t               }t        dd      |_        t        dg      j                  j                  dd       t        |      } fd}|j                  |       |S )z
        L{NameVirtualHost.render} returns the result of rendering the
        instance's C{default} if it is not L{None} and there is no host
        matching the value of the I{Host} header in the request.
           correct datar   r   rG      example.comc                 \    j                  dj                  j                        d       y )Nr   rT   rJ   r=   s    r   r?   zCNameVirtualHostTests.test_renderWithUnknownHost.<locals>.cbRendered   s     SXXgoo6Hr   )r   r   r   r
   rO   rP   r	   rA   rB   s   `   @r   test_renderWithUnknownHostz/NameVirtualHostTests.test_renderWithUnknownHostv   sf     ./&*?B&?#u%++G^D'1	I 	
j!r   c                      t               }t        dg      j                  j                  dd       t	        |      } fd}|j                  |       |S )z
        L{NameVirtualHost.render} returns a response with a status of I{NOT
        FOUND} if the instance's C{default} is L{None} and there is no host
        matching the value of the I{Host} header in the request.
        r   rG   rU   c                 F    j                  j                  t               y r:   r;   r=   s    r   r?   zLNameVirtualHostTests.test_renderWithUnknownHostNoDefault.<locals>.cbRendered   r@   r   )r   r
   rO   rP   r	   rA   rB   s   `   @r   #test_renderWithUnknownHostNoDefaultz8NameVirtualHostTests.test_renderWithUnknownHostNoDefault   sU     ./u%++G^D'1	> 	
j!r   c                    K   t               }t        dg      }|j                  j                  dd       t	        ||       d{    | j                  ddj                  |j                               y7 0w)zs
        L{NameVirtualHost.render} doesn't echo unescaped HTML when present in
        the I{Host} header.
        r   rG   s   <b>example</b>.comNs   <b>)r   r
   rO   rP   r	   assertNotInrK   rL   r5   s      r   test_renderWithHTMLHostz,NameVirtualHostTests.test_renderWithHTMLHost   sg     
 ./u%++G5JK)7333'//!:; 	4s   AA7A51A7c                    t               }t        dd      }d|_        t        dd      }|j                  d|       |j                  d|       t	        g       }|j
                  j                  dd       dg|_        | j                  |j                  d|      t               | j                  |j                  dg       | j                  |j                  g        t	        g       }|j
                  j                  dd       dg|_        | j                  |j                  d|      t               | j                  |j                  g        | j                  |j                  dg       y	)
z
        L{NameVirtualHost.getChild} returns correct I{Resource} based off
        the header and modifies I{Request} to ensure proper prepath and
        postpath are set.
        s	   leaf datar   Ts	   norm datas   leaf.example.orgs   norm.example.orgrG   r   N)r   r   isLeafr   r
   rO   rP   r   r!   r    r   r3   postpath)r"   r6   leafResourcenormResourcer(   s        r   r*   z"NameVirtualHostTests.test_getChild   s7    ./L"-"L"-##$7F##$7Fr"++G5HI%1::3H*U3%0))2.r"++G5HI%1::3H$O"-))C51r   N)r,   r-   r.   r/   r7   rD   rR   rW   rZ   r]   r*   r   r   r   r1   r1   8   s+    	Q -<$"<2r   r1   c                       e Zd ZdZd Zy)VHostMonsterResourceTestsz,
    Tests for L{VHostMonsterResource}.
    c                 X   t               }t        g       }| j                  |j                  d|      t               | j                  |j                                t        g       }| j                  |j                  d|      t               | j                  |j                                y)z
        L{VHostMonsterResource.getChild} returns I{_HostResource} and modifies
        I{Request} with correct L{Request.isSecure}.
        r   s   httpsN)r   r
   r!   r    r   assertFalser   
assertTrue)r"   vhmr(   s      r   r*   z'VHostMonsterResourceTests.test_getChild   s    
 #$r"cll7G<mL))+,r"cll8W=}M((*+r   Nr+   r   r   r   rd   rd      s    ,r   rd   N)r/   twisted.internet.deferr   twisted.trial.unittestr   twisted.web.httpr   twisted.web.resourcer   twisted.web.serverr   twisted.web.staticr   twisted.web.test._utilr	   twisted.web.test.test_webr
   twisted.web.vhostr   r   r   r   r1   rd   r   r   r   <module>rr      sR   
 1 + & + # # * 2 R R!0 !0HI28 I2X, ,r   