Skip to content

Commit

Permalink
Add e2e tests for secure cookie annotations (#7575) (#7619)
Browse files Browse the repository at this point in the history
Co-authored-by: Agoretti <[email protected]>

Co-authored-by: Agoretti <[email protected]>
  • Loading branch information
RenatoBrittoAraujo and AGoretti authored Sep 12, 2021
1 parent ff2b743 commit 0dbaadf
Showing 1 changed file with 70 additions and 0 deletions.
70 changes: 70 additions & 0 deletions test/e2e/annotations/affinity.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package annotations

import (
"context"
"crypto/tls"
"fmt"
"net/http"
"strings"
Expand Down Expand Up @@ -363,4 +364,73 @@ var _ = framework.DescribeAnnotation("affinity session-cookie-name", func() {
Header("Set-Cookie").Contains("SERVERID=")
})

ginkgo.It("should set secure in cookie with provided true annotation on http", func() {
host := "foo.com"
annotations := make(map[string]string)
annotations["nginx.ingress.kubernetes.io/affinity"] = "cookie"
annotations["nginx.ingress.kubernetes.io/session-cookie-name"] = "SERVERID"
annotations["nginx.ingress.kubernetes.io/session-cookie-secure"] = "true"

ing := framework.NewSingleIngress(host, "/bar", host, f.Namespace, framework.EchoService, 80, annotations)
f.EnsureIngress(ing)

f.WaitForNginxServer(host,
func(server string) bool {
return strings.Contains(server, fmt.Sprintf("server_name %s ;", host))
})

f.HTTPTestClient().
GET("/bar").
WithHeader("Host", host).
Expect().
Status(http.StatusOK).
Header("Set-Cookie").Contains("; Secure")
})

ginkgo.It("should not set secure in cookie with provided false annotation on http", func() {
host := "foo.com"
annotations := make(map[string]string)
annotations["nginx.ingress.kubernetes.io/affinity"] = "cookie"
annotations["nginx.ingress.kubernetes.io/session-cookie-name"] = "SERVERID"
annotations["nginx.ingress.kubernetes.io/session-cookie-secure"] = "false"

ing := framework.NewSingleIngress(host, "/bar", host, f.Namespace, framework.EchoService, 80, annotations)
f.EnsureIngress(ing)

f.WaitForNginxServer(host,
func(server string) bool {
return strings.Contains(server, fmt.Sprintf("server_name %s ;", host))
})

f.HTTPTestClient().
GET("/bar").
WithHeader("Host", host).
Expect().
Status(http.StatusOK).
Header("Set-Cookie").NotContains("; Secure")
})

ginkgo.It("should set secure in cookie with provided false annotation on https", func() {
host := "foo.com"
annotations := make(map[string]string)
annotations["nginx.ingress.kubernetes.io/affinity"] = "cookie"
annotations["nginx.ingress.kubernetes.io/session-cookie-name"] = "SERVERID"
annotations["nginx.ingress.kubernetes.io/session-cookie-secure"] = "false"

f.EnsureIngress(framework.NewSingleIngressWithTLS(host, "/", host, []string{host}, f.Namespace, framework.EchoService, 80, annotations))

f.WaitForNginxServer(host,
func(server string) bool {
return strings.Contains(server, fmt.Sprintf("server_name %s ;", host)) &&
strings.Contains(server, "listen 443")
})

f.HTTPTestClientWithTLSConfig(&tls.Config{ServerName: host, InsecureSkipVerify: true}).
GET("/").
WithURL(f.GetURL(framework.HTTPS)).
WithHeader("Host", host).
Expect().
Status(http.StatusOK).
Header("Set-Cookie").Contains("; Secure")
})
})

0 comments on commit 0dbaadf

Please sign in to comment.