HEX
Server: Apache
System: Linux scp1.abinfocom.com 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64
User: confeduphaar (1010)
PHP: 8.1.33
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //lib/python3/dist-packages/twisted/web/test/__pycache__/test_vhost.cpython-38.pyc
U

s�@g��@s�dZddlmZmZddlmZddlmZddlm	Z	ddl
mZddlm
Z
ddlmZdd	lmZmZmZdd
lmZddlmZGdd
�d
e�ZGdd�de�ZGdd�de�ZdS)z!
Tests for L{twisted.web.vhost}.
�)�absolute_import�division)�
gatherResults)�TestCase)�	NOT_FOUND)�
NoResource)�Data)�Site)�
_HostResource�NameVirtualHost�VHostMonsterResource)�DummyRequest)�_renderc@seZdZdZdd�ZdS)�HostResourceTestsz%
    Tests for L{_HostResource}.
    cCs�tdd�}tdd�}tdd�}|�d|�|�d|�t�}t�}tdd�|_|�d|�tddg�}d	d
dg|_t|�|_	dd�|_
d
|_|�d|�}|�
|t�tddg�}|�d|�}|�
|t�dS)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�suri datas	test datastestsurisdefault datasbaz.comsbar�httpcSsdS)NF�rrr�=/usr/lib/python3/dist-packages/twisted/web/test/test_vhost.py�<lambda>/�z1HostResourceTests.test_getChild.<locals>.<lambda>rN)rZputChildr
r�default�addHostr
�prepathr	Zsite�isSecureZhost�getChild�assertIsInstancer)�selfZbazrootZbazuriZbaztestZhr�root�request�steprrr�
test_getChilds&




zHostResourceTests.test_getChildN��__name__�
__module__�__qualname__�__doc__r rrrrrsrc@sHeZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dS)�NameVirtualHostTestsz'
    Tests for L{NameVirtualHost}.
    cCs2t�}tdd�|_tdg�}|�|�|�d�dS)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.
        scorrect resultrN)rrrr
�assertEqualZrender)r�virtualHostResourcerrrr�test_renderWithoutHost?s
�z+NameVirtualHostTests.test_renderWithoutHostcs6t�}tdg��t|��}��fdd�}|�|�|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.
        rcs���jt�dS�N�r'ZresponseCoder��ignored�rrrr�
cbRenderedUszHNameVirtualHostTests.test_renderWithoutHostNoDefault.<locals>.cbRendered)rr
r�addCallback�rr(�dr/rr.r�test_renderWithoutHostNoDefaultLs


z4NameVirtualHostTests.test_renderWithoutHostNoDefaultcs�t�}|�dtdd��tdg�}|j�dd�t||�}�fdd�}|�||�tdg�}|j�dd�t||�}�fd	d�}|�||�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.
        sexample.org�winnerrr�hostcs��d�|j�d�dS�Nrr4�r'�join�written)r-r�rrrr/gsz<NameVirtualHostTests.test_renderWithHost.<locals>.cbRenderedsexample.org:8000cs��d�|j�d�dSr6r7)r-�requestWithPortr:rrr/os)	rrrr
�requestHeaders�addRawHeaderrr0r)rr(rr2r/r;Z	dWithPortrr:r�test_renderWithHost[s



z(NameVirtualHostTests.test_renderWithHostcsPt�}tdd�|_tdg���j�dd�t|��}��fdd�}|�|�|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 datarrr5�example.comcs��d��j�d�dS)Nrr?r7r,r.rrr/�szCNameVirtualHostTests.test_renderWithUnknownHost.<locals>.cbRendered)rrrr
r<r=rr0r1rr.r�test_renderWithUnknownHostvs


z/NameVirtualHostTests.test_renderWithUnknownHostcsDt�}tdg���j�dd�t|��}��fdd�}|�|�|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.
        rr5r@cs���jt�dSr*r+r,r.rrr/�szLNameVirtualHostTests.test_renderWithUnknownHostNoDefault.<locals>.cbRendered�rr
r<r=rr0r1rr.r�#test_renderWithUnknownHostNoDefault�s


z8NameVirtualHostTests.test_renderWithUnknownHostNoDefaultcsDt�}tdg���j�dd�t|��}��fdd�}|�|�|S)zs
        L{NameVirtualHost.render} doesn't echo unescaped HTML when present in
        the I{Host} header.
        rr5s<b>example</b>.comcs��d�j�dS)Nz<b>)ZassertNotInr9r,r.rrr/�sz@NameVirtualHostTests.test_renderWithHTMLHost.<locals>.cbRenderedrBr1rr.r�test_renderWithHTMLHost�s


z,NameVirtualHostTests.test_renderWithHTMLHostcCs�t�}tdd�}d|_tdd�}|�d|�|�d|�tg�}|j�dd�dg|_|�|�	d|�t
�|�|jdg�|�|jg�tg�}|j�dd�dg|_|�|�	d|�t�|�|jg�|�|jdg�d	S)
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 datarTs	norm datasleaf.example.orgsnorm.example.orgr5rN)
rrZisLeafrr
r<r=rrrrr'Zpostpath)rr(ZleafResourceZnormResourcerrrrr �s,

��z"NameVirtualHostTests.test_getChildN)r"r#r$r%r)r3r>rArCrDr rrrrr&;s
r&c@seZdZdZdd�ZdS)�VHostMonsterResourceTestsz,
    Tests for L{VHostMonsterResource}.
    cCs^t�}tg�}|�|�d|�t�|�|���tg�}|�|�d|�t�|�|���dS)z�
        L{VHostMonsterResource.getChild} returns I{_HostResource} and modifies
        I{Request} with correct L{Request.isSecure}.
        rshttpsN)rr
rrr
ZassertFalserZ
assertTrue)rZvhmrrrrr �sz'VHostMonsterResourceTests.test_getChildNr!rrrrrE�srEN)r%Z
__future__rrZtwisted.internet.deferrZtwisted.trial.unittestrZtwisted.web.httprZtwisted.web.resourcerZtwisted.web.staticrZtwisted.web.serverr	Ztwisted.web.vhostr
rrZtwisted.web.test.test_webr
Ztwisted.web.test._utilrrr&rErrrr�<module>s$