AnonSec Shell
Server IP : 209.38.156.173  /  Your IP : 216.73.216.122   [ Reverse IP ]
Web Server : Apache/2.4.52 (Ubuntu)
System : Linux lakekumayuhotel 5.15.0-136-generic #147-Ubuntu SMP Sat Mar 15 15:53:30 UTC 2025 x86_64
User : root ( 0)
PHP Version : 8.1.2-1ubuntu2.22
Disable Function : NONE
Domains : 2 Domains
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : ON
Directory :  /usr/lib/python3/dist-packages/twisted/web/test/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ HOME ]     [ BACKUP SHELL ]     [ JUMPING ]     [ MASS DEFACE ]     [ SCAN ROOT ]     [ SYMLINK ]     

Current File : /usr/lib/python3/dist-packages/twisted/web/test/__pycache__/test_proxy.cpython-310.pyc
o

�bNN�@s�dZddlmZmZddlmZddlmZmZm	Z	m
Z
mZddlm
Z
ddlmZddlmZGdd	�d	e�ZGd
d�d�ZGdd
�d
e�ZGdd�de�ZGdd�de�ZGdd�d�ZGdd�de�ZdS)z 
Test for L{twisted.web.proxy}.
�)�
MemoryReactor� StringTransportWithDisconnection)�TestCase)�ProxyClient�ProxyClientFactory�ProxyRequest�ReverseProxyRequest�ReverseProxyResource)�Resource)�Site��DummyRequestc@s@eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dS)�ReverseProxyResourceTestsz,
    Tests for L{ReverseProxyResource}.
    cCs�t�}t�}tddd|�}|�d|�t|�}t�}|�d�}|�|�|�|j	d�|�
d|d�|j\\}	}
}}}
|�|	d�|�|
d�|�
|t�|�|j|�|�|jdd	�dS)
z�
        Check that a request pointing at C{uri} produce a new proxy connection,
        with the path of this request pointing at C{expectedURI}.
        �	127.0.0.1���/pathsindexNsGET s  HTTP/1.1
Accept: text/html

�hosts127.0.0.1:1234)r
rr	�putChildrr�
buildProtocol�makeConnection�
addCleanup�connectionLost�dataReceived�
tcpClients�assertEqual�assertIsInstancer�rest�headers)�self�uri�expectedURI�root�reactor�resource�site�	transport�channel�host�port�factory�_timeout�
_bind_addr�r,�=/usr/lib/python3/dist-packages/twisted/web/test/test_proxy.py�_testRenders 

z%ReverseProxyResourceTests._testRendercC�|�dd�S)z�
        Test that L{ReverseProxyResource.render} initiates a connection to the
        given server with a L{ProxyClientFactory} as parameter.
        s/indexr�r.�rr,r,r-�test_render8�z%ReverseProxyResourceTests.test_rendercCr/)z�
        Test that L{ReverseProxyResource.render} will instantiate a child
        resource that will initiate a connection to the given server
        requesting the apropiate url subpath.
        s/index/page1s/path/page1r0r1r,r,r-�test_render_subpage?�z-ReverseProxyResourceTests.test_render_subpagecCr/)zr
        Test that L{ReverseProxyResource.render} passes query parameters to the
        created factory.
        s/index?foo=bars
/path?foo=barr0r1r,r,r-�test_renderWithQueryGr3z.ReverseProxyResourceTests.test_renderWithQuerycCsjt�}tddd|�}|�dd�}|�|t�|�|jd�|�|jd�|�|jd�|�|j	|j	�dS)a
        The L{ReverseProxyResource.getChild} method should return a resource
        instance with the same class as the originating resource, forward
        port, host, and reactor values, and update the path value with the
        value passed.
        rrr�fooNs	/path/foo)
rr	�getChildrr�pathr(r'�assertIdenticalr")rr"r#�childr,r,r-�
test_getChildNsz'ReverseProxyResourceTests.test_getChildcCs*tddd�}|�dd�}|�|jd�dS)zu
        The L{ReverseProxyResource} return by C{getChild} has a path which has
        already been quoted.
        rrrs /%Ns/path/%20%2F%25)r	r8rr9)rr#r;r,r,r-�test_getChildWithSpecial_sz2ReverseProxyResourceTests.test_getChildWithSpecialN)
�__name__�
__module__�__qualname__�__doc__r.r2r4r6r<r=r,r,r,r-rsrc@s0eZdZdZdd�Zdd�Zdd�Zdd	�Zd
S)�DummyChannelz�
    A dummy HTTP channel, that does nothing but holds a transport and saves
    connection lost.

    @ivar transport: the transport used by the client.
    @ivar lostReason: the reason saved at connection lost.
    cCs||_d|_dS)z4
        Hold a reference to the transport.
        N)r%�
