Validate url_pattern format in control API append operation
Closes: #38 Co-authored-by: César Gallego Rodríguez <cesar.gallego.next@bbva.com>
This commit is contained in:
@@ -70,6 +70,10 @@ func listRoutes(res http.ResponseWriter, req *http.Request) {
|
||||
var funcAdd func(model.Route) model.Route = user.Routes.Append
|
||||
var idGenerator = uuid.NewUUID
|
||||
|
||||
var pathValidator func(string) error = func(path string) error {
|
||||
return mux.NewRouter().NewRoute().BuildOnly().Path(path).GetError()
|
||||
}
|
||||
|
||||
func addRoute(res http.ResponseWriter, req *http.Request) {
|
||||
var route model.Route
|
||||
|
||||
@@ -88,6 +92,12 @@ func addRoute(res http.ResponseWriter, req *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
err = pathValidator(route.Pattern)
|
||||
if err != nil {
|
||||
res.WriteHeader(http.StatusUnprocessableEntity)
|
||||
return
|
||||
}
|
||||
|
||||
id, err := idGenerator()
|
||||
if err != nil {
|
||||
res.WriteHeader(http.StatusInternalServerError)
|
||||
|
||||
Reference in New Issue
Block a user