summaryrefslogtreecommitdiff
path: root/modules/caddyhttp/matchers_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'modules/caddyhttp/matchers_test.go')
-rw-r--r--modules/caddyhttp/matchers_test.go38
1 files changed, 31 insertions, 7 deletions
diff --git a/modules/caddyhttp/matchers_test.go b/modules/caddyhttp/matchers_test.go
index 34a1647..8e06546 100644
--- a/modules/caddyhttp/matchers_test.go
+++ b/modules/caddyhttp/matchers_test.go
@@ -183,8 +183,18 @@ func TestPathMatcher(t *testing.T) {
expect: false,
},
{
+ match: MatchPath{"/foo/bar/"},
+ input: "/foo/bar/",
+ expect: true,
+ },
+ {
match: MatchPath{"/foo/bar/", "/other"},
input: "/other/",
+ expect: false,
+ },
+ {
+ match: MatchPath{"/foo/bar/", "/other"},
+ input: "/other",
expect: true,
},
{
@@ -213,19 +223,19 @@ func TestPathMatcher(t *testing.T) {
expect: false,
},
{
- match: MatchPath{"=/foo"},
- input: "/foo",
+ match: MatchPath{"*substring*"},
+ input: "/foo/substring/bar.txt",
expect: true,
},
{
- match: MatchPath{"=/foo"},
+ match: MatchPath{"/foo"},
input: "/foo/bar",
expect: false,
},
{
- match: MatchPath{"=/foo"},
- input: "/FOO",
- expect: true,
+ match: MatchPath{"/foo"},
+ input: "/foo/bar",
+ expect: false,
},
{
match: MatchPath{"/foo"},
@@ -233,12 +243,21 @@ func TestPathMatcher(t *testing.T) {
expect: true,
},
{
+ match: MatchPath{"/foo*"},
+ input: "/FOOOO",
+ expect: true,
+ },
+ {
match: MatchPath{"/foo/bar.txt"},
input: "/foo/BAR.txt",
expect: true,
},
} {
req := &http.Request{URL: &url.URL{Path: tc.input}}
+ repl := caddy.NewReplacer()
+ ctx := context.WithValue(req.Context(), caddy.ReplacerCtxKey, repl)
+ req = req.WithContext(ctx)
+
actual := tc.match.Match(req)
if actual != tc.expect {
t.Errorf("Test %d %v: Expected %t, got %t for '%s'", i, tc.match, tc.expect, actual, tc.input)
@@ -251,8 +270,13 @@ func TestPathMatcherWindows(t *testing.T) {
// only Windows has this bug where it will ignore
// trailing dots and spaces in a filename, but we
// test for it on all platforms to be more consistent
- match := MatchPath{"*.php"}
+
req := &http.Request{URL: &url.URL{Path: "/index.php . . .."}}
+ repl := caddy.NewReplacer()
+ ctx := context.WithValue(req.Context(), caddy.ReplacerCtxKey, repl)
+ req = req.WithContext(ctx)
+
+ match := MatchPath{"*.php"}
matched := match.Match(req)
if !matched {
t.Errorf("Expected to match; should ignore trailing dots and spaces")