[tests] Add env-set and docroot tests

personal/stbuehler/wip
Stefan Bühler 12 years ago
parent 01f0c1606f
commit 8a2fce79e8
  1. 55
      tests/t-basic-docroot.py
  2. 83
      tests/t-env-set.py

@ -0,0 +1,55 @@
# -*- coding: utf-8 -*-
from base import *
from requests import *
class TestSimple(CurlRequest):
vhost = "xyz.abc.basic-docroot"
URL = "/?simple"
EXPECT_RESPONSE_BODY = "/var/www/xyz.abc.basic-docroot/htdocs"
EXPECT_RESPONSE_CODE = 200
class TestSubdir(CurlRequest):
vhost = "xyz.abc.basic-docroot"
URL = "/?subdir"
EXPECT_RESPONSE_BODY = "/var/www/basic-docroot/xyz.abc.basic-docroot/htdocs"
EXPECT_RESPONSE_CODE = 200
class TestSubdirOpenRange(CurlRequest):
vhost = "test.xyz.abc.basic-docroot"
URL = "/?subdir-open-range"
EXPECT_RESPONSE_BODY = "/var/www/basic-docroot/test.xyz.abc/htdocs"
EXPECT_RESPONSE_CODE = 200
class TestSubdirFixedRange(CurlRequest):
vhost = "test.xyz.abc.basic-docroot"
URL = "/?subdir-fixed-range"
EXPECT_RESPONSE_BODY = "/var/www/basic-docroot/xyz.abc/htdocs"
EXPECT_RESPONSE_CODE = 200
class Test(GroupTest):
group = [
TestSimple,
TestSubdir,
TestSubdirOpenRange,
TestSubdirFixedRange,
]
vhost = "basic-docroot"
subdomains = True
config = """
if req.query == "simple" {
docroot "/var/www/$0/htdocs";
} else if req.query == "subdir" {
docroot "/var/www/$[1]/$[0]/htdocs";
} else if req.query == "subdir-open-range" {
docroot "/var/www/$1/$[2-]/htdocs";
} else if req.query == "subdir-fixed-range" {
docroot "/var/www/$1/$[2-3]/htdocs";
}
env.set "INFO" => "%{phys.docroot}";
show_env_info;
"""

@ -0,0 +1,83 @@
# -*- coding: utf-8 -*-
from base import *
from requests import *
class TestPatternCapture(CurlRequest):
# use capture from previous regex conditional
config = """
if req.path =~ "(.*)" {
env.set "INFO" => "%1";
show_env_info;
}
"""
URL = "/path/?a_simple_query"
EXPECT_RESPONSE_BODY = "/path/"
EXPECT_RESPONSE_CODE = 200
todo = True
class TestPatternCaptureRange(CurlRequest):
# use capture from previous regex conditional
config = """
if req.path =~ "/([^/]*)/(.*)" {
env.set "INFO" => "%[1-2]";
show_env_info;
}
"""
URL = "/path/xyz"
EXPECT_RESPONSE_BODY = "pathxyz"
EXPECT_RESPONSE_CODE = 200
todo = True
class TestPatternCaptureRevRange(CurlRequest):
# use capture from previous regex conditional
config = """
if req.path =~ "/([^/]*)/(.*)" {
env.set "INFO" => "%[2-1]";
show_env_info;
}
"""
URL = "/path/xyz"
EXPECT_RESPONSE_BODY = "xyzpath"
EXPECT_RESPONSE_CODE = 200
todo = True
class TestPatternEncodingPath(CurlRequest):
# encoding path
config = """
env.set "INFO" => "%{enc:req.path}";
show_env_info;
"""
URL = "/complicated%3fpath%3d%20%24"
EXPECT_RESPONSE_BODY = "/complicated%3fpath%3d%20%24"
EXPECT_RESPONSE_CODE = 200
class TestPatternCombine(CurlRequest):
# combine several pieces
config = """
env.set "INFO" => "Abc:%{enc:req.path}:%{req.query}:%{req.host}";
show_env_info;
"""
URL = "/complicated%3fpath%3d%20%24?a_simple_query"
EXPECT_RESPONSE_CODE = 200
def Prepare(self):
self.EXPECT_RESPONSE_BODY = "Abc:/complicated%3fpath%3d%20%24:a_simple_query:" + self.vhost
class TestPatternEscape(CurlRequest):
config = """
env.set "INFO" => "\\\\%\\\\?\\\\$\\\\%{req.path}";
show_env_info;
"""
URL = "/abc"
EXPECT_RESPONSE_BODY = "%?$%{req.path}"
EXPECT_RESPONSE_CODE = 200
class Test(GroupTest):
group = [
TestPatternCapture,
TestPatternEncodingPath,
TestPatternCombine,
TestPatternEscape,
]
Loading…
Cancel
Save