alcionai / corso

Free, Secure, and Open-Source Backup for Microsoft 365
https://corsobackup.io
Apache License 2.0
184 stars 38 forks source link

Panic in setTenantUsers #628

Closed vkamra closed 2 years ago

vkamra commented 2 years ago

Description: GC call setTenantUsers hit a panic in the integration tests. This started to fail when a new AD user was created with no email address set.

Issue: graph_connector.go is dereferencing user.GetMail() without checking if it's set.

gc.Users[*user.GetMail()] = *user.GetId()

Proposed Fix and followup:

[1] Panic call stack:

suite.go:77: test panicked: runtime error: invalid memory address or nil pointer dereference
        goroutine 55 [running]:
        runtime/debug.Stack()
                /opt/homebrew/Cellar/go/1.18.5/libexec/src/runtime/debug/stack.go:24 +0x68
        github.com/stretchr/testify/suite.failOnPanic(0x14000190820, {0x105be68c0, 0x108754630})
                /Users/keepers/go/pkg/mod/github.com/stretchr/testify@v1.8.0/suite/suite.go:77 +0x38
        github.com/stretchr/testify/suite.Run.func1.1()
                /Users/keepers/go/pkg/mod/github.com/stretchr/testify@v1.8.0/suite/suite.go:161 +0x1f0
        panic({0x105be68c0, 0x108754630})
                /opt/homebrew/Cellar/go/1.18.5/libexec/src/runtime/panic.go:838 +0x204
        github.com/alcionai/corso/internal/connector.(*GraphConnector).setTenantUsers.func1({0x1065de940?, 0x140014cd000?})
                /Users/keepers/go/src/github.com/alcionai/corso/src/internal/connector/graph_connector.go:154 +0x80
        github.com/microsoftgraph/msgraph-sdk-go-core.(*PageIterator).enumerate(0x14001487200, 0x140004cab68)
                /Users/keepers/go/pkg/mod/github.com/microsoftgraph/msgraph-sdk-go-core@v0.27.0/page_iterator.go:175 +0xb4
        github.com/microsoftgraph/msgraph-sdk-go-core.(*PageIterator).Iterate(0x14001487200, 0x1400149cc30?)
                /Users/keepers/go/pkg/mod/github.com/microsoftgraph/msgraph-sdk-go-core@v0.27.0/page_iterator.go:83 +0x38
        github.com/alcionai/corso/internal/connector.(*GraphConnector).setTenantUsers(0x1400060c700)
                /Users/keepers/go/src/github.com/alcionai/corso/src/internal/connector/graph_connector.go:157 +0x210
        github.com/alcionai/corso/internal/connector.NewGraphConnector({0x0?, 0x140001175f0?})
                /Users/keepers/go/src/github.com/alcionai/corso/src/internal/connector/graph_connector.go:86 +0x180
        github.com/alcionai/corso/internal/operations.(*BackupOperation).Run(0x140004cb3d0, {0x10660a6e0, 0x1400005a0c8})
                /Users/keepers/go/src/github.com/alcionai/corso/src/internal/operations/backup.go:102 +0xb4
        github.com/alcionai/corso/internal/operations.(*BackupOpIntegrationSuite).TestBackup_Run(0x0?)
                /Users/keepers/go/src/github.com/alcionai/corso/src/internal/operations/backup_test.go:166 +0x440
        reflect.Value.call({0x14000180a80?, 0x140001967d8?, 0x13?}, {0x10511f81f, 0x4}, {0x1400009be68, 0x1, 0x1?})
                /opt/homebrew/Cellar/go/1.18.5/libexec/src/reflect/value.go:556 +0x5e4
        reflect.Value.Call({0x14000180a80?, 0x140001967d8?, 0x1400060a810?}, {0x14000089668, 0x1, 0x1})
                /opt/homebrew/Cellar/go/1.18.5/libexec/src/reflect/value.go:339 +0x98
        github.com/stretchr/testify/suite.Run.func1(0x14000190820)
                /Users/keepers/go/pkg/mod/github.com/stretchr/testify@v1.8.0/suite/suite.go:175 +0x3e8
        testing.tRunner(0x14000190820, 0x140000fa000)
                /opt/homebrew/Cellar/go/1.18.5/libexec/src/testing/testing.go:1439 +0x110
        created by testing.(*T).Run
                /opt/homebrew/Cellar/go/1.18.5/libexec/src/testing/testing.go:1486 +0x300
dadams39 commented 2 years ago

Fix in PR: