From 0fc97211abd46098f5953fc6b152aa891060fca5 Mon Sep 17 00:00:00 2001 From: Matthew Holt Date: Fri, 15 Nov 2019 12:47:06 -0700 Subject: http: Make path matcher case-insensitive Adds tests for both the path matcher and host matcher for case insensitivity. If case sensitivity is required for the path, a regexp matcher can be used instead. This is the v2 equivalent fix of PR #2882. --- modules/caddyhttp/matchers_test.go | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) (limited to 'modules/caddyhttp/matchers_test.go') diff --git a/modules/caddyhttp/matchers_test.go b/modules/caddyhttp/matchers_test.go index 81cb1d0..4569425 100644 --- a/modules/caddyhttp/matchers_test.go +++ b/modules/caddyhttp/matchers_test.go @@ -47,6 +47,16 @@ func TestHostMatcher(t *testing.T) { input: "example.com", expect: true, }, + { + match: MatchHost{"EXAMPLE.COM"}, + input: "example.com", + expect: true, + }, + { + match: MatchHost{"example.com"}, + input: "EXAMPLE.COM", + expect: true, + }, { match: MatchHost{"example.com"}, input: "foo.example.com", @@ -72,6 +82,11 @@ func TestHostMatcher(t *testing.T) { input: "example.com", expect: false, }, + { + match: MatchHost{"*.example.com"}, + input: "SUB.EXAMPLE.COM", + expect: true, + }, { match: MatchHost{"*.example.com"}, input: "foo.example.com", @@ -174,7 +189,12 @@ func TestPathMatcher(t *testing.T) { }, { match: MatchPath{"*.ext"}, - input: "foo.ext", + input: "/foo.ext", + expect: true, + }, + { + match: MatchPath{"*.php"}, + input: "/index.PHP", expect: true, }, { @@ -192,6 +212,16 @@ func TestPathMatcher(t *testing.T) { input: "/foo/bar/bam", expect: false, }, + { + match: MatchPath{"/foo"}, + input: "/FOO", + expect: true, + }, + { + match: MatchPath{"/foo/bar.txt"}, + input: "/foo/BAR.txt", + expect: true, + }, } { req := &http.Request{URL: &url.URL{Path: tc.input}} actual := tc.match.Match(req) -- cgit v1.2.3