weldr: Check blueprint POST distro or set it to host

This commit is contained in:
Brian C. Lane 2021-04-16 15:27:15 -07:00 committed by Ondřej Budai
parent b476078570
commit 3caa6ba24d
2 changed files with 14 additions and 0 deletions

View file

@ -1711,6 +1711,18 @@ func (api *API) blueprintsNewHandler(writer http.ResponseWriter, request *http.R
return
}
// Check the blueprint's distro to make sure it is valid
if len(blueprint.Distro) > 0 {
if !common.IsStringInSortedSlice(api.distros.List(), blueprint.Distro) {
errors := responseError{
ID: "BlueprintsError",
Msg: fmt.Sprintf("'%s' is not a valid distribution", blueprint.Distro),
}
statusResponseError(writer, http.StatusBadRequest, errors)
return
}
}
commitMsg := "Recipe " + blueprint.Name + ", version " + blueprint.Version + " saved."
err = api.store.PushBlueprint(blueprint, commitMsg)
if err != nil {

View file

@ -97,6 +97,8 @@ func TestBlueprintsNew(t *testing.T) {
{"POST", "/api/v0/blueprints/new", `{"name":"test","description":"Test","packages:}`, http.StatusBadRequest, `{"status":false,"errors":[{"id":"BlueprintsError","msg":"400 Bad Request: The browser (or proxy) sent a request that this server could not understand: unexpected EOF"}]}`},
{"POST", "/api/v0/blueprints/new", `{"name":"","description":"Test","packages":[{"name":"httpd","version":"2.4.*"}],"version":"0.0.0"}`, http.StatusBadRequest, `{"status":false,"errors":[{"id":"InvalidChars","msg":"Invalid characters in API path"}]}`},
{"POST", "/api/v0/blueprints/new", ``, http.StatusBadRequest, `{"status":false,"errors":[{"id":"BlueprintsError","msg":"Missing blueprint"}]}`},
{"POST", "/api/v0/blueprints/new", `{"name":"test","description":"Test","distro":"test-distro","packages":[],"version":""}`, http.StatusOK, `{"status":true}`},
{"POST", "/api/v0/blueprints/new", `{"name":"test","description":"Test","distro":"fedora-1","packages":[],"version":""}`, http.StatusBadRequest, `{"status":false,"errors":[{"id":"BlueprintsError","msg":"'fedora-1' is not a valid distribution"}]}`},
}
tempdir, err := ioutil.TempDir("", "weldr-tests-")