nil pointer protection in populateResource (#4489)

#### Does this PR need a docs update or release note?

- [x]  No

#### Type of change

- [x] 🐛 Bugfix

#### Test Plan

- [x]  Unit test
- [x] 💚 E2E
This commit is contained in:
Keepers 2023-10-12 19:29:43 -06:00 committed by GitHub
parent 7b6484663b
commit aa287131cf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 0 deletions

View File

@ -20,6 +20,8 @@ import (
"github.com/alcionai/corso/src/pkg/services/m365/api"
)
var ErrNoResourceLookup = clues.New("missing resource lookup client")
// must comply with BackupProducer and RestoreConsumer
var (
_ inject.BackupProducer = &Controller{}
@ -290,6 +292,10 @@ func (ctrl *Controller) PopulateProtectedResourceIDAndName(
resourceID string, // input value, can be either id or name
ins idname.Cacher,
) (idname.Provider, error) {
if ctrl.ownerLookup == nil {
return nil, clues.Stack(ErrNoResourceLookup).WithClues(ctx)
}
pr, err := ctrl.ownerLookup.GetResourceIDAndNameFrom(ctx, resourceID, ins)
if err != nil {
return nil, clues.Wrap(err, "identifying resource owner")

View File

@ -254,6 +254,18 @@ func (suite *ControllerUnitSuite) TestPopulateOwnerIDAndNamesFrom() {
}
}
func (suite *ControllerUnitSuite) TestPopulateOwnerIDAndNamesFrom_nilCheck() {
t := suite.T()
ctx, flush := tester.NewContext(t)
defer flush()
ctrl := &Controller{ownerLookup: nil}
_, err := ctrl.PopulateProtectedResourceIDAndName(ctx, "", nil)
require.ErrorIs(t, err, ErrNoResourceLookup, clues.ToCore(err))
}
func (suite *ControllerUnitSuite) TestController_Wait() {
t := suite.T()