diff --git a/internal/store/store.go b/internal/store/store.go index 103e4ae8f..1ab0e1dc1 100644 --- a/internal/store/store.go +++ b/internal/store/store.go @@ -198,6 +198,10 @@ func (s *Store) GetBlueprintChanges(name string) []blueprint.Change { func (s *Store) PushBlueprint(bp blueprint.Blueprint, commitMsg string) error { return s.change(func() error { + if len(bp.Name) == 0 { + return fmt.Errorf("empty blueprint name not allowed") + } + commit, err := randomSHA1String() if err != nil { return err @@ -237,6 +241,10 @@ func (s *Store) PushBlueprint(bp blueprint.Blueprint, commitMsg string) error { func (s *Store) PushBlueprintToWorkspace(bp blueprint.Blueprint) error { return s.change(func() error { + if len(bp.Name) == 0 { + return fmt.Errorf("empty blueprint name not allowed") + } + // Make sure the blueprint has default values and that the version is valid err := bp.Initialize() if err != nil { diff --git a/internal/weldr/api_test.go b/internal/weldr/api_test.go index 4064d7069..0e710f0cc 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.StatusOK, `{"status":true}`) + 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}`) // 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...)