From ac2a43efd0a19f1496ff247108b48bc5d9361eda Mon Sep 17 00:00:00 2001 From: Erlison Santos <98214640+MrErlison@users.noreply.github.com> Date: Fri, 26 Jul 2024 20:08:22 -0300 Subject: [PATCH] Add tests for tags with custom values (#11686) * Add tests for tags with custom values * Fix typo in comments --- .../template/crossplane/crossplane_test.go | 56 +++++++++++++++++-- 1 file changed, 51 insertions(+), 5 deletions(-) diff --git a/internal/ingress/controller/template/crossplane/crossplane_test.go b/internal/ingress/controller/template/crossplane/crossplane_test.go index 9b6b2fa9a5..68c83ad294 100644 --- a/internal/ingress/controller/template/crossplane/crossplane_test.go +++ b/internal/ingress/controller/template/crossplane/crossplane_test.go @@ -63,14 +63,60 @@ func TestCrossplaneTemplate(t *testing.T) { require.NoError(t, err) require.NoError(t, mimeFile.Close()) - t.Run("it should be able to marshall and unmarshall the current configuration", func(t *testing.T) { - tplConfig := &config.TemplateConfig{ - Cfg: config.NewDefault(), - } + tplConfig := &config.TemplateConfig{ + Cfg: config.NewDefault(), + } + tpl := crossplane.NewTemplate() + + t.Run("it should be able to marshall and unmarshall the default configuration", func(t *testing.T) { tplConfig.Cfg.DefaultSSLCertificate = defaultCertificate tplConfig.Cfg.EnableBrotli = true - tpl := crossplane.NewTemplate() + tpl.SetMimeFile(mimeFile.Name()) + content, err := tpl.Write(tplConfig) + require.NoError(t, err) + + tmpFile, err := os.CreateTemp("", "") + require.NoError(t, err) + _, err = tmpFile.Write(content) + require.NoError(t, err) + require.NoError(t, tmpFile.Close()) + + _, err = ngx_crossplane.Parse(tmpFile.Name(), &options) + require.NoError(t, err) + }) + + t.Run("it should be able to marshall and unmarshall the specified configuration", func(t *testing.T) { + tplConfig.Cfg.DefaultSSLCertificate = defaultCertificate + + tplConfig.Cfg.UseProxyProtocol = true + + tplConfig.Cfg.GRPCBufferSizeKb = 10 // default 0 + + tplConfig.Cfg.HTTP2MaxHeaderSize = "10" // default "" + tplConfig.Cfg.HTTP2MaxFieldSize = "10" // default "" + tplConfig.Cfg.HTTP2MaxRequests = 1 // default 0 + + tplConfig.Cfg.UseGzip = true // default false + tplConfig.Cfg.GzipDisable = "enable" + + tplConfig.Cfg.ShowServerTokens = true // default false + + tplConfig.Cfg.DisableAccessLog = false // TODO: test true + tplConfig.Cfg.DisableHTTPAccessLog = false + tplConfig.Cfg.EnableSyslog = true + tplConfig.Cfg.SyslogHost = "localhost" + + // Example: openssl rand 80 | openssl enc -A -base64 + tplConfig.Cfg.SSLSessionTicketKey = "lOj3+7Xe21K9GapKqqPIw/gCQm5S4C2lK8pVne6drEik0QqOQHAw1AaPSMdbAvXx2zZKKPCEG98+g3hzftmrfnePSIvokIIE+hHto3Kj1HQ=" + + tplConfig.Cfg.CustomHTTPErrors = []int{1024, 2048} + + tplConfig.Cfg.AllowBackendServerHeader = true // default false + tplConfig.Cfg.BlockCIDRs = []string{"192.168.0.0/24", " 200.200.0.0/16 "} // default 0 + tplConfig.Cfg.BlockUserAgents = []string{"someuseragent", " another/user-agent "} // default 0 + + tpl = crossplane.NewTemplate() tpl.SetMimeFile(mimeFile.Name()) content, err := tpl.Write(tplConfig) require.NoError(t, err)