diff --git a/internal/servers/controller/handlers/hosts/host_service.go b/internal/servers/controller/handlers/hosts/host_service.go index 1e59df85b..0d588bf64 100644 --- a/internal/servers/controller/handlers/hosts/host_service.go +++ b/internal/servers/controller/handlers/hosts/host_service.go @@ -493,25 +493,27 @@ func (s Service) parentAndAuthResult(ctx context.Context, id string, a action.Ty var cat host.Catalog switch host.SubtypeFromId(id) { case static.Subtype: - cat, err = staticRepo.LookupCatalog(ctx, parentId) + stcat, err := staticRepo.LookupCatalog(ctx, parentId) if err != nil { res.Error = err return nil, res } - if cat == nil { + if stcat == nil { res.Error = handlers.NotFoundError() return nil, res } + cat = stcat case plugin.Subtype: - cat, _, err = pluginRepo.LookupCatalog(ctx, parentId) + plcat, _, err := pluginRepo.LookupCatalog(ctx, parentId) if err != nil { res.Error = err return nil, res } - if cat == nil { + if plcat == nil { res.Error = handlers.NotFoundError() return nil, res } + cat = plcat } opts = append(opts, auth.WithScopeId(cat.GetScopeId()), auth.WithPin(parentId)) return cat, auth.Verify(ctx, opts...) diff --git a/internal/servers/controller/handlers/hosts/host_service_test.go b/internal/servers/controller/handlers/hosts/host_service_test.go index c5d43d2c7..cfffab5c0 100644 --- a/internal/servers/controller/handlers/hosts/host_service_test.go +++ b/internal/servers/controller/handlers/hosts/host_service_test.go @@ -280,6 +280,11 @@ func TestList_Static(t *testing.T) { req: &pbs.ListHostsRequest{HostCatalogId: hc.GetPublicId()}, res: &pbs.ListHostsResponse{Items: wantHs}, }, + { + name: "List Non Existing Hosts", + req: &pbs.ListHostsRequest{HostCatalogId: "hcst_doesntexist"}, + err: handlers.NotFoundError(), + }, { name: "List No Hosts", req: &pbs.ListHostsRequest{HostCatalogId: hcNoHosts.GetPublicId()}, @@ -396,6 +401,11 @@ func TestList_Plugin(t *testing.T) { req: &pbs.ListHostsRequest{HostCatalogId: hc.GetPublicId()}, res: &pbs.ListHostsResponse{Items: wantHs}, }, + { + name: "List Non Existing Hosts", + req: &pbs.ListHostsRequest{HostCatalogId: "hc_doesntexist"}, + err: handlers.NotFoundError(), + }, { name: "List No Hosts", req: &pbs.ListHostsRequest{HostCatalogId: hcNoHosts.GetPublicId()},