Skip to content

Feature/endpoint substring fix #224

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
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: 3 additions & 4 deletions service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package service

import (
"context"
"fmt"
"net/http"

"github.com/gorilla/handlers"
Expand Down Expand Up @@ -261,18 +260,18 @@ func CreateRouter(ctx context.Context, cfg *config.Config) *mux.Router {
func addVersionedHandlers(router *mux.Router, apiProxy *proxy.APIProxy, versions []string, path string) {
// Proxy any request after the path given to the target address
for _, version := range versions {
router.HandleFunc("/"+version+path+"{rest:.*}", apiProxy.Handle)
router.HandleFunc("/"+version+path+"{rest:$|/.*}", apiProxy.Handle)
}
}

func addTransitionalHandler(router *mux.Router, apiProxy *proxy.APIProxy, path string) {
// Proxy any request after the path given to the target address
router.HandleFunc(fmt.Sprintf("/%s"+path+"{rest:$|/.*}", apiProxy.Version), apiProxy.LegacyHandle)
router.HandleFunc("/"+apiProxy.Version+path+"{rest:$|/.*}", apiProxy.LegacyHandle)
}

func addLegacyHandler(router *mux.Router, apiProxy *proxy.APIProxy, path string) {
// Proxy any request after the path given to the target address
router.HandleFunc(path+"{rest:.*}", apiProxy.LegacyHandle)
router.HandleFunc(path+"{rest:$|/.*}", apiProxy.LegacyHandle)
}

// Close gracefully shuts the service down in the required order, with timeout
Expand Down
12 changes: 12 additions & 0 deletions service/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ func TestNotProxied(t *testing.T) {
So(w.Code, ShouldEqual, http.StatusNotFound)
assertOnlyThisURLIsCalled(zebedeeURL)
})

Convey("A request to an endpoint with extra chars falls through to the default zebedee handler", func() {
w := createRouterTest(cfg, "http://localhost:23200/v1/datasetsNOT")
So(w.Code, ShouldEqual, http.StatusNotFound)
assertOnlyThisURLIsCalled(zebedeeURL)
})
})
}

Expand Down Expand Up @@ -116,6 +122,12 @@ func TestRouterPublicAPIs(t *testing.T) {
verifyProxied("/code-lists", codelistAPIURL)
})

Convey("A request to code-list path with trailing slash succeeds and is proxied to codeListAPIURL", func() {
w := createRouterTest(cfg, "http://localhost:23200/v1/code-lists/")
So(w.Code, ShouldEqual, http.StatusOK)
verifyProxied("/code-lists/", codelistAPIURL)
})

Convey("A request to code-list subpath succeeds and is proxied to codeListAPIURL", func() {
w := createRouterTest(cfg, "http://localhost:23200/v1/code-lists/subpath")
So(w.Code, ShouldEqual, http.StatusOK)
Expand Down