Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 46 lines (34 sloc) 1.189 kb
cfb4bcf @alobbs Adds X-Forwarded-For support to the previous X-Real-IP support on the
alobbs authored
1 from base import *
2
3 DIR = "x_forwarded_for_cgi_1"
4 REMOTE_IP = "1.2.3.4"
5
6 CONF = """
7 vserver!1!rule!2520!match = directory
8 vserver!1!rule!2520!match!directory = /%s
9 vserver!1!rule!2520!handler = cgi
10 vserver!1!rule!2520!handler!x_real_ip_enabled = 1
11 vserver!1!rule!2520!handler!x_real_ip_access_all = 0
12 vserver!1!rule!2520!handler!x_real_ip_access = ::1,127.0.0.1
13 """ % (DIR)
14
15 CGI_CODE = """#!/bin/sh
16
17 echo "Content-Type: text/plain"
18 echo
19
20 echo "REMOTE_ADDR ->${REMOTE_ADDR}<-"
21 echo
22 """
23
24 class Test (TestBase):
25 def __init__ (self):
26 TestBase.__init__ (self, __file__)
27 self.name = "X-Forwared-For to REMOTE_ADDR"
28
29 self.request = "GET /%s/test HTTP/1.0\r\n" % (DIR) + \
30 "X-Forwarded-For: %s\r\n" % (REMOTE_IP)
31 self.expected_error = 200
32 self.conf = CONF
33 self.proxy_suitable = False
34
35 def CustomTest (self):
36 body = self.reply.split ("\r\n\r\n")[1]
37
38 if "REMOTE_ADDR ->%s<-" %(REMOTE_IP) in body:
39 return 0
40
41 return -1
42
43 def Prepare (self, www):
44 d = self.Mkdir (www, DIR, 0777)
45 self.WriteFile (d, "test", 0555, CGI_CODE)
Something went wrong with that request. Please try again.