summaryrefslogtreecommitdiff
path: root/modules/caddyhttp/matchers_test.go
diff options
context:
space:
mode:
authorJames Birtles <jameshbirtles@gmail.com>2020-06-26 22:14:47 +0100
committerGitHub <noreply@github.com>2020-06-26 15:14:47 -0600
commitddd690de4cc133bc728f765b2492ccb54f9d84ca (patch)
treee45c3554f03138efabd00b532aaad5bae521c282 /modules/caddyhttp/matchers_test.go
parent6004d3f779b8175d92d8eb7819ed800e8eddbff6 (diff)
caddyhttp: Support placeholders in query matcher (#3521)
Diffstat (limited to 'modules/caddyhttp/matchers_test.go')
-rw-r--r--modules/caddyhttp/matchers_test.go17
1 files changed, 17 insertions, 0 deletions
diff --git a/modules/caddyhttp/matchers_test.go b/modules/caddyhttp/matchers_test.go
index 1ac9588..883680f 100644
--- a/modules/caddyhttp/matchers_test.go
+++ b/modules/caddyhttp/matchers_test.go
@@ -546,11 +546,28 @@ func TestQueryMatcher(t *testing.T) {
input: "/?",
expect: false,
},
+ {
+ scenario: "match against a placeholder value",
+ match: MatchQuery{"debug": []string{"{http.vars.debug}"}},
+ input: "/?debug=1",
+ expect: true,
+ },
+ {
+ scenario: "match against a placeholder key",
+ match: MatchQuery{"{http.vars.key}": []string{"1"}},
+ input: "/?somekey=1",
+ expect: true,
+ },
} {
u, _ := url.Parse(tc.input)
req := &http.Request{URL: u}
+ repl := caddy.NewReplacer()
+ ctx := context.WithValue(req.Context(), caddy.ReplacerCtxKey, repl)
+ repl.Set("http.vars.debug", "1")
+ repl.Set("http.vars.key", "somekey")
+ 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)