diff --git a/staging/src/k8s.io/apiserver/pkg/endpoints/handlers/responsewriters/errors.go b/staging/src/k8s.io/apiserver/pkg/endpoints/handlers/responsewriters/errors.go index 6a2d226c05a..b831abdec1d 100644 --- a/staging/src/k8s.io/apiserver/pkg/endpoints/handlers/responsewriters/errors.go +++ b/staging/src/k8s.io/apiserver/pkg/endpoints/handlers/responsewriters/errors.go @@ -44,7 +44,6 @@ func BadGatewayError(w http.ResponseWriter, req *http.Request) { func Forbidden(ctx request.Context, attributes authorizer.Attributes, w http.ResponseWriter, req *http.Request, reason string, s runtime.NegotiatedSerializer) { msg := sanitizer.Replace(forbiddenMessage(attributes)) w.Header().Set("X-Content-Type-Options", "nosniff") - w.WriteHeader(http.StatusForbidden) var errMsg string if len(reason) == 0 { diff --git a/staging/src/k8s.io/apiserver/pkg/endpoints/handlers/responsewriters/errors_test.go b/staging/src/k8s.io/apiserver/pkg/endpoints/handlers/responsewriters/errors_test.go index 9af22c73f3a..8ea30401e27 100644 --- a/staging/src/k8s.io/apiserver/pkg/endpoints/handlers/responsewriters/errors_test.go +++ b/staging/src/k8s.io/apiserver/pkg/endpoints/handlers/responsewriters/errors_test.go @@ -63,18 +63,19 @@ func TestErrors(t *testing.T) { func TestForbidden(t *testing.T) { u := &user.DefaultInfo{Name: "NAME"} cases := []struct { - expected string - attributes authorizer.Attributes - reason string + expected string + attributes authorizer.Attributes + reason string + contentType string }{ {`{"metadata":{},"status":"Failure","message":" \"\" is forbidden: User \"NAME\" cannot GET path \"/whatever\".","reason":"Forbidden","details":{},"code":403} -`, authorizer.AttributesRecord{User: u, Verb: "GET", Path: "/whatever"}, ""}, +`, authorizer.AttributesRecord{User: u, Verb: "GET", Path: "/whatever"}, "", "application/json"}, {`{"metadata":{},"status":"Failure","message":" \"\" is forbidden: User \"NAME\" cannot GET path \"/\u0026lt;script\u0026gt;\".","reason":"Forbidden","details":{},"code":403} -`, authorizer.AttributesRecord{User: u, Verb: "GET", Path: "/