Skip to content
This repository
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 51 lines (40 sloc) 1.324 kb
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 *
from util import *

from cStringIO import StringIO
import gzip
from gzip import GzipFile

DIR = "217_CGI_Encoded"
MAGIC = "Random text follows: " + letters_random (64 * 1024)

CONF = """
vserver!1!rule!2170!encoder!gzip = 1
vserver!1!rule!2170!match = directory
vserver!1!rule!2170!match!directory = /%s
vserver!1!rule!2170!handler = cgi
""" % (DIR)

CGI_BASE = """#!/bin/sh
echo "Content-Type: text/plain"
echo "Content-Encoding: gzip"
echo
cat %s
"""

class Test (TestBase):
    def __init__ (self):
        TestBase.__init__ (self, __file__)
        self.name = "GZip encoded CGI"
        self.request = "GET /%s/file HTTP/1.0\r\n" % (DIR)+\
                                 "Accept-Encoding: gzip\r\n"
        self.conf = CONF
        self.expected_error = 200
        self.forbidden_content = "Random text follows"

    def CustomTest (self):
        body_gz = self.reply[self.reply.find("\r\n\r\n")+4:]
        body = gzip.GzipFile('','r',0,StringIO(body_gz)).read()

        if body != MAGIC:
            return -1
        return 0

    def Prepare (self, www):
        d = self.Mkdir (www, DIR)

        g = gzip.open('%s/temp.gz'%(d), 'wb')
        g.write(MAGIC)
        g.close()

        self.WriteFile (d, "file", 0755, CGI_BASE%("%s/temp.gz"%(d)))
Something went wrong with that request. Please try again.