lostReason)rr%r,r,r-�__init__rs
zDummyChannel.__init__cCs
||_dS)z;
        Keep track of the connection lost reason.
        N)rC)r�reasonr,r,r-ry�
zDummyChannel.connectionLostcC�
|j��S)z:
        Get peer information from the transport.
        )r%�getPeerr1r,r,r-rHrFzDummyChannel.getPeercCrG)z:
        Get host information from the transport.
        )r%�getHostr1r,r,r-rI�rFzDummyChannel.getHostN)r>r?r@rArDrrHrIr,r,r,r-rBisrBc@s�eZdZdZdd�Zdd�Zd&d	d
�Zdd�Zd
d�Zdd�Z	dd�Z
			d'dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zd d!�Zd"d#�Zd$d%�ZdS)(�ProxyClientTestsz#
    Tests for L{ProxyClient}.
    cCs:|�d�\}}|�d�}|�d�}|tdd�|D��|fS)aC
        Parse the headers out of some web content.

        @param content: Bytes received from a web server.
        @return: A tuple of (requestLine, headers, body). C{headers} is a dict
            of headers, C{requestLine} is the first line (e.g. "POST /foo ...")
            and C{body} is whatever is left.
        s

�
rcss�|]}|�d�VqdS)�: N)�split)�.0�headerr,r,r-�	<genexpr>�s�z4ProxyClientTests._parseOutHeaders.<locals>.<genexpr>)rM�pop�dict)r�contentr�body�requestLiner,r,r-�_parseOutHeaders�s	

z!ProxyClientTests._parseOutHeaderscCst|�S)z�
        Make a dummy request object for the URL path.

        @param path: A URL path, beginning with a slash.
        @return: A L{DummyRequest}.
        r)rr9r,r,r-�makeRequest�szProxyClientTests.makeRequest�GETN�cCs,|durddi}d|j}t||d|||�S)a�
        Make a L{ProxyClient} object used for testing.

        @param request: The request to use.
        @param method: The HTTP method to use, GET by default.
        @param headers: The HTTP headers to use expressed as a dict. If not
            provided, defaults to {'accept': 'text/html'}.
        @param requestBody: The body of the request. Defaults to the empty
            string.
        @return: A L{ProxyClient}
        N�accept�	text/html�/�HTTP/1.0)�postpathr)r�request�methodr�requestBodyr9r,r,r-�makeProxyClient�s
z ProxyClientTests.makeProxyClientcCst�}||_|�|�|S)z�
        Connect a proxy client to a L{StringTransportWithDisconnection}.

        @param proxyClient: A L{ProxyClient}.
        @return: The L{StringTransportWithDisconnection}.
        )r�protocolr)r�proxyClient�clientTransportr,r,r-�connectProxy�s
zProxyClientTests.connectProxycCs@|�|�|j��}|�|�\}}}|�||�|�||�|S)a`
        Assert that C{proxyClient} sends C{headers} when it connects.

        @param proxyClient: A L{ProxyClient}.
        @param requestLine: The request line we expect to be sent.
        @param headers: A dict of headers we expect to be sent.
        @return: If the assertion is successful, return the request body as
            bytes.
        )rfr%�valuerVr)rrdrUr�requestContent�receivedLine�receivedHeadersrTr,r,r-�assertForwardsHeaders�s


z&ProxyClientTests.assertForwardsHeadersc	Cs^dt|��d�d|g}|D]\}}|D]}|�|d|�qq|�d|g�d�|�S)Ns	HTTP/1.0 �ascii� rLrYrK)�str�encode�append�extend�join)	r�code�messagerrT�linesrO�valuesrgr,r,r-�makeResponseBytes�s�
z"ProxyClientTests.makeResponseBytescCsj|�|j|�|�|j|�t|j���}|��|dd�}|��|�||�|�d�|j�|�dS)aK
        Assert that C{request} has forwarded a response from the server.

        @param request: A L{DummyRequest}.
        @param code: The expected HTTP response code.
        @param message: The expected HTTP message.
        @param headers: The expected HTTP headers.
        @param body: The expected response body.
        NrY)	r�responseCode�responseMessage�list�responseHeaders�getAllRawHeaders�sortrr�written)rr_rsrtrrTrj�expectedHeadersr,r,r-�assertForwardsResponse�s
z'ProxyClientTests.assertForwardsResponseTcCs�|�d�}|�||ddi|�}	|�|	|dddd��}
|�|
|�|	�|�||||��|�|||||�|r<|	j��|�	|	jj
�|�|jd�dS)	z�
        Build a fake proxy connection, and send C{data} over it, checking that
        it's forwarded to the originating request.
        r7rZr[s /foo HTTP/1.0�close)�
connectionrZ�N)rWrbrkrrrwr�r%�loseConnection�assertFalse�	connected�finished)rrsrtrrTr`rar�r_�client�receivedBodyr,r,r-�_testDataForward�s 
��
z!ProxyClientTests._testDataForwardcCs|�dddddgfgd�S)z�
        When connected to the server, L{ProxyClient} should send the saved
        request, with modifications of the headers, and then forward the result
        to the parent request.
        ���OK�Foo�barsbaz�Some data
