aboutsummaryrefslogtreecommitdiffhomepage
path: root/modules/caddyhttp/matchers_test.go
diff options
context:
space:
mode:
authorAziz Rmadi <[email protected]>2024-01-21 20:36:44 -0600
committerGitHub <[email protected]>2024-01-22 02:36:44 +0000
commited7e3c906ab7ab8a91b5ce4d4345c46e4a351d2a (patch)
treebcd74aa681ac730ed2dc5ce86966d8c8913ee30a /modules/caddyhttp/matchers_test.go
parentc0273f1f049aa66e4426023d8e43d68fbdbccbb6 (diff)
downloadcaddy-ed7e3c906ab7ab8a91b5ce4d4345c46e4a351d2a.tar.gz
caddy-ed7e3c906ab7ab8a91b5ce4d4345c46e4a351d2a.zip
matchers: `query` now ANDs multiple keys (#6054)
Co-authored-by: Francis Lavoie <[email protected]>
Diffstat (limited to 'modules/caddyhttp/matchers_test.go')
-rw-r--r--modules/caddyhttp/matchers_test.go36
1 files changed, 36 insertions, 0 deletions
diff --git a/modules/caddyhttp/matchers_test.go b/modules/caddyhttp/matchers_test.go
index 100813096..5f76a36b1 100644
--- a/modules/caddyhttp/matchers_test.go
+++ b/modules/caddyhttp/matchers_test.go
@@ -763,6 +763,42 @@ func TestQueryMatcher(t *testing.T) {
input: "/?somekey=1",
expect: true,
},
+ {
+ scenario: "do not match when not all query params are present",
+ match: MatchQuery{"debug": []string{"1"}, "foo": []string{"bar"}},
+ input: "/?debug=1",
+ expect: false,
+ },
+ {
+ scenario: "match when all query params are present",
+ match: MatchQuery{"debug": []string{"1"}, "foo": []string{"bar"}},
+ input: "/?debug=1&foo=bar",
+ expect: true,
+ },
+ {
+ scenario: "do not match when the value of a query param does not match",
+ match: MatchQuery{"debug": []string{"1"}, "foo": []string{"bar"}},
+ input: "/?debug=2&foo=bar",
+ expect: false,
+ },
+ {
+ scenario: "do not match when all the values the query params do not match",
+ match: MatchQuery{"debug": []string{"1"}, "foo": []string{"bar"}},
+ input: "/?debug=2&foo=baz",
+ expect: false,
+ },
+ {
+ scenario: "match against two values for the same key",
+ match: MatchQuery{"debug": []string{"1"}},
+ input: "/?debug=1&debug=2",
+ expect: true,
+ },
+ {
+ scenario: "match against two values for the same key",
+ match: MatchQuery{"debug": []string{"2", "1"}},
+ input: "/?debug=2&debug=1",
+ expect: true,
+ },
} {
u, _ := url.Parse(tc.input)