Skip to content
This repository has been archived by the owner on Nov 28, 2022. It is now read-only.

[release-v1.4] Ignore trailing slashes for Broker addresses (#6471) #1836

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
7 changes: 4 additions & 3 deletions pkg/broker/ingress/ingress_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,15 @@ import (
"go.uber.org/zap"
"k8s.io/apimachinery/pkg/types"

"knative.dev/pkg/network"

"knative.dev/eventing/pkg/apis/eventing"
eventingv1 "knative.dev/eventing/pkg/apis/eventing/v1"
broker "knative.dev/eventing/pkg/broker"
"knative.dev/eventing/pkg/broker"
eventinglisters "knative.dev/eventing/pkg/client/listers/eventing/v1"
"knative.dev/eventing/pkg/kncloudevents"
"knative.dev/eventing/pkg/tracing"
"knative.dev/eventing/pkg/utils"
"knative.dev/pkg/network"
)

const (
Expand Down Expand Up @@ -120,7 +121,7 @@ func (h *Handler) ServeHTTP(writer http.ResponseWriter, request *http.Request) {
writer.WriteHeader(http.StatusNotFound)
return
}
nsBrokerName := strings.Split(request.RequestURI, "/")
nsBrokerName := strings.Split(strings.TrimSuffix(request.RequestURI, "/"), "/")
if len(nsBrokerName) != 3 {
h.Logger.Info("Malformed uri", zap.String("URI", request.RequestURI))
writer.WriteHeader(http.StatusBadRequest)
Expand Down
21 changes: 19 additions & 2 deletions pkg/broker/ingress/ingress_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,13 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"

duckv1 "knative.dev/pkg/apis/duck/v1"

"knative.dev/eventing/pkg/apis/eventing"
eventingv1 "knative.dev/eventing/pkg/apis/eventing/v1"
broker "knative.dev/eventing/pkg/broker"
"knative.dev/eventing/pkg/broker"
"knative.dev/eventing/pkg/kncloudevents"
reconcilertestingv1 "knative.dev/eventing/pkg/reconciler/testing/v1"
duckv1 "knative.dev/pkg/apis/duck/v1"
)

const (
Expand Down Expand Up @@ -135,6 +136,22 @@ func TestHandler_ServeHTTP(t *testing.T) {
makeBroker("name", "ns"),
},
},
{
name: "valid - ignore trailing slash (happy path POST)",
method: nethttp.MethodPost,
uri: "/ns/name/",
body: getValidEvent(),
expectedHeaders: nethttp.Header{
"Allow": []string{"PUT, OPTIONS"},
},
statusCode: senderResponseStatusCode,
handler: handler(),
reporter: &mockReporter{StatusCode: senderResponseStatusCode, EventDispatchTimeReported: true},
defaulter: broker.TTLDefaulter(logger, 100),
brokers: []*eventingv1.Broker{
makeBroker("name", "ns"),
},
},
{
name: "invalid event",
method: nethttp.MethodPost,
Expand Down