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:
parent
77fd2a0d8b
commit
7bd020ca11
2 changed files with 48 additions and 2 deletions
|
|
@ -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" {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue