summaryrefslogtreecommitdiffhomepage
path: root/test
diff options
context:
space:
mode:
authorZhidao HONG <z.hong@f5.com>2021-09-30 22:17:28 +0800
committerZhidao HONG <z.hong@f5.com>2021-09-30 22:17:28 +0800
commitc5220944d2acdb912c129fc82ac8a83d24e9845d (patch)
tree8cea32d295c7bde273cfe3a14b6044463aaec155 /test
parent37144d68499217d086c26a2030e6e9f6f7342152 (diff)
downloadunit-c5220944d2acdb912c129fc82ac8a83d24e9845d.tar.gz
unit-c5220944d2acdb912c129fc82ac8a83d24e9845d.tar.bz2
Static: variables in the "share" option.
This commit supports variable in the "share" option, the finding path to file serve is the value from "share". An example: { "share": "/www/data/static$uri" }
Diffstat (limited to '')
-rw-r--r--test/test_static.py4
-rw-r--r--test/test_static_chroot.py18
-rw-r--r--test/test_static_fallback.py6
-rw-r--r--test/test_static_mount.py14
-rw-r--r--test/test_static_symlink.py12
-rw-r--r--test/test_static_types.py37
6 files changed, 48 insertions, 43 deletions
diff --git a/test/test_static.py b/test/test_static.py
index 669e265d..fa0a81a2 100644
--- a/test/test_static.py
+++ b/test/test_static.py
@@ -28,7 +28,9 @@ class TestStatic(TestApplicationProto):
self._load_conf(
{
"listeners": {"*:7080": {"pass": "routes"}},
- "routes": [{"action": {"share": option.temp_dir + "/assets"}}],
+ "routes": [
+ {"action": {"share": option.temp_dir + "/assets$uri"}}
+ ],
"settings": {
"http": {
"static": {
diff --git a/test/test_static_chroot.py b/test/test_static_chroot.py
index f9bc93a8..aa2952a1 100644
--- a/test/test_static_chroot.py
+++ b/test/test_static_chroot.py
@@ -21,7 +21,7 @@ class TestStaticChroot(TestApplicationProto):
self._load_conf(
{
"listeners": {"*:7080": {"pass": "routes"}},
- "routes": [{"action": {"share": temp_dir + "/assets"}}],
+ "routes": [{"action": {"share": temp_dir + "/assets$uri"}}],
}
)
@@ -31,7 +31,7 @@ class TestStaticChroot(TestApplicationProto):
assert 'success' in self.conf(
{
- "share": temp_dir + "/assets",
+ "share": temp_dir + "/assets$uri",
"chroot": temp_dir + "/assets/dir",
},
'routes/0/action',
@@ -49,7 +49,7 @@ class TestStaticChroot(TestApplicationProto):
assert 'success' in self.conf(
{
- "share": temp_dir + "/assets",
+ "share": temp_dir + "/assets$uri",
"chroot": temp_dir + "/assets/dir",
},
'routes/0/action',
@@ -59,7 +59,8 @@ class TestStaticChroot(TestApplicationProto):
def test_static_chroot_empty(self, temp_dir):
assert 'success' in self.conf(
- {"share": temp_dir + "/assets", "chroot": ""}, 'routes/0/action',
+ {"share": temp_dir + "/assets$uri", "chroot": ""},
+ 'routes/0/action',
), 'configure chroot empty absolute'
assert (
@@ -67,7 +68,7 @@ class TestStaticChroot(TestApplicationProto):
), 'chroot empty absolute'
assert 'success' in self.conf(
- {"share": ".", "chroot": ""}, 'routes/0/action',
+ {"share": ".$uri", "chroot": ""}, 'routes/0/action',
), 'configure chroot empty relative'
assert (
@@ -79,19 +80,20 @@ class TestStaticChroot(TestApplicationProto):
pytest.skip('does\'t work under root')
assert 'success' in self.conf(
- {"share": temp_dir + "/assets", "chroot": "."}, 'routes/0/action',
+ {"share": temp_dir + "/assets$uri", "chroot": "."},
+ 'routes/0/action',
), 'configure relative chroot'
assert self.get(url='/dir/file')['status'] == 403, 'relative chroot'
assert 'success' in self.conf(
- {"share": "."}, 'routes/0/action',
+ {"share": ".$uri"}, 'routes/0/action',
), 'configure relative share'
assert self.get(url=self.test_path)['status'] == 200, 'relative share'
assert 'success' in self.conf(
- {"share": ".", "chroot": "."}, 'routes/0/action',
+ {"share": ".$uri", "chroot": "."}, 'routes/0/action',
), 'configure relative'
assert self.get(url=self.test_path)['status'] == 200, 'relative'
diff --git a/test/test_static_fallback.py b/test/test_static_fallback.py
index dc9056b9..4cfebcec 100644
--- a/test/test_static_fallback.py
+++ b/test/test_static_fallback.py
@@ -23,7 +23,7 @@ class TestStaticFallback(TestApplicationProto):
"*:7080": {"pass": "routes"},
"*:7081": {"pass": "routes"},
},
- "routes": [{"action": {"share": temp_dir + "/assets"}}],
+ "routes": [{"action": {"share": temp_dir + "/assets$uri"}}],
"applications": {},
}
)
@@ -50,7 +50,7 @@ class TestStaticFallback(TestApplicationProto):
def test_static_fallback_valid_path(self, temp_dir):
self.action_update(
- {"share": temp_dir + "/assets", "fallback": {"return": 200}}
+ {"share": temp_dir + "/assets$uri", "fallback": {"return": 200}}
)
resp = self.get()
assert resp['status'] == 200, 'fallback status'
@@ -83,7 +83,7 @@ class TestStaticFallback(TestApplicationProto):
def test_static_fallback_share(self, temp_dir):
self.action_update(
- {"share": "/blah", "fallback": {"share": temp_dir + "/assets"},}
+ {"share": "/blah", "fallback": {"share": temp_dir + "/assets$uri"},}
)
resp = self.get()
diff --git a/test/test_static_mount.py b/test/test_static_mount.py
index 570f6439..fb4fbe4b 100644
--- a/test/test_static_mount.py
+++ b/test/test_static_mount.py
@@ -44,7 +44,7 @@ class TestStaticMount(TestApplicationProto):
self._load_conf(
{
"listeners": {"*:7080": {"pass": "routes"}},
- "routes": [{"action": {"share": temp_dir + "/assets/dir"}}],
+ "routes": [{"action": {"share": temp_dir + "/assets/dir$uri"}}],
}
)
@@ -72,14 +72,14 @@ class TestStaticMount(TestApplicationProto):
assert resp['body'] == 'mount'
assert 'success' in self.conf(
- {"share": temp_dir + "/assets/dir", "traverse_mounts": False},
+ {"share": temp_dir + "/assets/dir$uri", "traverse_mounts": False},
'routes/0/action',
), 'configure mount disable'
assert self.get(url='/mount/')['status'] == 403
assert 'success' in self.conf(
- {"share": temp_dir + "/assets/dir", "traverse_mounts": True},
+ {"share": temp_dir + "/assets/dir$uri", "traverse_mounts": True},
'routes/0/action',
), 'configure mount enable'
@@ -97,14 +97,14 @@ class TestStaticMount(TestApplicationProto):
{
"match": {"method": "HEAD"},
"action": {
- "share": temp_dir + "/assets/dir",
+ "share": temp_dir + "/assets/dir$uri",
"traverse_mounts": False,
},
},
{
"match": {"method": "GET"},
"action": {
- "share": temp_dir + "/assets/dir",
+ "share": temp_dir + "/assets/dir$uri",
"traverse_mounts": True,
},
},
@@ -120,7 +120,7 @@ class TestStaticMount(TestApplicationProto):
assert 'success' in self.conf(
{
- "share": temp_dir + "/assets/dir",
+ "share": temp_dir + "/assets/dir$uri",
"chroot": temp_dir + "/assets",
},
'routes/0/action',
@@ -130,7 +130,7 @@ class TestStaticMount(TestApplicationProto):
assert 'success' in self.conf(
{
- "share": temp_dir + "/assets/dir",
+ "share": temp_dir + "/assets/dir$uri",
"chroot": temp_dir + "/assets",
"traverse_mounts": False,
},
diff --git a/test/test_static_symlink.py b/test/test_static_symlink.py
index 35eb402a..e0fd7277 100644
--- a/test/test_static_symlink.py
+++ b/test/test_static_symlink.py
@@ -18,7 +18,7 @@ class TestStaticSymlink(TestApplicationProto):
self._load_conf(
{
"listeners": {"*:7080": {"pass": "routes"}},
- "routes": [{"action": {"share": temp_dir + "/assets"}}],
+ "routes": [{"action": {"share": temp_dir + "/assets$uri"}}],
}
)
@@ -33,14 +33,14 @@ class TestStaticSymlink(TestApplicationProto):
assert self.get(url='/link/file')['status'] == 200, 'symlink file'
assert 'success' in self.conf(
- {"share": temp_dir + "/assets", "follow_symlinks": False},
+ {"share": temp_dir + "/assets$uri", "follow_symlinks": False},
'routes/0/action',
), 'configure symlink disable'
assert self.get(url='/link/file')['status'] == 403, 'symlink disabled'
assert 'success' in self.conf(
- {"share": temp_dir + "/assets", "follow_symlinks": True},
+ {"share": temp_dir + "/assets$uri", "follow_symlinks": True},
'routes/0/action',
), 'configure symlink enable'
@@ -56,14 +56,14 @@ class TestStaticSymlink(TestApplicationProto):
{
"match": {"method": "HEAD"},
"action": {
- "share": temp_dir + "/assets",
+ "share": temp_dir + "/assets$uri",
"follow_symlinks": False,
},
},
{
"match": {"method": "GET"},
"action": {
- "share": temp_dir + "/assets",
+ "share": temp_dir + "/assets$uri",
"follow_symlinks": True,
},
},
@@ -85,7 +85,7 @@ class TestStaticSymlink(TestApplicationProto):
assert 'success' in self.conf(
{
- "share": temp_dir + "/assets",
+ "share": temp_dir + "/assets$uri",
"chroot": temp_dir + "/assets/dir/dir",
},
'routes/0/action',
diff --git a/test/test_static_types.py b/test/test_static_types.py
index 20defddf..41ab7368 100644
--- a/test/test_static_types.py
+++ b/test/test_static_types.py
@@ -22,7 +22,7 @@ class TestStaticTypes(TestApplicationProto):
"*:7080": {"pass": "routes"},
"*:7081": {"pass": "routes"},
},
- "routes": [{"action": {"share": temp_dir + "/assets"}}],
+ "routes": [{"action": {"share": temp_dir + "/assets$uri"}}],
"applications": {},
}
)
@@ -36,39 +36,39 @@ class TestStaticTypes(TestApplicationProto):
assert resp['body'] == body, 'body'
def test_static_types_basic(self, temp_dir):
- self.action_update({"share": temp_dir + "/assets"})
+ self.action_update({"share": temp_dir + "/assets$uri"})
self.check_body('/index.html', 'index')
self.check_body('/file.xml', '.xml')
self.action_update(
- {"share": temp_dir + "/assets", "types": "application/xml"}
+ {"share": temp_dir + "/assets$uri", "types": "application/xml"}
)
self.check_body('/file.xml', '.xml')
self.action_update(
- {"share": temp_dir + "/assets", "types": ["application/xml"]}
+ {"share": temp_dir + "/assets$uri", "types": ["application/xml"]}
)
self.check_body('/file.xml', '.xml')
- self.action_update({"share": temp_dir + "/assets", "types": [""]})
+ self.action_update({"share": temp_dir + "/assets$uri", "types": [""]})
assert self.get(url='/file.xml')['status'] == 403, 'no mtype'
def test_static_types_wildcard(self, temp_dir):
self.action_update(
- {"share": temp_dir + "/assets", "types": ["application/*"]}
+ {"share": temp_dir + "/assets$uri", "types": ["application/*"]}
)
self.check_body('/file.xml', '.xml')
assert self.get(url='/file.mp4')['status'] == 403, 'app * mtype mp4'
self.action_update(
- {"share": temp_dir + "/assets", "types": ["video/*"]}
+ {"share": temp_dir + "/assets$uri", "types": ["video/*"]}
)
assert self.get(url='/file.xml')['status'] == 403, 'video * mtype xml'
self.check_body('/file.mp4', '.mp4')
def test_static_types_negation(self, temp_dir):
self.action_update(
- {"share": temp_dir + "/assets", "types": ["!application/xml"]}
+ {"share": temp_dir + "/assets$uri", "types": ["!application/xml"]}
)
assert self.get(url='/file.xml')['status'] == 403, 'forbidden negation'
self.check_body('/file.mp4', '.mp4')
@@ -76,7 +76,7 @@ class TestStaticTypes(TestApplicationProto):
# sorting negation
self.action_update(
{
- "share": temp_dir + "/assets",
+ "share": temp_dir + "/assets$uri",
"types": ["!video/*", "image/png", "!image/jpg"],
}
)
@@ -86,7 +86,7 @@ class TestStaticTypes(TestApplicationProto):
def test_static_types_regex(self, temp_dir):
self.action_update(
- {"share": temp_dir + "/assets", "types": ["~text/(html|plain)"]}
+ {"share": temp_dir + "/assets$uri", "types": ["~text/(html|plain)"]}
)
assert self.get(url='/file.php')['status'] == 403, 'regex fail'
self.check_body('/file.html', '.html')
@@ -94,7 +94,7 @@ class TestStaticTypes(TestApplicationProto):
def test_static_types_case(self, temp_dir):
self.action_update(
- {"share": temp_dir + "/assets", "types": ["!APpliCaTiOn/xMl"]}
+ {"share": temp_dir + "/assets$uri", "types": ["!APpliCaTiOn/xMl"]}
)
self.check_body('/file.mp4', '.mp4')
assert (
@@ -102,7 +102,7 @@ class TestStaticTypes(TestApplicationProto):
), 'mixed case xml negation'
self.action_update(
- {"share": temp_dir + "/assets", "types": ["vIdEo/mp4"]}
+ {"share": temp_dir + "/assets$uri", "types": ["vIdEo/mp4"]}
)
assert self.get(url='/file.mp4')['status'] == 200, 'mixed case'
assert (
@@ -110,7 +110,7 @@ class TestStaticTypes(TestApplicationProto):
), 'mixed case video negation'
self.action_update(
- {"share": temp_dir + "/assets", "types": ["vIdEo/*"]}
+ {"share": temp_dir + "/assets$uri", "types": ["vIdEo/*"]}
)
self.check_body('/file.mp4', '.mp4')
assert (
@@ -126,7 +126,7 @@ class TestStaticTypes(TestApplicationProto):
},
{
"action": {
- "share": temp_dir + "/assets",
+ "share": temp_dir + "/assets$uri",
"types": ["!application/x-httpd-php"],
"fallback": {"proxy": "http://127.0.0.1:7081"},
}
@@ -140,17 +140,18 @@ class TestStaticTypes(TestApplicationProto):
def test_static_types_index(self, temp_dir):
self.action_update(
- {"share": temp_dir + "/assets", "types": "application/xml"}
+ {"share": temp_dir + "/assets$uri", "types": "application/xml"}
)
self.check_body('/', 'index')
self.check_body('/file.xml', '.xml')
+ assert self.get(url='/index.html')['status'] == 403, 'forbidden mtype'
assert self.get(url='/file.mp4')['status'] == 403, 'forbidden mtype'
def test_static_types_custom_mime(self, temp_dir):
self._load_conf(
{
"listeners": {"*:7080": {"pass": "routes"}},
- "routes": [{"action": {"share": temp_dir + "/assets"}}],
+ "routes": [{"action": {"share": temp_dir + "/assets$uri"}}],
"applications": {},
"settings": {
"http": {
@@ -160,10 +161,10 @@ class TestStaticTypes(TestApplicationProto):
}
)
- self.action_update({"share": temp_dir + "/assets", "types": [""]})
+ self.action_update({"share": temp_dir + "/assets$uri", "types": [""]})
assert self.get(url='/file')['status'] == 403, 'forbidden custom mime'
self.action_update(
- {"share": temp_dir + "/assets", "types": ["test/mime-type"]}
+ {"share": temp_dir + "/assets$uri", "types": ["test/mime-type"]}
)
self.check_body('/file', '')