diff --git a/internal/weldr/api.go b/internal/weldr/api.go index 374264323..4f843caae 100644 --- a/internal/weldr/api.go +++ b/internal/weldr/api.go @@ -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 { diff --git a/internal/weldr/api_test.go b/internal/weldr/api_test.go index 3171fa3b5..742300384 100644 --- a/internal/weldr/api_test.go +++ b/internal/weldr/api_test.go @@ -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-")