Refactor e2e tests to use testify y httpexpect

This commit is contained in:
Manuel Alejandro de Brito Fontes 2020-02-19 00:08:56 -03:00
parent 046e2d959d
commit f9624cbe46
80 changed files with 2280 additions and 2631 deletions

View file

@ -22,10 +22,8 @@ import (
"strings"
"time"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/parnurzeal/gorequest"
"github.com/onsi/ginkgo"
"github.com/stretchr/testify/assert"
networking "k8s.io/api/networking/v1beta1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/intstr"
@ -36,11 +34,11 @@ import (
var _ = framework.DescribeAnnotation("affinity session-cookie-name", func() {
f := framework.NewDefaultFramework("affinity")
BeforeEach(func() {
ginkgo.BeforeEach(func() {
f.NewEchoDeploymentWithReplicas(2)
})
It("should set sticky cookie SERVERID", func() {
ginkgo.It("should set sticky cookie SERVERID", func() {
host := "sticky.foo.com"
annotations := map[string]string{
"nginx.ingress.kubernetes.io/affinity": "cookie",
@ -55,17 +53,15 @@ var _ = framework.DescribeAnnotation("affinity session-cookie-name", func() {
return strings.Contains(server, fmt.Sprintf("server_name %s ;", host))
})
resp, _, errs := gorequest.New().
Get(f.GetURL(framework.HTTP)).
Set("Host", host).
End()
Expect(errs).Should(BeEmpty())
Expect(resp.StatusCode).Should(Equal(http.StatusOK))
Expect(resp.Header.Get("Set-Cookie")).Should(ContainSubstring("SERVERID="))
f.HTTPTestClient().
GET("/").
WithHeader("Host", host).
Expect().
Status(http.StatusOK).
Header("Set-Cookie").Contains("SERVERID=")
})
It("should change cookie name on ingress definition change", func() {
ginkgo.It("should change cookie name on ingress definition change", func() {
host := "change.foo.com"
annotations := map[string]string{
"nginx.ingress.kubernetes.io/affinity": "cookie",
@ -80,29 +76,28 @@ var _ = framework.DescribeAnnotation("affinity session-cookie-name", func() {
return strings.Contains(server, fmt.Sprintf("server_name %s ;", host))
})
resp, _, errs := gorequest.New().
Get(f.GetURL(framework.HTTP)).
Set("Host", host).
End()
Expect(errs).Should(BeEmpty())
Expect(resp.StatusCode).Should(Equal(http.StatusOK))
Expect(resp.Header.Get("Set-Cookie")).Should(ContainSubstring("SERVERID"))
f.HTTPTestClient().
GET("/").
WithHeader("Host", host).
Expect().
Status(http.StatusOK).
Header("Set-Cookie").Contains("SERVERID")
ing.ObjectMeta.Annotations["nginx.ingress.kubernetes.io/session-cookie-name"] = "OTHERCOOKIENAME"
f.EnsureIngress(ing)
resp, _, errs = gorequest.New().
Get(f.GetURL(framework.HTTP)).
Set("Host", host).
End()
_, err := f.KubeClientSet.NetworkingV1beta1().Ingresses(f.Namespace).Update(ing)
assert.Nil(ginkgo.GinkgoT(), err, "updating ingress")
time.Sleep(5 * time.Second)
Expect(errs).Should(BeEmpty())
Expect(resp.StatusCode).Should(Equal(http.StatusOK))
Expect(resp.Header.Get("Set-Cookie")).Should(ContainSubstring("OTHERCOOKIENAME"))
f.HTTPTestClient().
GET("/").
WithHeader("Host", host).
Expect().
Status(http.StatusOK).
Header("Set-Cookie").Contains("OTHERCOOKIENAME")
})
It("should set the path to /something on the generated cookie", func() {
ginkgo.It("should set the path to /something on the generated cookie", func() {
host := "path.foo.com"
annotations := map[string]string{
"nginx.ingress.kubernetes.io/affinity": "cookie",
@ -117,17 +112,15 @@ var _ = framework.DescribeAnnotation("affinity session-cookie-name", func() {
return strings.Contains(server, fmt.Sprintf("server_name %s ;", host))
})
resp, _, errs := gorequest.New().
Get(f.GetURL(framework.HTTP)+"/something").
Set("Host", host).
End()
Expect(errs).Should(BeEmpty())
Expect(resp.StatusCode).Should(Equal(http.StatusOK))
Expect(resp.Header.Get("Set-Cookie")).Should(ContainSubstring("Path=/something"))
f.HTTPTestClient().
GET("/something").
WithHeader("Host", host).
Expect().
Status(http.StatusOK).
Header("Set-Cookie").Contains("Path=/something")
})
It("does not set the path to / on the generated cookie if there's more than one rule referring to the same backend", func() {
ginkgo.It("does not set the path to / on the generated cookie if there's more than one rule referring to the same backend", func() {
host := "morethanonerule.foo.com"
annotations := map[string]string{
"nginx.ingress.kubernetes.io/affinity": "cookie",
@ -174,26 +167,22 @@ var _ = framework.DescribeAnnotation("affinity session-cookie-name", func() {
return strings.Contains(server, fmt.Sprintf("server_name %s ;", host))
})
resp, _, errs := gorequest.New().
Get(f.GetURL(framework.HTTP)+"/something").
Set("Host", host).
End()
f.HTTPTestClient().
GET("/something").
WithHeader("Host", host).
Expect().
Status(http.StatusOK).
Header("Set-Cookie").Contains("Path=/something")
Expect(errs).Should(BeEmpty())
Expect(resp.StatusCode).Should(Equal(http.StatusOK))
Expect(resp.Header.Get("Set-Cookie")).Should(ContainSubstring("Path=/something;"))
resp, _, errs = gorequest.New().
Get(f.GetURL(framework.HTTP)+"/somewhereelese").
Set("Host", host).
End()
Expect(errs).Should(BeEmpty())
Expect(resp.StatusCode).Should(Equal(http.StatusOK))
Expect(resp.Header.Get("Set-Cookie")).Should(ContainSubstring("Path=/somewhereelese;"))
f.HTTPTestClient().
GET("/somewhereelese").
WithHeader("Host", host).
Expect().
Status(http.StatusOK).
Header("Set-Cookie").Contains("Path=/somewhereelese")
})
It("should set cookie with expires", func() {
ginkgo.It("should set cookie with expires", func() {
host := "cookieexpires.foo.com"
annotations := map[string]string{
"nginx.ingress.kubernetes.io/affinity": "cookie",
@ -210,25 +199,22 @@ var _ = framework.DescribeAnnotation("affinity session-cookie-name", func() {
return strings.Contains(server, fmt.Sprintf("server_name %s ;", host))
})
resp, _, errs := gorequest.New().
Get(f.GetURL(framework.HTTP)).
Set("Host", host).
End()
Expect(errs).Should(BeEmpty())
Expect(resp.StatusCode).Should(Equal(http.StatusOK))
local, err := time.LoadLocation("GMT")
Expect(err).ToNot(HaveOccurred())
Expect(local).ShouldNot(BeNil())
assert.Nil(ginkgo.GinkgoT(), err, "loading GMT location")
assert.NotNil(ginkgo.GinkgoT(), local, "expected a location but none returned")
duration, _ := time.ParseDuration("48h")
expected := time.Now().In(local).Add(duration).Format("Mon, 02-Jan-06 15:04")
Expect(resp.Header.Get("Set-Cookie")).Should(ContainSubstring(fmt.Sprintf("Expires=%s", expected)))
Expect(resp.Header.Get("Set-Cookie")).Should(ContainSubstring("Max-Age=259200"))
f.HTTPTestClient().
GET("/").
WithHeader("Host", host).
Expect().
Status(http.StatusOK).
Header("Set-Cookie").Contains(fmt.Sprintf("Expires=%s", expected)).Contains("Max-Age=259200")
})
It("should work with use-regex annotation and session-cookie-path", func() {
ginkgo.It("should work with use-regex annotation and session-cookie-path", func() {
host := "useregex.foo.com"
annotations := map[string]string{
"nginx.ingress.kubernetes.io/affinity": "cookie",
@ -245,18 +231,15 @@ var _ = framework.DescribeAnnotation("affinity session-cookie-name", func() {
return strings.Contains(server, fmt.Sprintf("server_name %s ;", host))
})
resp, _, errs := gorequest.New().
Get(f.GetURL(framework.HTTP)+"/foo/bar").
Set("Host", host).
End()
Expect(errs).Should(BeEmpty())
Expect(resp.StatusCode).Should(Equal(http.StatusOK))
Expect(resp.Header.Get("Set-Cookie")).Should(ContainSubstring("SERVERID="))
Expect(resp.Header.Get("Set-Cookie")).Should(ContainSubstring("Path=/foo/bar"))
f.HTTPTestClient().
GET("/foo/bar").
WithHeader("Host", host).
Expect().
Status(http.StatusOK).
Header("Set-Cookie").Contains("Path=/foo/bar").Contains("SERVERID=")
})
It("should warn user when use-regex is true and session-cookie-path is not set", func() {
ginkgo.It("should warn user when use-regex is true and session-cookie-path is not set", func() {
host := "useregexwarn.foo.com"
annotations := map[string]string{
"nginx.ingress.kubernetes.io/affinity": "cookie",
@ -272,20 +255,18 @@ var _ = framework.DescribeAnnotation("affinity session-cookie-name", func() {
return strings.Contains(server, fmt.Sprintf("server_name %s ;", host))
})
resp, _, errs := gorequest.New().
Get(f.GetURL(framework.HTTP)+"/foo/bar").
Set("Host", host).
End()
Expect(errs).Should(BeEmpty())
Expect(resp.StatusCode).Should(Equal(http.StatusOK))
f.HTTPTestClient().
GET("/foo/bar").
WithHeader("Host", host).
Expect().
Status(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`))
assert.Nil(ginkgo.GinkgoT(), err, "obtaining nginx logs")
assert.Contains(ginkgo.GinkgoT(), logs, `session-cookie-path should be set when use-regex is true`)
})
It("should not set affinity across all server locations when using separate ingresses", func() {
ginkgo.It("should not set affinity across all server locations when using separate ingresses", func() {
host := "separate.foo.com"
annotations := map[string]string{
@ -302,26 +283,22 @@ var _ = framework.DescribeAnnotation("affinity session-cookie-name", func() {
return strings.Contains(server, `location /foo/bar`) && strings.Contains(server, `location /foo`)
})
resp, _, errs := gorequest.New().
Get(f.GetURL(framework.HTTP)+"/foo").
Set("Host", host).
End()
f.HTTPTestClient().
GET("/foo").
WithHeader("Host", host).
Expect().
Status(http.StatusOK).
Header("Set-Cookie").Empty()
Expect(errs).Should(BeEmpty())
Expect(resp.StatusCode).Should(Equal(http.StatusOK))
Expect(resp.Header.Get("Set-Cookie")).Should(Equal(""))
resp, _, errs = gorequest.New().
Get(f.GetURL(framework.HTTP)+"/foo/bar").
Set("Host", host).
End()
Expect(errs).Should(BeEmpty())
Expect(resp.StatusCode).Should(Equal(http.StatusOK))
Expect(resp.Header.Get("Set-Cookie")).Should(ContainSubstring("Path=/foo/bar"))
f.HTTPTestClient().
GET("/foo/bar").
WithHeader("Host", host).
Expect().
Status(http.StatusOK).
Header("Set-Cookie").Contains("Path=/foo/bar")
})
It("should set sticky cookie without host", func() {
ginkgo.It("should set sticky cookie without host", func() {
annotations := map[string]string{
"nginx.ingress.kubernetes.io/affinity": "cookie",
"nginx.ingress.kubernetes.io/session-cookie-name": "SERVERID",
@ -335,12 +312,10 @@ var _ = framework.DescribeAnnotation("affinity session-cookie-name", func() {
return strings.Contains(server, "server_name _")
})
resp, _, errs := gorequest.New().
Get(f.GetURL(framework.HTTP)).
End()
Expect(errs).Should(BeEmpty())
Expect(resp.StatusCode).Should(Equal(http.StatusOK))
Expect(resp.Header.Get("Set-Cookie")).Should(ContainSubstring("SERVERID="))
f.HTTPTestClient().
GET("/").
Expect().
Status(http.StatusOK).
Header("Set-Cookie").Contains("SERVERID=")
})
})

View file

@ -19,10 +19,9 @@ package annotations
import (
"fmt"
"net/http"
"strings"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/parnurzeal/gorequest"
"github.com/onsi/ginkgo"
"k8s.io/ingress-nginx/test/e2e/framework"
)
@ -30,42 +29,37 @@ import (
var _ = framework.DescribeAnnotation("server-alias", func() {
f := framework.NewDefaultFramework("alias")
BeforeEach(func() {
ginkgo.BeforeEach(func() {
f.NewEchoDeployment()
})
It("should return status code 200 for host 'foo' and 404 for 'bar'", func() {
ginkgo.It("should return status code 200 for host 'foo' and 404 for 'bar'", func() {
host := "foo"
annotations := map[string]string{}
ing := framework.NewSingleIngress(host, "/", host, f.Namespace, framework.EchoService, 80, annotations)
ing := framework.NewSingleIngress(host, "/", host, f.Namespace, framework.EchoService, 80, nil)
f.EnsureIngress(ing)
f.WaitForNginxServer(host,
func(server string) bool {
return Expect(server).Should(ContainSubstring("server_name foo"))
return strings.Contains(server, fmt.Sprintf("server_name %v", host))
})
resp, body, errs := gorequest.New().
Get(f.GetURL(framework.HTTP)).
Set("Host", host).
End()
f.HTTPTestClient().
GET("/").
WithHeader("Host", host).
Expect().
Status(http.StatusOK).
Body().Contains(fmt.Sprintf("host=%v", host))
Expect(errs).Should(BeEmpty())
Expect(resp.StatusCode).Should(Equal(http.StatusOK))
Expect(body).Should(ContainSubstring(fmt.Sprintf("host=%v", host)))
resp, body, errs = gorequest.New().
Get(f.GetURL(framework.HTTP)).
Set("Host", "bar").
End()
Expect(errs).Should(BeEmpty())
Expect(resp.StatusCode).Should(Equal(http.StatusNotFound))
Expect(body).Should(ContainSubstring("404 Not Found"))
f.HTTPTestClient().
GET("/").
WithHeader("Host", "bar").
Expect().
Status(http.StatusNotFound).
Body().Contains("404 Not Found")
})
It("should return status code 200 for host 'foo' and 'bar'", func() {
ginkgo.It("should return status code 200 for host 'foo' and 'bar'", func() {
host := "foo"
annotations := map[string]string{
"nginx.ingress.kubernetes.io/server-alias": "bar",
@ -76,19 +70,17 @@ var _ = framework.DescribeAnnotation("server-alias", func() {
f.WaitForNginxServer(host,
func(server string) bool {
return Expect(server).Should(ContainSubstring("server_name foo"))
return strings.Contains(server, fmt.Sprintf("server_name %v", host))
})
hosts := []string{"foo", "bar"}
for _, host := range hosts {
resp, body, errs := gorequest.New().
Get(f.GetURL(framework.HTTP)).
Set("Host", host).
End()
Expect(errs).Should(BeEmpty())
Expect(resp.StatusCode).Should(Equal(http.StatusOK))
Expect(body).Should(ContainSubstring(fmt.Sprintf("host=%v", host)))
f.HTTPTestClient().
GET("/").
WithHeader("Host", host).
Expect().
Status(http.StatusOK).
Body().Contains(fmt.Sprintf("host=%v", host))
}
})
})

View file

@ -18,22 +18,21 @@ package annotations
import (
"net/http"
"time"
"strings"
"github.com/onsi/ginkgo"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/parnurzeal/gorequest"
"k8s.io/ingress-nginx/test/e2e/framework"
)
var _ = framework.DescribeAnnotation("app-root", func() {
f := framework.NewDefaultFramework("approot")
BeforeEach(func() {
f.NewEchoDeploymentWithReplicas(2)
ginkgo.BeforeEach(func() {
f.NewEchoDeployment()
})
It("should redirect to /foo", func() {
ginkgo.It("should redirect to /foo", func() {
host := "approot.bar.com"
annotations := map[string]string{
@ -45,19 +44,15 @@ var _ = framework.DescribeAnnotation("app-root", func() {
f.WaitForNginxServer(host,
func(server string) bool {
return Expect(server).Should(ContainSubstring(`if ($uri = /) {`)) &&
Expect(server).Should(ContainSubstring(`return 302 /foo;`))
return strings.Contains(server, `if ($uri = /) {`) &&
strings.Contains(server, `return 302 /foo;`)
})
resp, _, errs := gorequest.New().
Get(f.GetURL(framework.HTTP)).
Retry(10, 1*time.Second, http.StatusNotFound).
RedirectPolicy(noRedirectPolicyFunc).
Set("Host", host).
End()
Expect(errs).Should(BeEmpty())
Expect(resp.StatusCode).Should(Equal(http.StatusFound))
Expect(resp.Header.Get("Location")).Should(Equal("http://approot.bar.com/foo"))
f.HTTPTestClient().
GET("/").
WithHeader("Host", host).
Expect().
Status(http.StatusFound).
Header("Location").Equal("http://approot.bar.com/foo")
})
})

View file

@ -21,11 +21,11 @@ import (
"net/http"
"net/url"
"os/exec"
"time"
"regexp"
"strings"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/parnurzeal/gorequest"
"github.com/onsi/ginkgo"
"github.com/stretchr/testify/assert"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@ -36,14 +36,11 @@ import (
var _ = framework.DescribeAnnotation("auth-*", func() {
f := framework.NewDefaultFramework("auth")
BeforeEach(func() {
ginkgo.BeforeEach(func() {
f.NewEchoDeployment()
})
AfterEach(func() {
})
It("should return status code 200 when no authentication is configured", func() {
ginkgo.It("should return status code 200 when no authentication is configured", func() {
host := "auth"
ing := framework.NewSingleIngress(host, "/", host, f.Namespace, framework.EchoService, 80, nil)
@ -51,21 +48,18 @@ var _ = framework.DescribeAnnotation("auth-*", func() {
f.WaitForNginxServer(host,
func(server string) bool {
return Expect(server).Should(ContainSubstring("server_name auth"))
return strings.Contains(server, "server_name auth")
})
resp, body, errs := gorequest.New().
Get(f.GetURL(framework.HTTP)).
Retry(10, 1*time.Second, http.StatusNotFound).
Set("Host", host).
End()
Expect(errs).Should(BeEmpty())
Expect(resp.StatusCode).Should(Equal(http.StatusOK))
Expect(body).Should(ContainSubstring(fmt.Sprintf("host=%v", host)))
f.HTTPTestClient().
GET("/").
WithHeader("Host", host).
Expect().
Status(http.StatusOK).
Body().Contains(fmt.Sprintf("host=%v", host))
})
It("should return status code 503 when authentication is configured with an invalid secret", func() {
ginkgo.It("should return status code 503 when authentication is configured with an invalid secret", func() {
host := "auth"
annotations := map[string]string{
"nginx.ingress.kubernetes.io/auth-type": "basic",
@ -78,21 +72,18 @@ var _ = framework.DescribeAnnotation("auth-*", func() {
f.WaitForNginxServer(host,
func(server string) bool {
return Expect(server).Should(ContainSubstring("server_name auth"))
return strings.Contains(server, "server_name auth")
})
resp, body, errs := gorequest.New().
Get(f.GetURL(framework.HTTP)).
Retry(10, 1*time.Second, http.StatusNotFound).
Set("Host", host).
End()
Expect(errs).Should(BeEmpty())
Expect(resp.StatusCode).Should(Equal(http.StatusServiceUnavailable))
Expect(body).Should(ContainSubstring("503 Service Temporarily Unavailable"))
f.HTTPTestClient().
GET("/").
WithHeader("Host", host).
Expect().
Status(http.StatusServiceUnavailable).
Body().Contains("503 Service Temporarily Unavailable")
})
It("should return status code 401 when authentication is configured but Authorization header is not configured", func() {
ginkgo.It("should return status code 401 when authentication is configured but Authorization header is not configured", func() {
host := "auth"
s := f.EnsureSecret(buildSecret("foo", "bar", "test", f.Namespace))
@ -108,21 +99,18 @@ var _ = framework.DescribeAnnotation("auth-*", func() {
f.WaitForNginxServer(host,
func(server string) bool {
return Expect(server).Should(ContainSubstring("server_name auth"))
return strings.Contains(server, "server_name auth")
})
resp, body, errs := gorequest.New().
Get(f.GetURL(framework.HTTP)).
Retry(10, 1*time.Second, http.StatusNotFound).
Set("Host", host).
End()
Expect(errs).Should(BeEmpty())
Expect(resp.StatusCode).Should(Equal(http.StatusUnauthorized))
Expect(body).Should(ContainSubstring("401 Authorization Required"))
f.HTTPTestClient().
GET("/").
WithHeader("Host", host).
Expect().
Status(http.StatusUnauthorized).
Body().Contains("401 Authorization Required")
})
It("should return status code 401 when authentication is configured and Authorization header is sent with invalid credentials", func() {
ginkgo.It("should return status code 401 when authentication is configured and Authorization header is sent with invalid credentials", func() {
host := "auth"
s := f.EnsureSecret(buildSecret("foo", "bar", "test", f.Namespace))
@ -138,22 +126,19 @@ var _ = framework.DescribeAnnotation("auth-*", func() {
f.WaitForNginxServer(host,
func(server string) bool {
return Expect(server).Should(ContainSubstring("server_name auth"))
return strings.Contains(server, "server_name auth")
})
resp, body, errs := gorequest.New().
Get(f.GetURL(framework.HTTP)).
Retry(10, 1*time.Second, http.StatusNotFound).
Set("Host", host).
SetBasicAuth("user", "pass").
End()
Expect(errs).Should(BeEmpty())
Expect(resp.StatusCode).Should(Equal(http.StatusUnauthorized))
Expect(body).Should(ContainSubstring("401 Authorization Required"))
f.HTTPTestClient().
GET("/").
WithHeader("Host", host).
WithBasicAuth("user", "pass").
Expect().
Status(http.StatusUnauthorized).
Body().Contains("401 Authorization Required")
})
It("should return status code 200 when authentication is configured and Authorization header is sent", func() {
ginkgo.It("should return status code 200 when authentication is configured and Authorization header is sent", func() {
host := "auth"
s := f.EnsureSecret(buildSecret("foo", "bar", "test", f.Namespace))
@ -169,21 +154,18 @@ var _ = framework.DescribeAnnotation("auth-*", func() {
f.WaitForNginxServer(host,
func(server string) bool {
return Expect(server).Should(ContainSubstring("server_name auth"))
return strings.Contains(server, "server_name auth")
})
resp, _, errs := gorequest.New().
Get(f.GetURL(framework.HTTP)).
Retry(10, 1*time.Second, http.StatusNotFound).
Set("Host", host).
SetBasicAuth("foo", "bar").
End()
Expect(errs).Should(BeEmpty())
Expect(resp.StatusCode).Should(Equal(http.StatusOK))
f.HTTPTestClient().
GET("/").
WithHeader("Host", host).
WithBasicAuth("foo", "bar").
Expect().
Status(http.StatusOK)
})
It("should return status code 200 when authentication is configured with a map and Authorization header is sent", func() {
ginkgo.It("should return status code 200 when authentication is configured with a map and Authorization header is sent", func() {
host := "auth"
s := f.EnsureSecret(buildMapSecret("foo", "bar", "test", f.Namespace))
@ -200,21 +182,18 @@ var _ = framework.DescribeAnnotation("auth-*", func() {
f.WaitForNginxServer(host,
func(server string) bool {
return Expect(server).Should(ContainSubstring("server_name auth"))
return strings.Contains(server, "server_name auth")
})
resp, _, errs := gorequest.New().
Get(f.GetURL(framework.HTTP)).
Retry(10, 1*time.Second, http.StatusNotFound).
Set("Host", host).
SetBasicAuth("foo", "bar").
End()
Expect(errs).Should(BeEmpty())
Expect(resp.StatusCode).Should(Equal(http.StatusOK))
f.HTTPTestClient().
GET("/").
WithHeader("Host", host).
WithBasicAuth("foo", "bar").
Expect().
Status(http.StatusOK)
})
It("should return status code 401 when authentication is configured with invalid content and Authorization header is sent", func() {
ginkgo.It("should return status code 401 when authentication is configured with invalid content and Authorization header is sent", func() {
host := "auth"
s := f.EnsureSecret(
@ -242,21 +221,18 @@ var _ = framework.DescribeAnnotation("auth-*", func() {
f.WaitForNginxServer(host,
func(server string) bool {
return Expect(server).Should(ContainSubstring("server_name auth"))
return strings.Contains(server, "server_name auth")
})
resp, _, errs := gorequest.New().
Get(f.GetURL(framework.HTTP)).
Retry(10, 1*time.Second, http.StatusNotFound).
Set("Host", host).
SetBasicAuth("foo", "bar").
End()
Expect(errs).Should(BeEmpty())
Expect(resp.StatusCode).Should(Equal(http.StatusUnauthorized))
f.HTTPTestClient().
GET("/").
WithHeader("Host", host).
WithBasicAuth("foo", "bar").
Expect().
Status(http.StatusUnauthorized)
})
It(`should set snippet "proxy_set_header My-Custom-Header 42;" when external auth is configured`, func() {
ginkgo.It(`should set snippet "proxy_set_header My-Custom-Header 42;" when external auth is configured`, func() {
host := "auth"
annotations := map[string]string{
@ -270,11 +246,11 @@ var _ = framework.DescribeAnnotation("auth-*", func() {
f.WaitForNginxServer(host,
func(server string) bool {
return Expect(server).Should(ContainSubstring(`proxy_set_header My-Custom-Header 42;`))
return strings.Contains(server, `proxy_set_header My-Custom-Header 42;`)
})
})
It(`should not set snippet "proxy_set_header My-Custom-Header 42;" when external auth is not configured`, func() {
ginkgo.It(`should not set snippet "proxy_set_header My-Custom-Header 42;" when external auth is not configured`, func() {
host := "auth"
annotations := map[string]string{
@ -287,11 +263,11 @@ var _ = framework.DescribeAnnotation("auth-*", func() {
f.WaitForNginxServer(host,
func(server string) bool {
return Expect(server).ShouldNot(ContainSubstring(`proxy_set_header My-Custom-Header 42;`))
return !strings.Contains(server, `proxy_set_header My-Custom-Header 42;`)
})
})
It(`should set "proxy_set_header 'My-Custom-Header' '42';" when auth-headers are set`, func() {
ginkgo.It(`should set "proxy_set_header 'My-Custom-Header' '42';" when auth-headers are set`, func() {
host := "auth"
annotations := map[string]string{
@ -308,11 +284,11 @@ var _ = framework.DescribeAnnotation("auth-*", func() {
f.WaitForNginxServer(host,
func(server string) bool {
return Expect(server).Should(ContainSubstring(`proxy_set_header 'My-Custom-Header' '42';`))
return strings.Contains(server, `proxy_set_header 'My-Custom-Header' '42';`)
})
})
It(`should set cache_key when external auth cache is configured`, func() {
ginkgo.It(`should set cache_key when external auth cache is configured`, func() {
host := "auth"
annotations := map[string]string{
@ -324,16 +300,18 @@ var _ = framework.DescribeAnnotation("auth-*", func() {
ing := framework.NewSingleIngress(host, "/", host, f.Namespace, framework.EchoService, 80, annotations)
f.EnsureIngress(ing)
cacheRegex := regexp.MustCompile(`\$cache_key.*foo`)
f.WaitForNginxServer(host,
func(server string) bool {
return Expect(server).Should(MatchRegexp(`\$cache_key.*foo`)) &&
Expect(server).Should(ContainSubstring(`proxy_cache_valid 200 202 401 30m;`))
return cacheRegex.MatchString(server) &&
strings.Contains(server, `proxy_cache_valid 200 202 401 30m;`)
})
})
It("retains cookie set by external authentication server", func() {
Skip("Skipping test until refactoring")
ginkgo.It("retains cookie set by external authentication server", func() {
ginkgo.Skip("Skipping test until refactoring")
// TODO: this test should look like https://gist.github.com/aledbf/250645d76c080677c695929273f8fd22
host := "auth"
@ -343,10 +321,10 @@ var _ = framework.DescribeAnnotation("auth-*", func() {
var httpbinIP string
err := framework.WaitForEndpoints(f.KubeClientSet, framework.DefaultTimeout, framework.HTTPBinService, f.Namespace, 1)
Expect(err).NotTo(HaveOccurred())
assert.Nil(ginkgo.GinkgoT(), err)
e, err := f.KubeClientSet.CoreV1().Endpoints(f.Namespace).Get(framework.HTTPBinService, metav1.GetOptions{})
Expect(err).NotTo(HaveOccurred())
assert.Nil(ginkgo.GinkgoT(), err)
httpbinIP = e.Subsets[0].Addresses[0].IP
@ -359,38 +337,32 @@ var _ = framework.DescribeAnnotation("auth-*", func() {
f.EnsureIngress(ing)
f.WaitForNginxServer(host, func(server string) bool {
return Expect(server).Should(ContainSubstring("server_name auth"))
return strings.Contains(server, "server_name auth")
})
resp, _, errs := gorequest.New().
Get(f.GetURL(framework.HTTP)).
Retry(10, 1*time.Second, http.StatusNotFound).
Set("Host", host).
Param("a", "b").
Param("c", "d").
End()
for _, err := range errs {
Expect(err).NotTo(HaveOccurred())
}
framework.Logf("Cookie: %v", resp.Header)
Expect(resp.Header.Get("Set-Cookie")).Should(ContainSubstring("alma=armud"))
f.HTTPTestClient().
GET("/").
WithHeader("Host", host).
WithQuery("a", "b").
WithQuery("c", "d").
Expect().
Status(http.StatusOK).
Header("Set-Cookie").Contains("alma=armud")
})
Context("when external authentication is configured", func() {
ginkgo.Context("when external authentication is configured", func() {
host := "auth"
BeforeEach(func() {
ginkgo.BeforeEach(func() {
f.NewHttpbinDeployment()
var httpbinIP string
err := framework.WaitForEndpoints(f.KubeClientSet, framework.DefaultTimeout, framework.HTTPBinService, f.Namespace, 1)
Expect(err).NotTo(HaveOccurred())
assert.Nil(ginkgo.GinkgoT(), err)
e, err := f.KubeClientSet.CoreV1().Endpoints(f.Namespace).Get(framework.HTTPBinService, metav1.GetOptions{})
Expect(err).NotTo(HaveOccurred())
assert.Nil(ginkgo.GinkgoT(), err)
httpbinIP = e.Subsets[0].Addresses[0].IP
@ -403,61 +375,48 @@ var _ = framework.DescribeAnnotation("auth-*", func() {
f.EnsureIngress(ing)
f.WaitForNginxServer(host, func(server string) bool {
return Expect(server).Should(ContainSubstring("server_name auth"))
return strings.Contains(server, "server_name auth")
})
})
It("should return status code 200 when signed in", func() {
resp, _, errs := gorequest.New().
Get(f.GetURL(framework.HTTP)).
Retry(10, 1*time.Second, http.StatusNotFound).
Set("Host", host).
SetBasicAuth("user", "password").
End()
for _, err := range errs {
Expect(err).NotTo(HaveOccurred())
}
Expect(resp.StatusCode).Should(Equal(http.StatusOK))
ginkgo.It("should return status code 200 when signed in", func() {
f.HTTPTestClient().
GET("/").
WithHeader("Host", host).
WithBasicAuth("user", "password").
Expect().
Status(http.StatusOK)
})
It("should redirect to signin url when not signed in", func() {
resp, _, errs := gorequest.New().
Get(f.GetURL(framework.HTTP)).
Retry(10, 1*time.Second, http.StatusNotFound).
Set("Host", host).
RedirectPolicy(func(req gorequest.Request, via []gorequest.Request) error {
return http.ErrUseLastResponse
}).
Param("a", "b").
Param("c", "d").
End()
for _, err := range errs {
Expect(err).NotTo(HaveOccurred())
}
Expect(resp.StatusCode).Should(Equal(http.StatusFound))
Expect(resp.Header.Get("Location")).Should(Equal(fmt.Sprintf("http://%s/auth/start?rd=http://%s%s", host, host, url.QueryEscape("/?a=b&c=d"))))
ginkgo.It("should redirect to signin url when not signed in", func() {
f.HTTPTestClient().
GET("/").
WithHeader("Host", host).
WithQuery("a", "b").
WithQuery("c", "d").
Expect().
Status(http.StatusFound).
Header("Location").Equal(fmt.Sprintf("http://%s/auth/start?rd=http://%s%s", host, host, url.QueryEscape("/?a=b&c=d")))
})
})
Context("when external authentication with caching is configured", func() {
ginkgo.Context("when external authentication with caching is configured", func() {
thisHost := "auth"
thatHost := "different"
fooPath := "/foo"
barPath := "/bar"
BeforeEach(func() {
ginkgo.BeforeEach(func() {
f.NewHttpbinDeployment()
var httpbinIP string
err := framework.WaitForEndpoints(f.KubeClientSet, framework.DefaultTimeout, framework.HTTPBinService, f.Namespace, 1)
Expect(err).NotTo(HaveOccurred())
assert.Nil(ginkgo.GinkgoT(), err)
e, err := f.KubeClientSet.CoreV1().Endpoints(f.Namespace).Get(framework.HTTPBinService, metav1.GetOptions{})
Expect(err).NotTo(HaveOccurred())
assert.Nil(ginkgo.GinkgoT(), err)
httpbinIP = e.Subsets[0].Addresses[0].IP
@ -469,154 +428,106 @@ var _ = framework.DescribeAnnotation("auth-*", func() {
}
for _, host := range []string{thisHost, thatHost} {
By("Adding an ingress rule for /foo")
ginkgo.By("Adding an ingress rule for /foo")
fooIng := framework.NewSingleIngress(fmt.Sprintf("foo-%s-ing", host), fooPath, host, f.Namespace, framework.EchoService, 80, annotations)
f.EnsureIngress(fooIng)
f.WaitForNginxServer(host, func(server string) bool {
return Expect(server).Should(ContainSubstring("location /foo"))
return strings.Contains(server, "location /foo")
})
By("Adding an ingress rule for /bar")
ginkgo.By("Adding an ingress rule for /bar")
barIng := framework.NewSingleIngress(fmt.Sprintf("bar-%s-ing", host), barPath, host, f.Namespace, framework.EchoService, 80, annotations)
f.EnsureIngress(barIng)
f.WaitForNginxServer(host, func(server string) bool {
return Expect(server).Should(ContainSubstring("location /bar"))
return strings.Contains(server, "location /bar")
})
}
})
It("should return status code 200 when signed in after auth backend is deleted ", func() {
resp, _, errs := gorequest.New().
Get(f.GetURL(framework.HTTP)+fooPath).
Retry(10, 1*time.Second, http.StatusNotFound).
Set("Host", thisHost).
SetBasicAuth("user", "password").
End()
for _, err := range errs {
Expect(err).NotTo(HaveOccurred())
}
Expect(resp.StatusCode).Should(Equal(http.StatusOK))
ginkgo.It("should return status code 200 when signed in after auth backend is deleted ", func() {
f.HTTPTestClient().
GET(fooPath).
WithHeader("Host", thisHost).
WithBasicAuth("user", "password").
Expect().
Status(http.StatusOK)
err := f.DeleteDeployment(framework.HTTPBinService)
Expect(err).NotTo(HaveOccurred())
assert.Nil(ginkgo.GinkgoT(), err)
resp, _, errs = gorequest.New().
Get(f.GetURL(framework.HTTP)+fooPath).
Retry(10, 1*time.Second, http.StatusNotFound).
Set("Host", thisHost).
SetBasicAuth("user", "password").
End()
for _, err := range errs {
Expect(err).NotTo(HaveOccurred())
}
Expect(resp.StatusCode).Should(Equal(http.StatusOK))
f.HTTPTestClient().
GET(fooPath).
WithHeader("Host", thisHost).
WithBasicAuth("user", "password").
Expect().
Status(http.StatusOK)
})
It("should deny login for different location on same server", func() {
resp, _, errs := gorequest.New().
Get(f.GetURL(framework.HTTP)+fooPath).
Retry(10, 1*time.Second, http.StatusNotFound).
Set("Host", thisHost).
SetBasicAuth("user", "password").
End()
for _, err := range errs {
Expect(err).NotTo(HaveOccurred())
}
Expect(resp.StatusCode).Should(Equal(http.StatusOK))
ginkgo.It("should deny login for different location on same server", func() {
f.HTTPTestClient().
GET(fooPath).
WithHeader("Host", thisHost).
WithBasicAuth("user", "password").
Expect().
Status(http.StatusOK)
err := f.DeleteDeployment(framework.HTTPBinService)
Expect(err).NotTo(HaveOccurred())
assert.Nil(ginkgo.GinkgoT(), err)
_, _, errs = gorequest.New().
Get(f.GetURL(framework.HTTP)+fooPath).
Retry(10, 1*time.Second, http.StatusNotFound).
Set("Host", thisHost).
SetBasicAuth("user", "password").
End()
f.HTTPTestClient().
GET(fooPath).
WithHeader("Host", thisHost).
WithBasicAuth("user", "password").
Expect().
Status(http.StatusOK)
for _, err := range errs {
Expect(err).NotTo(HaveOccurred())
}
ginkgo.By("receiving an internal server error without cache on location /bar")
f.HTTPTestClient().
GET(barPath).
WithHeader("Host", thisHost).
WithBasicAuth("user", "password").
Expect().
Status(http.StatusInternalServerError)
resp, _, errs = gorequest.New().
Get(f.GetURL(framework.HTTP)+barPath).
Retry(10, 1*time.Second, http.StatusNotFound).
Set("Host", thisHost).
SetBasicAuth("user", "password").
End()
for _, err := range errs {
Expect(err).NotTo(HaveOccurred())
}
By("receiving an internal server error without cache on location /bar")
Expect(resp.StatusCode).Should(Equal(http.StatusInternalServerError))
})
It("should deny login for different servers", func() {
By("logging into server thisHost /foo")
resp, _, errs := gorequest.New().
Get(f.GetURL(framework.HTTP)+fooPath).
Retry(10, 1*time.Second, http.StatusNotFound).
Set("Host", thisHost).
SetBasicAuth("user", "password").
End()
for _, err := range errs {
Expect(err).NotTo(HaveOccurred())
}
Expect(resp.StatusCode).Should(Equal(http.StatusOK))
ginkgo.It("should deny login for different servers", func() {
ginkgo.By("logging into server thisHost /foo")
f.HTTPTestClient().
GET(fooPath).
WithHeader("Host", thisHost).
WithBasicAuth("user", "password").
Expect().
Status(http.StatusOK)
err := f.DeleteDeployment(framework.HTTPBinService)
Expect(err).NotTo(HaveOccurred())
assert.Nil(ginkgo.GinkgoT(), err)
resp, _, errs = gorequest.New().
Get(f.GetURL(framework.HTTP)+fooPath).
Retry(10, 1*time.Second, http.StatusNotFound).
Set("Host", thisHost).
SetBasicAuth("user", "password").
End()
ginkgo.By("receiving an internal server error without cache on thisHost location /bar")
f.HTTPTestClient().
GET(fooPath).
WithHeader("Host", thisHost).
WithBasicAuth("user", "password").
Expect().
Status(http.StatusOK)
for _, err := range errs {
Expect(err).NotTo(HaveOccurred())
}
Expect(resp.StatusCode).Should(Equal(http.StatusOK))
resp, _, errs = gorequest.New().
Get(f.GetURL(framework.HTTP)+fooPath).
Retry(10, 1*time.Second, http.StatusNotFound).
Set("Host", thatHost).
SetBasicAuth("user", "password").
End()
for _, err := range errs {
Expect(err).NotTo(HaveOccurred())
}
By("receiving an internal server error without cache on thisHost location /bar")
Expect(resp.StatusCode).Should(Equal(http.StatusInternalServerError))
f.HTTPTestClient().
GET(fooPath).
WithHeader("Host", thatHost).
WithBasicAuth("user", "password").
Expect().
Status(http.StatusInternalServerError)
})
It("should redirect to signin url when not signed in", func() {
resp, _, errs := gorequest.New().
Get(f.GetURL(framework.HTTP)).
Retry(10, 1*time.Second, http.StatusNotFound).
Set("Host", thisHost).
RedirectPolicy(func(req gorequest.Request, via []gorequest.Request) error {
return http.ErrUseLastResponse
}).
Param("a", "b").
Param("c", "d").
End()
for _, err := range errs {
Expect(err).NotTo(HaveOccurred())
}
Expect(resp.StatusCode).Should(Equal(http.StatusFound))
Expect(resp.Header.Get("Location")).Should(Equal(fmt.Sprintf("http://%s/auth/start?rd=http://%s%s", thisHost, thisHost, url.QueryEscape("/?a=b&c=d"))))
ginkgo.It("should redirect to signin url when not signed in", func() {
f.HTTPTestClient().
GET("/").
WithHeader("Host", thisHost).
WithQuery("a", "b").
WithQuery("c", "d").
Expect().
Status(http.StatusFound).
Header("Location").Equal(fmt.Sprintf("http://%s/auth/start?rd=http://%s%s", thisHost, thisHost, url.QueryEscape("/?a=b&c=d")))
})
})
})
@ -630,7 +541,7 @@ var _ = framework.DescribeAnnotation("auth-*", func() {
func buildSecret(username, password, name, namespace string) *corev1.Secret {
out, err := exec.Command("openssl", "passwd", "-crypt", password).CombinedOutput()
encpass := fmt.Sprintf("%v:%s\n", username, out)
Expect(err).NotTo(HaveOccurred())
assert.Nil(ginkgo.GinkgoT(), err)
return &corev1.Secret{
ObjectMeta: metav1.ObjectMeta{
@ -647,7 +558,7 @@ func buildSecret(username, password, name, namespace string) *corev1.Secret {
func buildMapSecret(username, password, name, namespace string) *corev1.Secret {
out, err := exec.Command("openssl", "passwd", "-crypt", password).CombinedOutput()
Expect(err).NotTo(HaveOccurred())
assert.Nil(ginkgo.GinkgoT(), err)
return &corev1.Secret{
ObjectMeta: metav1.ObjectMeta{

View file

@ -22,20 +22,19 @@ import (
"net/http"
"strings"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/parnurzeal/gorequest"
"github.com/onsi/ginkgo"
"github.com/stretchr/testify/assert"
"k8s.io/ingress-nginx/test/e2e/framework"
)
var _ = framework.DescribeAnnotation("auth-tls-*", func() {
f := framework.NewDefaultFramework("authtls")
BeforeEach(func() {
ginkgo.BeforeEach(func() {
f.NewEchoDeploymentWithReplicas(2)
})
It("should set valid auth-tls-secret", func() {
ginkgo.It("should set valid auth-tls-secret", func() {
host := "authtls.foo.com"
nameSpace := f.Namespace
@ -44,7 +43,7 @@ var _ = framework.DescribeAnnotation("auth-tls-*", func() {
host,
host,
nameSpace)
Expect(err).ToNot(HaveOccurred())
assert.Nil(ginkgo.GinkgoT(), err)
annotations := map[string]string{
"nginx.ingress.kubernetes.io/auth-tls-secret": nameSpace + "/" + host,
@ -55,27 +54,23 @@ var _ = framework.DescribeAnnotation("auth-tls-*", func() {
assertSslClientCertificateConfig(f, host, "on", "1")
// Send Request without Client Certs
req := gorequest.New()
uri := "/"
resp, _, errs := req.
Get(f.GetURL(framework.HTTPS)+uri).
TLSClientConfig(&tls.Config{ServerName: host, InsecureSkipVerify: true}).
Set("Host", host).
End()
Expect(errs).Should(BeEmpty())
Expect(resp.StatusCode).Should(Equal(http.StatusBadRequest))
f.HTTPTestClientWithTLSConfig(&tls.Config{ServerName: host, InsecureSkipVerify: true}).
GET("/").
WithURL(f.GetURL(framework.HTTPS)).
WithHeader("Host", host).
Expect().
Status(http.StatusBadRequest)
// Send Request Passing the Client Certs
resp, _, errs = req.
Get(f.GetURL(framework.HTTPS)+uri).
TLSClientConfig(clientConfig).
Set("Host", host).
End()
Expect(errs).Should(BeEmpty())
Expect(resp.StatusCode).Should(Equal(http.StatusOK))
f.HTTPTestClientWithTLSConfig(clientConfig).
GET("/").
WithURL(f.GetURL(framework.HTTPS)).
WithHeader("Host", host).
Expect().
Status(http.StatusOK)
})
It("should set valid auth-tls-secret, sslVerify to off, and sslVerifyDepth to 2", func() {
ginkgo.It("should set valid auth-tls-secret, sslVerify to off, and sslVerifyDepth to 2", func() {
host := "authtls.foo.com"
nameSpace := f.Namespace
@ -84,7 +79,7 @@ var _ = framework.DescribeAnnotation("auth-tls-*", func() {
host,
host,
nameSpace)
Expect(err).ToNot(HaveOccurred())
assert.Nil(ginkgo.GinkgoT(), err)
annotations := map[string]string{
"nginx.ingress.kubernetes.io/auth-tls-secret": nameSpace + "/" + host,
@ -97,18 +92,15 @@ var _ = framework.DescribeAnnotation("auth-tls-*", func() {
assertSslClientCertificateConfig(f, host, "off", "2")
// Send Request without Client Certs
req := gorequest.New()
uri := "/"
resp, _, errs := req.
Get(f.GetURL(framework.HTTPS)+uri).
TLSClientConfig(&tls.Config{ServerName: host, InsecureSkipVerify: true}).
Set("Host", host).
End()
Expect(errs).Should(BeEmpty())
Expect(resp.StatusCode).Should(Equal(http.StatusOK))
f.HTTPTestClient().
GET("/").
WithURL(f.GetURL(framework.HTTPS)).
WithHeader("Host", host).
Expect().
Status(http.StatusOK)
})
It("should set valid auth-tls-secret, pass certificate to upstream, and error page", func() {
ginkgo.It("should set valid auth-tls-secret, pass certificate to upstream, and error page", func() {
host := "authtls.foo.com"
nameSpace := f.Namespace
@ -119,7 +111,7 @@ var _ = framework.DescribeAnnotation("auth-tls-*", func() {
host,
host,
nameSpace)
Expect(err).ToNot(HaveOccurred())
assert.Nil(ginkgo.GinkgoT(), err)
annotations := map[string]string{
"nginx.ingress.kubernetes.io/auth-tls-secret": nameSpace + "/" + host,
@ -141,26 +133,21 @@ var _ = framework.DescribeAnnotation("auth-tls-*", func() {
})
// Send Request without Client Certs
req := gorequest.New()
uri := "/"
resp, _, errs := req.
Get(f.GetURL(framework.HTTPS)+uri).
TLSClientConfig(&tls.Config{ServerName: host, InsecureSkipVerify: true}).
Set("Host", host).
RedirectPolicy(noRedirectPolicyFunc).
End()
Expect(errs).Should(BeEmpty())
Expect(resp.StatusCode).Should(Equal(http.StatusFound))
Expect(resp.Header.Get("Location")).Should(Equal(f.GetURL(framework.HTTP) + errorPath))
f.HTTPTestClient().
GET("/").
WithURL(f.GetURL(framework.HTTPS)).
WithHeader("Host", host).
Expect().
Status(http.StatusFound).
Header("Location").Equal(f.GetURL(framework.HTTP) + errorPath)
// Send Request Passing the Client Certs
resp, _, errs = req.
Get(f.GetURL(framework.HTTPS)+uri).
TLSClientConfig(clientConfig).
Set("Host", host).
End()
Expect(errs).Should(BeEmpty())
Expect(resp.StatusCode).Should(Equal(http.StatusOK))
f.HTTPTestClientWithTLSConfig(clientConfig).
GET("/").
WithURL(f.GetURL(framework.HTTPS)).
WithHeader("Host", host).
Expect().
Status(http.StatusOK)
})
})

View file

@ -17,19 +17,21 @@ limitations under the License.
package annotations
import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"strings"
"github.com/onsi/ginkgo"
"k8s.io/ingress-nginx/test/e2e/framework"
)
var _ = framework.DescribeAnnotation("backend-protocol", func() {
f := framework.NewDefaultFramework("backendprotocol")
BeforeEach(func() {
f.NewEchoDeploymentWithReplicas(2)
ginkgo.BeforeEach(func() {
f.NewEchoDeployment()
})
It("should set backend protocol to https:// and use proxy_pass", func() {
ginkgo.It("should set backend protocol to https:// and use proxy_pass", func() {
host := "backendprotocol.foo.com"
annotations := map[string]string{
"nginx.ingress.kubernetes.io/backend-protocol": "HTTPS",
@ -40,11 +42,11 @@ var _ = framework.DescribeAnnotation("backend-protocol", func() {
f.WaitForNginxServer(host,
func(server string) bool {
return Expect(server).Should(ContainSubstring("proxy_pass https://upstream_balancer;"))
return strings.Contains(server, "proxy_pass https://upstream_balancer;")
})
})
It("should set backend protocol to grpc:// and use grpc_pass", func() {
ginkgo.It("should set backend protocol to grpc:// and use grpc_pass", func() {
host := "backendprotocol.foo.com"
annotations := map[string]string{
"nginx.ingress.kubernetes.io/backend-protocol": "GRPC",
@ -55,11 +57,11 @@ var _ = framework.DescribeAnnotation("backend-protocol", func() {
f.WaitForNginxServer(host,
func(server string) bool {
return Expect(server).Should(ContainSubstring("grpc_pass grpc://upstream_balancer;"))
return strings.Contains(server, "grpc_pass grpc://upstream_balancer;")
})
})
It("should set backend protocol to grpcs:// and use grpc_pass", func() {
ginkgo.It("should set backend protocol to grpcs:// and use grpc_pass", func() {
host := "backendprotocol.foo.com"
annotations := map[string]string{
"nginx.ingress.kubernetes.io/backend-protocol": "GRPCS",
@ -70,11 +72,11 @@ var _ = framework.DescribeAnnotation("backend-protocol", func() {
f.WaitForNginxServer(host,
func(server string) bool {
return Expect(server).Should(ContainSubstring("grpc_pass grpcs://upstream_balancer;"))
return strings.Contains(server, "grpc_pass grpcs://upstream_balancer;")
})
})
It("should set backend protocol to '' and use fastcgi_pass", func() {
ginkgo.It("should set backend protocol to '' and use fastcgi_pass", func() {
host := "backendprotocol.foo.com"
annotations := map[string]string{
"nginx.ingress.kubernetes.io/backend-protocol": "FCGI",
@ -85,11 +87,11 @@ var _ = framework.DescribeAnnotation("backend-protocol", func() {
f.WaitForNginxServer(host,
func(server string) bool {
return Expect(server).Should(ContainSubstring("fastcgi_pass upstream_balancer;"))
return strings.Contains(server, "fastcgi_pass upstream_balancer;")
})
})
It("should set backend protocol to '' and use ajp_pass", func() {
ginkgo.It("should set backend protocol to '' and use ajp_pass", func() {
host := "backendprotocol.foo.com"
annotations := map[string]string{
"nginx.ingress.kubernetes.io/backend-protocol": "AJP",
@ -100,7 +102,7 @@ var _ = framework.DescribeAnnotation("backend-protocol", func() {
f.WaitForNginxServer(host,
func(server string) bool {
return Expect(server).Should(ContainSubstring("ajp_pass upstream_balancer;"))
return strings.Contains(server, "ajp_pass upstream_balancer;")
})
})
})

View file

@ -19,11 +19,12 @@ package annotations
import (
"fmt"
"net/http"
"strings"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/parnurzeal/gorequest"
"github.com/onsi/ginkgo"
"github.com/stretchr/testify/assert"
networking "k8s.io/api/networking/v1beta1"
"k8s.io/ingress-nginx/test/e2e/framework"
)
@ -34,7 +35,7 @@ const (
var _ = framework.DescribeAnnotation("canary-*", func() {
f := framework.NewDefaultFramework("canary")
BeforeEach(func() {
ginkgo.BeforeEach(func() {
// Deployment for main backend
f.NewEchoDeployment()
@ -42,17 +43,18 @@ var _ = framework.DescribeAnnotation("canary-*", func() {
f.NewEchoDeploymentWithNameAndReplicas(canaryService, 1)
})
Context("when canary is created", func() {
It("should response with a 200 status from the mainline upstream when requests are made to the mainline ingress", func() {
ginkgo.Context("when canary is created", func() {
ginkgo.It("should response with a 200 status from the mainline upstream when requests are made to the mainline ingress", func() {
host := "foo"
annotations := map[string]string{}
ing := framework.NewSingleIngress(host, "/", host, f.Namespace, framework.EchoService, 80, annotations)
ing := framework.NewSingleIngress(host, "/", host, f.Namespace,
framework.EchoService, 80, annotations)
f.EnsureIngress(ing)
f.WaitForNginxServer(host,
func(server string) bool {
return Expect(server).Should(ContainSubstring("server_name foo"))
return strings.Contains(server, "server_name foo")
})
canaryAnnotations := map[string]string{
@ -62,21 +64,19 @@ var _ = framework.DescribeAnnotation("canary-*", func() {
canaryIngName := fmt.Sprintf("%v-canary", host)
canaryIng := framework.NewSingleIngress(canaryIngName, "/", host, f.Namespace, canaryService, 80, canaryAnnotations)
canaryIng := framework.NewSingleIngress(canaryIngName, "/", host,
f.Namespace, canaryService, 80, canaryAnnotations)
f.EnsureIngress(canaryIng)
resp, body, errs := gorequest.New().
Get(f.GetURL(framework.HTTP)).
Set("Host", host).
End()
Expect(errs).Should(BeEmpty())
Expect(resp.StatusCode).Should(Equal(http.StatusOK))
Expect(body).Should(ContainSubstring(framework.EchoService))
Expect(body).ShouldNot(ContainSubstring(canaryService))
f.HTTPTestClient().
GET("/").
WithHeader("Host", host).
Expect().
Status(http.StatusOK).
Body().Contains(framework.EchoService).NotContains(canaryService)
})
It("should return 404 status for requests to the canary if no matching ingress is found", func() {
ginkgo.It("should return 404 status for requests to the canary if no matching ingress is found", func() {
host := "foo"
canaryAnnotations := map[string]string{
@ -86,19 +86,17 @@ var _ = framework.DescribeAnnotation("canary-*", func() {
canaryIngName := fmt.Sprintf("%v-canary", host)
canaryIng := framework.NewSingleIngress(canaryIngName, "/", host, f.Namespace, canaryService,
80, canaryAnnotations)
canaryIng := framework.NewSingleIngress(canaryIngName, "/", host,
f.Namespace, canaryService, 80, canaryAnnotations)
f.EnsureIngress(canaryIng)
resp, _, errs := gorequest.New().
Get(f.GetURL(framework.HTTP)).
Set("Host", host).
Set("CanaryByHeader", "always").
End()
Expect(errs).Should(BeEmpty())
Expect(resp.StatusCode).Should(Equal(http.StatusNotFound))
f.HTTPTestClient().
GET("/").
WithHeader("Host", host).
WithHeader("CanaryByHeader", "always").
Expect().
Status(http.StatusNotFound)
})
/*
@ -114,7 +112,7 @@ var _ = framework.DescribeAnnotation("canary-*", func() {
f.WaitForNginxServer(host,
func(server string) bool {
return Expect(server).Should(ContainSubstring("server_name foo"))
return strings.Contains(server,"server_name foo")
})
canaryAnnotations := map[string]string{
@ -130,7 +128,7 @@ var _ = framework.DescribeAnnotation("canary-*", func() {
By("returning a 503 status when the mainline deployment has 0 replicas and a request is sent to the canary")
ginkgo.By("returning a 503 status when the mainline deployment has 0 replicas and a request is sent to the canary")
f.NewEchoDeploymentWithReplicas(0)
@ -143,7 +141,7 @@ var _ = framework.DescribeAnnotation("canary-*", func() {
Expect(errs).Should(BeEmpty())
Expect(resp.StatusCode).Should(Equal(http.StatusServiceUnavailable))
By("returning a 200 status when the canary deployment has 0 replicas and a request is sent to the mainline ingress")
ginkgo.By("returning a 200 status when the canary deployment has 0 replicas and a request is sent to the mainline ingress")
f.NewEchoDeploymentWithReplicas(1)
f.NewDeployment(canaryService, "gcr.io/kubernetes-e2e-test-images/echoserver:2.2", 8080, 0)
@ -159,16 +157,17 @@ var _ = framework.DescribeAnnotation("canary-*", func() {
})
*/
It("should route requests to the correct upstream if mainline ingress is created before the canary ingress", func() {
ginkgo.It("should route requests to the correct upstream if mainline ingress is created before the canary ingress", func() {
host := "foo"
annotations := map[string]string{}
ing := framework.NewSingleIngress(host, "/", host, f.Namespace, framework.EchoService, 80, annotations)
ing := framework.NewSingleIngress(host, "/", host, f.Namespace,
framework.EchoService, 80, annotations)
f.EnsureIngress(ing)
f.WaitForNginxServer(host,
func(server string) bool {
return Expect(server).Should(ContainSubstring("server_name foo"))
return strings.Contains(server, "server_name foo")
})
canaryAnnotations := map[string]string{
@ -178,36 +177,32 @@ var _ = framework.DescribeAnnotation("canary-*", func() {
canaryIngName := fmt.Sprintf("%v-canary", host)
canaryIng := framework.NewSingleIngress(canaryIngName, "/", host, f.Namespace, canaryService,
80, canaryAnnotations)
canaryIng := framework.NewSingleIngress(canaryIngName, "/", host,
f.Namespace, canaryService, 80, canaryAnnotations)
f.EnsureIngress(canaryIng)
By("routing requests destined for the mainline ingress to the maineline upstream")
resp, body, errs := gorequest.New().
Get(f.GetURL(framework.HTTP)).
Set("Host", host).
Set("CanaryByHeader", "never").
End()
ginkgo.By("routing requests destined for the mainline ingress to the maineline upstream")
Expect(errs).Should(BeEmpty())
Expect(resp.StatusCode).Should(Equal(http.StatusOK))
Expect(body).Should(ContainSubstring(framework.EchoService))
Expect(body).ShouldNot(ContainSubstring(canaryService))
f.HTTPTestClient().
GET("/").
WithHeader("Host", host).
WithHeader("CanaryByHeader", "never").
Expect().
Status(http.StatusOK).
Body().Contains(framework.EchoService).NotContains(canaryService)
By("routing requests destined for the canary ingress to the canary upstream")
ginkgo.By("routing requests destined for the canary ingress to the canary upstream")
resp, body, errs = gorequest.New().
Get(f.GetURL(framework.HTTP)).
Set("Host", host).
Set("CanaryByHeader", "always").
End()
Expect(errs).Should(BeEmpty())
Expect(resp.StatusCode).Should(Equal(http.StatusOK))
Expect(body).Should(ContainSubstring(canaryService))
f.HTTPTestClient().
GET("/").
WithHeader("Host", host).
WithHeader("CanaryByHeader", "always").
Expect().
Status(http.StatusOK).
Body().Contains(canaryService)
})
It("should route requests to the correct upstream if mainline ingress is created after the canary ingress", func() {
ginkgo.It("should route requests to the correct upstream if mainline ingress is created after the canary ingress", func() {
host := "foo"
canaryAnnotations := map[string]string{
@ -217,55 +212,51 @@ var _ = framework.DescribeAnnotation("canary-*", func() {
canaryIngName := fmt.Sprintf("%v-canary", host)
canaryIng := framework.NewSingleIngress(canaryIngName, "/", host, f.Namespace, canaryService,
80, canaryAnnotations)
canaryIng := framework.NewSingleIngress(canaryIngName, "/", host,
f.Namespace, canaryService, 80, canaryAnnotations)
f.EnsureIngress(canaryIng)
annotations := map[string]string{}
ing := framework.NewSingleIngress(host, "/", host, f.Namespace, framework.EchoService, 80, annotations)
ing := framework.NewSingleIngress(host, "/", host, f.Namespace,
framework.EchoService, 80, annotations)
f.EnsureIngress(ing)
f.WaitForNginxServer(host,
func(server string) bool {
return Expect(server).Should(ContainSubstring("server_name foo"))
return strings.Contains(server, "server_name foo")
})
By("routing requests destined for the mainline ingress to the mainelin upstream")
resp, body, errs := gorequest.New().
Get(f.GetURL(framework.HTTP)).
Set("Host", host).
Set("CanaryByHeader", "never").
End()
ginkgo.By("routing requests destined for the mainline ingress to the mainelin upstream")
f.HTTPTestClient().
GET("/").
WithHeader("Host", host).
WithHeader("CanaryByHeader", "never").
Expect().
Status(http.StatusOK).
Body().Contains(framework.EchoService).NotContains(canaryService)
Expect(errs).Should(BeEmpty())
Expect(resp.StatusCode).Should(Equal(http.StatusOK))
Expect(body).Should(ContainSubstring(framework.EchoService))
Expect(body).ShouldNot(ContainSubstring(canaryService))
By("routing requests destined for the canary ingress to the canary upstream")
resp, body, errs = gorequest.New().
Get(f.GetURL(framework.HTTP)).
Set("Host", host).
Set("CanaryByHeader", "always").
End()
Expect(errs).Should(BeEmpty())
Expect(resp.StatusCode).Should(Equal(http.StatusOK))
Expect(body).Should(ContainSubstring(canaryService))
ginkgo.By("routing requests destined for the canary ingress to the canary upstream")
f.HTTPTestClient().
GET("/").
WithHeader("Host", host).
WithHeader("CanaryByHeader", "always").
Expect().
Status(http.StatusOK).
Body().Contains(canaryService)
})
It("should route requests to the correct upstream if the mainline ingress is modified", func() {
ginkgo.It("should route requests to the correct upstream if the mainline ingress is modified", func() {
host := "foo"
annotations := map[string]string{}
ing := framework.NewSingleIngress(host, "/", host, f.Namespace, framework.EchoService, 80, annotations)
ing := framework.NewSingleIngress(host, "/", host, f.Namespace,
framework.EchoService, 80, annotations)
f.EnsureIngress(ing)
f.WaitForNginxServer(host,
func(server string) bool {
return Expect(server).Should(ContainSubstring("server_name foo"))
return strings.Contains(server, "server_name foo")
})
canaryAnnotations := map[string]string{
@ -275,59 +266,54 @@ var _ = framework.DescribeAnnotation("canary-*", func() {
canaryIngName := fmt.Sprintf("%v-canary", host)
canaryIng := framework.NewSingleIngress(canaryIngName, "/", host, f.Namespace, canaryService,
80, canaryAnnotations)
canaryIng := framework.NewSingleIngress(canaryIngName, "/", host,
f.Namespace, canaryService, 80, canaryAnnotations)
f.EnsureIngress(canaryIng)
modAnnotations := map[string]string{
"foo": "bar",
}
modIng := framework.NewSingleIngress(host, "/", host, f.Namespace, framework.EchoService, 80, modAnnotations)
modIng := framework.NewSingleIngress(host, "/", host, f.Namespace,
framework.EchoService, 80, modAnnotations)
f.EnsureIngress(modIng)
f.WaitForNginxServer(host,
func(server string) bool {
return Expect(server).Should(ContainSubstring("server_name foo"))
return strings.Contains(server, "server_name foo")
})
By("routing requests destined fro the mainline ingress to the mainline upstream")
ginkgo.By("routing requests destined fro the mainline ingress to the mainline upstream")
f.HTTPTestClient().
GET("/").
WithHeader("Host", host).
WithHeader("CanaryByHeader", "never").
Expect().
Status(http.StatusOK).
Body().Contains(framework.EchoService).NotContains(canaryService)
resp, body, errs := gorequest.New().
Get(f.GetURL(framework.HTTP)).
Set("Host", host).
Set("CanaryByHeader", "never").
End()
Expect(errs).Should(BeEmpty())
Expect(resp.StatusCode).Should(Equal(http.StatusOK))
Expect(body).Should(ContainSubstring(framework.EchoService))
Expect(body).ShouldNot(ContainSubstring(canaryService))
By("routing requests destined for the canary ingress to the canary upstream")
resp, body, errs = gorequest.New().
Get(f.GetURL(framework.HTTP)).
Set("Host", host).
Set("CanaryByHeader", "always").
End()
Expect(errs).Should(BeEmpty())
Expect(resp.StatusCode).Should(Equal(http.StatusOK))
Expect(body).Should(ContainSubstring(canaryService))
ginkgo.By("routing requests destined for the canary ingress to the canary upstream")
f.HTTPTestClient().
GET("/").
WithHeader("Host", host).
WithHeader("CanaryByHeader", "always").
Expect().
Status(http.StatusOK).
Body().Contains(canaryService)
})
It("should route requests to the correct upstream if the canary ingress is modified", func() {
ginkgo.It("should route requests to the correct upstream if the canary ingress is modified", func() {
host := "foo"
annotations := map[string]string{}
ing := framework.NewSingleIngress(host, "/", host, f.Namespace, framework.EchoService, 80, annotations)
ing := framework.NewSingleIngress(host, "/", host, f.Namespace,
framework.EchoService, 80, annotations)
f.EnsureIngress(ing)
f.WaitForNginxServer(host,
func(server string) bool {
return Expect(server).Should(ContainSubstring("server_name foo"))
return strings.Contains(server, "server_name foo")
})
canaryAnnotations := map[string]string{
@ -337,56 +323,51 @@ var _ = framework.DescribeAnnotation("canary-*", func() {
canaryIngName := fmt.Sprintf("%v-canary", host)
canaryIng := framework.NewSingleIngress(canaryIngName, "/", host, f.Namespace, canaryService,
80, canaryAnnotations)
canaryIng := framework.NewSingleIngress(canaryIngName, "/", host,
f.Namespace, canaryService, 80, canaryAnnotations)
f.EnsureIngress(canaryIng)
modCanaryAnnotations := map[string]string{
"nginx.ingress.kubernetes.io/canary": "true",
"nginx.ingress.kubernetes.io/canary-by-header": "CanaryByHeader2",
}
err := framework.UpdateIngress(f.KubeClientSet, f.Namespace, canaryIngName,
func(ingress *networking.Ingress) error {
ingress.ObjectMeta.Annotations = map[string]string{
"nginx.ingress.kubernetes.io/canary": "true",
"nginx.ingress.kubernetes.io/canary-by-header": "CanaryByHeader2",
}
return nil
})
assert.Nil(ginkgo.GinkgoT(), err)
modCanaryIng := framework.NewSingleIngress(canaryIngName, "/", host, f.Namespace, canaryService, 80, modCanaryAnnotations)
f.EnsureIngress(modCanaryIng)
ginkgo.By("routing requests destined for the mainline ingress to the mainline upstream")
f.HTTPTestClient().
GET("/").
WithHeader("Host", host).
WithHeader("CanaryByHeader2", "never").
Expect().
Status(http.StatusOK).
Body().Contains(framework.EchoService).NotContains(canaryService)
By("routing requests destined for the mainline ingress to the mainline upstream")
resp, body, errs := gorequest.New().
Get(f.GetURL(framework.HTTP)).
Set("Host", host).
Set("CanaryByHeader2", "never").
End()
Expect(errs).Should(BeEmpty())
Expect(resp.StatusCode).Should(Equal(http.StatusOK))
Expect(body).Should(ContainSubstring(framework.EchoService))
Expect(body).ShouldNot(ContainSubstring(canaryService))
By("routing requests destined for the canary ingress to the canary upstream")
resp, body, errs = gorequest.New().
Get(f.GetURL(framework.HTTP)).
Set("Host", host).
Set("CanaryByHeader2", "always").
End()
Expect(errs).Should(BeEmpty())
Expect(resp.StatusCode).Should(Equal(http.StatusOK))
Expect(body).Should(ContainSubstring(canaryService))
ginkgo.By("routing requests destined for the canary ingress to the canary upstream")
f.HTTPTestClient().
GET("/").
WithHeader("Host", host).
WithHeader("CanaryByHeader2", "always").
Expect().
Status(http.StatusOK).
Body().Contains(canaryService)
})
})
Context("when canaried by header with no value", func() {
It("should route requests to the correct upstream", func() {
ginkgo.Context("when canaried by header with no value", func() {
ginkgo.It("should route requests to the correct upstream", func() {
host := "foo"
annotations := map[string]string{}
ing := framework.NewSingleIngress(host, "/", host, f.Namespace, framework.EchoService, 80, annotations)
ing := framework.NewSingleIngress(host, "/", host, f.Namespace,
framework.EchoService, 80, nil)
f.EnsureIngress(ing)
f.WaitForNginxServer(host,
func(server string) bool {
return Expect(server).Should(ContainSubstring("server_name foo"))
return strings.Contains(server, "server_name foo")
})
canaryAnnotations := map[string]string{
@ -396,61 +377,52 @@ var _ = framework.DescribeAnnotation("canary-*", func() {
canaryIngName := fmt.Sprintf("%v-canary", host)
canaryIng := framework.NewSingleIngress(canaryIngName, "/", host, f.Namespace, canaryService,
80, canaryAnnotations)
canaryIng := framework.NewSingleIngress(canaryIngName, "/", host,
f.Namespace, canaryService, 80, canaryAnnotations)
f.EnsureIngress(canaryIng)
By("routing requests to the canary upstream when header is set to 'always'")
ginkgo.By("routing requests to the canary upstream when header is set to 'always'")
f.HTTPTestClient().
GET("/").
WithHeader("Host", host).
WithHeader("CanaryByHeader", "always").
Expect().
Status(http.StatusOK).
Body().Contains(canaryService)
resp, body, errs := gorequest.New().
Get(f.GetURL(framework.HTTP)).
Set("Host", host).
Set("CanaryByHeader", "always").
End()
ginkgo.By("routing requests to the mainline upstream when header is set to 'never'")
f.HTTPTestClient().
GET("/").
WithHeader("Host", host).
WithHeader("CanaryByHeader", "never").
Expect().
Status(http.StatusOK).
Body().
Contains(framework.EchoService).NotContains(canaryService)
Expect(errs).Should(BeEmpty())
Expect(resp.StatusCode).Should(Equal(http.StatusOK))
Expect(body).Should(ContainSubstring(canaryService))
By("routing requests to the mainline upstream when header is set to 'never'")
resp, body, errs = gorequest.New().
Get(f.GetURL(framework.HTTP)).
Set("Host", host).
Set("CanaryByHeader", "never").
End()
Expect(errs).Should(BeEmpty())
Expect(resp.StatusCode).Should(Equal(http.StatusOK))
Expect(body).Should(ContainSubstring(framework.EchoService))
Expect(body).ShouldNot(ContainSubstring(canaryService))
By("routing requests to the mainline upstream when header is set to anything else")
resp, body, errs = gorequest.New().
Get(f.GetURL(framework.HTTP)).
Set("Host", host).
Set("CanaryByHeader", "badheadervalue").
End()
Expect(errs).Should(BeEmpty())
Expect(resp.StatusCode).Should(Equal(http.StatusOK))
Expect(body).Should(ContainSubstring(framework.EchoService))
Expect(body).ShouldNot(ContainSubstring(canaryService))
ginkgo.By("routing requests to the mainline upstream when header is set to anything else")
f.HTTPTestClient().
GET("/").
WithHeader("Host", host).
WithHeader("CanaryByHeader", "badheadervalue").
Expect().
Status(http.StatusOK).
Body().Contains(framework.EchoService).NotContains(canaryService)
})
})
Context("when canaried by header with value", func() {
It("should route requests to the correct upstream", func() {
ginkgo.Context("when canaried by header with value", func() {
ginkgo.It("should route requests to the correct upstream", func() {
host := "foo"
annotations := map[string]string{}
ing := framework.NewSingleIngress(host, "/", host, f.Namespace, framework.EchoService, 80, annotations)
ing := framework.NewSingleIngress(host, "/", host,
f.Namespace, framework.EchoService, 80, annotations)
f.EnsureIngress(ing)
f.WaitForNginxServer(host,
func(server string) bool {
return Expect(server).Should(ContainSubstring("server_name foo"))
return strings.Contains(server, "server_name foo")
})
canaryAnnotations := map[string]string{
@ -461,74 +433,60 @@ var _ = framework.DescribeAnnotation("canary-*", func() {
canaryIngName := fmt.Sprintf("%v-canary", host)
canaryIng := framework.NewSingleIngress(canaryIngName, "/", host, f.Namespace, canaryService,
80, canaryAnnotations)
canaryIng := framework.NewSingleIngress(canaryIngName, "/", host,
f.Namespace, canaryService, 80, canaryAnnotations)
f.EnsureIngress(canaryIng)
By("routing requests to the canary upstream when header is set to 'DoCanary'")
ginkgo.By("routing requests to the canary upstream when header is set to 'DoCanary'")
f.HTTPTestClient().
GET("/").
WithHeader("Host", host).
WithHeader("CanaryByHeader", "DoCanary").
Expect().
Status(http.StatusOK).
Body().Contains(canaryService)
resp, body, errs := gorequest.New().
Get(f.GetURL(framework.HTTP)).
Set("Host", host).
Set("CanaryByHeader", "DoCanary").
End()
ginkgo.By("routing requests to the mainline upstream when header is set to 'always'")
f.HTTPTestClient().
GET("/").
WithHeader("Host", host).
WithHeader("CanaryByHeader", "always").
Expect().
Status(http.StatusOK).
Body().Contains(framework.EchoService).NotContains(canaryService)
Expect(errs).Should(BeEmpty())
Expect(resp.StatusCode).Should(Equal(http.StatusOK))
Expect(body).Should(ContainSubstring(canaryService))
ginkgo.By("routing requests to the mainline upstream when header is set to 'never'")
f.HTTPTestClient().
GET("/").
WithHeader("Host", host).
WithHeader("CanaryByHeader", "never").
Expect().
Status(http.StatusOK).
Body().Contains(framework.EchoService).NotContains(canaryService)
By("routing requests to the mainline upstream when header is set to 'always'")
resp, body, errs = gorequest.New().
Get(f.GetURL(framework.HTTP)).
Set("Host", host).
Set("CanaryByHeader", "always").
End()
Expect(errs).Should(BeEmpty())
Expect(resp.StatusCode).Should(Equal(http.StatusOK))
Expect(body).Should(ContainSubstring(framework.EchoService))
Expect(body).ShouldNot(ContainSubstring(canaryService))
By("routing requests to the mainline upstream when header is set to 'never'")
resp, body, errs = gorequest.New().
Get(f.GetURL(framework.HTTP)).
Set("Host", host).
Set("CanaryByHeader", "never").
End()
Expect(errs).Should(BeEmpty())
Expect(resp.StatusCode).Should(Equal(http.StatusOK))
Expect(body).Should(ContainSubstring(framework.EchoService))
Expect(body).ShouldNot(ContainSubstring(canaryService))
By("routing requests to the mainline upstream when header is set to anything else")
resp, body, errs = gorequest.New().
Get(f.GetURL(framework.HTTP)).
Set("Host", host).
Set("CanaryByHeader", "otherheadervalue").
End()
Expect(errs).Should(BeEmpty())
Expect(resp.StatusCode).Should(Equal(http.StatusOK))
Expect(body).Should(ContainSubstring(framework.EchoService))
Expect(body).ShouldNot(ContainSubstring(canaryService))
ginkgo.By("routing requests to the mainline upstream when header is set to anything else")
f.HTTPTestClient().
GET("/").
WithHeader("Host", host).
WithHeader("CanaryByHeader", "otherheadervalue").
Expect().
Status(http.StatusOK).
Body().Contains(framework.EchoService).NotContains(canaryService)
})
})
Context("when canaried by header with value and cookie", func() {
It("should route requests to the correct upstream", func() {
ginkgo.Context("when canaried by header with value and cookie", func() {
ginkgo.It("should route requests to the correct upstream", func() {
host := "foo"
annotations := map[string]string{}
ing := framework.NewSingleIngress(host, "/", host, f.Namespace, framework.EchoService, 80, annotations)
ing := framework.NewSingleIngress(host, "/", host,
f.Namespace, framework.EchoService, 80, annotations)
f.EnsureIngress(ing)
f.WaitForNginxServer(host,
func(server string) bool {
return Expect(server).Should(ContainSubstring("server_name foo"))
return strings.Contains(server, "server_name foo")
})
canaryAnnotations := map[string]string{
@ -540,35 +498,34 @@ var _ = framework.DescribeAnnotation("canary-*", func() {
canaryIngName := fmt.Sprintf("%v-canary", host)
canaryIng := framework.NewSingleIngress(canaryIngName, "/", host, f.Namespace, canaryService,
80, canaryAnnotations)
canaryIng := framework.NewSingleIngress(canaryIngName, "/", host,
f.Namespace, canaryService, 80, canaryAnnotations)
f.EnsureIngress(canaryIng)
By("routing requests to the canary upstream when header value does not match and cookie is set to 'always'")
resp, body, errs := gorequest.New().
Get(f.GetURL(framework.HTTP)).
Set("Host", host).
Set("CanaryByHeader", "otherheadervalue").
AddCookie(&http.Cookie{Name: "CanaryByCookie", Value: "always"}).
End()
Expect(errs).Should(BeEmpty())
Expect(resp.StatusCode).Should(Equal(http.StatusOK))
Expect(body).Should(ContainSubstring(canaryService))
ginkgo.By("routing requests to the canary upstream when header value does not match and cookie is set to 'always'")
f.HTTPTestClient().
GET("/").
WithHeader("Host", host).
WithHeader("CanaryByHeader", "otherheadervalue").
WithCookie("CanaryByCookie", "always").
Expect().
Status(http.StatusOK).
Body().Contains(canaryService)
})
})
Context("when canaried by cookie", func() {
It("should route requests to the correct upstream", func() {
ginkgo.Context("when canaried by cookie", func() {
ginkgo.It("should route requests to the correct upstream", func() {
host := "foo"
annotations := map[string]string{}
ing := framework.NewSingleIngress(host, "/", host, f.Namespace, framework.EchoService, 80, annotations)
ing := framework.NewSingleIngress(host, "/", host,
f.Namespace, framework.EchoService, 80, annotations)
f.EnsureIngress(ing)
f.WaitForNginxServer(host,
func(server string) bool {
return Expect(server).Should(ContainSubstring("server_name foo"))
return strings.Contains(server, "server_name foo")
})
canaryAnnotations := map[string]string{
@ -578,111 +535,98 @@ var _ = framework.DescribeAnnotation("canary-*", func() {
canaryIngName := fmt.Sprintf("%v-canary", host)
canaryIng := framework.NewSingleIngress(canaryIngName, "/", host, f.Namespace, canaryService,
80, canaryAnnotations)
canaryIng := framework.NewSingleIngress(canaryIngName, "/", host,
f.Namespace, canaryService, 80, canaryAnnotations)
f.EnsureIngress(canaryIng)
By("routing requests to the canary upstream when cookie is set to 'always'")
resp, body, errs := gorequest.New().
Get(f.GetURL(framework.HTTP)).
Set("Host", host).
AddCookie(&http.Cookie{Name: "Canary-By-Cookie", Value: "always"}).
End()
ginkgo.By("routing requests to the canary upstream when cookie is set to 'always'")
f.HTTPTestClient().
GET("/").
WithHeader("Host", host).
WithCookie("Canary-By-Cookie", "always").
Expect().
Status(http.StatusOK).
Body().Contains(canaryService)
Expect(errs).Should(BeEmpty())
Expect(resp.StatusCode).Should(Equal(http.StatusOK))
Expect(body).Should(ContainSubstring(canaryService))
ginkgo.By("routing requests to the mainline upstream when cookie is set to 'never'")
f.HTTPTestClient().
GET("/").
WithHeader("Host", host).
WithCookie("Canary-By-Cookie", "never").
Expect().
Status(http.StatusOK).
Body().Contains(framework.EchoService).NotContains(canaryService)
By("routing requests to the mainline upstream when cookie is set to 'never'")
resp, body, errs = gorequest.New().
Get(f.GetURL(framework.HTTP)).
Set("Host", host).
AddCookie(&http.Cookie{Name: "Canary-By-Cookie", Value: "never"}).
End()
Expect(errs).Should(BeEmpty())
Expect(resp.StatusCode).Should(Equal(http.StatusOK))
Expect(body).Should(ContainSubstring(framework.EchoService))
Expect(body).ShouldNot(ContainSubstring(canaryService))
By("routing requests to the mainline upstream when cookie is set to anything else")
resp, body, errs = gorequest.New().
Get(f.GetURL(framework.HTTP)).
Set("Host", host).
AddCookie(&http.Cookie{Name: "Canary-By-Cookie", Value: "badcookievalue"}).
End()
Expect(errs).Should(BeEmpty())
Expect(resp.StatusCode).Should(Equal(http.StatusOK))
Expect(body).Should(ContainSubstring(framework.EchoService))
Expect(body).ShouldNot(ContainSubstring(canaryService))
ginkgo.By("routing requests to the mainline upstream when cookie is set to anything else")
f.HTTPTestClient().
GET("/").
WithHeader("Host", host).
WithCookie("Canary-By-Cookie", "badcookievalue").
Expect().
Status(http.StatusOK).
Body().Contains(framework.EchoService).NotContains(canaryService)
})
})
// TODO: add testing for canary-weight 0 < weight < 100
Context("when canaried by weight", func() {
It("should route requests to the correct upstream", func() {
ginkgo.Context("when canaried by weight", func() {
ginkgo.It("should route requests to the correct upstream", func() {
host := "foo"
annotations := map[string]string{}
ing := framework.NewSingleIngress(host, "/", host, f.Namespace, framework.EchoService, 80, annotations)
ing := framework.NewSingleIngress(host, "/", host,
f.Namespace, framework.EchoService, 80, annotations)
f.EnsureIngress(ing)
f.WaitForNginxServer(host,
func(server string) bool {
return Expect(server).Should(ContainSubstring("server_name foo"))
return strings.Contains(server, "server_name foo")
})
canaryIngName := fmt.Sprintf("%v-canary", host)
canaryAnnotations := map[string]string{
"nginx.ingress.kubernetes.io/canary": "true",
"nginx.ingress.kubernetes.io/canary-weight": "0",
}
canaryIngName := fmt.Sprintf("%v-canary", host)
canaryIng := framework.NewSingleIngress(canaryIngName, "/", host, f.Namespace, canaryService,
80, canaryAnnotations)
canaryIng := framework.NewSingleIngress(canaryIngName, "/", host,
f.Namespace, canaryService, 80, canaryAnnotations)
f.EnsureIngress(canaryIng)
By("returning requests from the mainline only when weight is equal to 0")
ginkgo.By("returning requests from the mainline only when weight is equal to 0")
f.HTTPTestClient().
GET("/").
WithHeader("Host", host).
Expect().
Status(http.StatusOK).
Body().
Contains(framework.EchoService).
NotContains(canaryService)
resp, body, errs := gorequest.New().
Get(f.GetURL(framework.HTTP)).
Set("Host", host).
End()
ginkgo.By("returning requests from the canary only when weight is equal to 100")
Expect(errs).Should(BeEmpty())
Expect(resp.StatusCode).Should(Equal(http.StatusOK))
Expect(body).Should(ContainSubstring(framework.EchoService))
Expect(body).ShouldNot(ContainSubstring(canaryService))
By("returning requests from the canary only when weight is equal to 100")
modCanaryAnnotations := map[string]string{
"nginx.ingress.kubernetes.io/canary": "true",
"nginx.ingress.kubernetes.io/canary-weight": "100",
}
modCanaryIng := framework.NewSingleIngress(canaryIngName, "/", host, f.Namespace, canaryService, 80, modCanaryAnnotations)
f.EnsureIngress(modCanaryIng)
resp, body, errs = gorequest.New().
Get(f.GetURL(framework.HTTP)).
Set("Host", host).
End()
Expect(errs).Should(BeEmpty())
Expect(resp.StatusCode).Should(Equal(http.StatusOK))
Expect(body).Should(ContainSubstring(canaryService))
err := framework.UpdateIngress(f.KubeClientSet, f.Namespace, canaryIngName,
func(ingress *networking.Ingress) error {
ingress.ObjectMeta.Annotations = map[string]string{
"nginx.ingress.kubernetes.io/canary": "true",
"nginx.ingress.kubernetes.io/canary-weight": "100",
}
return nil
})
assert.Nil(ginkgo.GinkgoT(), err)
f.HTTPTestClient().
GET("/").
WithHeader("Host", host).
Expect().
Status(http.StatusOK).
Body().
Contains(canaryService)
})
})
Context("Single canary Ingress", func() {
It("should not use canary as a catch-all server", func() {
ginkgo.Context("Single canary Ingress", func() {
ginkgo.It("should not use canary as a catch-all server", func() {
host := "foo"
canaryIngName := fmt.Sprintf("%v-canary", host)
annotations := map[string]string{
@ -690,24 +634,27 @@ var _ = framework.DescribeAnnotation("canary-*", func() {
"nginx.ingress.kubernetes.io/canary-by-header": "CanaryByHeader",
}
ing := framework.NewSingleCatchAllIngress(canaryIngName, f.Namespace, canaryService, 80, annotations)
ing := framework.NewSingleCatchAllIngress(canaryIngName,
f.Namespace, canaryService, 80, annotations)
f.EnsureIngress(ing)
ing = framework.NewSingleCatchAllIngress(host, f.Namespace, framework.EchoService, 80, nil)
ing = framework.NewSingleCatchAllIngress(host, f.Namespace,
framework.EchoService, 80, nil)
f.EnsureIngress(ing)
f.WaitForNginxServer("_",
func(server string) bool {
upstreamName := fmt.Sprintf(`set $proxy_upstream_name "%s-%s-%s";`, f.Namespace, framework.EchoService, "80")
canaryUpstreamName := fmt.Sprintf(`set $proxy_upstream_name "%s-%s-%s";`, f.Namespace, canaryService, "80")
return Expect(server).Should(ContainSubstring(`set $ingress_name "`+host+`";`)) &&
Expect(server).ShouldNot(ContainSubstring(`set $proxy_upstream_name "upstream-default-backend";`)) &&
Expect(server).ShouldNot(ContainSubstring(canaryUpstreamName)) &&
Expect(server).Should(ContainSubstring(upstreamName))
return strings.Contains(server, fmt.Sprintf(`set $ingress_name "%v";`, host)) &&
!strings.Contains(server, `set $proxy_upstream_name "upstream-default-backend";`) &&
!strings.Contains(server, canaryUpstreamName) &&
strings.Contains(server, upstreamName)
})
})
It("should not use canary with domain as a server", func() {
ginkgo.It("should not use canary with domain as a server", func() {
host := "foo"
canaryIngName := fmt.Sprintf("%v-canary", host)
annotations := map[string]string{
@ -715,21 +662,23 @@ var _ = framework.DescribeAnnotation("canary-*", func() {
"nginx.ingress.kubernetes.io/canary-by-header": "CanaryByHeader",
}
ing := framework.NewSingleIngress(canaryIngName, "/", host, f.Namespace, canaryService, 80, annotations)
ing := framework.NewSingleIngress(canaryIngName, "/", host,
f.Namespace, canaryService, 80, annotations)
f.EnsureIngress(ing)
otherHost := "bar"
ing = framework.NewSingleIngress(otherHost, "/", otherHost, f.Namespace, framework.EchoService, 80, nil)
ing = framework.NewSingleIngress(otherHost, "/", otherHost,
f.Namespace, framework.EchoService, 80, nil)
f.EnsureIngress(ing)
f.WaitForNginxConfiguration(func(cfg string) bool {
return Expect(cfg).Should(ContainSubstring("server_name "+otherHost)) &&
Expect(cfg).ShouldNot(ContainSubstring("server_name "+host))
return strings.Contains(cfg, "server_name "+otherHost) &&
!strings.Contains(cfg, "server_name "+host)
})
})
})
It("does not crash when canary ingress has multiple paths to the same non-matching backend", func() {
ginkgo.It("does not crash when canary ingress has multiple paths to the same non-matching backend", func() {
host := "foo"
canaryIngName := fmt.Sprintf("%v-canary", host)
annotations := map[string]string{
@ -738,15 +687,17 @@ var _ = framework.DescribeAnnotation("canary-*", func() {
}
paths := []string{"/foo", "/bar"}
ing := framework.NewSingleIngressWithMultiplePaths(canaryIngName, paths, host, f.Namespace, "httpy-svc-canary", 80, annotations)
ing := framework.NewSingleIngressWithMultiplePaths(canaryIngName, paths, host,
f.Namespace, "httpy-svc-canary", 80, annotations)
f.EnsureIngress(ing)
ing = framework.NewSingleIngress(host, "/", host, f.Namespace, framework.EchoService, 80, nil)
ing = framework.NewSingleIngress(host, "/", host, f.Namespace,
framework.EchoService, 80, nil)
f.EnsureIngress(ing)
f.WaitForNginxServer(host,
func(server string) bool {
return Expect(server).Should(ContainSubstring("server_name foo"))
return strings.Contains(server, "server_name foo")
})
})
})

View file

@ -17,19 +17,21 @@ limitations under the License.
package annotations
import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"strings"
"github.com/onsi/ginkgo"
"k8s.io/ingress-nginx/test/e2e/framework"
)
var _ = framework.DescribeAnnotation("client-body-buffer-size", func() {
f := framework.NewDefaultFramework("clientbodybuffersize")
BeforeEach(func() {
f.NewEchoDeploymentWithReplicas(2)
ginkgo.BeforeEach(func() {
f.NewEchoDeployment()
})
It("should set client_body_buffer_size to 1000", func() {
ginkgo.It("should set client_body_buffer_size to 1000", func() {
host := "proxy.foo.com"
annotations := map[string]string{
"nginx.ingress.kubernetes.io/client-body-buffer-size": "1000",
@ -40,11 +42,11 @@ var _ = framework.DescribeAnnotation("client-body-buffer-size", func() {
f.WaitForNginxServer(host,
func(server string) bool {
return Expect(server).Should(ContainSubstring("client_body_buffer_size 1000;"))
return strings.Contains(server, "client_body_buffer_size 1000;")
})
})
It("should set client_body_buffer_size to 1K", func() {
ginkgo.It("should set client_body_buffer_size to 1K", func() {
host := "proxy.foo.com"
annotations := map[string]string{
"nginx.ingress.kubernetes.io/client-body-buffer-size": "1K",
@ -55,11 +57,11 @@ var _ = framework.DescribeAnnotation("client-body-buffer-size", func() {
f.WaitForNginxServer(host,
func(server string) bool {
return Expect(server).Should(ContainSubstring("client_body_buffer_size 1K;"))
return strings.Contains(server, "client_body_buffer_size 1K;")
})
})
It("should set client_body_buffer_size to 1k", func() {
ginkgo.It("should set client_body_buffer_size to 1k", func() {
host := "proxy.foo.com"
annotations := map[string]string{
"nginx.ingress.kubernetes.io/client-body-buffer-size": "1k",
@ -70,11 +72,11 @@ var _ = framework.DescribeAnnotation("client-body-buffer-size", func() {
f.WaitForNginxServer(host,
func(server string) bool {
return Expect(server).Should(ContainSubstring("client_body_buffer_size 1k;"))
return strings.Contains(server, "client_body_buffer_size 1k;")
})
})
It("should set client_body_buffer_size to 1m", func() {
ginkgo.It("should set client_body_buffer_size to 1m", func() {
host := "proxy.foo.com"
annotations := map[string]string{
"nginx.ingress.kubernetes.io/client-body-buffer-size": "1m",
@ -85,11 +87,11 @@ var _ = framework.DescribeAnnotation("client-body-buffer-size", func() {
f.WaitForNginxServer(host,
func(server string) bool {
return Expect(server).Should(ContainSubstring("client_body_buffer_size 1m;"))
return strings.Contains(server, "client_body_buffer_size 1m;")
})
})
It("should set client_body_buffer_size to 1M", func() {
ginkgo.It("should set client_body_buffer_size to 1M", func() {
host := "proxy.foo.com"
annotations := map[string]string{
"nginx.ingress.kubernetes.io/client-body-buffer-size": "1M",
@ -100,11 +102,11 @@ var _ = framework.DescribeAnnotation("client-body-buffer-size", func() {
f.WaitForNginxServer(host,
func(server string) bool {
return Expect(server).Should(ContainSubstring("client_body_buffer_size 1M;"))
return strings.Contains(server, "client_body_buffer_size 1M;")
})
})
It("should not set client_body_buffer_size to invalid 1b", func() {
ginkgo.It("should not set client_body_buffer_size to invalid 1b", func() {
host := "proxy.foo.com"
annotations := map[string]string{
"nginx.ingress.kubernetes.io/client-body-buffer-size": "1b",
@ -115,7 +117,7 @@ var _ = framework.DescribeAnnotation("client-body-buffer-size", func() {
f.WaitForNginxServer(host,
func(server string) bool {
return Expect(server).ShouldNot(ContainSubstring("client_body_buffer_size 1b;"))
return !strings.Contains(server, "client_body_buffer_size 1b;")
})
})
})

View file

@ -19,22 +19,21 @@ package annotations
import (
"fmt"
"net/http"
"time"
"strings"
"github.com/onsi/ginkgo"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/parnurzeal/gorequest"
"k8s.io/ingress-nginx/test/e2e/framework"
)
var _ = framework.DescribeAnnotation("connection-proxy-header", func() {
f := framework.NewDefaultFramework("connection")
BeforeEach(func() {
f.NewEchoDeploymentWithReplicas(2)
ginkgo.BeforeEach(func() {
f.NewEchoDeployment()
})
It("set connection header to keep-alive", func() {
ginkgo.It("set connection header to keep-alive", func() {
host := "connection.foo.com"
annotations := map[string]string{
"nginx.ingress.kubernetes.io/connection-proxy-header": "keep-alive",
@ -45,17 +44,14 @@ var _ = framework.DescribeAnnotation("connection-proxy-header", func() {
f.WaitForNginxServer(host,
func(server string) bool {
return Expect(server).Should(ContainSubstring(`proxy_set_header Connection keep-alive;`))
return strings.Contains(server, "proxy_set_header Connection keep-alive;")
})
resp, body, errs := gorequest.New().
Get(f.GetURL(framework.HTTP)).
Retry(10, 1*time.Second, http.StatusNotFound).
Set("Host", host).
End()
Expect(errs).Should(BeEmpty())
Expect(resp.StatusCode).Should(Equal(http.StatusOK))
Expect(body).Should(ContainSubstring(fmt.Sprintf("connection=keep-alive")))
f.HTTPTestClient().
GET("/").
WithHeader("Host", host).
Expect().
Status(http.StatusOK).
Body().Contains(fmt.Sprintf("connection=keep-alive"))
})
})

View file

@ -18,10 +18,9 @@ package annotations
import (
"net/http"
"strings"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/parnurzeal/gorequest"
"github.com/onsi/ginkgo"
"k8s.io/ingress-nginx/test/e2e/framework"
)
@ -29,11 +28,11 @@ import (
var _ = framework.DescribeAnnotation("cors-*", func() {
f := framework.NewDefaultFramework("cors")
BeforeEach(func() {
ginkgo.BeforeEach(func() {
f.NewEchoDeploymentWithReplicas(2)
})
It("should enable cors", func() {
ginkgo.It("should enable cors", func() {
host := "cors.foo.com"
annotations := map[string]string{
"nginx.ingress.kubernetes.io/enable-cors": "true",
@ -44,39 +43,21 @@ var _ = framework.DescribeAnnotation("cors-*", func() {
f.WaitForNginxServer(host,
func(server string) bool {
return Expect(server).Should(ContainSubstring("more_set_headers 'Access-Control-Allow-Methods: GET, PUT, POST, DELETE, PATCH, OPTIONS';"))
return strings.Contains(server, "more_set_headers 'Access-Control-Allow-Methods: GET, PUT, POST, DELETE, PATCH, OPTIONS';") &&
strings.Contains(server, "more_set_headers 'Access-Control-Allow-Origin: *';") &&
strings.Contains(server, "more_set_headers 'Access-Control-Allow-Headers: DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization';") &&
strings.Contains(server, "more_set_headers 'Access-Control-Max-Age: 1728000';") &&
strings.Contains(server, "more_set_headers 'Access-Control-Allow-Credentials: true';")
})
f.WaitForNginxServer(host,
func(server string) bool {
return Expect(server).Should(ContainSubstring("more_set_headers 'Access-Control-Allow-Origin: *';"))
})
f.WaitForNginxServer(host,
func(server string) bool {
return Expect(server).Should(ContainSubstring("more_set_headers 'Access-Control-Allow-Headers: DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization';"))
})
f.WaitForNginxServer(host,
func(server string) bool {
return Expect(server).Should(ContainSubstring("more_set_headers 'Access-Control-Max-Age: 1728000';"))
})
f.WaitForNginxServer(host,
func(server string) bool {
return Expect(server).Should(ContainSubstring("more_set_headers 'Access-Control-Allow-Credentials: true';"))
})
uri := "/"
resp, _, errs := gorequest.New().
Options(f.GetURL(framework.HTTP)+uri).
Set("Host", host).
End()
Expect(errs).Should(BeEmpty())
Expect(resp.StatusCode).Should(Equal(http.StatusNoContent))
f.HTTPTestClient().
GET("/").
WithHeader("Host", host).
Expect().
Status(http.StatusOK)
})
It("should set cors methods to only allow POST, GET", func() {
ginkgo.It("should set cors methods to only allow POST, GET", func() {
host := "cors.foo.com"
annotations := map[string]string{
"nginx.ingress.kubernetes.io/enable-cors": "true",
@ -88,11 +69,11 @@ var _ = framework.DescribeAnnotation("cors-*", func() {
f.WaitForNginxServer(host,
func(server string) bool {
return Expect(server).Should(ContainSubstring("more_set_headers 'Access-Control-Allow-Methods: POST, GET';"))
return strings.Contains(server, "more_set_headers 'Access-Control-Allow-Methods: POST, GET';")
})
})
It("should set cors max-age", func() {
ginkgo.It("should set cors max-age", func() {
host := "cors.foo.com"
annotations := map[string]string{
"nginx.ingress.kubernetes.io/enable-cors": "true",
@ -104,11 +85,11 @@ var _ = framework.DescribeAnnotation("cors-*", func() {
f.WaitForNginxServer(host,
func(server string) bool {
return Expect(server).Should(ContainSubstring("more_set_headers 'Access-Control-Max-Age: 200';"))
return strings.Contains(server, "more_set_headers 'Access-Control-Max-Age: 200';")
})
})
It("should disable cors allow credentials", func() {
ginkgo.It("should disable cors allow credentials", func() {
host := "cors.foo.com"
annotations := map[string]string{
"nginx.ingress.kubernetes.io/enable-cors": "true",
@ -120,11 +101,11 @@ var _ = framework.DescribeAnnotation("cors-*", func() {
f.WaitForNginxServer(host,
func(server string) bool {
return Expect(server).ShouldNot(ContainSubstring("more_set_headers 'Access-Control-Allow-Credentials: true';"))
return !strings.Contains(server, "more_set_headers 'Access-Control-Allow-Credentials: true';")
})
})
It("should allow origin for cors", func() {
ginkgo.It("should allow origin for cors", func() {
host := "cors.foo.com"
annotations := map[string]string{
"nginx.ingress.kubernetes.io/enable-cors": "true",
@ -136,11 +117,11 @@ var _ = framework.DescribeAnnotation("cors-*", func() {
f.WaitForNginxServer(host,
func(server string) bool {
return Expect(server).Should(ContainSubstring("more_set_headers 'Access-Control-Allow-Origin: https://origin.cors.com:8080';"))
return strings.Contains(server, "more_set_headers 'Access-Control-Allow-Origin: https://origin.cors.com:8080';")
})
})
It("should allow headers for cors", func() {
ginkgo.It("should allow headers for cors", func() {
host := "cors.foo.com"
annotations := map[string]string{
"nginx.ingress.kubernetes.io/enable-cors": "true",
@ -152,7 +133,7 @@ var _ = framework.DescribeAnnotation("cors-*", func() {
f.WaitForNginxServer(host,
func(server string) bool {
return Expect(server).Should(ContainSubstring("more_set_headers 'Access-Control-Allow-Headers: DNT, User-Agent';"))
return strings.Contains(server, "more_set_headers 'Access-Control-Allow-Headers: DNT, User-Agent';")
})
})
})

View file

@ -20,8 +20,8 @@ import (
"fmt"
"strings"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/onsi/ginkgo"
"github.com/stretchr/testify/assert"
networking "k8s.io/api/networking/v1beta1"
"k8s.io/ingress-nginx/test/e2e/framework"
@ -34,11 +34,11 @@ func errorBlockName(upstreamName string, errorCode string) string {
var _ = framework.DescribeAnnotation("custom-http-errors", func() {
f := framework.NewDefaultFramework("custom-http-errors")
BeforeEach(func() {
f.NewEchoDeploymentWithReplicas(1)
ginkgo.BeforeEach(func() {
f.NewEchoDeployment()
})
It("configures Nginx correctly", func() {
ginkgo.It("configures Nginx correctly", func() {
host := "customerrors.foo.com"
errorCodes := []string{"404", "500"}
@ -56,25 +56,26 @@ var _ = framework.DescribeAnnotation("custom-http-errors", func() {
return strings.Contains(serverConfig, fmt.Sprintf("server_name %s", host))
})
By("turning on proxy_intercept_errors directive")
Expect(serverConfig).Should(ContainSubstring("proxy_intercept_errors on;"))
ginkgo.By("turning on proxy_intercept_errors directive")
assert.Contains(ginkgo.GinkgoT(), serverConfig, "proxy_intercept_errors on;")
By("configuring error_page directive")
ginkgo.By("configuring error_page directive")
for _, code := range errorCodes {
Expect(serverConfig).Should(ContainSubstring(fmt.Sprintf("error_page %s = %s", code, errorBlockName("upstream-default-backend", code))))
assert.Contains(ginkgo.GinkgoT(), serverConfig, fmt.Sprintf("error_page %s = %s", code, errorBlockName("upstream-default-backend", code)))
}
By("creating error locations")
ginkgo.By("creating error locations")
for _, code := range errorCodes {
Expect(serverConfig).Should(ContainSubstring(fmt.Sprintf("location %s", errorBlockName("upstream-default-backend", code))))
assert.Contains(ginkgo.GinkgoT(), serverConfig, fmt.Sprintf("location %s", errorBlockName("upstream-default-backend", code)))
}
By("updating configuration when only custom-http-error value changes")
ginkgo.By("updating configuration when only custom-http-error value changes")
err := framework.UpdateIngress(f.KubeClientSet, f.Namespace, host, func(ingress *networking.Ingress) error {
ingress.ObjectMeta.Annotations["nginx.ingress.kubernetes.io/custom-http-errors"] = "503"
return nil
})
Expect(err).ToNot(HaveOccurred())
assert.Nil(ginkgo.GinkgoT(), err)
f.WaitForNginxServer(host, func(sc string) bool {
if serverConfig != sc {
serverConfig = sc
@ -82,22 +83,23 @@ var _ = framework.DescribeAnnotation("custom-http-errors", func() {
}
return false
})
Expect(serverConfig).Should(ContainSubstring(fmt.Sprintf("location %s", errorBlockName("upstream-default-backend", "503"))))
Expect(serverConfig).ShouldNot(ContainSubstring(fmt.Sprintf("location %s", errorBlockName("upstream-default-backend", "404"))))
Expect(serverConfig).ShouldNot(ContainSubstring(fmt.Sprintf("location %s", errorBlockName("upstream-default-backend", "500"))))
assert.Contains(ginkgo.GinkgoT(), serverConfig, fmt.Sprintf("location %s", errorBlockName("upstream-default-backend", "503")))
assert.NotContains(ginkgo.GinkgoT(), serverConfig, fmt.Sprintf("location %s", errorBlockName("upstream-default-backend", "404")))
assert.NotContains(ginkgo.GinkgoT(), serverConfig, fmt.Sprintf("location %s", errorBlockName("upstream-default-backend", "500")))
By("ignoring duplicate values (503 in this case) per server")
ginkgo.By("ignoring duplicate values (503 in this case) per server")
annotations["nginx.ingress.kubernetes.io/custom-http-errors"] = "404, 503"
ing = framework.NewSingleIngress(fmt.Sprintf("%s-else", host), "/else", host, f.Namespace, framework.EchoService, 80, annotations)
f.EnsureIngress(ing)
f.WaitForNginxServer(host, func(sc string) bool {
serverConfig = sc
return strings.Contains(serverConfig, "location /else")
})
count := strings.Count(serverConfig, fmt.Sprintf("location %s", errorBlockName("upstream-default-backend", "503")))
Expect(count).Should(Equal(1))
assert.Equal(ginkgo.GinkgoT(), count, 1)
By("using the custom default-backend from annotation for upstream")
ginkgo.By("using the custom default-backend from annotation for upstream")
customDefaultBackend := "from-annotation"
f.NewEchoDeploymentWithNameAndReplicas(customDefaultBackend, 1)
@ -105,7 +107,8 @@ var _ = framework.DescribeAnnotation("custom-http-errors", func() {
ingress.ObjectMeta.Annotations["nginx.ingress.kubernetes.io/default-backend"] = customDefaultBackend
return nil
})
Expect(err).ToNot(HaveOccurred())
assert.Nil(ginkgo.GinkgoT(), err)
f.WaitForNginxServer(host, func(sc string) bool {
if serverConfig != sc {
serverConfig = sc
@ -113,7 +116,7 @@ var _ = framework.DescribeAnnotation("custom-http-errors", func() {
}
return false
})
Expect(serverConfig).Should(ContainSubstring(errorBlockName(fmt.Sprintf("custom-default-backend-%s", customDefaultBackend), "503")))
Expect(serverConfig).Should(ContainSubstring(fmt.Sprintf("error_page %s = %s", "503", errorBlockName(fmt.Sprintf("custom-default-backend-%s", customDefaultBackend), "503"))))
assert.Contains(ginkgo.GinkgoT(), serverConfig, errorBlockName(fmt.Sprintf("custom-default-backend-%s", customDefaultBackend), "503"))
assert.Contains(ginkgo.GinkgoT(), serverConfig, fmt.Sprintf("error_page %s = %s", "503", errorBlockName(fmt.Sprintf("custom-default-backend-%s", customDefaultBackend), "503")))
})
})

View file

@ -19,10 +19,9 @@ package annotations
import (
"fmt"
"net/http"
"strings"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/parnurzeal/gorequest"
"github.com/onsi/ginkgo"
"k8s.io/ingress-nginx/test/e2e/framework"
)
@ -30,12 +29,12 @@ import (
var _ = framework.DescribeAnnotation("default-backend", func() {
f := framework.NewDefaultFramework("default-backend")
BeforeEach(func() {
ginkgo.BeforeEach(func() {
f.NewEchoDeployment()
})
Context("when default backend annotation is enabled", func() {
It("should use a custom default backend as upstream", func() {
ginkgo.Context("when default backend annotation is enabled", func() {
ginkgo.It("should use a custom default backend as upstream", func() {
host := "default-backend"
annotations := map[string]string{
"nginx.ingress.kubernetes.io/default-backend": framework.EchoService,
@ -46,24 +45,21 @@ var _ = framework.DescribeAnnotation("default-backend", func() {
f.WaitForNginxServer(host,
func(server string) bool {
return Expect(server).Should(ContainSubstring(fmt.Sprintf("server_name %v", host)))
return strings.Contains(server, fmt.Sprintf("server_name %v", host))
})
uri := "/alma/armud"
requestId := "something-unique"
resp, body, errs := gorequest.New().
Get(f.GetURL(framework.HTTP)+uri).
Set("Host", host).
Set("x-request-id", requestId).
End()
Expect(errs).Should(BeEmpty())
Expect(resp.StatusCode).Should(Equal(http.StatusOK))
Expect(body).To(ContainSubstring("x-code=503"))
Expect(body).To(ContainSubstring(fmt.Sprintf("x-ingress-name=%s", host)))
Expect(body).To(ContainSubstring("x-service-name=invalid"))
Expect(body).To(ContainSubstring(fmt.Sprintf("x-request-id=%s", requestId)))
f.HTTPTestClient().
GET("/alma/armud").
WithHeader("Host", host).
WithHeader("x-request-id", requestId).
Expect().
Status(http.StatusOK).
Body().Contains("x-code=503").
Contains(fmt.Sprintf("x-ingress-name=%s", host)).
Contains("x-service-name=invalid").
Contains(fmt.Sprintf("x-request-id=%s", requestId))
})
})
})

View file

@ -18,10 +18,10 @@ package annotations
import (
"net/http"
"strings"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/parnurzeal/gorequest"
"github.com/onsi/ginkgo"
"github.com/stretchr/testify/assert"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@ -31,11 +31,11 @@ import (
var _ = framework.DescribeAnnotation("backend-protocol - FastCGI", func() {
f := framework.NewDefaultFramework("fastcgi")
BeforeEach(func() {
ginkgo.BeforeEach(func() {
f.NewFastCGIHelloServerDeployment()
})
It("should use fastcgi_pass in the configuration file", func() {
ginkgo.It("should use fastcgi_pass in the configuration file", func() {
host := "fastcgi"
annotations := map[string]string{
@ -47,12 +47,12 @@ var _ = framework.DescribeAnnotation("backend-protocol - FastCGI", func() {
f.WaitForNginxServer(host,
func(server string) bool {
return Expect(server).Should(ContainSubstring("include /etc/nginx/fastcgi_params;")) &&
Expect(server).Should(ContainSubstring("fastcgi_pass"))
return strings.Contains(server, "include /etc/nginx/fastcgi_params;") &&
strings.Contains(server, "fastcgi_pass")
})
})
It("should add fastcgi_index in the configuration file", func() {
ginkgo.It("should add fastcgi_index in the configuration file", func() {
host := "fastcgi-index"
annotations := map[string]string{
@ -65,11 +65,11 @@ var _ = framework.DescribeAnnotation("backend-protocol - FastCGI", func() {
f.WaitForNginxServer(host,
func(server string) bool {
return Expect(server).Should(ContainSubstring("fastcgi_index \"index.php\";"))
return strings.Contains(server, "fastcgi_index \"index.php\";")
})
})
It("should add fastcgi_param in the configuration file", func() {
ginkgo.It("should add fastcgi_param in the configuration file", func() {
configuration := &corev1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
Name: "fastcgi-configmap",
@ -82,8 +82,8 @@ var _ = framework.DescribeAnnotation("backend-protocol - FastCGI", func() {
}
cm, err := f.EnsureConfigMap(configuration)
Expect(err).NotTo(HaveOccurred(), "failed to create an the configmap")
Expect(cm).NotTo(BeNil(), "expected a configmap but none returned")
assert.Nil(ginkgo.GinkgoT(), err, "creating configmap")
assert.NotNil(ginkgo.GinkgoT(), cm, "expected a configmap but none returned")
host := "fastcgi-params-configmap"
@ -97,12 +97,12 @@ var _ = framework.DescribeAnnotation("backend-protocol - FastCGI", func() {
f.WaitForNginxServer(host,
func(server string) bool {
return Expect(server).Should(ContainSubstring("fastcgi_param SCRIPT_FILENAME \"/home/www/scripts/php$fastcgi_script_name\";")) &&
Expect(server).Should(ContainSubstring("fastcgi_param REDIRECT_STATUS \"200\";"))
return strings.Contains(server, "fastcgi_param SCRIPT_FILENAME \"/home/www/scripts/php$fastcgi_script_name\";") &&
strings.Contains(server, "fastcgi_param REDIRECT_STATUS \"200\";")
})
})
It("should return OK for service with backend protocol FastCGI", func() {
ginkgo.It("should return OK for service with backend protocol FastCGI", func() {
host := "fastcgi-helloserver"
path := "/hello"
@ -115,16 +115,14 @@ var _ = framework.DescribeAnnotation("backend-protocol - FastCGI", func() {
f.WaitForNginxServer(host,
func(server string) bool {
return Expect(server).Should(ContainSubstring("fastcgi_pass"))
return strings.Contains(server, "fastcgi_pass")
})
resp, body, errs := gorequest.New().
Get(f.GetURL(framework.HTTP)+path).
Set("Host", host).
End()
Expect(errs).Should(BeEmpty())
Expect(resp.StatusCode).Should(Equal(http.StatusOK))
Expect(body).Should(ContainSubstring("Hello world!"))
f.HTTPTestClient().
GET(path).
WithHeader("Host", host).
Expect().
Status(http.StatusOK).
Body().Contains("Hello world!")
})
})

View file

@ -18,22 +18,20 @@ package annotations
import (
"net/http"
"time"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/parnurzeal/gorequest"
"github.com/onsi/ginkgo"
"k8s.io/ingress-nginx/test/e2e/framework"
)
var _ = framework.DescribeAnnotation("force-ssl-redirect", func() {
f := framework.NewDefaultFramework("forcesslredirect")
BeforeEach(func() {
f.NewEchoDeploymentWithReplicas(2)
ginkgo.BeforeEach(func() {
f.NewEchoDeployment()
})
It("should redirect to https", func() {
ginkgo.It("should redirect to https", func() {
host := "forcesslredirect.bar.com"
annotations := map[string]string{
@ -43,15 +41,11 @@ var _ = framework.DescribeAnnotation("force-ssl-redirect", func() {
ing := framework.NewSingleIngress(host, "/", host, f.Namespace, framework.EchoService, 80, annotations)
f.EnsureIngress(ing)
resp, _, errs := gorequest.New().
Get(f.GetURL(framework.HTTP)).
Retry(10, 1*time.Second, http.StatusNotFound).
RedirectPolicy(noRedirectPolicyFunc).
Set("Host", host).
End()
Expect(errs).Should(BeEmpty())
Expect(resp.StatusCode).Should(Equal(http.StatusPermanentRedirect))
Expect(resp.Header.Get("Location")).Should(Equal("https://forcesslredirect.bar.com/"))
f.HTTPTestClient().
GET("/").
WithHeader("Host", host).
Expect().
Status(http.StatusPermanentRedirect).
Header("Location").Equal("https://forcesslredirect.bar.com/")
})
})

View file

@ -20,11 +20,11 @@ import (
"crypto/tls"
"fmt"
"net/http"
"strings"
"time"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/parnurzeal/gorequest"
"github.com/onsi/ginkgo"
"github.com/stretchr/testify/assert"
"k8s.io/ingress-nginx/test/e2e/framework"
)
@ -32,12 +32,12 @@ import (
var _ = framework.DescribeAnnotation("from-to-www-redirect", func() {
f := framework.NewDefaultFramework("fromtowwwredirect")
BeforeEach(func() {
f.NewEchoDeploymentWithReplicas(1)
ginkgo.BeforeEach(func() {
f.NewEchoDeployment()
})
It("should redirect from www HTTP to HTTP", func() {
By("setting up server for redirect from www")
ginkgo.It("should redirect from www HTTP to HTTP", func() {
ginkgo.By("setting up server for redirect from www")
host := "fromtowwwredirect.bar.com"
annotations := map[string]string{
@ -49,26 +49,21 @@ var _ = framework.DescribeAnnotation("from-to-www-redirect", func() {
f.WaitForNginxConfiguration(
func(cfg string) bool {
return Expect(cfg).Should(ContainSubstring(`server_name www.fromtowwwredirect.bar.com;`)) &&
Expect(cfg).Should(ContainSubstring(`return 308 $scheme://fromtowwwredirect.bar.com$request_uri;`))
return strings.Contains(cfg, `server_name www.fromtowwwredirect.bar.com;`) &&
strings.Contains(cfg, `return 308 $scheme://fromtowwwredirect.bar.com$request_uri;`)
})
By("sending request to www.fromtowwwredirect.bar.com")
resp, _, errs := gorequest.New().
Get(fmt.Sprintf("%s/%s", f.GetURL(framework.HTTP), "foo")).
Retry(10, 1*time.Second, http.StatusNotFound).
RedirectPolicy(noRedirectPolicyFunc).
Set("Host", fmt.Sprintf("%s.%s", "www", host)).
End()
Expect(errs).Should(BeEmpty())
Expect(resp.StatusCode).Should(Equal(http.StatusPermanentRedirect))
Expect(resp.Header.Get("Location")).Should(Equal("http://fromtowwwredirect.bar.com/foo"))
ginkgo.By("sending request to www.fromtowwwredirect.bar.com")
f.HTTPTestClient().
GET("/foo").
WithHeader("Host", fmt.Sprintf("%s.%s", "www", host)).
Expect().
Status(http.StatusPermanentRedirect).
Header("Location").Equal("http://fromtowwwredirect.bar.com/foo")
})
It("should redirect from www HTTPS to HTTPS", func() {
By("setting up server for redirect from www")
ginkgo.It("should redirect from www HTTPS to HTTPS", func() {
ginkgo.By("setting up server for redirect from www")
fromHost := fmt.Sprintf("%s.nip.io", f.GetNginxIP())
toHost := fmt.Sprintf("www.%s", fromHost)
@ -85,45 +80,37 @@ var _ = framework.DescribeAnnotation("from-to-www-redirect", func() {
ing.Spec.TLS[0].Hosts,
ing.Spec.TLS[0].SecretName,
ing.Namespace)
Expect(err).ToNot(HaveOccurred())
assert.Nil(ginkgo.GinkgoT(), err)
time.Sleep(5 * time.Second)
f.WaitForNginxServer(toHost,
func(server string) bool {
return Expect(server).Should(ContainSubstring(fmt.Sprintf(`server_name %v;`, toHost))) &&
Expect(server).Should(ContainSubstring(fmt.Sprintf(`return 308 $scheme://%v$request_uri;`, fromHost)))
return strings.Contains(server, fmt.Sprintf(`server_name %v;`, toHost)) &&
strings.Contains(server, fmt.Sprintf(`return 308 $scheme://%v$request_uri;`, fromHost))
})
By("sending request to www should redirect to domain without www")
ginkgo.By("sending request to www should redirect to domain")
f.HTTPTestClientWithTLSConfig(&tls.Config{
InsecureSkipVerify: true,
ServerName: toHost,
}).
GET("/").
WithURL(f.GetURL(framework.HTTPS)).
WithHeader("Host", toHost).
Expect().
Status(http.StatusPermanentRedirect).
Header("Location").Equal(fmt.Sprintf("https://%v/", fromHost))
resp, _, errs := gorequest.New().
TLSClientConfig(&tls.Config{
InsecureSkipVerify: true,
ServerName: toHost,
}).
Get(f.GetURL(framework.HTTPS)).
Retry(10, 1*time.Second, http.StatusNotFound).
RedirectPolicy(noRedirectPolicyFunc).
Set("host", toHost).
End()
Expect(errs).Should(BeEmpty())
Expect(resp.StatusCode).Should(Equal(http.StatusPermanentRedirect))
Expect(resp.Header.Get("Location")).Should(Equal(fmt.Sprintf("https://%v/", fromHost)))
By("sending request to domain should redirect to domain with www")
req := gorequest.New().
TLSClientConfig(&tls.Config{
InsecureSkipVerify: true,
ServerName: toHost,
}).
Get(f.GetURL(framework.HTTPS)).
Set("host", toHost)
resp, _, errs = req.End()
Expect(errs).Should(BeEmpty())
Expect(resp.StatusCode).Should(Equal(http.StatusOK))
Expect(resp.Header.Get("ExpectedHost")).Should(Equal(fromHost))
ginkgo.By("sending request to domain should not redirect to www")
f.HTTPTestClientWithTLSConfig(&tls.Config{
InsecureSkipVerify: true,
ServerName: fromHost,
}).
GET("/").
WithURL(f.GetURL(framework.HTTPS)).
WithHeader("Host", fromHost).
Expect().
Status(http.StatusOK).
Header("ExpectedHost").Equal(fromHost)
})
})

View file

@ -21,10 +21,9 @@ import (
"fmt"
"strings"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
pb "github.com/moul/pb/grpcbin/go-grpc"
"github.com/onsi/ginkgo"
"github.com/stretchr/testify/assert"
"golang.org/x/net/context"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials"
@ -39,7 +38,7 @@ import (
var _ = framework.DescribeAnnotation("backend-protocol - GRPC", func() {
f := framework.NewDefaultFramework("grpc")
It("should use grpc_pass in the configuration file", func() {
ginkgo.It("should use grpc_pass in the configuration file", func() {
f.NewGRPCFortuneTellerDeployment()
host := "grpc"
@ -53,18 +52,18 @@ var _ = framework.DescribeAnnotation("backend-protocol - GRPC", func() {
f.WaitForNginxServer(host,
func(server string) bool {
return Expect(server).Should(ContainSubstring(fmt.Sprintf("server_name %v", host)))
return strings.Contains(server, fmt.Sprintf("server_name %v", host))
})
f.WaitForNginxServer(host,
func(server string) bool {
return Expect(server).Should(ContainSubstring("grpc_pass")) &&
Expect(server).Should(ContainSubstring("grpc_set_header")) &&
Expect(server).ShouldNot(ContainSubstring("proxy_pass"))
return strings.Contains(server, "grpc_pass") &&
strings.Contains(server, "grpc_set_header") &&
!strings.Contains(server, "proxy_pass")
})
})
It("should return OK for service with backend protocol GRPC", func() {
ginkgo.It("should return OK for service with backend protocol GRPC", func() {
f.NewGRPCBinDeployment()
host := "echo"
@ -116,14 +115,14 @@ var _ = framework.DescribeAnnotation("backend-protocol - GRPC", func() {
ctx := context.Background()
res, err := client.HeadersUnary(ctx, &pb.EmptyMessage{})
Expect(err).Should(BeNil())
assert.Nil(ginkgo.GinkgoT(), err)
metadata := res.GetMetadata()
Expect(metadata["content-type"].Values[0]).Should(Equal("application/grpc"))
assert.Equal(ginkgo.GinkgoT(), metadata["content-type"].Values[0], "application/grpc")
})
It("should return OK for service with backend protocol GRPCS", func() {
Skip("GRPCS test temporarily disabled")
ginkgo.It("should return OK for service with backend protocol GRPCS", func() {
ginkgo.Skip("GRPCS test temporarily disabled")
f.NewGRPCBinDeployment()
@ -181,9 +180,9 @@ var _ = framework.DescribeAnnotation("backend-protocol - GRPC", func() {
ctx := context.Background()
res, err := client.HeadersUnary(ctx, &pb.EmptyMessage{})
Expect(err).Should(BeNil())
assert.Nil(ginkgo.GinkgoT(), err)
metadata := res.GetMetadata()
Expect(metadata["content-type"].Values[0]).Should(Equal("application/grpc"))
assert.Equal(ginkgo.GinkgoT(), metadata["content-type"].Values[0], "application/grpc")
})
})

View file

@ -17,19 +17,21 @@ limitations under the License.
package annotations
import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"strings"
"github.com/onsi/ginkgo"
"k8s.io/ingress-nginx/test/e2e/framework"
)
var _ = framework.DescribeAnnotation("http2-push-preload", func() {
f := framework.NewDefaultFramework("http2pushpreload")
BeforeEach(func() {
f.NewEchoDeploymentWithReplicas(2)
ginkgo.BeforeEach(func() {
f.NewEchoDeployment()
})
It("enable the http2-push-preload directive", func() {
ginkgo.It("enable the http2-push-preload directive", func() {
host := "http2pp.foo.com"
annotations := map[string]string{
"nginx.ingress.kubernetes.io/http2-push-preload": "true",
@ -40,7 +42,7 @@ var _ = framework.DescribeAnnotation("http2-push-preload", func() {
f.WaitForNginxServer(host,
func(server string) bool {
return Expect(server).Should(ContainSubstring("http2_push_preload on;"))
return strings.Contains(server, "http2_push_preload on;")
})
})
})

View file

@ -21,31 +21,30 @@ import (
"fmt"
"net/http"
"os/exec"
"strings"
"time"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
jsoniter "github.com/json-iterator/go"
"github.com/parnurzeal/gorequest"
"github.com/onsi/ginkgo"
"github.com/stretchr/testify/assert"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/intstr"
"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/ingress-nginx/test/e2e/framework"
)
var _ = framework.DescribeAnnotation("influxdb-*", func() {
f := framework.NewDefaultFramework("influxdb")
BeforeEach(func() {
ginkgo.BeforeEach(func() {
f.NewInfluxDBDeployment()
f.NewEchoDeployment()
})
Context("when influxdb is enabled", func() {
It("should send the request metric to the influxdb server", func() {
ginkgo.Context("when influxdb is enabled", func() {
ginkgo.It("should send the request metric to the influxdb server", func() {
ifs := createInfluxDBService(f)
// Ingress configured with InfluxDB annotations
@ -66,13 +65,11 @@ var _ = framework.DescribeAnnotation("influxdb-*", func() {
// Do a request to the echo server ingress that sends metrics
// to the InfluxDB backend.
res, _, errs := gorequest.New().
Get(f.GetURL(framework.HTTP)).
Set("Host", host).
End()
Expect(len(errs)).Should(Equal(0))
Expect(res.StatusCode).Should(Equal(http.StatusOK))
f.HTTPTestClient().
GET("/").
WithHeader("Host", host).
Expect().
Status(http.StatusOK)
time.Sleep(10 * time.Second)
@ -86,14 +83,14 @@ var _ = framework.DescribeAnnotation("influxdb-*", func() {
}
return true, nil
})
Expect(err).NotTo(HaveOccurred())
assert.Nil(ginkgo.GinkgoT(), err)
var results map[string][]map[string]interface{}
_ = jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal([]byte(measurements), &results)
Expect(len(measurements)).ShouldNot(Equal(0))
assert.NotEqual(ginkgo.GinkgoT(), len(measurements), 0)
for _, elem := range results["results"] {
Expect(len(elem)).ShouldNot(Equal(0))
assert.NotEqual(ginkgo.GinkgoT(), len(elem), 0)
}
})
})
@ -128,7 +125,7 @@ func createInfluxDBIngress(f *framework.Framework, host, service string, port in
f.WaitForNginxServer(host,
func(server string) bool {
return Expect(server).Should(ContainSubstring(fmt.Sprintf("server_name %v", host)))
return strings.Contains(server, fmt.Sprintf("server_name %v", host))
})
}

View file

@ -19,19 +19,18 @@ package annotations
import (
"strings"
. "github.com/onsi/ginkgo"
"github.com/onsi/ginkgo"
"k8s.io/ingress-nginx/test/e2e/framework"
)
var _ = framework.DescribeAnnotation("whitelist-source-range", func() {
f := framework.NewDefaultFramework("ipwhitelist")
BeforeEach(func() {
f.NewEchoDeploymentWithReplicas(2)
ginkgo.BeforeEach(func() {
f.NewEchoDeployment()
})
It("should set valid ip whitelist range", func() {
ginkgo.It("should set valid ip whitelist range", func() {
host := "ipwhitelist.foo.com"
nameSpace := f.Namespace

View file

@ -17,8 +17,9 @@ limitations under the License.
package annotations
import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"strings"
"github.com/onsi/ginkgo"
"k8s.io/ingress-nginx/test/e2e/framework"
)
@ -26,11 +27,11 @@ import (
var _ = framework.DescribeAnnotation("enable-access-log enable-rewrite-log", func() {
f := framework.NewDefaultFramework("log")
BeforeEach(func() {
f.NewEchoDeploymentWithReplicas(2)
ginkgo.BeforeEach(func() {
f.NewEchoDeployment()
})
It("set access_log off", func() {
ginkgo.It("set access_log off", func() {
host := "log.foo.com"
annotations := map[string]string{
"nginx.ingress.kubernetes.io/enable-access-log": "false",
@ -41,11 +42,11 @@ var _ = framework.DescribeAnnotation("enable-access-log enable-rewrite-log", fun
f.WaitForNginxServer(host,
func(server string) bool {
return Expect(server).Should(ContainSubstring(`access_log off;`))
return strings.Contains(server, `access_log off;`)
})
})
It("set rewrite_log on", func() {
ginkgo.It("set rewrite_log on", func() {
host := "log.foo.com"
annotations := map[string]string{
"nginx.ingress.kubernetes.io/enable-rewrite-log": "true",
@ -56,7 +57,7 @@ var _ = framework.DescribeAnnotation("enable-access-log enable-rewrite-log", fun
f.WaitForNginxServer(host,
func(server string) bool {
return Expect(server).Should(ContainSubstring(`rewrite_log on;`))
return strings.Contains(server, `rewrite_log on;`)
})
})
})

View file

@ -20,7 +20,7 @@ import (
"fmt"
"strings"
. "github.com/onsi/ginkgo"
"github.com/onsi/ginkgo"
"k8s.io/ingress-nginx/test/e2e/framework"
)
@ -29,11 +29,11 @@ var _ = framework.DescribeAnnotation("mirror-*", func() {
f := framework.NewDefaultFramework("mirror")
host := "mirror.foo.com"
BeforeEach(func() {
ginkgo.BeforeEach(func() {
f.NewEchoDeployment()
})
It("should set mirror-target to http://localhost/mirror", func() {
ginkgo.It("should set mirror-target to http://localhost/mirror", func() {
annotations := map[string]string{
"nginx.ingress.kubernetes.io/mirror-target": "http://localhost/mirror",
}
@ -48,7 +48,7 @@ var _ = framework.DescribeAnnotation("mirror-*", func() {
})
})
It("should set mirror-target to https://test.env.com/$request_uri", func() {
ginkgo.It("should set mirror-target to https://test.env.com/$request_uri", func() {
annotations := map[string]string{
"nginx.ingress.kubernetes.io/mirror-target": "https://test.env.com/$request_uri",
}
@ -64,7 +64,7 @@ var _ = framework.DescribeAnnotation("mirror-*", func() {
})
})
It("should disable mirror-request-body", func() {
ginkgo.It("should disable mirror-request-body", func() {
annotations := map[string]string{
"nginx.ingress.kubernetes.io/mirror-target": "http://localhost/mirror",
"nginx.ingress.kubernetes.io/mirror-request-body": "off",

View file

@ -19,18 +19,18 @@ package annotations
import (
"strings"
. "github.com/onsi/ginkgo"
"github.com/onsi/ginkgo"
"k8s.io/ingress-nginx/test/e2e/framework"
)
var _ = framework.DescribeAnnotation("modsecurity owasp", func() {
f := framework.NewDefaultFramework("modsecuritylocation")
BeforeEach(func() {
ginkgo.BeforeEach(func() {
f.NewEchoDeployment()
})
It("should enable modsecurity", func() {
ginkgo.It("should enable modsecurity", func() {
host := "modsecurity.foo.com"
nameSpace := f.Namespace
@ -48,7 +48,7 @@ var _ = framework.DescribeAnnotation("modsecurity owasp", func() {
})
})
It("should enable modsecurity with transaction ID and OWASP rules", func() {
ginkgo.It("should enable modsecurity with transaction ID and OWASP rules", func() {
host := "modsecurity.foo.com"
nameSpace := f.Namespace
@ -69,7 +69,7 @@ var _ = framework.DescribeAnnotation("modsecurity owasp", func() {
})
})
It("should disable modsecurity", func() {
ginkgo.It("should disable modsecurity", func() {
host := "modsecurity.foo.com"
nameSpace := f.Namespace
@ -86,7 +86,7 @@ var _ = framework.DescribeAnnotation("modsecurity owasp", func() {
})
})
It("should enable modsecurity with snippet", func() {
ginkgo.It("should enable modsecurity with snippet", func() {
host := "modsecurity.foo.com"
nameSpace := f.Namespace

View file

@ -19,8 +19,7 @@ package annotations
import (
"strings"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/onsi/ginkgo"
"k8s.io/ingress-nginx/test/e2e/framework"
)
@ -29,11 +28,11 @@ var _ = framework.DescribeAnnotation("proxy-*", func() {
f := framework.NewDefaultFramework("proxy")
host := "proxy.foo.com"
BeforeEach(func() {
f.NewEchoDeploymentWithReplicas(2)
ginkgo.BeforeEach(func() {
f.NewEchoDeployment()
})
It("should set proxy_redirect to off", 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",
@ -44,11 +43,11 @@ var _ = framework.DescribeAnnotation("proxy-*", func() {
f.WaitForNginxServer(host,
func(server string) bool {
return Expect(server).Should(ContainSubstring("proxy_redirect off;"))
return strings.Contains(server, "proxy_redirect off;")
})
})
It("should set proxy_redirect to default", func() {
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",
@ -59,11 +58,11 @@ var _ = framework.DescribeAnnotation("proxy-*", func() {
f.WaitForNginxServer(host,
func(server string) bool {
return Expect(server).Should(ContainSubstring("proxy_redirect default;"))
return strings.Contains(server, "proxy_redirect default;")
})
})
It("should set proxy_redirect to hello.com goodbye.com", func() {
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",
@ -74,11 +73,11 @@ var _ = framework.DescribeAnnotation("proxy-*", func() {
f.WaitForNginxServer(host,
func(server string) bool {
return Expect(server).Should(ContainSubstring("proxy_redirect hello.com goodbye.com;"))
return strings.Contains(server, "proxy_redirect hello.com goodbye.com;")
})
})
It("should set proxy client-max-body-size to 8m", func() {
ginkgo.It("should set proxy client-max-body-size to 8m", func() {
annotations := map[string]string{
"nginx.ingress.kubernetes.io/proxy-body-size": "8m",
}
@ -88,11 +87,11 @@ var _ = framework.DescribeAnnotation("proxy-*", func() {
f.WaitForNginxServer(host,
func(server string) bool {
return Expect(server).Should(ContainSubstring("client_max_body_size 8m;"))
return strings.Contains(server, "client_max_body_size 8m;")
})
})
It("should not set proxy client-max-body-size to incorrect value", func() {
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",
}
@ -102,11 +101,11 @@ var _ = framework.DescribeAnnotation("proxy-*", func() {
f.WaitForNginxServer(host,
func(server string) bool {
return Expect(server).ShouldNot(ContainSubstring("client_max_body_size 15r;"))
return !strings.Contains(server, "client_max_body_size 15r;")
})
})
It("should set valid proxy timeouts", func() {
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",
@ -124,7 +123,7 @@ var _ = framework.DescribeAnnotation("proxy-*", func() {
})
})
It("should not set invalid proxy timeouts", func() {
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",
@ -142,7 +141,7 @@ var _ = framework.DescribeAnnotation("proxy-*", func() {
})
})
It("should turn on proxy-buffering", func() {
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",
@ -161,7 +160,7 @@ var _ = framework.DescribeAnnotation("proxy-*", func() {
})
})
It("should turn off proxy-request-buffering", func() {
ginkgo.It("should turn off proxy-request-buffering", func() {
annotations := map[string]string{
"nginx.ingress.kubernetes.io/proxy-request-buffering": "off",
}
@ -171,11 +170,11 @@ var _ = framework.DescribeAnnotation("proxy-*", func() {
f.WaitForNginxServer(host,
func(server string) bool {
return Expect(server).Should(ContainSubstring("proxy_request_buffering off;"))
return strings.Contains(server, "proxy_request_buffering off;")
})
})
It("should build proxy next upstream", func() {
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",
@ -193,7 +192,7 @@ var _ = framework.DescribeAnnotation("proxy-*", func() {
})
})
It("should build proxy next upstream using configmap values", func() {
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)
@ -212,7 +211,7 @@ var _ = framework.DescribeAnnotation("proxy-*", func() {
})
})
It("should setup proxy cookies", func() {
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/ /",
@ -228,7 +227,7 @@ var _ = framework.DescribeAnnotation("proxy-*", func() {
})
})
It("should change the default proxy HTTP version", func() {
ginkgo.It("should change the default proxy HTTP version", func() {
annotations := map[string]string{
"nginx.ingress.kubernetes.io/proxy-http-version": "1.0",
}

View file

@ -20,26 +20,27 @@ import (
"fmt"
"strings"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/onsi/ginkgo"
"github.com/stretchr/testify/assert"
"k8s.io/ingress-nginx/test/e2e/framework"
)
var _ = framework.DescribeAnnotation("proxy-ssl-*", func() {
f := framework.NewDefaultFramework("proxyssl")
BeforeEach(func() {
f.NewEchoDeploymentWithReplicas(2)
ginkgo.BeforeEach(func() {
f.NewEchoDeployment()
})
It("should set valid proxy-ssl-secret", func() {
ginkgo.It("should set valid proxy-ssl-secret", func() {
host := "proxyssl.foo.com"
annotations := map[string]string{
"nginx.ingress.kubernetes.io/proxy-ssl-secret": f.Namespace + "/" + host,
}
_, err := framework.CreateIngressMASecret(f.KubeClientSet, host, host, f.Namespace)
Expect(err).ToNot(HaveOccurred())
assert.Nil(ginkgo.GinkgoT(), err)
ing := framework.NewSingleIngressWithTLS(host, "/", host, []string{host}, f.Namespace, framework.EchoService, 80, annotations)
f.EnsureIngress(ing)
@ -47,7 +48,7 @@ var _ = framework.DescribeAnnotation("proxy-ssl-*", func() {
assertProxySSL(f, host, "DEFAULT", "TLSv1 TLSv1.1 TLSv1.2", "off", 1)
})
It("should set valid proxy-ssl-secret, proxy-ssl-verify to on, and proxy-ssl-verify-depth to 2", func() {
ginkgo.It("should set valid proxy-ssl-secret, proxy-ssl-verify to on, and proxy-ssl-verify-depth to 2", func() {
host := "proxyssl.foo.com"
annotations := map[string]string{
"nginx.ingress.kubernetes.io/proxy-ssl-secret": f.Namespace + "/" + host,
@ -56,7 +57,7 @@ var _ = framework.DescribeAnnotation("proxy-ssl-*", func() {
}
_, err := framework.CreateIngressMASecret(f.KubeClientSet, host, host, f.Namespace)
Expect(err).ToNot(HaveOccurred())
assert.Nil(ginkgo.GinkgoT(), err)
ing := framework.NewSingleIngressWithTLS(host, "/", host, []string{host}, f.Namespace, framework.EchoService, 80, annotations)
f.EnsureIngress(ing)
@ -64,7 +65,7 @@ var _ = framework.DescribeAnnotation("proxy-ssl-*", func() {
assertProxySSL(f, host, "DEFAULT", "TLSv1 TLSv1.1 TLSv1.2", "on", 2)
})
It("should set valid proxy-ssl-secret, proxy-ssl-ciphers to HIGH:!AES", func() {
ginkgo.It("should set valid proxy-ssl-secret, proxy-ssl-ciphers to HIGH:!AES", func() {
host := "proxyssl.foo.com"
annotations := map[string]string{
"nginx.ingress.kubernetes.io/proxy-ssl-secret": f.Namespace + "/" + host,
@ -72,7 +73,7 @@ var _ = framework.DescribeAnnotation("proxy-ssl-*", func() {
}
_, err := framework.CreateIngressMASecret(f.KubeClientSet, host, host, f.Namespace)
Expect(err).ToNot(HaveOccurred())
assert.Nil(ginkgo.GinkgoT(), err)
ing := framework.NewSingleIngressWithTLS(host, "/", host, []string{host}, f.Namespace, framework.EchoService, 80, annotations)
f.EnsureIngress(ing)
@ -80,7 +81,7 @@ var _ = framework.DescribeAnnotation("proxy-ssl-*", func() {
assertProxySSL(f, host, "HIGH:!AES", "TLSv1 TLSv1.1 TLSv1.2", "off", 1)
})
It("should set valid proxy-ssl-secret, proxy-ssl-protocols", func() {
ginkgo.It("should set valid proxy-ssl-secret, proxy-ssl-protocols", func() {
host := "proxyssl.foo.com"
annotations := map[string]string{
"nginx.ingress.kubernetes.io/proxy-ssl-secret": f.Namespace + "/" + host,
@ -88,7 +89,7 @@ var _ = framework.DescribeAnnotation("proxy-ssl-*", func() {
}
_, err := framework.CreateIngressMASecret(f.KubeClientSet, host, host, f.Namespace)
Expect(err).ToNot(HaveOccurred())
assert.Nil(ginkgo.GinkgoT(), err)
ing := framework.NewSingleIngressWithTLS(host, "/", host, []string{host}, f.Namespace, framework.EchoService, 80, annotations)
f.EnsureIngress(ing)

View file

@ -22,29 +22,24 @@ import (
"strconv"
"strings"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/parnurzeal/gorequest"
"github.com/onsi/ginkgo"
"k8s.io/ingress-nginx/test/e2e/framework"
)
func noRedirectPolicyFunc(gorequest.Request, []gorequest.Request) error {
return http.ErrUseLastResponse
}
var _ = framework.DescribeAnnotation("permanen-redirect permanen-redirect-code", func() {
f := framework.NewDefaultFramework("redirect")
It("should respond with a standard redirect code", func() {
By("setting permanent-redirect annotation")
ginkgo.It("should respond with a standard redirect code", func() {
ginkgo.By("setting permanent-redirect annotation")
host := "redirect"
redirectPath := "/something"
redirectURL := "http://redirect.example.com"
annotations := map[string]string{"nginx.ingress.kubernetes.io/permanent-redirect": redirectURL}
annotations := map[string]string{
"nginx.ingress.kubernetes.io/permanent-redirect": redirectURL,
}
ing := framework.NewSingleIngress(host, redirectPath, host, f.Namespace, framework.EchoService, 80, annotations)
f.EnsureIngress(ing)
@ -55,22 +50,17 @@ var _ = framework.DescribeAnnotation("permanen-redirect permanen-redirect-code",
strings.Contains(server, fmt.Sprintf("return 301 %s;", redirectURL))
})
By("sending request to redirected URL path")
resp, body, errs := gorequest.New().
Get(f.GetURL(framework.HTTP)+redirectPath).
Set("Host", host).
RedirectPolicy(noRedirectPolicyFunc).
End()
Expect(errs).To(BeNil())
Expect(resp.StatusCode).Should(BeNumerically("==", http.StatusMovedPermanently))
Expect(resp.Header.Get("Location")).Should(Equal(redirectURL))
Expect(body).Should(ContainSubstring("nginx/"))
ginkgo.By("sending request to redirected URL path")
f.HTTPTestClient().
GET(redirectPath).
WithHeader("Host", host).
Expect().
Status(http.StatusMovedPermanently).
Header("Location").Equal(redirectURL)
})
It("should respond with a custom redirect code", func() {
By("setting permanent-redirect-code annotation")
ginkgo.It("should respond with a custom redirect code", func() {
ginkgo.By("setting permanent-redirect-code annotation")
host := "redirect"
redirectPath := "/something"
@ -91,17 +81,12 @@ var _ = framework.DescribeAnnotation("permanen-redirect permanen-redirect-code",
strings.Contains(server, fmt.Sprintf("return %d %s;", redirectCode, redirectURL))
})
By("sending request to redirected URL path")
resp, body, errs := gorequest.New().
Get(f.GetURL(framework.HTTP)+redirectPath).
Set("Host", host).
RedirectPolicy(noRedirectPolicyFunc).
End()
Expect(errs).To(BeNil())
Expect(resp.StatusCode).Should(BeNumerically("==", redirectCode))
Expect(resp.Header.Get("Location")).Should(Equal(redirectURL))
Expect(body).Should(ContainSubstring("nginx/"))
ginkgo.By("sending request to redirected URL path")
f.HTTPTestClient().
GET(redirectPath).
WithHeader("Host", host).
Expect().
Status(redirectCode).
Header("Location").Equal(redirectURL)
})
})

View file

@ -21,10 +21,8 @@ import (
"net/http"
"strings"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/parnurzeal/gorequest"
"github.com/onsi/ginkgo"
"github.com/stretchr/testify/assert"
"k8s.io/ingress-nginx/test/e2e/framework"
)
@ -32,12 +30,12 @@ import (
var _ = framework.DescribeAnnotation("rewrite-target use-regex enable-rewrite-log", func() {
f := framework.NewDefaultFramework("rewrite")
BeforeEach(func() {
ginkgo.BeforeEach(func() {
f.NewEchoDeployment()
})
It("should write rewrite logs", func() {
By("setting enable-rewrite-log annotation")
ginkgo.It("should write rewrite logs", func() {
ginkgo.By("setting enable-rewrite-log annotation")
host := "rewrite.bar.com"
annotations := map[string]string{
@ -53,24 +51,22 @@ var _ = framework.DescribeAnnotation("rewrite-target use-regex enable-rewrite-lo
return strings.Contains(server, "rewrite_log on;")
})
resp, _, errs := gorequest.New().
Get(f.GetURL(framework.HTTP)+"/something").
Set("Host", host).
End()
Expect(len(errs)).Should(Equal(0))
Expect(resp.StatusCode).Should(Equal(http.StatusOK))
f.HTTPTestClient().
GET("/something").
WithHeader("Host", host).
Expect().
Status(http.StatusOK)
logs, err := f.NginxLogs()
Expect(err).ToNot(HaveOccurred())
Expect(logs).To(ContainSubstring(`"(?i)/something" matches "/something", client:`))
Expect(logs).To(ContainSubstring(`rewritten data: "/", args: "",`))
assert.Nil(ginkgo.GinkgoT(), err)
assert.Contains(ginkgo.GinkgoT(), logs, `"(?i)/something" matches "/something", client:`)
assert.Contains(ginkgo.GinkgoT(), logs, `rewritten data: "/", args: "",`)
})
It("should use correct longest path match", func() {
ginkgo.It("should use correct longest path match", func() {
host := "rewrite.bar.com"
By("creating a regular ingress definition")
ginkgo.By("creating a regular ingress definition")
ing := framework.NewSingleIngress("kube-lego", "/.well-known/acme/challenge", host, f.Namespace, framework.EchoService, 80, nil)
f.EnsureIngress(ing)
@ -79,17 +75,17 @@ var _ = framework.DescribeAnnotation("rewrite-target use-regex enable-rewrite-lo
return strings.Contains(server, "/.well-known/acme/challenge")
})
By("making a request to the non-rewritten location")
resp, body, errs := gorequest.New().
Get(f.GetURL(framework.HTTP)+"/.well-known/acme/challenge").
Set("Host", host).
End()
ginkgo.By("making a request to the non-rewritten location")
expectBodyRequestURI := fmt.Sprintf("request_uri=http://%v:80/.well-known/acme/challenge", host)
Expect(len(errs)).Should(Equal(0))
Expect(resp.StatusCode).Should(Equal(http.StatusOK))
Expect(body).Should(ContainSubstring(expectBodyRequestURI))
By(`creating an ingress definition with the rewrite-target annotation set on the "/" location`)
f.HTTPTestClient().
GET("/.well-known/acme/challenge").
WithHeader("Host", host).
Expect().
Status(http.StatusOK).
Body().Contains(expectBodyRequestURI)
ginkgo.By(`creating an ingress definition with the rewrite-target annotation set on the "/" location`)
annotations := map[string]string{
"nginx.ingress.kubernetes.io/rewrite-target": "/new/backend",
}
@ -102,20 +98,19 @@ var _ = framework.DescribeAnnotation("rewrite-target use-regex enable-rewrite-lo
return strings.Contains(server, `location ~* "^/" {`) && strings.Contains(server, `location ~* "^/.well-known/acme/challenge" {`)
})
By("making a second request to the non-rewritten location")
resp, body, errs = gorequest.New().
Get(f.GetURL(framework.HTTP)+"/.well-known/acme/challenge").
Set("Host", host).
End()
Expect(len(errs)).Should(Equal(0))
Expect(resp.StatusCode).Should(Equal(http.StatusOK))
Expect(body).Should(ContainSubstring(expectBodyRequestURI))
ginkgo.By("making a second request to the non-rewritten location")
f.HTTPTestClient().
GET("/.well-known/acme/challenge").
WithHeader("Host", host).
Expect().
Status(http.StatusOK).
Body().Contains(expectBodyRequestURI)
})
It("should use ~* location modifier if regex annotation is present", func() {
ginkgo.It("should use ~* location modifier if regex annotation is present", func() {
host := "rewrite.bar.com"
By("creating a regular ingress definition")
ginkgo.By("creating a regular ingress definition")
ing := framework.NewSingleIngress("foo", "/foo", host, f.Namespace, framework.EchoService, 80, nil)
f.EnsureIngress(ing)
@ -124,7 +119,7 @@ var _ = framework.DescribeAnnotation("rewrite-target use-regex enable-rewrite-lo
return strings.Contains(server, "location /foo {")
})
By(`creating an ingress definition with the use-regex amd rewrite-target annotation`)
ginkgo.By(`creating an ingress definition with the use-regex amd rewrite-target annotation`)
annotations := map[string]string{
"nginx.ingress.kubernetes.io/use-regex": "true",
"nginx.ingress.kubernetes.io/rewrite-target": "/new/backend",
@ -137,35 +132,35 @@ var _ = framework.DescribeAnnotation("rewrite-target use-regex enable-rewrite-lo
return strings.Contains(server, `location ~* "^/foo" {`) && strings.Contains(server, `location ~* "^/foo.+" {`)
})
By("ensuring '/foo' matches '~* ^/foo'")
resp, body, errs := gorequest.New().
Get(f.GetURL(framework.HTTP)+"/foo").
Set("Host", host).
End()
ginkgo.By("ensuring '/foo' matches '~* ^/foo'")
expectBodyRequestURI := fmt.Sprintf("request_uri=http://%v:80/foo", host)
Expect(len(errs)).Should(Equal(0))
Expect(resp.StatusCode).Should(Equal(http.StatusOK))
Expect(body).Should(ContainSubstring(expectBodyRequestURI))
By("ensuring '/foo/bar' matches '~* ^/foo.+'")
resp, body, errs = gorequest.New().
Get(f.GetURL(framework.HTTP)+"/foo/bar").
Set("Host", host).
End()
f.HTTPTestClient().
GET("/foo").
WithHeader("Host", host).
Expect().
Status(http.StatusOK).
Body().Contains(expectBodyRequestURI)
ginkgo.By("ensuring '/foo/bar' matches '~* ^/foo.+'")
expectBodyRequestURI = fmt.Sprintf("request_uri=http://%v:80/new/backend", host)
Expect(len(errs)).Should(Equal(0))
Expect(resp.StatusCode).Should(Equal(http.StatusOK))
Expect(body).Should(ContainSubstring(expectBodyRequestURI))
f.HTTPTestClient().
GET("/foo/bar").
WithHeader("Host", host).
Expect().
Status(http.StatusOK).
Body().Contains(expectBodyRequestURI)
})
It("should fail to use longest match for documented warning", func() {
ginkgo.It("should fail to use longest match for documented warning", func() {
host := "rewrite.bar.com"
By("creating a regular ingress definition")
ginkgo.By("creating a regular ingress definition")
ing := framework.NewSingleIngress("foo", "/foo/bar/bar", host, f.Namespace, framework.EchoService, 80, nil)
f.EnsureIngress(ing)
By(`creating an ingress definition with the use-regex annotation`)
ginkgo.By(`creating an ingress definition with the use-regex annotation`)
annotations := map[string]string{
"nginx.ingress.kubernetes.io/use-regex": "true",
"nginx.ingress.kubernetes.io/rewrite-target": "/new/backend",
@ -175,24 +170,25 @@ var _ = framework.DescribeAnnotation("rewrite-target use-regex enable-rewrite-lo
f.WaitForNginxServer(host,
func(server string) bool {
return strings.Contains(server, `location ~* "^/foo/bar/bar" {`) && strings.Contains(server, `location ~* "^/foo/bar/[a-z]{3}" {`)
return strings.Contains(server, `location ~* "^/foo/bar/bar" {`) &&
strings.Contains(server, `location ~* "^/foo/bar/[a-z]{3}" {`)
})
By("check that '/foo/bar/bar' does not match the longest exact path")
resp, body, errs := gorequest.New().
Get(f.GetURL(framework.HTTP)+"/foo/bar/bar").
Set("Host", host).
End()
ginkgo.By("check that '/foo/bar/bar' does not match the longest exact path")
expectBodyRequestURI := fmt.Sprintf("request_uri=http://%v:80/new/backend", host)
Expect(len(errs)).Should(Equal(0))
Expect(resp.StatusCode).Should(Equal(http.StatusOK))
Expect(body).Should(ContainSubstring(expectBodyRequestURI))
f.HTTPTestClient().
GET("/foo/bar/bar").
WithHeader("Host", host).
Expect().
Status(http.StatusOK).
Body().Contains(expectBodyRequestURI)
})
It("should allow for custom rewrite parameters", func() {
ginkgo.It("should allow for custom rewrite parameters", func() {
host := "rewrite.bar.com"
By(`creating an ingress definition with the use-regex annotation`)
ginkgo.By(`creating an ingress definition with the use-regex annotation`)
annotations := map[string]string{
"nginx.ingress.kubernetes.io/use-regex": "true",
"nginx.ingress.kubernetes.io/rewrite-target": "/new/backend/$1",
@ -205,15 +201,14 @@ var _ = framework.DescribeAnnotation("rewrite-target use-regex enable-rewrite-lo
return strings.Contains(server, `location ~* "^/foo/bar/(.+)" {`)
})
By("check that '/foo/bar/bar' redirects to custom rewrite")
resp, body, errs := gorequest.New().
Get(f.GetURL(framework.HTTP)+"/foo/bar/bar").
Set("Host", host).
End()
ginkgo.By("check that '/foo/bar/bar' redirects to custom rewrite")
expectBodyRequestURI := fmt.Sprintf("request_uri=http://%v:80/new/backend/bar", host)
Expect(len(errs)).Should(Equal(0))
Expect(resp.StatusCode).Should(Equal(http.StatusOK))
Expect(body).Should(ContainSubstring(expectBodyRequestURI))
})
f.HTTPTestClient().
GET("/foo/bar/bar").
WithHeader("Host", host).
Expect().
Status(http.StatusOK).
Body().Contains(expectBodyRequestURI)
})
})

View file

@ -20,24 +20,25 @@ import (
"fmt"
"net/http"
"net/url"
"time"
"strings"
"github.com/onsi/ginkgo"
"github.com/stretchr/testify/assert"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/parnurzeal/gorequest"
networking "k8s.io/api/networking/v1beta1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/ingress-nginx/test/e2e/framework"
)
var _ = framework.DescribeAnnotation("satisfy", func() {
f := framework.NewDefaultFramework("satisfy")
BeforeEach(func() {
ginkgo.BeforeEach(func() {
f.NewEchoDeployment()
})
It("should configure satisfy directive correctly", func() {
ginkgo.It("should configure satisfy directive correctly", func() {
host := "satisfy"
annotationKey := "nginx.ingress.kubernetes.io/satisfy"
@ -63,36 +64,33 @@ var _ = framework.DescribeAnnotation("satisfy", func() {
ingress.ObjectMeta.Annotations[annotationKey] = annotations[key]
return nil
})
Expect(err).ToNot(HaveOccurred())
assert.Nil(ginkgo.GinkgoT(), err)
f.WaitForNginxServer(host,
func(server string) bool {
return Expect(server).Should(ContainSubstring(result))
return strings.Contains(server, result)
})
resp, body, errs := gorequest.New().
Get(f.GetURL(framework.HTTP)).
Retry(10, 1*time.Second, http.StatusNotFound).
Set("Host", host).
End()
Expect(errs).Should(BeEmpty())
Expect(resp.StatusCode).Should(Equal(http.StatusOK))
Expect(body).Should(ContainSubstring(fmt.Sprintf("host=%v", host)))
f.HTTPTestClient().
GET("/").
WithHeader("Host", host).
Expect().
Status(http.StatusOK).
Body().Contains(fmt.Sprintf("host=%v", host))
}
})
It("should allow multiple auth with satisfy any", func() {
ginkgo.It("should allow multiple auth with satisfy any", func() {
host := "auth"
// setup external auth
f.NewHttpbinDeployment()
err := framework.WaitForEndpoints(f.KubeClientSet, framework.DefaultTimeout, framework.HTTPBinService, f.Namespace, 1)
Expect(err).NotTo(HaveOccurred())
assert.Nil(ginkgo.GinkgoT(), err)
e, err := f.KubeClientSet.CoreV1().Endpoints(f.Namespace).Get(framework.HTTPBinService, metav1.GetOptions{})
Expect(err).NotTo(HaveOccurred())
assert.Nil(ginkgo.GinkgoT(), err)
httpbinIP := e.Subsets[0].Addresses[0].IP
@ -117,30 +115,25 @@ var _ = framework.DescribeAnnotation("satisfy", func() {
f.EnsureIngress(ing)
f.WaitForNginxServer(host, func(server string) bool {
return Expect(server).Should(ContainSubstring("server_name auth"))
return strings.Contains(server, "server_name auth")
})
// with basic auth cred
resp, _, errs := gorequest.New().
Get(f.GetURL(framework.HTTP)).
Retry(10, 1*time.Second, http.StatusNotFound).
Set("Host", host).
SetBasicAuth("uname", "pwd").End()
Expect(errs).Should(BeEmpty())
Expect(resp.StatusCode).Should(Equal(http.StatusOK))
f.HTTPTestClient().
GET("/").
WithHeader("Host", host).
WithBasicAuth("uname", "pwd").
Expect().
Status(http.StatusOK)
// reroute to signin if without basic cred
resp, _, errs = gorequest.New().
Get(f.GetURL(framework.HTTP)).
Retry(10, 1*time.Second, http.StatusNotFound).
Set("Host", host).
RedirectPolicy(func(req gorequest.Request, via []gorequest.Request) error {
return http.ErrUseLastResponse
}).Param("a", "b").Param("c", "d").
End()
Expect(errs).Should(BeEmpty())
Expect(resp.StatusCode).Should(Equal(http.StatusFound))
Expect(resp.Header.Get("Location")).Should(Equal(fmt.Sprintf("http://%s/auth/start?rd=http://%s%s", host, host, url.QueryEscape("/?a=b&c=d"))))
f.HTTPTestClient().
GET("/").
WithHeader("Host", host).
WithQuery("a", "b").
WithQuery("c", "d").
Expect().
Status(http.StatusFound).
Header("Location").Equal(fmt.Sprintf("http://%s/auth/start?rd=http://%s%s", host, host, url.QueryEscape("/?a=b&c=d")))
})
})

View file

@ -28,7 +28,7 @@ var _ = framework.DescribeAnnotation("server-snippet", func() {
f := framework.NewDefaultFramework("serversnippet")
BeforeEach(func() {
f.NewEchoDeploymentWithReplicas(2)
f.NewEchoDeployment()
})
It(`add valid directives to server via server snippet"`, func() {
@ -44,7 +44,8 @@ var _ = framework.DescribeAnnotation("server-snippet", func() {
f.WaitForNginxServer(host,
func(server string) bool {
return strings.Contains(server, `more_set_headers "Content-Length: $content_length`) && strings.Contains(server, `more_set_headers "Content-Type: $content_type";`)
return strings.Contains(server, `more_set_headers "Content-Length: $content_length`) &&
strings.Contains(server, `more_set_headers "Content-Type: $content_type";`)
})
})
})

View file

@ -17,19 +17,21 @@ limitations under the License.
package annotations
import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"strings"
"github.com/onsi/ginkgo"
"k8s.io/ingress-nginx/test/e2e/framework"
)
var _ = framework.DescribeAnnotation("configuration-snippet", func() {
f := framework.NewDefaultFramework("configurationsnippet")
BeforeEach(func() {
f.NewEchoDeploymentWithReplicas(2)
ginkgo.BeforeEach(func() {
f.NewEchoDeployment()
})
It(`set snippet "more_set_headers "Request-Id: $req_id";" in all locations"`, func() {
ginkgo.It(`set snippet "more_set_headers "Request-Id: $req_id";" in all locations"`, func() {
host := "configurationsnippet.foo.com"
annotations := map[string]string{
"nginx.ingress.kubernetes.io/configuration-snippet": `
@ -41,7 +43,7 @@ var _ = framework.DescribeAnnotation("configuration-snippet", func() {
f.WaitForNginxServer(host,
func(server string) bool {
return Expect(server).Should(ContainSubstring(`more_set_headers "Request-Id: $req_id";`))
return strings.Contains(server, `more_set_headers "Request-Id: $req_id";`)
})
})
})

View file

@ -17,8 +17,9 @@ limitations under the License.
package annotations
import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"strings"
"github.com/onsi/ginkgo"
"k8s.io/ingress-nginx/test/e2e/framework"
)
@ -26,11 +27,11 @@ import (
var _ = framework.DescribeAnnotation("ssl-ciphers", func() {
f := framework.NewDefaultFramework("sslciphers")
BeforeEach(func() {
f.NewEchoDeploymentWithReplicas(2)
ginkgo.BeforeEach(func() {
f.NewEchoDeployment()
})
It("should change ssl ciphers", func() {
ginkgo.It("should change ssl ciphers", func() {
host := "ciphers.foo.com"
annotations := map[string]string{
"nginx.ingress.kubernetes.io/ssl-ciphers": "ALL:!aNULL:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP",
@ -41,7 +42,7 @@ var _ = framework.DescribeAnnotation("ssl-ciphers", func() {
f.WaitForNginxServer(host,
func(server string) bool {
return Expect(server).Should(ContainSubstring("ssl_ciphers ALL:!aNULL:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP;"))
return strings.Contains(server, "ssl_ciphers ALL:!aNULL:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP;")
})
})
})

View file

@ -22,9 +22,8 @@ import (
"regexp"
"strings"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/parnurzeal/gorequest"
"github.com/onsi/ginkgo"
"github.com/stretchr/testify/assert"
"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/ingress-nginx/test/e2e/framework"
@ -41,32 +40,34 @@ func startIngress(f *framework.Framework, annotations map[string]string) map[str
})
err := wait.PollImmediate(framework.Poll, framework.DefaultTimeout, func() (bool, error) {
resp, _, _ := gorequest.New().
Get(f.GetURL(framework.HTTP)).
Set("Host", host).
End()
resp := f.HTTPTestClient().
GET("/").
WithHeader("Host", host).
Expect().Raw()
if resp.StatusCode == http.StatusOK {
return true, nil
}
return false, nil
})
Expect(err).Should(BeNil())
assert.Nil(ginkgo.GinkgoT(), err)
re, _ := regexp.Compile(fmt.Sprintf(`Hostname: %v.*`, framework.EchoService))
podMap := map[string]bool{}
for i := 0; i < 100; i++ {
_, body, errs := gorequest.New().
Get(f.GetURL(framework.HTTP)).
Set("Host", host).
End()
data := f.HTTPTestClient().
GET("/").
WithHeader("Host", host).
Expect().
Body().Raw()
Expect(errs).Should(BeEmpty())
podName := re.FindString(body)
Expect(podName).ShouldNot(Equal(""))
podName := re.FindString(data)
assert.NotEmpty(ginkgo.GinkgoT(), podName, "expected a pod name")
podMap[podName] = true
}
return podMap
@ -75,21 +76,20 @@ func startIngress(f *framework.Framework, annotations map[string]string) map[str
var _ = framework.DescribeAnnotation("upstream-hash-by-*", func() {
f := framework.NewDefaultFramework("upstream-hash-by")
BeforeEach(func() {
ginkgo.BeforeEach(func() {
f.NewEchoDeploymentWithReplicas(6)
})
It("should connect to the same pod", func() {
ginkgo.It("should connect to the same pod", func() {
annotations := map[string]string{
"nginx.ingress.kubernetes.io/upstream-hash-by": "$request_uri",
}
podMap := startIngress(f, annotations)
Expect(len(podMap)).Should(Equal(1))
assert.Equal(ginkgo.GinkgoT(), len(podMap), 1)
})
It("should connect to the same subset of pods", func() {
ginkgo.It("should connect to the same subset of pods", func() {
annotations := map[string]string{
"nginx.ingress.kubernetes.io/upstream-hash-by": "$request_uri",
"nginx.ingress.kubernetes.io/upstream-hash-by-subset": "true",
@ -97,6 +97,6 @@ var _ = framework.DescribeAnnotation("upstream-hash-by-*", func() {
}
podMap := startIngress(f, annotations)
Expect(len(podMap)).Should(Equal(3))
assert.Equal(ginkgo.GinkgoT(), len(podMap), 3)
})
})

View file

@ -17,19 +17,21 @@ limitations under the License.
package annotations
import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"strings"
"github.com/onsi/ginkgo"
"k8s.io/ingress-nginx/test/e2e/framework"
)
var _ = framework.DescribeAnnotation("upstream-vhost", func() {
f := framework.NewDefaultFramework("upstreamvhost")
BeforeEach(func() {
f.NewEchoDeploymentWithReplicas(2)
ginkgo.BeforeEach(func() {
f.NewEchoDeployment()
})
It("set host to upstreamvhost.bar.com", func() {
ginkgo.It("set host to upstreamvhost.bar.com", func() {
host := "upstreamvhost.foo.com"
annotations := map[string]string{
"nginx.ingress.kubernetes.io/upstream-vhost": "upstreamvhost.bar.com",
@ -40,7 +42,7 @@ var _ = framework.DescribeAnnotation("upstream-vhost", func() {
f.WaitForNginxServer(host,
func(server string) bool {
return Expect(server).Should(ContainSubstring(`proxy_set_header Host "upstreamvhost.bar.com";`))
return strings.Contains(server, `proxy_set_header Host "upstreamvhost.bar.com";`)
})
})
})

View file

@ -18,21 +18,21 @@ package annotations
import (
"net/http"
"strings"
"github.com/onsi/ginkgo"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/parnurzeal/gorequest"
"k8s.io/ingress-nginx/test/e2e/framework"
)
var _ = framework.DescribeAnnotation("x-forwarded-prefix", func() {
f := framework.NewDefaultFramework("xforwardedprefix")
BeforeEach(func() {
ginkgo.BeforeEach(func() {
f.NewEchoDeployment()
})
It("should set the X-Forwarded-Prefix to the annotation value", func() {
ginkgo.It("should set the X-Forwarded-Prefix to the annotation value", func() {
host := "xfp.baz.com"
annotations := map[string]string{
"nginx.ingress.kubernetes.io/x-forwarded-prefix": "/test/value",
@ -42,21 +42,19 @@ var _ = framework.DescribeAnnotation("x-forwarded-prefix", func() {
f.EnsureIngress(framework.NewSingleIngress(host, "/", host, f.Namespace, framework.EchoService, 80, annotations))
f.WaitForNginxServer(host,
func(server string) bool {
return Expect(server).Should(ContainSubstring("proxy_set_header X-Forwarded-Prefix \"/test/value\";"))
return strings.Contains(server, host) &&
strings.Contains(server, "proxy_set_header X-Forwarded-Prefix \"/test/value\";")
})
uri := "/"
resp, body, errs := gorequest.New().
Get(f.GetURL(framework.HTTP)+uri).
Set("Host", host).
End()
Expect(errs).Should(BeEmpty())
Expect(resp.StatusCode).Should(Equal(http.StatusOK))
Expect(body).To(ContainSubstring("x-forwarded-prefix=/test/value"))
f.HTTPTestClient().
GET("/").
WithHeader("Host", host).
Expect().
Status(http.StatusOK).
Body().Contains("x-forwarded-prefix=/test/value")
})
It("should not add X-Forwarded-Prefix if the annotation value is empty", func() {
ginkgo.It("should not add X-Forwarded-Prefix if the annotation value is empty", func() {
host := "noxfp.baz.com"
annotations := map[string]string{
"nginx.ingress.kubernetes.io/x-forwarded-prefix": "",
@ -66,17 +64,15 @@ var _ = framework.DescribeAnnotation("x-forwarded-prefix", func() {
f.EnsureIngress(framework.NewSingleIngress(host, "/", host, f.Namespace, framework.EchoService, 80, annotations))
f.WaitForNginxServer(host,
func(server string) bool {
return Expect(server).Should(And(ContainSubstring(host), Not(ContainSubstring("proxy_set_header X-Forwarded-Prefix"))))
return strings.Contains(server, host) &&
!strings.Contains(server, "proxy_set_header X-Forwarded-Prefix")
})
uri := "/"
resp, body, errs := gorequest.New().
Get(f.GetURL(framework.HTTP)+uri).
Set("Host", host).
End()
Expect(errs).Should(BeEmpty())
Expect(resp.StatusCode).Should(Equal(http.StatusOK))
Expect(body).To(Not(ContainSubstring("x-forwarded-prefix")))
f.HTTPTestClient().
GET("/").
WithHeader("Host", host).
Expect().
Status(http.StatusOK).
Body().NotContains("x-forwarded-prefix")
})
})