mirror of
https://github.com/traefik/traefik.git
synced 2026-06-09 08:43:26 -04:00
Use QuoteMeta for cookie name when building canary rules
Some checks failed
CodeQL / Analyze (push) Has been cancelled
Build and Publish Documentation / Doc Process (push) Has been cancelled
Build experimental image on branch / build-webui (push) Has been cancelled
Build experimental image on branch / Build experimental image on branch (push) Has been cancelled
Some checks failed
CodeQL / Analyze (push) Has been cancelled
Build and Publish Documentation / Doc Process (push) Has been cancelled
Build experimental image on branch / build-webui (push) Has been cancelled
Build experimental image on branch / Build experimental image on branch (push) Has been cancelled
This commit is contained in:
parent
7c5b3e8853
commit
2b9ffc4261
3 changed files with 5 additions and 5 deletions
|
|
@ -27,7 +27,7 @@ metadata:
|
|||
namespace: default
|
||||
annotations:
|
||||
nginx.ingress.kubernetes.io/canary: "true"
|
||||
nginx.ingress.kubernetes.io/canary-by-cookie: "foo"
|
||||
nginx.ingress.kubernetes.io/canary-by-cookie: "foo.bar"
|
||||
|
||||
spec:
|
||||
ingressClassName: nginx
|
||||
|
|
|
|||
|
|
@ -147,7 +147,7 @@ func (c canaryBackend) AppendCanaryRule(rule string) string {
|
|||
}
|
||||
|
||||
if c.Cookie != "" {
|
||||
cookieRule := fmt.Sprintf(`HeaderRegexp("Cookie", %q)`, fmt.Sprintf("(^|;\\s*)%s=always(;|$)", c.Cookie))
|
||||
cookieRule := fmt.Sprintf(`HeaderRegexp("Cookie", %q)`, fmt.Sprintf("(^|;\\s*)%s=always(;|$)", regexp.QuoteMeta(c.Cookie)))
|
||||
if c.Header != "" && c.HeaderValue == "" && c.HeaderPattern == "" {
|
||||
cookieRule = fmt.Sprintf("(%s && !%s)", cookieRule, fmt.Sprintf(`Header(%q, "never")`, c.Header))
|
||||
}
|
||||
|
|
@ -165,7 +165,7 @@ func (c canaryBackend) AppendNonCanaryRule(rule string) string {
|
|||
rules = append(rules, fmt.Sprintf(`Header(%q, "never")`, c.Header))
|
||||
}
|
||||
if c.Cookie != "" {
|
||||
rules = append(rules, fmt.Sprintf(`HeaderRegexp("Cookie", %q)`, fmt.Sprintf("(^|;\\s*)%s=never(;|$)", c.Cookie)))
|
||||
rules = append(rules, fmt.Sprintf(`HeaderRegexp("Cookie", %q)`, fmt.Sprintf("(^|;\\s*)%s=never(;|$)", regexp.QuoteMeta(c.Cookie))))
|
||||
}
|
||||
|
||||
return fmt.Sprintf("(%s) && (%s)", rule, strings.Join(rules, " || "))
|
||||
|
|
|
|||
|
|
@ -11070,7 +11070,7 @@ func TestLoadIngresses(t *testing.T) {
|
|||
},
|
||||
"default-ingress-with-canary-by-cookie-rule-0-path-0-canary": {
|
||||
EntryPoints: []string{"http"},
|
||||
Rule: `(Host("production.localhost") && PathPrefix("/")) && (HeaderRegexp("Cookie", "(^|;\\s*)foo=always(;|$)"))`,
|
||||
Rule: `(Host("production.localhost") && PathPrefix("/")) && (HeaderRegexp("Cookie", "(^|;\\s*)foo\\.bar=always(;|$)"))`,
|
||||
RuleSyntax: "default",
|
||||
Service: "default-ingress-with-canary-by-cookie-whoami-80-canary",
|
||||
Observability: &dynamic.RouterObservabilityConfig{
|
||||
|
|
@ -11105,7 +11105,7 @@ func TestLoadIngresses(t *testing.T) {
|
|||
},
|
||||
"default-ingress-with-canary-by-cookie-rule-0-path-0-canary-tls": {
|
||||
EntryPoints: []string{"https"},
|
||||
Rule: `(Host("production.localhost") && PathPrefix("/")) && (HeaderRegexp("Cookie", "(^|;\\s*)foo=always(;|$)"))`,
|
||||
Rule: `(Host("production.localhost") && PathPrefix("/")) && (HeaderRegexp("Cookie", "(^|;\\s*)foo\\.bar=always(;|$)"))`,
|
||||
RuleSyntax: "default",
|
||||
Service: "default-ingress-with-canary-by-cookie-whoami-80-canary",
|
||||
Observability: &dynamic.RouterObservabilityConfig{
|
||||
|
|
|
|||
Loading…
Reference in a new issue