Add annotation for session affinity path

This commit is contained in:
Zenara Daley 2018-11-19 09:15:24 -05:00
parent d53b492d73
commit 50b29feb4a
8 changed files with 105 additions and 7 deletions

View file

@ -223,4 +223,65 @@ var _ = framework.IngressNginxDescribe("Annotations - Affinity/Sticky Sessions",
Expect(resp.Header.Get("Set-Cookie")).Should(ContainSubstring(fmt.Sprintf("Expires=%s", expected)))
Expect(resp.Header.Get("Set-Cookie")).Should(ContainSubstring("Max-Age=259200"))
})
It("should work with use-regex annotation and session-cookie-path", func() {
host := "cookie.foo.com"
annotations := map[string]string{
"nginx.ingress.kubernetes.io/affinity": "cookie",
"nginx.ingress.kubernetes.io/session-cookie-name": "SERVERID",
"nginx.ingress.kubernetes.io/use-regex": "true",
"nginx.ingress.kubernetes.io/session-cookie-path": "/foo/bar",
}
ing := framework.NewSingleIngress(host, "/foo/.*", host, f.IngressController.Namespace, "http-svc", 80, &annotations)
f.EnsureIngress(ing)
f.WaitForNginxServer(host,
func(server string) bool {
return strings.Contains(server, fmt.Sprintf("server_name %s ;", host))
})
resp, _, errs := gorequest.New().
Get(f.IngressController.HTTPURL+"/foo/bar").
Set("Host", host).
End()
md5Regex := regexp.MustCompile("SERVERID=[0-9a-f]{32}")
match := md5Regex.FindStringSubmatch(resp.Header.Get("Set-Cookie"))
Expect(len(match)).Should(BeNumerically("==", 1))
Expect(errs).Should(BeEmpty())
Expect(resp.StatusCode).Should(Equal(http.StatusOK))
Expect(resp.Header.Get("Set-Cookie")).Should(ContainSubstring(match[0]))
Expect(resp.Header.Get("Set-Cookie")).Should(ContainSubstring("Path=/foo/bar"))
})
It("should warn user when use-regex is true and session-cookie-path is not set", func() {
host := "cookie.foo.com"
annotations := map[string]string{
"nginx.ingress.kubernetes.io/affinity": "cookie",
"nginx.ingress.kubernetes.io/session-cookie-name": "SERVERID",
"nginx.ingress.kubernetes.io/use-regex": "true",
}
ing := framework.NewSingleIngress(host, "/foo/.*", host, f.IngressController.Namespace, "http-svc", 80, &annotations)
f.EnsureIngress(ing)
f.WaitForNginxServer(host,
func(server string) bool {
return strings.Contains(server, fmt.Sprintf("server_name %s ;", host))
})
resp, _, errs := gorequest.New().
Get(f.IngressController.HTTPURL+"/foo/bar").
Set("Host", host).
End()
Expect(errs).Should(BeEmpty())
Expect(resp.StatusCode).Should(Equal(http.StatusOK))
logs, err := f.NginxLogs()
Expect(err).ToNot(HaveOccurred())
Expect(logs).To(ContainSubstring(`session-cookie-path should be set when use-regex is true`))
})
})