Skip to content

Commit

Permalink
Merge pull request #3325 from aledbf/fix-e2e-tests
Browse files Browse the repository at this point in the history
Fix e2e tests
  • Loading branch information
k8s-ci-robot authored Oct 30, 2018
2 parents 5671c17 + c9668dd commit 5ceb723
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 39 deletions.
2 changes: 1 addition & 1 deletion internal/ingress/annotations/rewrite/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ type Config struct {
// AppRoot defines the Application Root that the Controller must redirect if it's in '/' context
AppRoot string `json:"appRoot"`
// UseRegex indicates whether or not the locations use regex paths
UseRegex bool `json:useRegex`
UseRegex bool `json:"useRegex"`
}

// Equal tests for equality between two Redirect types
Expand Down
27 changes: 7 additions & 20 deletions test/e2e/annotations/affinity.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ var _ = framework.IngressNginxDescribe("Annotations - Affinity/Sticky Sessions",
f := framework.NewDefaultFramework("affinity")

BeforeEach(func() {
err := f.NewEchoDeploymentWithReplicas(2)
Expect(err).NotTo(HaveOccurred())
f.NewEchoDeploymentWithReplicas(2)
})

AfterEach(func() {
Expand All @@ -51,16 +50,12 @@ var _ = framework.IngressNginxDescribe("Annotations - Affinity/Sticky Sessions",
}

ing := framework.NewSingleIngress(host, "/", host, f.IngressController.Namespace, "http-svc", 80, &annotations)
_, err := f.EnsureIngress(ing)
f.EnsureIngress(ing)

Expect(err).NotTo(HaveOccurred())
Expect(ing).NotTo(BeNil())

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

resp, _, errs := gorequest.New().
Get(f.IngressController.HTTPURL).
Expand All @@ -80,16 +75,12 @@ var _ = framework.IngressNginxDescribe("Annotations - Affinity/Sticky Sessions",
}

ing := framework.NewSingleIngress(host, "/something", host, f.IngressController.Namespace, "http-svc", 80, &annotations)
_, err := f.EnsureIngress(ing)

Expect(err).NotTo(HaveOccurred())
Expect(ing).NotTo(BeNil())
f.EnsureIngress(ing)

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

resp, _, errs := gorequest.New().
Get(f.IngressController.HTTPURL+"/something").
Expand All @@ -108,7 +99,7 @@ var _ = framework.IngressNginxDescribe("Annotations - Affinity/Sticky Sessions",
"nginx.ingress.kubernetes.io/session-cookie-name": "SERVERID",
}

ing, err := f.EnsureIngress(&v1beta1.Ingress{
f.EnsureIngress(&v1beta1.Ingress{
ObjectMeta: metav1.ObjectMeta{
Name: host,
Namespace: f.IngressController.Namespace,
Expand Down Expand Up @@ -143,14 +134,10 @@ var _ = framework.IngressNginxDescribe("Annotations - Affinity/Sticky Sessions",
},
})

Expect(err).NotTo(HaveOccurred())
Expect(ing).NotTo(BeNil())

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

resp, _, errs := gorequest.New().
Get(f.IngressController.HTTPURL+"/something").
Expand Down
1 change: 1 addition & 0 deletions test/e2e/lua/dynamic_certificates.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ var _ = framework.IngressNginxDescribe("Dynamic Certificate", func() {

It("picks up the updated certificate without reloading", func() {
ing, err := f.KubeClientSet.ExtensionsV1beta1().Ingresses(f.IngressController.Namespace).Get(host, metav1.GetOptions{})
Expect(err).ToNot(HaveOccurred())

ensureHTTPSRequest(fmt.Sprintf("%s?id=dummy_log_splitter_foo_bar", f.IngressController.HTTPSURL), host, host)

Expand Down
30 changes: 12 additions & 18 deletions test/e2e/settings/geoip2.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@ package settings
import (
"strings"

"net/http"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/parnurzeal/gorequest"
"k8s.io/ingress-nginx/test/e2e/framework"
"net/http"
)

var _ = framework.IngressNginxDescribe("Geoip2", func() {
Expand All @@ -32,27 +33,23 @@ var _ = framework.IngressNginxDescribe("Geoip2", func() {
host := "geoip2"

BeforeEach(func() {
err := f.NewEchoDeployment()
Expect(err).NotTo(HaveOccurred())
f.NewEchoDeployment()
})

It("should only allow requests from specific countries", func() {
err := f.UpdateNginxConfigMapData("use-geoip2", "true")
Expect(err).NotTo(HaveOccurred())
f.UpdateNginxConfigMapData("use-geoip2", "true")

httpSnippetAllowingOnlyAustralia :=
`map $geoip2_city_country_code $blocked_country {
default 1;
AU 0;
}`
err = f.UpdateNginxConfigMapData("http-snippet", httpSnippetAllowingOnlyAustralia)
Expect(err).NotTo(HaveOccurred())
f.UpdateNginxConfigMapData("http-snippet", httpSnippetAllowingOnlyAustralia)

err = f.WaitForNginxConfiguration(
f.WaitForNginxConfiguration(
func(cfg string) bool {
return strings.Contains(cfg, "map $geoip2_city_country_code $blocked_country")
})
Expect(err).NotTo(HaveOccurred())

configSnippet :=
`if ($blocked_country) {
Expand All @@ -63,32 +60,29 @@ var _ = framework.IngressNginxDescribe("Geoip2", func() {
"nginx.ingress.kubernetes.io/configuration-snippet": configSnippet,
}

ing, err := f.EnsureIngress(framework.NewSingleIngress(host, "/", host, f.IngressController.Namespace, "http-svc", 80, &annotations))
Expect(err).NotTo(HaveOccurred())
Expect(ing).NotTo(BeNil())
f.EnsureIngress(framework.NewSingleIngress(host, "/", host, f.IngressController.Namespace, "http-svc", 80, &annotations))

err = f.WaitForNginxConfiguration(
f.WaitForNginxConfiguration(
func(cfg string) bool {
return strings.Contains(cfg, "if ($blocked_country)")
})
Expect(err).NotTo(HaveOccurred())

// Should be blocked
usIp := "8.8.8.8"
usIP := "8.8.8.8"
resp, _, errs := gorequest.New().
Get(f.IngressController.HTTPURL).
Set("Host", host).
Set("X-Forwarded-For", usIp).
Set("X-Forwarded-For", usIP).
End()
Expect(errs).To(BeNil())
Expect(resp.StatusCode).Should(Equal(http.StatusForbidden))

// Shouldn't be blocked
australianIp := "1.1.1.1"
australianIP := "1.1.1.1"
resp, _, errs = gorequest.New().
Get(f.IngressController.HTTPURL).
Set("Host", host).
Set("X-Forwarded-For", australianIp).
Set("X-Forwarded-For", australianIP).
End()
Expect(errs).To(BeNil())
Expect(resp.StatusCode).Should(Equal(http.StatusOK))
Expand Down

0 comments on commit 5ceb723

Please sign in to comment.