diff --git a/internal/host/static/repository.go b/internal/host/static/repository.go index c574d63db0..d8d27f0ed5 100644 --- a/internal/host/static/repository.go +++ b/internal/host/static/repository.go @@ -53,6 +53,9 @@ func (r *Repository) CreateCatalog(ctx context.Context, c *HostCatalog, opt ...O if c == nil { return nil, fmt.Errorf("create: static host catalog: %w", db.ErrNilParameter) } + if c.HostCatalog == nil { + return nil, fmt.Errorf("create: static host catalog: embedded HostCatalog: %w", db.ErrNilParameter) + } if c.HostCatalog.ScopeId == "" { return nil, fmt.Errorf("create: static host catalog: no scope id: %w", db.ErrInvalidParameter) } @@ -109,6 +112,9 @@ func (r *Repository) UpdateCatalog(ctx context.Context, c *HostCatalog, fieldMas if c == nil { return nil, db.NoRowsAffected, fmt.Errorf("update: static host catalog: %w", db.ErrNilParameter) } + if c.HostCatalog == nil { + return nil, db.NoRowsAffected, fmt.Errorf("update: static host catalog: embedded HostCatalog: %w", db.ErrNilParameter) + } if c.PublicId == "" { return nil, db.NoRowsAffected, fmt.Errorf("update: static host catalog: missing public id: %w", db.ErrInvalidParameter) } diff --git a/internal/host/static/repository_test.go b/internal/host/static/repository_test.go index f0e5b7c1fc..928d965f27 100644 --- a/internal/host/static/repository_test.go +++ b/internal/host/static/repository_test.go @@ -138,6 +138,11 @@ func TestRepository_CreateCatalog(t *testing.T) { name: "nil-catalog", wantIsErr: db.ErrNilParameter, }, + { + name: "nil-embedded-catalog", + in: &HostCatalog{}, + wantIsErr: db.ErrNilParameter, + }, { name: "valid-no-options", in: &HostCatalog{ @@ -183,7 +188,7 @@ func TestRepository_CreateCatalog(t *testing.T) { assert.NoError(err) assert.NotNil(repo) _, prj := iam.TestScopes(t, conn) - if tt.in != nil { + if tt.in != nil && tt.in.HostCatalog != nil { tt.in.ScopeId = prj.GetPublicId() assert.Empty(tt.in.PublicId) } @@ -310,6 +315,12 @@ func TestRepository_UpdateCatalog(t *testing.T) { } } + makeEmbeddedNil := func() func(*HostCatalog) *HostCatalog { + return func(c *HostCatalog) *HostCatalog { + return &HostCatalog{} + } + } + deletePublicId := func() func(*HostCatalog) *HostCatalog { return func(c *HostCatalog) *HostCatalog { c.PublicId = "" @@ -351,6 +362,15 @@ func TestRepository_UpdateCatalog(t *testing.T) { masks: []string{"Name", "Description"}, wantIsErr: db.ErrNilParameter, }, + { + name: "nil-embedded-catalog", + orig: &HostCatalog{ + HostCatalog: &store.HostCatalog{}, + }, + chgFn: makeEmbeddedNil(), + masks: []string{"Name", "Description"}, + wantIsErr: db.ErrNilParameter, + }, { name: "no-public-id", orig: &HostCatalog{