Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix e2e tests #3325

Merged
merged 1 commit into from
Oct 30, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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