Fix nil pointer error when listing by non existing host catalog. (#1720)
* Fix nil pointer error when listing hosts from nonexisting host catalog.
This commit is contained in:
2 files changed
+16
-4
No files matched your search
@@ -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...)
|
||||
|
||||
@@ -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()},
|
||||
|
||||
Reference in new issue
Block a user