�r�r1r,r,r-�test_forwards�zProxyClientTests.test_forwardcCs|�ddddgfgddd�S)z~
        Try to post content in the request, and check that the proxy client
        forward the body of the request.
        r�r�r�r�r��POST�Some contentr�r1r,r,r-�
test_postData's�zProxyClientTests.test_postDatacCs|�ddgd�S)z�
        If the response contains a status with a message, it should be
        forwarded to the parent request with all the information.
        i�s	Not FoundrYr�r1r,r,r-�test_statusWithMessage0�z'ProxyClientTests.test_statusWithMessagecCs*d}|�dddtt|���d�gfg|�S)z�
        If the response contains a I{Content-Length} header, the inbound
        request object should still only have C{finish} called on it once.
        �foo bar bazr�r��Content-Lengthrl�r�rn�lenro�r�datar,r,r-�test_contentLength7s�z#ProxyClientTests.test_contentLengthcCs.d}|jdddtt|���d�gfg|dd�S)z�
        If the response contains a I{Content-Length} header, the outgoing
        connection is closed when all response body data has been received.
        r�r�r�r�rlF)r�r�r�r,r,r-�test_losesConnectionAs�z%ProxyClientTests.test_losesConnectioncCs0tdddddd�dd�}|�|jdd	d
��dS)z�
        The headers given at initialization should be modified:
        B{proxy-connection} should be removed if present, and B{connection}
        should be added.
        rX�/foor]r[r7)rZsproxy-connectionrYNr��rZr�)rrr)rr�r,r,r-�test_headersCleanupsOs��z%ProxyClientTests.test_headersCleanupscCsFdddd�}|��}d|d<|d=tddd	|d
d�}|�|d|�dS)
z�
        The proxy doesn't really know what to do with keepalive things from
        the remote server, so we stomp over any keepalive header we get from
        the client.
        r[s300�
keep-alive)rZr�r�r�r�rXr�r]rYNsGET /foo HTTP/1.0)�copyrrk)rrrr�r,r,r-�test_keepaliveNotForwardedas�z+ProxyClientTests.test_keepaliveNotForwardedcCs�|�d�}|j�ddg�|j�ddg�|j�ddg�|j|dd	id
�}|�|�dgdgd
gd�}|�|�dd|��d��|�|ddt	|���d�dS)z�
        L{server.Request} within the proxy sets certain response headers by
        default. When we get these headers back from the remote server, the
        defaults are overridden rather than simply appended.
        r7sserversold-barsdatesold-bazscontent-typesold/quxrZr[)rr�s
2010-01-01sapplication/x-baz)sServersDate�Content-Typer�r�rYN)
rWr{�
setRawHeadersrbrfrrw�itemsr�rz)rr_r�rr,r,r-�test_defaultHeadersOverriddenrs

�z.ProxyClientTests.test_defaultHeadersOverridden)rXNrY)rXrYT)r>r?r@rArVrWrbrfrkrwr�r�r�r�r�r�r�r�r�r�r,r,r,r-rJ�s*
	
�,
	
rJc@s eZdZdZdd�Zdd�ZdS)�ProxyClientFactoryTestsz*
    Tests for L{ProxyClientFactory}.
    cCs�tdg�}tdddddid|�}|�dd�|�|jd	�|�|jd
