Skip to content

Commit

Permalink
Fix for issue #2749 - trailing slash request handling
Browse files Browse the repository at this point in the history
  • Loading branch information
alperdedeoglu authored and danail-branekov committed Mar 14, 2024
1 parent b263ac7 commit c641873
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 0 deletions.
2 changes: 2 additions & 0 deletions api/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
toolsregistry "code.cloudfoundry.org/korifi/tools/registry"
"code.cloudfoundry.org/korifi/version"

chiMiddlewares "github.com/go-chi/chi/middleware"
buildv1alpha2 "github.com/pivotal/kpack/pkg/apis/build/v1alpha2"
"k8s.io/apimachinery/pkg/util/cache"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
Expand Down Expand Up @@ -243,6 +244,7 @@ func main() {
middleware.Correlation(ctrl.Log),
middleware.CFCliVersion,
middleware.HTTPLogging,
chiMiddlewares.StripSlashes,
)

authInfoParser := authorization.NewInfoParser()
Expand Down
1 change: 1 addition & 0 deletions api/routing/router_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ var _ = Describe("Router", func() {
Expect(res).To(HaveHTTPBody(MatchJSON(`{"not":"allowed"}`)))
})
})

})

func mkReq(handler http.Handler, method, url string) (*http.Response, error) {
Expand Down
47 changes: 47 additions & 0 deletions tests/e2e/root_v3_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package e2e_test

import (
"net/http"

"github.com/go-resty/resty/v2"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)

type RootV3Resource struct {
Links struct {
Self struct {
Href string `json:"href"`
} `json:"self"`
} `json:"links"`
}

var _ = Describe("RootV3", func() {
var (
httpResp *resty.Response
requestPath string
)

BeforeEach(func() {
requestPath = "/v3"
})
JustBeforeEach(func() {
var err error
httpResp, err = adminClient.R().
Get(requestPath)
Expect(err).NotTo(HaveOccurred())
})

It("succeeds", func() {
Expect(httpResp).To(HaveRestyStatusCode(http.StatusOK))
})

When("Request ends with a trailing slash", func() {
BeforeEach(func() {
requestPath = "/v3/"
})
It("succeeds", func() {
Expect(httpResp).To(HaveRestyStatusCode(http.StatusOK))
})
})
})

0 comments on commit c641873

Please sign in to comment.