weldr: Adding sources with empty name should return an error

Currently, if a TOML source is added with no name, or the source is
incorrectly inside a [section] it will add an empty source, causing
depsolving to crash.

This adds tests for 'name' and 'type' fields as a minimum requirement,
and returns an API error if they are empty or missing.

This also includes unit and integration tests.

Closes PR#462
This commit is contained in:
Brian C. Lane 2020-04-03 10:30:45 -07:00 committed by Tom Gundersen
parent 58c16f1e6d
commit 0eb3bfe89a
3 changed files with 53 additions and 0 deletions

View file

@ -379,6 +379,15 @@ func (api *API) sourceNewHandler(writer http.ResponseWriter, request *http.Reque
err = errors_package.New("blueprint must be in json or toml format")
}
// Basic check of the source, should at least have a name and type
if err == nil {
if len(source.Name) == 0 {
err = errors_package.New("'name' field is missing from API v0 request")
} else if len(source.Type) == 0 {
err = errors_package.New("'type' field is missing from API v0 request")
}
}
if err != nil {
errors := responseError{
ID: "ProjectsError",