summaryrefslogtreecommitdiff
path: root/modules/caddyhttp/fileserver/matcher_test.go
diff options
context:
space:
mode:
authorMatthew Holt <mholt@users.noreply.github.com>2020-07-31 13:55:01 -0600
committerMatthew Holt <mholt@users.noreply.github.com>2020-07-31 13:55:01 -0600
commit3860b235d074209c495d34a3966fc7fb2d5015a5 (patch)
tree444621ef8c11e2445a81e3d01b09285e476862fb /modules/caddyhttp/fileserver/matcher_test.go
parent6f73a358f43013a43c55d57f0c7726a6277f62b6 (diff)
fileserver: Don't assume len(str) == len(ToLower(str)) (fix #3623)
We can't use a positional index on an original string that we got from its lower-cased equivalent. Implement our own IndexFold() function b/c the std lib does not have one.
Diffstat (limited to 'modules/caddyhttp/fileserver/matcher_test.go')
-rw-r--r--modules/caddyhttp/fileserver/matcher_test.go63
1 files changed, 39 insertions, 24 deletions
diff --git a/modules/caddyhttp/fileserver/matcher_test.go b/modules/caddyhttp/fileserver/matcher_test.go
index aa84900..e3f2911 100644
--- a/modules/caddyhttp/fileserver/matcher_test.go
+++ b/modules/caddyhttp/fileserver/matcher_test.go
@@ -22,69 +22,84 @@ import (
"github.com/caddyserver/caddy/v2/modules/caddyhttp"
)
-func TestPhpFileMatcher(t *testing.T) {
-
+func TestPHPFileMatcher(t *testing.T) {
for i, tc := range []struct {
- path string
+ path string
expectedPath string
- matched bool
+ matched bool
}{
{
- path: "/index.php",
+ path: "/index.php",
expectedPath: "/index.php",
- matched: true,
+ matched: true,
},
{
- path: "/index.php/somewhere",
+ path: "/index.php/somewhere",
expectedPath: "/index.php",
- matched: true,
+ matched: true,
},
{
- path: "/remote.php",
+ path: "/remote.php",
expectedPath: "/remote.php",
- matched: true,
+ matched: true,
},
{
- path: "/remote.php/somewhere",
+ path: "/remote.php/somewhere",
expectedPath: "/remote.php",
- matched: true,
+ matched: true,
},
{
- path: "/missingfile.php",
+ path: "/missingfile.php",
matched: false,
},
{
- path: "/notphp.php.txt",
+ path: "/notphp.php.txt",
expectedPath: "/notphp.php.txt",
- matched: true,
+ matched: true,
},
{
- path: "/notphp.php.txt/",
+ path: "/notphp.php.txt/",
expectedPath: "/notphp.php.txt",
- matched: true,
+ matched: true,
},
{
- path: "/notphp.php.txt.suffixed",
+ path: "/notphp.php.txt.suffixed",
matched: false,
},
{
- path: "/foo.php.php/index.php",
+ path: "/foo.php.php/index.php",
expectedPath: "/foo.php.php/index.php",
- matched: true,
+ matched: true,
+ },
+ {
+ path: "/foo.php.PHP/index.php",
+ expectedPath: "/foo.php.PHP/index.php",
+ matched: true,
+ },
+ {
+ // See https://github.com/caddyserver/caddy/issues/3623
+ path: "/%E2%C3",
+ expectedPath: "/%E2%C3",
+ matched: false,
},
} {
m := &MatchFile{
Root: "./testdata",
- TryFiles: []string{"{http.request.uri.path}"},
+ TryFiles: []string{"{http.request.uri.path}", "{http.request.uri.path}/index.php"},
SplitPath: []string{".php"},
}
- req := &http.Request{URL: &url.URL{Path: tc.path}}
+ u, err := url.Parse(tc.path)
+ if err != nil {
+ t.Fatalf("Test %d: parsing path: %v", i, err)
+ }
+
+ req := &http.Request{URL: u}
repl := caddyhttp.NewTestReplacer(req)
result := m.Match(req)
if result != tc.matched {
- t.Fatalf("Test %d: match bool result: %v, expected: %v", i, result, tc.matched)
+ t.Fatalf("Test %d: expected match=%t, got %t", i, tc.matched, result)
}
rel, ok := repl.Get("http.matchers.file.relative")
@@ -99,4 +114,4 @@ func TestPhpFileMatcher(t *testing.T) {
t.Fatalf("Test %d: actual path: %v, expected: %v", i, rel, tc.expectedPath)
}
}
-} \ No newline at end of file
+}