Refactored test/e2e/annotations/proxy.go

This commit is contained in:
Balazs Szekeres 2020-02-27 09:41:27 +01:00
parent d8f84fde6a
commit 6757224996
2 changed files with 150 additions and 89 deletions

View file

@ -17,6 +17,7 @@ limitations under the License.
package annotations
import (
"fmt"
"strings"
"github.com/onsi/ginkgo"
@ -33,211 +34,214 @@ var _ = framework.DescribeAnnotation("proxy-*", func() {
})
ginkgo.It("should set proxy_redirect to off", func() {
annotations := map[string]string{
"nginx.ingress.kubernetes.io/proxy-redirect-from": "off",
"nginx.ingress.kubernetes.io/proxy-redirect-to": "goodbye.com",
}
proxyRedirectFrom := "off"
annotations := make(map[string]string)
annotations["nginx.ingress.kubernetes.io/proxy-redirect-from"] = proxyRedirectFrom
annotations["nginx.ingress.kubernetes.io/proxy-redirect-to"] = "goodbye.com"
ing := framework.NewSingleIngress(host, "/", host, f.Namespace, framework.EchoService, 80, annotations)
f.EnsureIngress(ing)
f.WaitForNginxServer(host,
func(server string) bool {
return strings.Contains(server, "proxy_redirect off;")
return strings.Contains(server, fmt.Sprintf("proxy_redirect %s;", proxyRedirectFrom))
})
})
ginkgo.It("should set proxy_redirect to default", func() {
annotations := map[string]string{
"nginx.ingress.kubernetes.io/proxy-redirect-from": "default",
"nginx.ingress.kubernetes.io/proxy-redirect-to": "goodbye.com",
}
proxyRedirectFrom := "default"
annotations := make(map[string]string)
annotations["nginx.ingress.kubernetes.io/proxy-redirect-from"] = proxyRedirectFrom
annotations["nginx.ingress.kubernetes.io/proxy-redirect-to"] = "goodbye.com"
ing := framework.NewSingleIngress(host, "/", host, f.Namespace, framework.EchoService, 80, annotations)
f.EnsureIngress(ing)
f.WaitForNginxServer(host,
func(server string) bool {
return strings.Contains(server, "proxy_redirect default;")
return strings.Contains(server, fmt.Sprintf("proxy_redirect %s;", proxyRedirectFrom))
})
})
ginkgo.It("should set proxy_redirect to hello.com goodbye.com", func() {
annotations := map[string]string{
"nginx.ingress.kubernetes.io/proxy-redirect-from": "hello.com",
"nginx.ingress.kubernetes.io/proxy-redirect-to": "goodbye.com",
}
proxyRedirectFrom := "hello.com"
proxyRedirectTo := "goodbye.com"
annotations := make(map[string]string)
annotations["nginx.ingress.kubernetes.io/proxy-redirect-from"] = proxyRedirectFrom
annotations["nginx.ingress.kubernetes.io/proxy-redirect-to"] = proxyRedirectTo
ing := framework.NewSingleIngress(host, "/", host, f.Namespace, framework.EchoService, 80, annotations)
f.EnsureIngress(ing)
f.WaitForNginxServer(host,
func(server string) bool {
return strings.Contains(server, "proxy_redirect hello.com goodbye.com;")
return strings.Contains(server, fmt.Sprintf("proxy_redirect %s %s;", proxyRedirectFrom, proxyRedirectTo))
})
})
ginkgo.It("should set proxy client-max-body-size to 8m", func() {
annotations := map[string]string{
"nginx.ingress.kubernetes.io/proxy-body-size": "8m",
}
proxyBodySize := "8m"
annotations := make(map[string]string)
annotations["nginx.ingress.kubernetes.io/proxy-body-size"] = proxyBodySize
ing := framework.NewSingleIngress(host, "/", host, f.Namespace, framework.EchoService, 80, annotations)
f.EnsureIngress(ing)
f.WaitForNginxServer(host,
func(server string) bool {
return strings.Contains(server, "client_max_body_size 8m;")
return strings.Contains(server, fmt.Sprintf("client_max_body_size %s;", proxyBodySize))
})
})
ginkgo.It("should not set proxy client-max-body-size to incorrect value", func() {
annotations := map[string]string{
"nginx.ingress.kubernetes.io/proxy-body-size": "15r",
}
proxyBodySize := "15r"
annotations := make(map[string]string)
annotations["nginx.ingress.kubernetes.io/proxy-body-size"] = proxyBodySize
ing := framework.NewSingleIngress(host, "/", host, f.Namespace, framework.EchoService, 80, annotations)
f.EnsureIngress(ing)
f.WaitForNginxServer(host,
func(server string) bool {
return !strings.Contains(server, "client_max_body_size 15r;")
return !strings.Contains(server, fmt.Sprintf("client_max_body_size %s;", proxyBodySize))
})
})
ginkgo.It("should set valid proxy timeouts", func() {
annotations := map[string]string{
"nginx.ingress.kubernetes.io/proxy-connect-timeout": "50",
"nginx.ingress.kubernetes.io/proxy-send-timeout": "20",
"nginx.ingress.kubernetes.io/proxy-read-timeout": "20",
}
proxyConnectTimeout := "50"
proxySendTimeout := "20"
proxyReadtimeout := "20"
annotations := make(map[string]string)
annotations["nginx.ingress.kubernetes.io/proxy-connect-timeout"] = proxyConnectTimeout
annotations["nginx.ingress.kubernetes.io/proxy-send-timeout"] = proxySendTimeout
annotations["nginx.ingress.kubernetes.io/proxy-read-timeout"] = proxyReadtimeout
ing := framework.NewSingleIngress(host, "/", host, f.Namespace, framework.EchoService, 80, annotations)
f.EnsureIngress(ing)
f.WaitForNginxServer(host,
func(server string) bool {
return strings.Contains(server, "proxy_connect_timeout 50s;") &&
strings.Contains(server, "proxy_send_timeout 20s;") &&
strings.Contains(server, "proxy_read_timeout 20s;")
return strings.Contains(server, fmt.Sprintf("proxy_connect_timeout %ss;", proxyConnectTimeout)) &&
strings.Contains(server, fmt.Sprintf("proxy_send_timeout %ss;", proxySendTimeout)) &&
strings.Contains(server, fmt.Sprintf("proxy_read_timeout %ss;", proxyReadtimeout))
})
})
ginkgo.It("should not set invalid proxy timeouts", func() {
annotations := map[string]string{
"nginx.ingress.kubernetes.io/proxy-connect-timeout": "50k",
"nginx.ingress.kubernetes.io/proxy-send-timeout": "20k",
"nginx.ingress.kubernetes.io/proxy-read-timeout": "20k",
}
proxyConnectTimeout := "50k"
proxySendTimeout := "20k"
proxyReadtimeout := "20k"
annotations := make(map[string]string)
annotations["nginx.ingress.kubernetes.io/proxy-connect-timeout"] = proxyConnectTimeout
annotations["nginx.ingress.kubernetes.io/proxy-send-timeout"] = proxySendTimeout
annotations["nginx.ingress.kubernetes.io/proxy-read-timeout"] = proxyReadtimeout
ing := framework.NewSingleIngress(host, "/", host, f.Namespace, framework.EchoService, 80, annotations)
f.EnsureIngress(ing)
f.WaitForNginxServer(host,
func(server string) bool {
return !strings.Contains(server, "proxy_connect_timeout 50ks;") &&
!strings.Contains(server, "proxy_send_timeout 20ks;") &&
!strings.Contains(server, "proxy_read_timeout 20ks;")
return !strings.Contains(server, fmt.Sprintf("proxy_connect_timeout %ss;", proxyConnectTimeout)) &&
!strings.Contains(server, fmt.Sprintf("proxy_connect_timeout %ss;", proxyConnectTimeout)) &&
!strings.Contains(server, fmt.Sprintf("proxy_connect_timeout %ss;", proxyConnectTimeout))
})
})
ginkgo.It("should turn on proxy-buffering", func() {
annotations := map[string]string{
"nginx.ingress.kubernetes.io/proxy-buffering": "on",
"nginx.ingress.kubernetes.io/proxy-buffers-number": "8",
"nginx.ingress.kubernetes.io/proxy-buffer-size": "8k",
}
proxyBuffering := "on"
proxyBufersNumber := "8"
proxyBufferSize := "8k"
annotations := make(map[string]string)
annotations["nginx.ingress.kubernetes.io/proxy-buffering"] = proxyBuffering
annotations["nginx.ingress.kubernetes.io/proxy-buffers-number"] = proxyBufersNumber
annotations["nginx.ingress.kubernetes.io/proxy-buffer-size"] = proxyBufferSize
ing := framework.NewSingleIngress(host, "/", host, f.Namespace, framework.EchoService, 80, annotations)
f.EnsureIngress(ing)
f.WaitForNginxServer(host,
func(server string) bool {
return strings.Contains(server, "proxy_buffering on;") &&
strings.Contains(server, "proxy_buffer_size 8k;") &&
strings.Contains(server, "proxy_buffers 8 8k;") &&
strings.Contains(server, "proxy_request_buffering on;")
return strings.Contains(server, fmt.Sprintf("proxy_buffering %s;", proxyBuffering)) &&
strings.Contains(server, fmt.Sprintf("proxy_buffer_size %s;", proxyBufferSize)) &&
strings.Contains(server, fmt.Sprintf("proxy_buffers %s %s;", proxyBufersNumber, proxyBufferSize)) &&
strings.Contains(server, fmt.Sprintf("proxy_request_buffering %s;", proxyBuffering))
})
})
ginkgo.It("should turn off proxy-request-buffering", func() {
annotations := map[string]string{
"nginx.ingress.kubernetes.io/proxy-request-buffering": "off",
}
proxyRequestBuffering := "off"
annotations := make(map[string]string)
annotations["nginx.ingress.kubernetes.io/proxy-request-buffering"] = proxyRequestBuffering
ing := framework.NewSingleIngress(host, "/", host, f.Namespace, framework.EchoService, 80, annotations)
f.EnsureIngress(ing)
f.WaitForNginxServer(host,
func(server string) bool {
return strings.Contains(server, "proxy_request_buffering off;")
return strings.Contains(server, fmt.Sprintf("proxy_request_buffering %s;", proxyRequestBuffering))
})
})
ginkgo.It("should build proxy next upstream", func() {
annotations := map[string]string{
"nginx.ingress.kubernetes.io/proxy-next-upstream": "error timeout http_502",
"nginx.ingress.kubernetes.io/proxy-next-upstream-timeout": "999999",
"nginx.ingress.kubernetes.io/proxy-next-upstream-tries": "888888",
}
proxyNextUpstream := "error timeout http_502"
proxyNextUpstreamTimeout := "999999"
proxyNextUpstreamTries := "888888"
annotations := make(map[string]string)
annotations["nginx.ingress.kubernetes.io/proxy-next-upstream"] = proxyNextUpstream
annotations["nginx.ingress.kubernetes.io/proxy-next-upstream-timeout"] = proxyNextUpstreamTimeout
annotations["nginx.ingress.kubernetes.io/proxy-next-upstream-tries"] = proxyNextUpstreamTries
ing := framework.NewSingleIngress(host, "/", host, f.Namespace, framework.EchoService, 80, annotations)
f.EnsureIngress(ing)
f.WaitForNginxServer(host,
func(server string) bool {
return strings.Contains(server, "error timeout http_502;") &&
strings.Contains(server, "999999;") &&
strings.Contains(server, "888888;")
})
})
ginkgo.It("should build proxy next upstream using configmap values", func() {
annotations := map[string]string{}
ing := framework.NewSingleIngress(host, "/", host, f.Namespace, framework.EchoService, 80, annotations)
f.EnsureIngress(ing)
f.SetNginxConfigMapData(map[string]string{
"proxy-next-upstream": "timeout http_502",
"proxy-next-upstream-timeout": "999999",
"proxy-next-upstream-tries": "888888",
})
f.WaitForNginxServer(host,
func(server string) bool {
return strings.Contains(server, "timeout http_502;") &&
strings.Contains(server, "999999;") &&
strings.Contains(server, "888888;")
return strings.Contains(server, fmt.Sprintf("proxy_next_upstream %s;", proxyNextUpstream)) &&
strings.Contains(server, fmt.Sprintf("proxy_next_upstream_timeout %s;", proxyNextUpstreamTimeout)) &&
strings.Contains(server, fmt.Sprintf("proxy_next_upstream_tries %s;", proxyNextUpstreamTries))
})
})
ginkgo.It("should setup proxy cookies", func() {
annotations := map[string]string{
"nginx.ingress.kubernetes.io/proxy-cookie-domain": "localhost example.org",
"nginx.ingress.kubernetes.io/proxy-cookie-path": "/one/ /",
}
proxyCookieDomain := "localhost example.org"
proxyCookiePath := "/one/ /"
annotations := make(map[string]string)
annotations["nginx.ingress.kubernetes.io/proxy-cookie-domain"] = proxyCookieDomain
annotations["nginx.ingress.kubernetes.io/proxy-cookie-path"] = proxyCookiePath
ing := framework.NewSingleIngress(host, "/", host, f.Namespace, framework.EchoService, 80, annotations)
f.EnsureIngress(ing)
f.WaitForNginxServer(host,
func(server string) bool {
return strings.Contains(server, "proxy_cookie_domain localhost example.org;") &&
strings.Contains(server, "proxy_cookie_path /one/ /;")
return strings.Contains(server, fmt.Sprintf("proxy_cookie_domain %s;", proxyCookieDomain)) &&
strings.Contains(server, fmt.Sprintf("proxy_cookie_path %s;", proxyCookiePath))
})
})
ginkgo.It("should change the default proxy HTTP version", func() {
annotations := map[string]string{
"nginx.ingress.kubernetes.io/proxy-http-version": "1.0",
}
proxyHTTPVersion := "1.0"
annotations := make(map[string]string)
annotations["nginx.ingress.kubernetes.io/proxy-http-version"] = proxyHTTPVersion
ing := framework.NewSingleIngress(host, "/", host, f.Namespace, framework.EchoService, 80, annotations)
f.EnsureIngress(ing)
f.WaitForNginxServer(host,
func(server string) bool {
return strings.Contains(server, "proxy_http_version 1.0;")
return strings.Contains(server, fmt.Sprintf("proxy_http_version %s;", proxyHTTPVersion))
})
})