fix golangci-lint findings
This commit is contained in:
parent
42dd6b643b
commit
47cb871d10
4 changed files with 21 additions and 22 deletions
|
@ -58,7 +58,7 @@ var customHeadersAnnotation = parser.Annotation{
|
||||||
Group: "backend",
|
Group: "backend",
|
||||||
Annotations: parser.AnnotationFields{
|
Annotations: parser.AnnotationFields{
|
||||||
customHeadersConfigMapAnnotation: {
|
customHeadersConfigMapAnnotation: {
|
||||||
Validator: parser.ValidateRegex(*parser.BasicCharsRegex, true),
|
Validator: parser.ValidateRegex(parser.BasicCharsRegex, true),
|
||||||
Scope: parser.AnnotationScopeLocation,
|
Scope: parser.AnnotationScopeLocation,
|
||||||
Risk: parser.AnnotationRiskMedium,
|
Risk: parser.AnnotationRiskMedium,
|
||||||
Documentation: `This annotation sets the name of a ConfigMap that specifies headers to pass to the client.
|
Documentation: `This annotation sets the name of a ConfigMap that specifies headers to pass to the client.
|
||||||
|
|
|
@ -101,11 +101,11 @@ func TestCustomHeadersParseAnnotations(t *testing.T) {
|
||||||
t.Errorf("expected a *Config type")
|
t.Errorf("expected a *Config type")
|
||||||
}
|
}
|
||||||
|
|
||||||
expected_response_headers := map[string]string{}
|
expectedResponseHeaders := map[string]string{}
|
||||||
expected_response_headers["Content-Type"] = "application/json"
|
expectedResponseHeaders["Content-Type"] = "application/json"
|
||||||
expected_response_headers["Access-Control-Max-Age"] = "600"
|
expectedResponseHeaders["Access-Control-Max-Age"] = "600"
|
||||||
|
|
||||||
c := &Config{expected_response_headers}
|
c := &Config{expectedResponseHeaders}
|
||||||
|
|
||||||
if !reflect.DeepEqual(c, val) {
|
if !reflect.DeepEqual(c, val) {
|
||||||
t.Errorf("expected %v but got %v", c, val)
|
t.Errorf("expected %v but got %v", c, val)
|
||||||
|
|
|
@ -255,7 +255,7 @@ func ReadConfig(src map[string]string) config.Configuration {
|
||||||
if val, ok := conf[globalAllowedResponseHeaders]; ok {
|
if val, ok := conf[globalAllowedResponseHeaders]; ok {
|
||||||
delete(conf, globalAllowedResponseHeaders)
|
delete(conf, globalAllowedResponseHeaders)
|
||||||
|
|
||||||
if len(val) != 0 {
|
if val != "" {
|
||||||
harr := splitAndTrimSpace(val, ",")
|
harr := splitAndTrimSpace(val, ",")
|
||||||
for _, header := range harr {
|
for _, header := range harr {
|
||||||
if !customheaders.ValidHeader(header) {
|
if !customheaders.ValidHeader(header) {
|
||||||
|
|
|
@ -26,6 +26,10 @@ import (
|
||||||
"k8s.io/ingress-nginx/test/e2e/framework"
|
"k8s.io/ingress-nginx/test/e2e/framework"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
customHeaderHost = "custom-headers"
|
||||||
|
)
|
||||||
|
|
||||||
var _ = framework.DescribeAnnotation("custom-headers-*", func() {
|
var _ = framework.DescribeAnnotation("custom-headers-*", func() {
|
||||||
f := framework.NewDefaultFramework("custom-headers")
|
f := framework.NewDefaultFramework("custom-headers")
|
||||||
|
|
||||||
|
@ -34,49 +38,44 @@ var _ = framework.DescribeAnnotation("custom-headers-*", func() {
|
||||||
})
|
})
|
||||||
|
|
||||||
ginkgo.It("should return status code 200 when no custom-headers is configured", func() {
|
ginkgo.It("should return status code 200 when no custom-headers is configured", func() {
|
||||||
host := "custom-headers"
|
ing := framework.NewSingleIngress(customHeaderHost, "/", customHeaderHost, f.Namespace, framework.EchoService, 80, nil)
|
||||||
|
|
||||||
ing := framework.NewSingleIngress(host, "/", host, f.Namespace, framework.EchoService, 80, nil)
|
|
||||||
f.EnsureIngress(ing)
|
f.EnsureIngress(ing)
|
||||||
|
|
||||||
f.WaitForNginxServer(host,
|
f.WaitForNginxServer(customHeaderHost,
|
||||||
func(server string) bool {
|
func(server string) bool {
|
||||||
return strings.Contains(server, "server_name custom-headers")
|
return strings.Contains(server, "server_name custom-headers")
|
||||||
})
|
})
|
||||||
|
|
||||||
f.HTTPTestClient().
|
f.HTTPTestClient().
|
||||||
GET("/").
|
GET("/").
|
||||||
WithHeader("Host", host).
|
WithHeader("Host", customHeaderHost).
|
||||||
Expect().
|
Expect().
|
||||||
Status(http.StatusOK).
|
Status(http.StatusOK).
|
||||||
Body().Contains(fmt.Sprintf("host=%v", host))
|
Body().Contains(fmt.Sprintf("host=%v", customHeaderHost))
|
||||||
})
|
})
|
||||||
|
|
||||||
ginkgo.It("should return status code 503 when custom-headers is configured with an invalid secret", func() {
|
ginkgo.It("should return status code 503 when custom-headers is configured with an invalid secret", func() {
|
||||||
host := "custom-headers"
|
|
||||||
annotations := map[string]string{
|
annotations := map[string]string{
|
||||||
"nginx.ingress.kubernetes.io/custom-headers": f.Namespace + "/custom-headers",
|
"nginx.ingress.kubernetes.io/custom-headers": f.Namespace + "/custom-headers",
|
||||||
}
|
}
|
||||||
|
|
||||||
ing := framework.NewSingleIngress(host, "/", host, f.Namespace, framework.EchoService, 80, annotations)
|
ing := framework.NewSingleIngress(customHeaderHost, "/", customHeaderHost, f.Namespace, framework.EchoService, 80, annotations)
|
||||||
f.EnsureIngress(ing)
|
f.EnsureIngress(ing)
|
||||||
|
|
||||||
f.WaitForNginxServer(host,
|
f.WaitForNginxServer(customHeaderHost,
|
||||||
func(server string) bool {
|
func(server string) bool {
|
||||||
return strings.Contains(server, "server_name custom-headers")
|
return strings.Contains(server, "server_name custom-headers")
|
||||||
})
|
})
|
||||||
|
|
||||||
f.HTTPTestClient().
|
f.HTTPTestClient().
|
||||||
GET("/").
|
GET("/").
|
||||||
WithHeader("Host", host).
|
WithHeader("Host", customHeaderHost).
|
||||||
Expect().
|
Expect().
|
||||||
Status(http.StatusServiceUnavailable).
|
Status(http.StatusServiceUnavailable).
|
||||||
Body().Contains("503 Service Temporarily Unavailable")
|
Body().Contains("503 Service Temporarily Unavailable")
|
||||||
})
|
})
|
||||||
|
|
||||||
ginkgo.It(`should set "more_set_headers 'My-Custom-Header' '42';" when custom-headers are set`, func() {
|
ginkgo.It(`should set "more_set_headers 'My-Custom-Header' '42';" when custom-headers are set`, func() {
|
||||||
host := "custom-headers"
|
|
||||||
|
|
||||||
annotations := map[string]string{
|
annotations := map[string]string{
|
||||||
"nginx.ingress.kubernetes.io/custom-headers": f.Namespace + "/custom-headers",
|
"nginx.ingress.kubernetes.io/custom-headers": f.Namespace + "/custom-headers",
|
||||||
}
|
}
|
||||||
|
@ -87,23 +86,23 @@ var _ = framework.DescribeAnnotation("custom-headers-*", func() {
|
||||||
})
|
})
|
||||||
f.UpdateNginxConfigMapData("global-allowed-response-headers", "My-Custom-Header,My-Custom-Header-Dollar")
|
f.UpdateNginxConfigMapData("global-allowed-response-headers", "My-Custom-Header,My-Custom-Header-Dollar")
|
||||||
|
|
||||||
ing := framework.NewSingleIngress(host, "/", host, f.Namespace, framework.EchoService, 80, annotations)
|
ing := framework.NewSingleIngress(customHeaderHost, "/", customHeaderHost, f.Namespace, framework.EchoService, 80, annotations)
|
||||||
f.EnsureIngress(ing)
|
f.EnsureIngress(ing)
|
||||||
|
|
||||||
f.WaitForNginxServer(host,
|
f.WaitForNginxServer(customHeaderHost,
|
||||||
func(server string) bool {
|
func(server string) bool {
|
||||||
return strings.Contains(server, `more_set_headers "My-Custom-Header: 42";`)
|
return strings.Contains(server, `more_set_headers "My-Custom-Header: 42";`)
|
||||||
})
|
})
|
||||||
|
|
||||||
f.HTTPTestClient().
|
f.HTTPTestClient().
|
||||||
GET("/").
|
GET("/").
|
||||||
WithHeader("Host", host).
|
WithHeader("Host", customHeaderHost).
|
||||||
Expect().
|
Expect().
|
||||||
Status(http.StatusOK).
|
Status(http.StatusOK).
|
||||||
Header("My-Custom-Header").Contains("42")
|
Header("My-Custom-Header").Contains("42")
|
||||||
f.HTTPTestClient().
|
f.HTTPTestClient().
|
||||||
GET("/").
|
GET("/").
|
||||||
WithHeader("Host", host).
|
WithHeader("Host", customHeaderHost).
|
||||||
Expect().
|
Expect().
|
||||||
Status(http.StatusOK).
|
Status(http.StatusOK).
|
||||||
Header("My-Custom-Header-Dollar").Contains("$remote_addr")
|
Header("My-Custom-Header-Dollar").Contains("$remote_addr")
|
||||||
|
|
Loading…
Reference in a new issue