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

test(gzip): reach ingress #9541

Merged
merged 1 commit into from
Feb 27, 2024
Merged
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
114 changes: 104 additions & 10 deletions test/e2e/settings/gzip.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package settings

import (
"fmt"
"net/http"
"strings"

"github.com/onsi/ginkgo/v2"
Expand All @@ -29,11 +30,27 @@ import (
var _ = framework.DescribeSetting("gzip", func() {
f := framework.NewDefaultFramework("gzip")

host := "gzip"

ginkgo.BeforeEach(func() {
f.NewHttpbinDeployment()
f.EnsureIngress(framework.NewSingleIngress(host, "/", host, f.Namespace, framework.HTTPBinService, 80, nil))
})

ginkgo.It("should be disabled by default", func() {
f.WaitForNginxConfiguration(
func(cfg string) bool {
return !strings.Contains(cfg, "gzip on;")
})
},
)

f.HTTPTestClient().
GET("/xml").
WithHeader("Host", host).
WithHeader("Accept-Encoding", "gzip").
Expect().
Status(http.StatusOK).
ContentEncoding()
})

ginkgo.It("should be enabled with default settings", func() {
Expand All @@ -50,7 +67,16 @@ var _ = framework.DescribeSetting("gzip", func() {
strings.Contains(cfg, fmt.Sprintf("gzip_types %s;", defaultCfg.GzipTypes)) &&
strings.Contains(cfg, "gzip_proxied any;") &&
strings.Contains(cfg, "gzip_vary on;")
})
},
)

f.HTTPTestClient().
GET("/xml").
WithHeader("Host", host).
WithHeader("Accept-Encoding", "gzip").
Expect().
Status(http.StatusOK).
ContentEncoding("gzip")
})

ginkgo.It("should set gzip_comp_level to 4", func() {
Expand All @@ -61,7 +87,16 @@ var _ = framework.DescribeSetting("gzip", func() {
func(cfg string) bool {
return strings.Contains(cfg, "gzip on;") &&
strings.Contains(cfg, "gzip_comp_level 4;")
})
},
)

f.HTTPTestClient().
GET("/xml").
WithHeader("Host", host).
WithHeader("Accept-Encoding", "gzip").
Expect().
Status(http.StatusOK).
ContentEncoding("gzip")
})

ginkgo.It("should set gzip_disable to msie6", func() {
Expand All @@ -72,28 +107,87 @@ var _ = framework.DescribeSetting("gzip", func() {
func(cfg string) bool {
return strings.Contains(cfg, "gzip on;") &&
strings.Contains(cfg, `gzip_disable "msie6";`)
})
},
)

f.HTTPTestClient().
GET("/xml").
WithHeader("Host", host).
WithHeader("Accept-Encoding", "gzip").
WithHeader("User-Agent", "Mozilla/4.8 [en] (Windows NT 5.1; U)").
Expect().
Status(http.StatusOK).
ContentEncoding("gzip")

f.HTTPTestClient().
GET("/xml").
WithHeader("Host", host).
WithHeader("Accept-Encoding", "gzip").
WithHeader("User-Agent", "Mozilla/45.0 (compatible; MSIE 6.0; Windows NT 5.1)").
Expect().
Status(http.StatusOK).
ContentEncoding()
})

ginkgo.It("should set gzip_min_length to 100", func() {
f.UpdateNginxConfigMapData("use-gzip", "true")
f.UpdateNginxConfigMapData("gzip-min-length", "100")
f.UpdateNginxConfigMapData("gzip-types", "application/octet-stream")

f.WaitForNginxConfiguration(
func(cfg string) bool {
return strings.Contains(cfg, "gzip on;") &&
strings.Contains(cfg, "gzip_min_length 100;")
})
strings.Contains(cfg, "gzip_min_length 100;") &&
strings.Contains(cfg, "gzip_types application/octet-stream;")
},
)

f.HTTPTestClient().
GET("/bytes/99").
WithHeader("Host", host).
WithHeader("Accept-Encoding", "gzip").
Expect().
Status(http.StatusOK).
ContentType("application/octet-stream").
ContentEncoding()

f.HTTPTestClient().
GET("/bytes/100").
WithHeader("Host", host).
WithHeader("Accept-Encoding", "gzip").
Expect().
Status(http.StatusOK).
ContentType("application/octet-stream").
ContentEncoding("gzip")
})

ginkgo.It("should set gzip_types to application/javascript", func() {
ginkgo.It("should set gzip_types to text/html", func() {
f.UpdateNginxConfigMapData("use-gzip", "true")
f.UpdateNginxConfigMapData("gzip-types", "application/javascript")
f.UpdateNginxConfigMapData("gzip-types", "text/html")

f.WaitForNginxConfiguration(
func(cfg string) bool {
return strings.Contains(cfg, "gzip on;") &&
strings.Contains(cfg, "gzip_types application/javascript;")
})
strings.Contains(cfg, "gzip_types text/html;")
},
)

f.HTTPTestClient().
GET("/xml").
WithHeader("Host", host).
WithHeader("Accept-Encoding", "gzip").
Expect().
Status(http.StatusOK).
ContentType("application/xml").
ContentEncoding()

f.HTTPTestClient().
GET("/html").
WithHeader("Host", host).
WithHeader("Accept-Encoding", "gzip").
Expect().
Status(http.StatusOK).
ContentType("text/html").
ContentEncoding("gzip")
})
})