Add basic RestoreAndBackup test for SharePoint (#2935)

Reuses a lot of the OneDrive logic to run
the test. Only tests basic things as it's
assuming the OneDrive set of tests will do
a more thorough job testing the overall
logic for backup/restore and permissions

Doesn't test permissions as those aren't
yet enabled for SharePoint

---

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

- [ ]  Yes, it's included
- [ ] 🕐 Yes, but in a later PR
- [x]  No

#### Type of change

- [ ] 🌻 Feature
- [ ] 🐛 Bugfix
- [ ] 🗺️ Documentation
- [x] 🤖 Supportability/Tests
- [ ] 💻 CI/Deployment
- [x] 🧹 Tech Debt/Cleanup

#### Issue(s)

* #2897

#### Test Plan

- [ ] 💪 Manual
- [x]  Unit test
- [ ] 💚 E2E
This commit is contained in:
ashmrtn 2023-03-27 15:41:50 -07:00 committed by GitHub
parent f9654ce994
commit 1548d51004
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 306 additions and 137 deletions

View File

@ -745,11 +745,20 @@ func compareOneDriveItem(
strings.HasSuffix(name, onedrive.DirMetaFileSuffix) strings.HasSuffix(name, onedrive.DirMetaFileSuffix)
if isMeta { if isMeta {
_, ok := item.(*onedrive.MetadataItem) var itemType *onedrive.MetadataItem
assert.True(t, ok, "metadata item")
assert.IsType(t, itemType, item)
} else { } else {
oitem := item.(*onedrive.Item) oitem := item.(*onedrive.Item)
assert.False(t, oitem.Info().OneDrive.IsMeta, "meta marker for non meta item %s", name) info := oitem.Info()
// Don't need to check SharePoint because it was added after we stopped
// adding meta files to backup details.
if info.OneDrive != nil {
assert.False(t, oitem.Info().OneDrive.IsMeta, "meta marker for non meta item %s", name)
} else if info.SharePoint == nil {
assert.Fail(t, "ItemInfo is not SharePoint or OneDrive")
}
} }
if isMeta { if isMeta {
@ -763,12 +772,14 @@ func compareOneDriveItem(
return true return true
} }
expectedData := expected[name] key := name
if strings.HasSuffix(name, onedrive.MetaFileSuffix) { if strings.HasSuffix(name, onedrive.MetaFileSuffix) {
expectedData = expected[itemMeta.FileName] key = itemMeta.FileName
} }
expectedData := expected[key]
if !assert.NotNil( if !assert.NotNil(
t, t,
expectedData, expectedData,
@ -868,6 +879,14 @@ func compareItem(
case path.OneDriveService: case path.OneDriveService:
return compareOneDriveItem(t, expected, item, restorePermissions, rootDir) return compareOneDriveItem(t, expected, item, restorePermissions, rootDir)
case path.SharePointService:
if category != path.LibrariesCategory {
assert.FailNowf(t, "unsupported SharePoint category: %s", category.String())
}
// SharePoint libraries reuses OneDrive code.
return compareOneDriveItem(t, expected, item, restorePermissions, rootDir)
default: default:
assert.FailNowf(t, "unexpected service: %s", service.String()) assert.FailNowf(t, "unexpected service: %s", service.String())
} }
@ -1038,6 +1057,38 @@ func makeOneDriveBackupSel(
return sel.Selector return sel.Selector
} }
func makeSharePointBackupSel(
t *testing.T,
dests []destAndCats,
) selectors.Selector {
toInclude := [][]selectors.SharePointScope{}
resourceOwners := map[string]struct{}{}
for _, d := range dests {
for c := range d.cats {
if c != path.LibrariesCategory {
assert.FailNowf(t, "unsupported category type %s", c.String())
}
resourceOwners[d.resourceOwner] = struct{}{}
// nil owners here, we'll need to stitch this together
// below after the loops are complete.
sel := selectors.NewSharePointBackup(nil)
toInclude = append(toInclude, sel.LibraryFolders(
[]string{d.dest},
selectors.PrefixMatch(),
))
}
}
sel := selectors.NewSharePointBackup(maps.Keys(resourceOwners))
sel.Include(toInclude...)
return sel.Selector
}
// backupSelectorForExpected creates a selector that can be used to backup the // backupSelectorForExpected creates a selector that can be used to backup the
// given items in expected based on the item paths. Fails the test if items from // given items in expected based on the item paths. Fails the test if items from
// multiple services are in expected. // multiple services are in expected.
@ -1055,6 +1106,9 @@ func backupSelectorForExpected(
case path.OneDriveService: case path.OneDriveService:
return makeOneDriveBackupSel(t, dests) return makeOneDriveBackupSel(t, dests)
case path.SharePointService:
return makeSharePointBackupSel(t, dests)
default: default:
assert.FailNow(t, "unknown service type %s", service.String()) assert.FailNow(t, "unknown service type %s", service.String())
} }
@ -1075,7 +1129,7 @@ func backupOutputPathFromRestore(
base := []string{restoreDest.ContainerName} base := []string{restoreDest.ContainerName}
// OneDrive has leading information like the drive ID. // OneDrive has leading information like the drive ID.
if inputPath.Service() == path.OneDriveService { if inputPath.Service() == path.OneDriveService || inputPath.Service() == path.SharePointService {
folders := inputPath.Folders() folders := inputPath.Folders()
base = append(append([]string{}, folders[:3]...), restoreDest.ContainerName) base = append(append([]string{}, folders[:3]...), restoreDest.ContainerName)
@ -1159,11 +1213,14 @@ func collectionsForInfo(
baseExpected[info.items[i].lookupKey] = info.items[i].data baseExpected[info.items[i].lookupKey] = info.items[i].data
// We do not count metadata files against item count // We do not count metadata files against item count
if backupVersion == 0 || service != path.OneDriveService || if backupVersion > 0 &&
(service == path.OneDriveService && (service == path.OneDriveService || service == path.SharePointService) &&
strings.HasSuffix(info.items[i].name, onedrive.DataFileSuffix)) { (strings.HasSuffix(info.items[i].name, onedrive.MetaFileSuffix) ||
totalItems++ strings.HasSuffix(info.items[i].name, onedrive.DirMetaFileSuffix)) {
continue
} }
totalItems++
} }
c := mockRestoreCollection{Collection: mc, auxItems: map[string]data.Stream{}} c := mockRestoreCollection{Collection: mc, auxItems: map[string]data.Stream{}}

View File

@ -1,12 +1,14 @@
package connector package connector
import ( import (
"context"
"encoding/base64" "encoding/base64"
"encoding/json" "encoding/json"
"fmt" "fmt"
"strings" "strings"
"testing" "testing"
"github.com/microsoftgraph/msgraph-sdk-go/models"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite" "github.com/stretchr/testify/suite"
@ -117,10 +119,12 @@ var (
func newOneDriveCollection( func newOneDriveCollection(
t *testing.T, t *testing.T,
service path.ServiceType,
pathElements []string, pathElements []string,
backupVersion int, backupVersion int,
) *onedriveCollection { ) *onedriveCollection {
return &onedriveCollection{ return &onedriveCollection{
service: service,
pathElements: pathElements, pathElements: pathElements,
backupVersion: backupVersion, backupVersion: backupVersion,
t: t, t: t,
@ -128,6 +132,7 @@ func newOneDriveCollection(
} }
type onedriveCollection struct { type onedriveCollection struct {
service path.ServiceType
pathElements []string pathElements []string
items []itemInfo items []itemInfo
aux []itemInfo aux []itemInfo
@ -136,9 +141,14 @@ type onedriveCollection struct {
} }
func (c onedriveCollection) collection() colInfo { func (c onedriveCollection) collection() colInfo {
cat := path.FilesCategory
if c.service == path.SharePointService {
cat = path.LibrariesCategory
}
return colInfo{ return colInfo{
pathElements: c.pathElements, pathElements: c.pathElements,
category: path.FilesCategory, category: cat,
items: c.items, items: c.items,
auxItems: c.aux, auxItems: c.aux,
} }
@ -276,11 +286,16 @@ type onedriveColInfo struct {
folders []itemData folders []itemData
} }
func testDataForInfo(t *testing.T, cols []onedriveColInfo, backupVersion int) []colInfo { func testDataForInfo(
t *testing.T,
service path.ServiceType,
cols []onedriveColInfo,
backupVersion int,
) []colInfo {
var res []colInfo var res []colInfo
for _, c := range cols { for _, c := range cols {
onedriveCol := newOneDriveCollection(t, c.pathElements, backupVersion) onedriveCol := newOneDriveCollection(t, service, c.pathElements, backupVersion)
for _, f := range c.files { for _, f := range c.files {
onedriveCol.withFile(f.name, f.data, f.perms) onedriveCol.withFile(f.name, f.data, f.perms)
@ -298,24 +313,166 @@ func testDataForInfo(t *testing.T, cols []onedriveColInfo, backupVersion int) []
return res return res
} }
type oneDriveSuite interface { func mustGetDefaultDriveID(
tester.Suite t *testing.T,
ctx context.Context, //revive:disable-line:context-as-argument
backupService path.ServiceType,
service graph.Servicer,
resourceOwner string,
) string {
var (
err error
d models.Driveable
)
switch backupService {
case path.OneDriveService:
d, err = service.Client().UsersById(resourceOwner).Drive().Get(ctx, nil)
case path.SharePointService:
d, err = service.Client().SitesById(resourceOwner).Drive().Get(ctx, nil)
default:
assert.FailNowf(t, "unknown service type %s", backupService.String())
}
if err != nil {
err = graph.Wrap(ctx, err, "retrieving drive")
}
require.NoError(t, err, clues.ToCore(err))
id := ptr.Val(d.GetId())
require.NotEmpty(t, id)
return id
}
type suiteInfo interface {
Service() graph.Servicer Service() graph.Servicer
Account() account.Account Account() account.Account
Tenant() string Tenant() string
// Returns (username, user ID) for the user. // Returns (username, user ID) for the user. These values are used for
// permissions.
PrimaryUser() (string, string) PrimaryUser() (string, string)
SecondaryUser() (string, string) SecondaryUser() (string, string)
// BackupResourceOwner returns the resource owner to run the backup/restore
// with. This can be different from the values used for permissions and it can
// also be a site.
BackupResourceOwner() string
BackupService() path.ServiceType
Resource() resource
} }
type GraphConnectorOneDriveIntegrationSuite struct { type oneDriveSuite interface {
tester.Suite tester.Suite
suiteInfo
}
type suiteInfoImpl struct {
connector *GraphConnector connector *GraphConnector
resourceOwner string
user string user string
userID string userID string
secondaryUser string secondaryUser string
secondaryUserID string secondaryUserID string
acct account.Account acct account.Account
service path.ServiceType
resourceType resource
}
func (si suiteInfoImpl) Service() graph.Servicer {
return si.connector.Service
}
func (si suiteInfoImpl) Account() account.Account {
return si.acct
}
func (si suiteInfoImpl) Tenant() string {
return si.connector.tenant
}
func (si suiteInfoImpl) PrimaryUser() (string, string) {
return si.user, si.userID
}
func (si suiteInfoImpl) SecondaryUser() (string, string) {
return si.secondaryUser, si.secondaryUserID
}
func (si suiteInfoImpl) BackupResourceOwner() string {
return si.resourceOwner
}
func (si suiteInfoImpl) BackupService() path.ServiceType {
return si.service
}
func (si suiteInfoImpl) Resource() resource {
return si.resourceType
}
// ---------------------------------------------------------------------------
// SharePoint Libraries
// ---------------------------------------------------------------------------
// SharePoint shares most of its libraries implementation with OneDrive so we
// only test simple things here and leave the more extensive testing to
// OneDrive.
//
// TODO(ashmrtn): SharePoint doesn't have permissions backup/restore enabled
// right now. Adjust the tests here when that is enabled so we have at least
// basic assurances that it's doing the right thing. We can leave the more
// extensive permissions tests to OneDrive as well.
type GraphConnectorSharePointIntegrationSuite struct {
tester.Suite
suiteInfo
}
func TestGraphConnectorSharePointIntegrationSuite(t *testing.T) {
suite.Run(t, &GraphConnectorSharePointIntegrationSuite{
Suite: tester.NewIntegrationSuite(
t,
[][]string{tester.M365AcctCredEnvs},
),
})
}
func (suite *GraphConnectorSharePointIntegrationSuite) SetupSuite() {
ctx, flush := tester.NewContext()
defer flush()
si := suiteInfoImpl{
connector: loadConnector(ctx, suite.T(), graph.HTTPClient(graph.NoTimeout()), Sites),
user: tester.M365UserID(suite.T()),
secondaryUser: tester.SecondaryM365UserID(suite.T()),
acct: tester.NewM365Account(suite.T()),
service: path.SharePointService,
resourceType: Sites,
}
si.resourceOwner = tester.M365SiteID(suite.T())
user, err := si.connector.Owners.Users().GetByID(ctx, si.user)
require.NoError(suite.T(), err, "fetching user", si.user, clues.ToCore(err))
si.userID = ptr.Val(user.GetId())
secondaryUser, err := si.connector.Owners.Users().GetByID(ctx, si.secondaryUser)
require.NoError(suite.T(), err, "fetching user", si.secondaryUser, clues.ToCore(err))
si.secondaryUserID = ptr.Val(secondaryUser.GetId())
suite.suiteInfo = si
}
func (suite *GraphConnectorSharePointIntegrationSuite) TestRestoreAndBackup_MultipleFilesAndFolders_NoPermissions() {
testRestoreAndBackupMultipleFilesAndFoldersNoPermissions(suite, version.Backup)
}
// ---------------------------------------------------------------------------
// OneDrive most recent backup version
// ---------------------------------------------------------------------------
type GraphConnectorOneDriveIntegrationSuite struct {
tester.Suite
suiteInfo
} }
func TestGraphConnectorOneDriveIntegrationSuite(t *testing.T) { func TestGraphConnectorOneDriveIntegrationSuite(t *testing.T) {
@ -331,38 +488,26 @@ func (suite *GraphConnectorOneDriveIntegrationSuite) SetupSuite() {
ctx, flush := tester.NewContext() ctx, flush := tester.NewContext()
defer flush() defer flush()
suite.connector = loadConnector(ctx, suite.T(), graph.HTTPClient(graph.NoTimeout()), Users) si := suiteInfoImpl{
suite.user = tester.M365UserID(suite.T()) connector: loadConnector(ctx, suite.T(), graph.HTTPClient(graph.NoTimeout()), Users),
suite.secondaryUser = tester.SecondaryM365UserID(suite.T()) user: tester.M365UserID(suite.T()),
suite.acct = tester.NewM365Account(suite.T()) secondaryUser: tester.SecondaryM365UserID(suite.T()),
acct: tester.NewM365Account(suite.T()),
service: path.OneDriveService,
resourceType: Users,
}
user, err := suite.connector.Owners.Users().GetByID(ctx, suite.user) si.resourceOwner = si.user
require.NoError(suite.T(), err, "fetching user", suite.user, clues.ToCore(err))
suite.userID = ptr.Val(user.GetId())
secondaryUser, err := suite.connector.Owners.Users().GetByID(ctx, suite.secondaryUser) user, err := si.connector.Owners.Users().GetByID(ctx, si.user)
require.NoError(suite.T(), err, "fetching user", suite.secondaryUser, clues.ToCore(err)) require.NoError(suite.T(), err, "fetching user", si.user, clues.ToCore(err))
suite.secondaryUserID = ptr.Val(secondaryUser.GetId()) si.userID = ptr.Val(user.GetId())
}
func (suite *GraphConnectorOneDriveIntegrationSuite) Service() graph.Servicer { secondaryUser, err := si.connector.Owners.Users().GetByID(ctx, si.secondaryUser)
return suite.connector.Service require.NoError(suite.T(), err, "fetching user", si.secondaryUser, clues.ToCore(err))
} si.secondaryUserID = ptr.Val(secondaryUser.GetId())
func (suite *GraphConnectorOneDriveIntegrationSuite) Account() account.Account { suite.suiteInfo = si
return suite.acct
}
func (suite *GraphConnectorOneDriveIntegrationSuite) Tenant() string {
return suite.connector.tenant
}
func (suite *GraphConnectorOneDriveIntegrationSuite) PrimaryUser() (string, string) {
return suite.user, suite.userID
}
func (suite *GraphConnectorOneDriveIntegrationSuite) SecondaryUser() (string, string) {
return suite.secondaryUser, suite.secondaryUserID
} }
func (suite *GraphConnectorOneDriveIntegrationSuite) TestRestoreAndBackup_MultipleFilesAndFolders_NoPermissions() { func (suite *GraphConnectorOneDriveIntegrationSuite) TestRestoreAndBackup_MultipleFilesAndFolders_NoPermissions() {
@ -391,14 +536,14 @@ func (suite *GraphConnectorOneDriveIntegrationSuite) TestPermissionsRestoreAndNo
t := suite.T() t := suite.T()
userName, _ := suite.PrimaryUser()
secondaryUserName, secondaryUserID := suite.SecondaryUser() secondaryUserName, secondaryUserID := suite.SecondaryUser()
driveID := mustGetDefaultDriveID( driveID := mustGetDefaultDriveID(
t, t,
ctx, ctx,
suite.BackupService(),
suite.Service(), suite.Service(),
userName, suite.BackupResourceOwner(),
) )
secondaryUserRead := permData{ secondaryUserRead := permData{
@ -414,12 +559,13 @@ func (suite *GraphConnectorOneDriveIntegrationSuite) TestPermissionsRestoreAndNo
} }
test := restoreBackupInfoMultiVersion{ test := restoreBackupInfoMultiVersion{
service: path.OneDriveService, service: suite.BackupService(),
resource: Users, resource: suite.Resource(),
backupVersion: version.Backup, backupVersion: version.Backup,
collectionsPrevious: []colInfo{ collectionsPrevious: []colInfo{
newOneDriveCollection( newOneDriveCollection(
suite.T(), suite.T(),
suite.BackupService(),
[]string{ []string{
"drives", "drives",
driveID, driveID,
@ -439,6 +585,7 @@ func (suite *GraphConnectorOneDriveIntegrationSuite) TestPermissionsRestoreAndNo
collection(), collection(),
newOneDriveCollection( newOneDriveCollection(
suite.T(), suite.T(),
suite.BackupService(),
[]string{ []string{
"drives", "drives",
driveID, driveID,
@ -460,6 +607,7 @@ func (suite *GraphConnectorOneDriveIntegrationSuite) TestPermissionsRestoreAndNo
collectionsLatest: []colInfo{ collectionsLatest: []colInfo{
newOneDriveCollection( newOneDriveCollection(
suite.T(), suite.T(),
suite.BackupService(),
[]string{ []string{
"drives", "drives",
driveID, driveID,
@ -479,6 +627,7 @@ func (suite *GraphConnectorOneDriveIntegrationSuite) TestPermissionsRestoreAndNo
collection(), collection(),
newOneDriveCollection( newOneDriveCollection(
suite.T(), suite.T(),
suite.BackupService(),
[]string{ []string{
"drives", "drives",
driveID, driveID,
@ -506,7 +655,7 @@ func (suite *GraphConnectorOneDriveIntegrationSuite) TestPermissionsRestoreAndNo
suite.Account(), suite.Account(),
test, test,
suite.Tenant(), suite.Tenant(),
[]string{userName}, []string{suite.BackupResourceOwner()},
control.Options{ control.Options{
RestorePermissions: true, RestorePermissions: true,
ToggleFeatures: control.Toggles{EnablePermissionsBackup: false}, ToggleFeatures: control.Toggles{EnablePermissionsBackup: false},
@ -514,14 +663,12 @@ func (suite *GraphConnectorOneDriveIntegrationSuite) TestPermissionsRestoreAndNo
) )
} }
// ---------------------------------------------------------------------------
// OneDrive regression
// ---------------------------------------------------------------------------
type GraphConnectorOneDriveNightlySuite struct { type GraphConnectorOneDriveNightlySuite struct {
tester.Suite tester.Suite
connector *GraphConnector suiteInfo
user string
userID string
secondaryUser string
secondaryUserID string
acct account.Account
} }
func TestGraphConnectorOneDriveNightlySuite(t *testing.T) { func TestGraphConnectorOneDriveNightlySuite(t *testing.T) {
@ -537,38 +684,26 @@ func (suite *GraphConnectorOneDriveNightlySuite) SetupSuite() {
ctx, flush := tester.NewContext() ctx, flush := tester.NewContext()
defer flush() defer flush()
suite.connector = loadConnector(ctx, suite.T(), graph.HTTPClient(graph.NoTimeout()), Users) si := suiteInfoImpl{
suite.user = tester.M365UserID(suite.T()) connector: loadConnector(ctx, suite.T(), graph.HTTPClient(graph.NoTimeout()), Users),
suite.secondaryUser = tester.SecondaryM365UserID(suite.T()) user: tester.M365UserID(suite.T()),
suite.acct = tester.NewM365Account(suite.T()) secondaryUser: tester.SecondaryM365UserID(suite.T()),
acct: tester.NewM365Account(suite.T()),
service: path.OneDriveService,
resourceType: Users,
}
user, err := suite.connector.Owners.Users().GetByID(ctx, suite.user) si.resourceOwner = si.user
require.NoError(suite.T(), err, "fetching user", suite.user, clues.ToCore(err))
suite.userID = ptr.Val(user.GetId())
secondaryUser, err := suite.connector.Owners.Users().GetByID(ctx, suite.secondaryUser) user, err := si.connector.Owners.Users().GetByID(ctx, si.user)
require.NoError(suite.T(), err, "fetching user", suite.secondaryUser, clues.ToCore(err)) require.NoError(suite.T(), err, "fetching user", si.user, clues.ToCore(err))
suite.secondaryUserID = ptr.Val(secondaryUser.GetId()) si.userID = ptr.Val(user.GetId())
}
func (suite *GraphConnectorOneDriveNightlySuite) Service() graph.Servicer { secondaryUser, err := si.connector.Owners.Users().GetByID(ctx, si.secondaryUser)
return suite.connector.Service require.NoError(suite.T(), err, "fetching user", si.secondaryUser, clues.ToCore(err))
} si.secondaryUserID = ptr.Val(secondaryUser.GetId())
func (suite *GraphConnectorOneDriveNightlySuite) Account() account.Account { suite.suiteInfo = si
return suite.acct
}
func (suite *GraphConnectorOneDriveNightlySuite) Tenant() string {
return suite.connector.tenant
}
func (suite *GraphConnectorOneDriveNightlySuite) PrimaryUser() (string, string) {
return suite.user, suite.userID
}
func (suite *GraphConnectorOneDriveNightlySuite) SecondaryUser() (string, string) {
return suite.secondaryUser, suite.secondaryUserID
} }
func (suite *GraphConnectorOneDriveNightlySuite) TestRestoreAndBackup_MultipleFilesAndFolders_NoPermissions() { func (suite *GraphConnectorOneDriveNightlySuite) TestRestoreAndBackup_MultipleFilesAndFolders_NoPermissions() {
@ -596,14 +731,13 @@ func testRestoreAndBackupMultipleFilesAndFoldersNoPermissions(
ctx, flush := tester.NewContext() ctx, flush := tester.NewContext()
defer flush() defer flush()
userName, _ := suite.PrimaryUser()
// Get the default drive ID for the test user. // Get the default drive ID for the test user.
driveID := mustGetDefaultDriveID( driveID := mustGetDefaultDriveID(
suite.T(), suite.T(),
ctx, ctx,
suite.BackupService(),
suite.Service(), suite.Service(),
userName, suite.BackupResourceOwner(),
) )
rootPath := []string{ rootPath := []string{
@ -705,16 +839,16 @@ func testRestoreAndBackupMultipleFilesAndFoldersNoPermissions(
}, },
} }
expected := testDataForInfo(suite.T(), cols, version.Backup) expected := testDataForInfo(suite.T(), suite.BackupService(), cols, version.Backup)
for vn := startVersion; vn <= version.Backup; vn++ { for vn := startVersion; vn <= version.Backup; vn++ {
suite.Run(fmt.Sprintf("Version%d", vn), func() { suite.Run(fmt.Sprintf("Version%d", vn), func() {
t := suite.T() t := suite.T()
input := testDataForInfo(t, cols, vn) input := testDataForInfo(t, suite.BackupService(), cols, vn)
testData := restoreBackupInfoMultiVersion{ testData := restoreBackupInfoMultiVersion{
service: path.OneDriveService, service: suite.BackupService(),
resource: Users, resource: suite.Resource(),
backupVersion: vn, backupVersion: vn,
collectionsPrevious: input, collectionsPrevious: input,
collectionsLatest: expected, collectionsLatest: expected,
@ -725,7 +859,7 @@ func testRestoreAndBackupMultipleFilesAndFoldersNoPermissions(
suite.Account(), suite.Account(),
testData, testData,
suite.Tenant(), suite.Tenant(),
[]string{userName}, []string{suite.BackupResourceOwner()},
control.Options{ control.Options{
RestorePermissions: true, RestorePermissions: true,
ToggleFeatures: control.Toggles{EnablePermissionsBackup: true}, ToggleFeatures: control.Toggles{EnablePermissionsBackup: true},
@ -739,15 +873,15 @@ func testPermissionsRestoreAndBackup(suite oneDriveSuite, startVersion int) {
ctx, flush := tester.NewContext() ctx, flush := tester.NewContext()
defer flush() defer flush()
userName, _ := suite.PrimaryUser()
secondaryUserName, secondaryUserID := suite.SecondaryUser() secondaryUserName, secondaryUserID := suite.SecondaryUser()
// Get the default drive ID for the test user. // Get the default drive ID for the test user.
driveID := mustGetDefaultDriveID( driveID := mustGetDefaultDriveID(
suite.T(), suite.T(),
ctx, ctx,
suite.BackupService(),
suite.Service(), suite.Service(),
userName, suite.BackupResourceOwner(),
) )
fileName2 := "test-file2.txt" fileName2 := "test-file2.txt"
@ -913,7 +1047,7 @@ func testPermissionsRestoreAndBackup(suite oneDriveSuite, startVersion int) {
}, },
} }
expected := testDataForInfo(suite.T(), cols, version.Backup) expected := testDataForInfo(suite.T(), suite.BackupService(), cols, version.Backup)
for vn := startVersion; vn <= version.Backup; vn++ { for vn := startVersion; vn <= version.Backup; vn++ {
suite.Run(fmt.Sprintf("Version%d", vn), func() { suite.Run(fmt.Sprintf("Version%d", vn), func() {
@ -921,11 +1055,11 @@ func testPermissionsRestoreAndBackup(suite oneDriveSuite, startVersion int) {
// Ideally this can always be true or false and still // Ideally this can always be true or false and still
// work, but limiting older versions to use emails so as // work, but limiting older versions to use emails so as
// to validate that flow as well. // to validate that flow as well.
input := testDataForInfo(t, cols, vn) input := testDataForInfo(t, suite.BackupService(), cols, vn)
testData := restoreBackupInfoMultiVersion{ testData := restoreBackupInfoMultiVersion{
service: path.OneDriveService, service: suite.BackupService(),
resource: Users, resource: suite.Resource(),
backupVersion: vn, backupVersion: vn,
collectionsPrevious: input, collectionsPrevious: input,
collectionsLatest: expected, collectionsLatest: expected,
@ -936,7 +1070,7 @@ func testPermissionsRestoreAndBackup(suite oneDriveSuite, startVersion int) {
suite.Account(), suite.Account(),
testData, testData,
suite.Tenant(), suite.Tenant(),
[]string{userName}, []string{suite.BackupResourceOwner()},
control.Options{ control.Options{
RestorePermissions: true, RestorePermissions: true,
ToggleFeatures: control.Toggles{EnablePermissionsBackup: true}, ToggleFeatures: control.Toggles{EnablePermissionsBackup: true},
@ -950,15 +1084,15 @@ func testPermissionsBackupAndNoRestore(suite oneDriveSuite, startVersion int) {
ctx, flush := tester.NewContext() ctx, flush := tester.NewContext()
defer flush() defer flush()
userName, _ := suite.PrimaryUser()
secondaryUserName, secondaryUserID := suite.SecondaryUser() secondaryUserName, secondaryUserID := suite.SecondaryUser()
// Get the default drive ID for the test user. // Get the default drive ID for the test user.
driveID := mustGetDefaultDriveID( driveID := mustGetDefaultDriveID(
suite.T(), suite.T(),
ctx, ctx,
suite.BackupService(),
suite.Service(), suite.Service(),
userName, suite.BackupResourceOwner(),
) )
inputCols := []onedriveColInfo{ inputCols := []onedriveColInfo{
@ -999,16 +1133,16 @@ func testPermissionsBackupAndNoRestore(suite oneDriveSuite, startVersion int) {
}, },
} }
expected := testDataForInfo(suite.T(), expectedCols, version.Backup) expected := testDataForInfo(suite.T(), suite.BackupService(), expectedCols, version.Backup)
for vn := startVersion; vn <= version.Backup; vn++ { for vn := startVersion; vn <= version.Backup; vn++ {
suite.Run(fmt.Sprintf("Version%d", vn), func() { suite.Run(fmt.Sprintf("Version%d", vn), func() {
t := suite.T() t := suite.T()
input := testDataForInfo(t, inputCols, vn) input := testDataForInfo(t, suite.BackupService(), inputCols, vn)
testData := restoreBackupInfoMultiVersion{ testData := restoreBackupInfoMultiVersion{
service: path.OneDriveService, service: suite.BackupService(),
resource: Users, resource: suite.Resource(),
backupVersion: vn, backupVersion: vn,
collectionsPrevious: input, collectionsPrevious: input,
collectionsLatest: expected, collectionsLatest: expected,
@ -1019,7 +1153,7 @@ func testPermissionsBackupAndNoRestore(suite oneDriveSuite, startVersion int) {
suite.Account(), suite.Account(),
testData, testData,
suite.Tenant(), suite.Tenant(),
[]string{userName}, []string{suite.BackupResourceOwner()},
control.Options{ control.Options{
RestorePermissions: false, RestorePermissions: false,
ToggleFeatures: control.Toggles{EnablePermissionsBackup: true}, ToggleFeatures: control.Toggles{EnablePermissionsBackup: true},
@ -1035,15 +1169,15 @@ func testPermissionsInheritanceRestoreAndBackup(suite oneDriveSuite, startVersio
ctx, flush := tester.NewContext() ctx, flush := tester.NewContext()
defer flush() defer flush()
userName, _ := suite.PrimaryUser()
secondaryUserName, secondaryUserID := suite.SecondaryUser() secondaryUserName, secondaryUserID := suite.SecondaryUser()
// Get the default drive ID for the test user. // Get the default drive ID for the test user.
driveID := mustGetDefaultDriveID( driveID := mustGetDefaultDriveID(
suite.T(), suite.T(),
ctx, ctx,
suite.BackupService(),
suite.Service(), suite.Service(),
userName, suite.BackupResourceOwner(),
) )
folderAName := "custom" folderAName := "custom"
@ -1148,7 +1282,7 @@ func testPermissionsInheritanceRestoreAndBackup(suite oneDriveSuite, startVersio
}, },
} }
expected := testDataForInfo(suite.T(), cols, version.Backup) expected := testDataForInfo(suite.T(), suite.BackupService(), cols, version.Backup)
for vn := startVersion; vn <= version.Backup; vn++ { for vn := startVersion; vn <= version.Backup; vn++ {
suite.Run(fmt.Sprintf("Version%d", vn), func() { suite.Run(fmt.Sprintf("Version%d", vn), func() {
@ -1156,11 +1290,11 @@ func testPermissionsInheritanceRestoreAndBackup(suite oneDriveSuite, startVersio
// Ideally this can always be true or false and still // Ideally this can always be true or false and still
// work, but limiting older versions to use emails so as // work, but limiting older versions to use emails so as
// to validate that flow as well. // to validate that flow as well.
input := testDataForInfo(t, cols, vn) input := testDataForInfo(t, suite.BackupService(), cols, vn)
testData := restoreBackupInfoMultiVersion{ testData := restoreBackupInfoMultiVersion{
service: path.OneDriveService, service: suite.BackupService(),
resource: Users, resource: suite.Resource(),
backupVersion: vn, backupVersion: vn,
collectionsPrevious: input, collectionsPrevious: input,
collectionsLatest: expected, collectionsLatest: expected,
@ -1171,7 +1305,7 @@ func testPermissionsInheritanceRestoreAndBackup(suite oneDriveSuite, startVersio
suite.Account(), suite.Account(),
testData, testData,
suite.Tenant(), suite.Tenant(),
[]string{userName}, []string{suite.BackupResourceOwner()},
control.Options{ control.Options{
RestorePermissions: true, RestorePermissions: true,
ToggleFeatures: control.Toggles{EnablePermissionsBackup: true}, ToggleFeatures: control.Toggles{EnablePermissionsBackup: true},

View File

@ -11,7 +11,6 @@ import (
"golang.org/x/exp/maps" "golang.org/x/exp/maps"
"github.com/alcionai/clues" "github.com/alcionai/clues"
"github.com/alcionai/corso/src/internal/common/ptr"
"github.com/alcionai/corso/src/internal/connector/graph" "github.com/alcionai/corso/src/internal/connector/graph"
"github.com/alcionai/corso/src/internal/connector/mockconnector" "github.com/alcionai/corso/src/internal/connector/mockconnector"
"github.com/alcionai/corso/src/internal/data" "github.com/alcionai/corso/src/internal/data"
@ -314,27 +313,6 @@ func (suite *GraphConnectorIntegrationSuite) TestEmptyCollections() {
// Exchange Functions // Exchange Functions
//------------------------------------------------------------- //-------------------------------------------------------------
//revive:disable:context-as-argument
func mustGetDefaultDriveID(
t *testing.T,
ctx context.Context,
service graph.Servicer,
userID string,
) string {
//revive:enable:context-as-argument
d, err := service.Client().UsersById(userID).Drive().Get(ctx, nil)
if err != nil {
err = graph.Wrap(ctx, err, "retrieving drive")
}
require.NoError(t, err, clues.ToCore(err))
id := ptr.Val(d.GetId())
require.NotEmpty(t, id)
return id
}
func getCollectionsAndExpected( func getCollectionsAndExpected(
t *testing.T, t *testing.T,
config configInfo, config configInfo,
@ -971,8 +949,8 @@ func (suite *GraphConnectorIntegrationSuite) TestMultiFolderBackupDifferentNames
// Always just 1 because it's just 1 collection. // Always just 1 because it's just 1 collection.
assert.Equal(t, totalItems, status.Metrics.Objects, "status.Metrics.Objects") assert.Equal(t, totalItems, status.Metrics.Objects, "status.Metrics.Objects")
assert.Equal(t, totalItems, status.Metrics.Successes, "status.Metrics.Successes") assert.Equal(t, totalItems, status.Metrics.Successes, "status.Metrics.Successes")
assert.Equal( assert.Len(
t, totalItems, len(deets.Entries), t, deets.Entries, totalItems,
"details entries contains same item count as total successful items restored") "details entries contains same item count as total successful items restored")
t.Log("Restore complete") t.Log("Restore complete")