summaryrefslogtreecommitdiffstats
path: root/test/pyhttpd/htdocs/cgi
diff options
context:
space:
mode:
authorStefan Eissing <icing@apache.org>2021-10-11 16:08:57 +0200
committerStefan Eissing <icing@apache.org>2021-10-11 16:08:57 +0200
commitded853c7cadc6a2b5590a0ceee5cddd0444da17a (patch)
tree2a8d944d77ba160559872ab5365bfe3a8682dccd /test/pyhttpd/htdocs/cgi
parentmod_proxy_uwsgi: Remove duplicate slashes at the beginning of PATH_INFO. (diff)
downloadapache2-ded853c7cadc6a2b5590a0ceee5cddd0444da17a.tar.xz
apache2-ded853c7cadc6a2b5590a0ceee5cddd0444da17a.zip
* test infrastruture:
- moved common pytest code into test/pyhttpd - does basic setup for a list of host names and some htdocs - added modules/core and moved encoding tests from http2 there - all test methods have module name in in prefix now, so to test only core, run > pytest -k test_core git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1894134 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'test/pyhttpd/htdocs/cgi')
-rw-r--r--test/pyhttpd/htdocs/cgi/echo.py14
-rw-r--r--test/pyhttpd/htdocs/cgi/echohd.py23
-rw-r--r--test/pyhttpd/htdocs/cgi/env.py39
-rw-r--r--test/pyhttpd/htdocs/cgi/files/empty.txt0
-rw-r--r--test/pyhttpd/htdocs/cgi/hecho.py46
-rw-r--r--test/pyhttpd/htdocs/cgi/hello.py15
-rw-r--r--test/pyhttpd/htdocs/cgi/mnot164.py21
-rw-r--r--test/pyhttpd/htdocs/cgi/necho.py54
-rw-r--r--test/pyhttpd/htdocs/cgi/upload.py62
9 files changed, 274 insertions, 0 deletions
diff --git a/test/pyhttpd/htdocs/cgi/echo.py b/test/pyhttpd/htdocs/cgi/echo.py
new file mode 100644
index 0000000000..5ffe6ed823
--- /dev/null
+++ b/test/pyhttpd/htdocs/cgi/echo.py
@@ -0,0 +1,14 @@
+#!/usr/bin/env python3
+import sys, cgi, os
+
+status = '200 Ok'
+
+content = ''
+for line in sys.stdin:
+ content += line
+
+# Just echo what we get
+print("Status: 200")
+print("Content-Type: application/data\n")
+sys.stdout.write(content)
+
diff --git a/test/pyhttpd/htdocs/cgi/echohd.py b/test/pyhttpd/htdocs/cgi/echohd.py
new file mode 100644
index 0000000000..371ae8b0f7
--- /dev/null
+++ b/test/pyhttpd/htdocs/cgi/echohd.py
@@ -0,0 +1,23 @@
+#!/usr/bin/env python3
+import cgi, os
+import cgitb; cgitb.enable()
+
+status = '200 Ok'
+
+form = cgi.FieldStorage()
+name = form.getvalue('name')
+
+if name:
+ print("Status: 200")
+ print("""\
+Content-Type: text/plain\n""")
+ print("""%s: %s""" % (name, os.environ['HTTP_'+name]))
+else:
+ print("Status: 400 Parameter Missing")
+ print("""\
+Content-Type: text/html\n
+<html><body>
+<p>No name was specified</p>
+</body></html>""")
+
+
diff --git a/test/pyhttpd/htdocs/cgi/env.py b/test/pyhttpd/htdocs/cgi/env.py
new file mode 100644
index 0000000000..5c9c0b1adb
--- /dev/null
+++ b/test/pyhttpd/htdocs/cgi/env.py
@@ -0,0 +1,39 @@
+#!/usr/bin/env python3
+import cgi, os
+import cgitb; cgitb.enable()
+
+status = '200 Ok'
+
+try:
+ form = cgi.FieldStorage()
+ input = form['name']
+
+ # Test if the file was uploaded
+ if input.value is not None:
+ val = os.environ[input.value] if input.value in os.environ else ""
+ print("Status: 200")
+ print("""\
+Content-Type: text/plain\n""")
+ print("{0}={1}".format(input.value, val))
+
+ else:
+ print("Status: 400 Parameter Missing")
+ print("""\
+Content-Type: text/html\n
+ <html><body>
+ <p>No name was specified: %s</p>
+ </body></html>""" % (count.value))
+
+except KeyError:
+ print("Status: 200 Ok")
+ print("""\
+Content-Type: text/html\n
+ <html><body>
+ Echo <form method="POST" enctype="application/x-www-form-urlencoded">
+ <input type="text" name="name">
+ <button type="submit">submit</button></form>
+ </body></html>""")
+ pass
+
+
+
diff --git a/test/pyhttpd/htdocs/cgi/files/empty.txt b/test/pyhttpd/htdocs/cgi/files/empty.txt
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/test/pyhttpd/htdocs/cgi/files/empty.txt
diff --git a/test/pyhttpd/htdocs/cgi/hecho.py b/test/pyhttpd/htdocs/cgi/hecho.py
new file mode 100644
index 0000000000..5c1f79a302
--- /dev/null
+++ b/test/pyhttpd/htdocs/cgi/hecho.py
@@ -0,0 +1,46 @@
+#!/usr/bin/env python3
+import cgi, os
+import cgitb; cgitb.enable()
+
+status = '200 Ok'
+
+try:
+ form = cgi.FieldStorage()
+
+ # A nested FieldStorage instance holds the file
+ name = form['name'].value
+ value = ''
+
+ try:
+ value = form['value'].value
+ except KeyError:
+ value = os.environ.get("HTTP_"+name, "unset")
+
+ # Test if a value was given
+ if name:
+ print("Status: 200")
+ print("%s: %s" % (name, value,))
+ print ("""\
+Content-Type: text/plain\n""")
+
+ else:
+ print("Status: 400 Parameter Missing")
+ print("""\
+Content-Type: text/html\n
+ <html><body>
+ <p>No name and value was specified: %s %s</p>
+ </body></html>""" % (name, value))
+
+except KeyError:
+ print("Status: 200 Ok")
+ print("""\
+Content-Type: text/html\n
+ <html><body>
+ Echo <form method="POST" enctype="application/x-www-form-urlencoded">
+ <input type="text" name="name">
+ <input type="text" name="value">
+ <button type="submit">Echo</button></form>
+ </body></html>""")
+ pass
+
+
diff --git a/test/pyhttpd/htdocs/cgi/hello.py b/test/pyhttpd/htdocs/cgi/hello.py
new file mode 100644
index 0000000000..191acb2fed
--- /dev/null
+++ b/test/pyhttpd/htdocs/cgi/hello.py
@@ -0,0 +1,15 @@
+#!/usr/bin/env python3
+
+import os
+
+print("Content-Type: application/json")
+print()
+print("{")
+print(" \"https\" : \"%s\"," % (os.getenv('HTTPS', '')))
+print(" \"host\" : \"%s\"," % (os.getenv('SERVER_NAME', '')))
+print(" \"protocol\" : \"%s\"," % (os.getenv('SERVER_PROTOCOL', '')))
+print(" \"ssl_protocol\" : \"%s\"," % (os.getenv('SSL_PROTOCOL', '')))
+print(" \"h2\" : \"%s\"," % (os.getenv('HTTP2', '')))
+print(" \"h2push\" : \"%s\"" % (os.getenv('H2PUSH', '')))
+print("}")
+
diff --git a/test/pyhttpd/htdocs/cgi/mnot164.py b/test/pyhttpd/htdocs/cgi/mnot164.py
new file mode 100644
index 0000000000..949b0f195b
--- /dev/null
+++ b/test/pyhttpd/htdocs/cgi/mnot164.py
@@ -0,0 +1,21 @@
+#!/usr/bin/env python3
+
+import cgi
+import cgitb; cgitb.enable()
+import os
+import sys
+
+try:
+ form = cgi.FieldStorage()
+ count = form['count'].value
+ text = form['text'].value
+except KeyError:
+ text="a"
+ count=77784
+
+
+print("Status: 200 OK")
+print("Content-Type: text/html")
+print()
+sys.stdout.write(text*int(count))
+
diff --git a/test/pyhttpd/htdocs/cgi/necho.py b/test/pyhttpd/htdocs/cgi/necho.py
new file mode 100644
index 0000000000..b9249b8969
--- /dev/null
+++ b/test/pyhttpd/htdocs/cgi/necho.py
@@ -0,0 +1,54 @@
+#!/usr/bin/env python3
+import cgi, os
+import time
+import cgitb; cgitb.enable()
+
+status = '200 Ok'
+
+try:
+ form = cgi.FieldStorage()
+ count = form['count']
+ text = form['text']
+
+ waitsec = float(form['wait1'].value) if 'wait1' in form else 0.0
+ if waitsec > 0:
+ time.sleep(waitsec)
+
+ if int(count.value):
+ print("Status: 200")
+ print("""\
+Content-Type: text/plain\n""")
+
+ waitsec = float(form['wait2'].value) if 'wait2' in form else 0.0
+ if waitsec > 0:
+ time.sleep(waitsec)
+
+ i = 0;
+ for i in range(0, int(count.value)):
+ print("%s" % (text.value))
+
+ waitsec = float(form['wait3'].value) if 'wait3' in form else 0.0
+ if waitsec > 0:
+ time.sleep(waitsec)
+
+ else:
+ print("Status: 400 Parameter Missing")
+ print("""\
+Content-Type: text/html\n
+ <html><body>
+ <p>No count was specified: %s</p>
+ </body></html>""" % (count.value))
+
+except KeyError:
+ print("Status: 200 Ok")
+ print("""\
+Content-Type: text/html\n
+ <html><body>
+ Echo <form method="POST" enctype="application/x-www-form-urlencoded">
+ <input type="text" name="count">
+ <input type="text" name="text">
+ <button type="submit">Echo</button></form>
+ </body></html>""")
+ pass
+
+
diff --git a/test/pyhttpd/htdocs/cgi/upload.py b/test/pyhttpd/htdocs/cgi/upload.py
new file mode 100644
index 0000000000..2c8d63aa10
--- /dev/null
+++ b/test/pyhttpd/htdocs/cgi/upload.py
@@ -0,0 +1,62 @@
+#!/usr/bin/env python3
+import cgi, os
+import cgitb
+cgitb.enable()
+
+status = '200 Ok'
+
+try: # Windows needs stdio set for binary mode.
+ import msvcrt
+ msvcrt.setmode (0, os.O_BINARY) # stdin = 0
+ msvcrt.setmode (1, os.O_BINARY) # stdout = 1
+except ImportError:
+ pass
+
+form = cgi.FieldStorage()
+
+# Test if the file was uploaded
+if 'file' in form:
+ fileitem = form['file']
+ # strip leading path from file name to avoid directory traversal attacks
+ fn = os.path.basename(fileitem.filename)
+ f = open(('%s/files/%s' % (os.environ["DOCUMENT_ROOT"], fn)), 'wb');
+ f.write(fileitem.file.read())
+ f.close()
+ message = "The file %s was uploaded successfully" % (fn)
+ print("Status: 201 Created")
+ print("Content-Type: text/html")
+ print("Location: %s://%s/files/%s" % (os.environ["REQUEST_SCHEME"], os.environ["HTTP_HOST"], fn))
+ print("")
+ print("<html><body><p>%s</p></body></html>" % (message))
+
+elif 'remove' in form:
+ remove = form['remove'].value
+ try:
+ fn = os.path.basename(remove)
+ os.remove('./files/' + fn)
+ message = 'The file "' + fn + '" was removed successfully'
+ except OSError as e:
+ message = 'Error removing ' + fn + ': ' + e.strerror
+ status = '404 File Not Found'
+ print("Status: %s" % (status))
+ print("""
+Content-Type: text/html
+
+<html><body>
+<p>%s</p>
+</body></html>""" % (message))
+
+else:
+ message = '''\
+ Upload File<form method="POST" enctype="multipart/form-data">
+ <input type="file" name="file">
+ <button type="submit">Upload</button></form>
+ '''
+ print("Status: %s" % (status))
+ print("""\
+Content-Type: text/html
+
+<html><body>
+<p>%s</p>
+</body></html>""" % (message))
+