�|�t|j���ddgfg�|�d�	|j
�d
�|�|jd�dS)z�
        Check that L{ProxyClientFactory.clientConnectionFailed} produces
        a B{501} response to the parent request.
        r7rXr�r]rZr[�Ni�s
Gateway errorr�rYs<H1>Could not connect</H1>r�)r
r�clientConnectionFailedrrxryrzr{r|rrr~r�)rr_r)r,r,r-�test_connectionFailed�s
�
�z-ProxyClientFactoryTests.test_connectionFailedcCsntdddddidd�}|�d�}|�|t�|�|jd�|�|jd�|�|jd�|�|jddd	��dS)
z�
        L{ProxyClientFactory.buildProtocol} should produce a L{ProxyClient}
        with the same values of attributes (with updates on the headers).
        rXr�r]rZr[s	Some dataNr�r�)	rrrrr�commandrr�r)rr)�protor,r,r-�test_buildProtocol�s�
�z*ProxyClientFactoryTests.test_buildProtocolN)r>r?r@rAr�r�r,r,r,r-r��sr�c@s:eZdZdZddd�Zdd�Zdd	�Zd
d�Zdd
�ZdS)�ProxyRequestTestsz$
    Tests for L{ProxyRequest}.
    rXrYc
Cs�t�}t|�}t�}t|d|�}|�t|��|�|�|�|d|d�|�t|j	�d�|�|j	ddd�|�|j	ddd�|j	dd}	|�
|	t�|�|	j|�|�|	j
d�|�|	jd	d
i�|�|	j|�|�|	j|�|�|	j|�dS)z�
        Build a request pointing at C{uri}, and check that a proxied request
        is created, pointing a C{expectedURI}.
        Fshttp://example.comr]r�r�example.com�P�r�example.comN)rrBrr�	gotLengthr��handleContentChunk�requestReceivedrrrrr��versionrr�r�father)
rrr r`r�r%r&r"r_r)r,r,r-�_testProcess�s$
zProxyRequestTests._testProcesscCs|�dd�S)a�
        L{ProxyRequest.process} should create a connection to the given server,
        with a L{ProxyClientFactory} as connection factory, with the correct
        parameters:
            - forward comment, version and data values
            - update headers with the B{host} value
            - remove the host from the URL
            - pass the request as parent request
        �/foo/bar�r�r1r,r,r-�test_process�s
zProxyRequestTests.test_processcCr/)z�
        If the incoming request doesn't contain a slash,
        L{ProxyRequest.process} should add one when instantiating
        L{ProxyClientFactory}.
        rYr\r�r1r,r,r-� test_processWithoutTrailingSlash�r5z2ProxyRequestTests.test_processWithoutTrailingSlashcCs|�dddd�S)zl
        L{ProxyRequest.process} should be able to retrieve request body and
        to forward it.
        r�r�r�r�r1r,r,r-�test_processWithData�r�z&ProxyRequestTests.test_processWithDatacCszt�}t|�}t�}t|d|�}|�d�|�ddd�|�t|j�d�|�|jddd�|�|jddd�d	S)
z�
        Check that L{ProxyRequest.process} correctly parse port in the incoming
        URL, and create an outgoing connection with this port.
        FrrXshttp://example.com:1234/foo/barr]r�r�rN)	rrBrrr�r�rr�r)rr%r&r"r_r,r,r-�test_processWithPort�s
z&ProxyRequestTests.test_processWithPortN)rXrY)	r>r?r@rAr�r�r�r�r�r,r,r,r-r��s
r�c@�eZdZdZdd�ZdS)�DummyFactoryz>
    A simple holder for C{host} and C{port} information.
    cCs||_||_dS)N)r'r()rr'r(r,r,r-rDs
zDummyFactory.__init__N)r>r?r@rArDr,r,r,r-r���r�c@r�)�ReverseProxyRequestTestsz+
    Tests for L{ReverseProxyRequest}.
    cCs�t�}t|�}t�}t|d|�}tdd�|_|�d�|�ddd�|�t	|j
�d�|�|j
ddd�|�|j
ddd�|j
dd	}|�|t�|�|j
d
di�dS)
a
        L{ReverseProxyRequest.process} should create a connection to its
        factory host/port, using a L{ProxyClientFactory} instantiated with the
        correct parameters, and particularly set the B{host} header to the
        factory host.
        Fr�rrrXr�r]r�r�rr�N)rrBrrr�r)r�r�rr�rrrr)rr%r&r"r_r)r,r,r-r�
s
z%ReverseProxyRequestTests.test_processN)r>r?r@rAr�r,r,r,r-r�r�r�N)rA�twisted.test.proto_helpersrr�twisted.trial.unittestr�twisted.web.proxyrrrrr	�twisted.web.resourcer
�twisted.web.serverr�twisted.web.test.test_webr
rrBrJr�r�r�r�r,r,r,r-�<module>sS#|+L

Anon7 - 2022
AnonSec Team