Skip to content

Commit

Permalink
fix(security): Mark AddRoute(unauthenticated) as Deprecated
Browse files Browse the repository at this point in the history
Closes #1437

Additionally adds error checks to unit tests

Signed-off-by: Bryon Nevis <bryon.nevis@intel.com>
  • Loading branch information
bnevis-i committed Jul 19, 2023
1 parent 10a2ee8 commit 2327eac
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
18 changes: 12 additions & 6 deletions internal/app/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,15 +98,17 @@ func TestAddRoute(t *testing.T) {
sdk := Service{
webserver: ws,
}
_ = sdk.AddRoute("/test", func(http.ResponseWriter, *http.Request) {}, http.MethodGet)
_ = router.Walk(func(route *mux.Route, router *mux.Router, ancestors []*mux.Route) error {
err := sdk.AddRoute("/test", func(http.ResponseWriter, *http.Request) {}, http.MethodGet)
require.NoError(t, err)
err = router.Walk(func(route *mux.Route, router *mux.Router, ancestors []*mux.Route) error {
path, err := route.GetPathTemplate()
if err != nil {
return err
}
assert.Equal(t, "/test", path)
return nil
})
require.NoError(t, err)

}

Expand All @@ -118,15 +120,17 @@ func TestAddCustomRouteUnauthenticated(t *testing.T) {
sdk := Service{
webserver: ws,
}
_ = sdk.AddCustomRoute("/test", interfaces.Unauthenticated, func(http.ResponseWriter, *http.Request) {}, http.MethodGet)
_ = router.Walk(func(route *mux.Route, router *mux.Router, ancestors []*mux.Route) error {
err := sdk.AddCustomRoute("/test", interfaces.Unauthenticated, func(http.ResponseWriter, *http.Request) {}, http.MethodGet)
require.NoError(t, err)
err = router.Walk(func(route *mux.Route, router *mux.Router, ancestors []*mux.Route) error {
path, err := route.GetPathTemplate()
if err != nil {
return err
}
assert.Equal(t, "/test", path)
return nil
})
require.NoError(t, err)

}

Expand All @@ -139,15 +143,17 @@ func TestAddCustomRouteAuthenticated(t *testing.T) {
webserver: ws,
dic: di.NewContainer(di.ServiceConstructorMap{}),
}
_ = sdk.AddCustomRoute("/test", interfaces.Authenticated, func(http.ResponseWriter, *http.Request) {}, http.MethodGet)
_ = router.Walk(func(route *mux.Route, router *mux.Router, ancestors []*mux.Route) error {
err := sdk.AddCustomRoute("/test", interfaces.Authenticated, func(http.ResponseWriter, *http.Request) {}, http.MethodGet)
require.NoError(t, err)
err = router.Walk(func(route *mux.Route, router *mux.Router, ancestors []*mux.Route) error {
path, err := route.GetPathTemplate()
if err != nil {
return err
}
assert.Equal(t, "/test", path)
return nil
})
require.NoError(t, err)

}

Expand Down
1 change: 1 addition & 0 deletions pkg/interfaces/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ type ApplicationService interface {
// AddRoute adds a custom REST route to the application service's internal webserver
// A reference to this ApplicationService is add the the context that is passed to the handler, which
// can be retrieved using the `AppService` key
// Deprecated: It is recommended to use AddCustomRoute() instead and enable authentication for custom routes
AddRoute(route string, handler func(http.ResponseWriter, *http.Request), methods ...string) error
// AddCustomRoute adds a custom REST route to the application service's internal webserver
// A reference to this ApplicationService is add the the context that is passed to the handler, which
Expand Down

0 comments on commit 2327eac

Please sign in to comment.