weldr: Return an error when an empty blueprint is received

The JSON and TOML parsers differ in how they handle an empty body so
check for a ContentLength of zero first and return a "Missing
blueprint" error to the client.

Includes updated tests for the JSON path, and new tests for empty TOML
blueprints.
This commit is contained in:
Brian C. Lane 2020-03-11 15:35:32 -07:00 committed by Tom Gundersen
parent 77fd2a0d8b
commit 7bd020ca11
2 changed files with 48 additions and 2 deletions

View file

@ -1162,6 +1162,15 @@ func (api *API) blueprintsNewHandler(writer http.ResponseWriter, request *http.R
return
}
if request.ContentLength == 0 {
errors := responseError{
ID: "BlueprintsError",
Msg: "Missing blueprint",
}
statusResponseError(writer, http.StatusBadRequest, errors)
return
}
var blueprint blueprint.Blueprint
var err error
if contentType[0] == "application/json" {
@ -1210,6 +1219,15 @@ func (api *API) blueprintsWorkspaceHandler(writer http.ResponseWriter, request *
return
}
if request.ContentLength == 0 {
errors := responseError{
ID: "BlueprintsError",
Msg: "Missing blueprint",
}
statusResponseError(writer, http.StatusBadRequest, errors)
return
}
var blueprint blueprint.Blueprint
var err error
if contentType[0] == "application/json" {