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,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)
})
})