diff --git a/internal/weldr/api.go b/internal/weldr/api.go index 92b84b012..43a3cca07 100644 --- a/internal/weldr/api.go +++ b/internal/weldr/api.go @@ -2021,6 +2021,15 @@ func (api *API) blueprintUndoHandler(writer http.ResponseWriter, request *http.R } bp := bpChange.Blueprint + if len(bpChange.Blueprint.Name) == 0 { + errors := responseError{ + ID: "BlueprintsError", + Msg: fmt.Sprintf("no blueprint found for commit %s", commit), + } + statusResponseError(writer, http.StatusBadRequest, errors) + return + } + commitMsg := name + ".toml reverted to commit " + commit err = api.store.PushBlueprint(bp, commitMsg) if err != nil { diff --git a/internal/weldr/api_test.go b/internal/weldr/api_test.go index 0e710f0cc..339097a2c 100644 --- a/internal/weldr/api_test.go +++ b/internal/weldr/api_test.go @@ -629,7 +629,7 @@ func TestOldBlueprintsUndo(t *testing.T) { commit := changes.BlueprintsChanges[0].Changes[2].Commit // Undo a known commit, that is old - test.TestRoute(t, api, true, "POST", "/api/v0/blueprints/undo/test-old-changes/"+commit, ``, http.StatusBadRequest, `{"errors":[{"id":"BlueprintsError", "msg":"empty blueprint name not allowed"}], "status":false}`) + test.TestRoute(t, api, true, "POST", "/api/v0/blueprints/undo/test-old-changes/"+commit, ``, http.StatusBadRequest, `{"errors":[{"id":"BlueprintsError", "msg":"no blueprint found for commit `+commit+`"}], "status":false}`) // Check to make sure the undo is not present (can't undo something not there) test.TestRoute(t, api, true, "GET", "/api/v0/blueprints/changes/test-old-changes", ``, http.StatusOK, `{"blueprints":[{"changes":[{"commit":"","message":"Change tmux version","revision":null,"timestamp":""},{"commit":"","message":"Add tmux package","revision":null,"timestamp":""},{"commit":"","message":"Initial commit","revision":null,"timestamp":""}],"name":"test-old-changes","total":3}],"errors":[],"limit":20,"offset":0}`, ignoreFields...)