-
Notifications
You must be signed in to change notification settings - Fork 104
/
202-xsendfile2.py
50 lines (41 loc) · 1.45 KB
/
202-xsendfile2.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
from base import *
DIR = "DirXsendfile2"
FILE = "test.cgi"
MAGIC = str_random(100)
DISCART = "This text should be discarted"
HDR_NAM1 = "X-Foo"
HDR_VAL1 = "0"
HDR_NAM2 = "X-Example"
HDR_VAL2 = "This is a Long Value"
CONF = """
vserver!1!rule!2020!match = directory
vserver!1!rule!2020!match!directory = /%s
vserver!1!rule!2020!handler = cgi
vserver!1!rule!2020!handler!xsendfile = 1
"""
CGI = """#!/bin/sh
echo "Content-Type: text/plain"
echo "%s: %s"
echo "X-Sendfile: %s"
echo "%s: %s"
echo
echo "%s"
"""
class Test (TestBase):
def __init__ (self):
TestBase.__init__ (self, __file__)
self.name = "X-Sendfile: File headers"
self.request = "GET /%s/%s HTTP/1.1\r\n" % (DIR, FILE) + \
"Host: default\r\n" + \
"Connection: Close\r\n"
self.expected_error = 200
self.expected_content = ["Content-Length: ", "ETag: ", "Last-Modified: ", MAGIC,
"%s: %s\r\n" %(HDR_NAM1, HDR_VAL1),
"%s: %s\r\n" %(HDR_NAM2, HDR_VAL2)]
self.forbidden_content = ["/bin/sh", "echo", DISCART, "chunked"]
self.conf = CONF % (DIR)
def Prepare (self, www):
temp = self.WriteTemp (MAGIC)
cgi = CGI % (HDR_NAM1, HDR_VAL1, temp, HDR_NAM2, HDR_VAL2, DISCART)
d = self.Mkdir (www, DIR)
f = self.WriteFile (d, FILE, 0755, cgi)