2
0

Compare commits

..

4 Commits

Author SHA1 Message Date
a5d3e11c1f [tests] add tests for mod_dirlist
Change-Id: I5d6ea970cd5dca7e202c8bd888142e44ef8f4211
2020-06-22 20:38:47 +02:00
76fccefc84 [core] encode path in li_vrequest_redirect_directory
To handle whitespace and ? (and other special chars).

Change-Id: Ie597c1d784d42dba70dd21650f5fc9770e9e6547
2020-06-22 20:36:58 +02:00
51a7fd577c [core]: fix query string handling in li_vrequest_redirect_directory (dirlist, index)
- use decoded path instead of orig raw path (which includes the query
  string); the decoded path should be safe, and we also really don't
  need to support any "raw" handling - we're at the filesystem level
  anyway.

Change-Id: Ic9a5b362bea9813873631b18aaa908c59f2bb0a6
2020-06-22 20:27:41 +02:00
92681fcde4 [tests] fix PrepareDir
Change-Id: Idb26de002ad1586101c9e9bdb0256170b8e287b9
2020-06-22 19:59:43 +02:00
3 changed files with 45 additions and 2 deletions

View File

@ -1,5 +1,6 @@
#include <lighttpd/base.h>
#include <lighttpd/encoding.h>
#include <lighttpd/plugin_core.h>
#include <lighttpd/filter_buffer_on_disk.h>
@ -563,7 +564,7 @@ gboolean li_vrequest_redirect_directory(liVRequest *vr) {
} else {
g_string_append_len(uri, GSTR_LEN(vr->coninfo->local_addr_str));
}
g_string_append_len(uri, GSTR_LEN(vr->request.uri.raw_orig_path));
li_string_encode_append(vr->request.uri.path->str, uri, LI_ENCODING_URI);
g_string_append_c(uri, '/');
if (vr->request.uri.query->len) {
g_string_append_c(uri, '?');

View File

@ -226,7 +226,7 @@ var.vhosts = var.vhosts + [ "%s" => {
def PrepareDir(self, dirname):
"""remembers which directories have been prepared and while remove them on cleanup; returns absolute pathname"""
self._test_cleanup_dirs.append(fname)
self._test_cleanup_dirs.append(dirname)
return self.tests.PrepareDir(dirname)
def MissingFeature(self, feature):

42
tests/t-dirlist.py Normal file
View File

@ -0,0 +1,42 @@
# -*- coding: utf-8 -*-
from base import *
from requests import *
class TestDirlist(CurlRequest):
URL = "/foo/"
EXPECT_RESPONSE_CODE = 200
EXPECT_RESPONSE_HEADERS = [("Content-Type", "text/html; charset=utf-8")]
class TestRedirectDir(CurlRequest):
URL = "/foo"
EXPECT_RESPONSE_CODE = 301
EXPECT_RESPONSE_HEADERS = [("Location", "http://dirlist/foo/")]
class TestRedirectDirWithQuery(CurlRequest):
URL = "/foo?bar=baz"
EXPECT_RESPONSE_CODE = 301
EXPECT_RESPONSE_HEADERS = [("Location", "http://dirlist/foo/?bar=baz")]
class TestRedirectDirWithQueryAndSpecialChars(CurlRequest):
URL = "/f%3f%20o?bar=baz"
EXPECT_RESPONSE_CODE = 301
EXPECT_RESPONSE_HEADERS = [("Location", "http://dirlist/f%3f%20o/?bar=baz")]
class Test(GroupTest):
group = [
TestDirlist,
TestRedirectDir,
TestRedirectDirWithQuery,
]
config = """
setup { module_load "mod_dirlist"; }
dirlist;
"""
def Prepare(self):
self.PrepareDir("www/vhosts/dirlist/foo")
self.PrepareFile("www/vhosts/dirlist/foo/test.txt", "abc")
self.PrepareDir("www/vhosts/dirlist/f? o")
self.PrepareFile("www/vhosts/dirlist/f? o/test.txt", "abc")