From e67e5be977f97ca09e1ec331fe4fc03a93f1c36d Mon Sep 17 00:00:00 2001 From: Keepers Date: Fri, 5 May 2023 14:28:14 -0600 Subject: [PATCH] remove cli support for exchange item msoft id lookup (#3316) removes the microsoft item ID from the exchange pathValues set when using only-name selector configuration. This is the standard config for the cli, thus this removes the ability to filter exchange items from the cli by using their m365 id. --- #### Does this PR need a docs update or release note? - [x] :white_check_mark: Yes, it's included #### Type of change - [x] :broom: Tech Debt/Cleanup #### Issue(s) * #3313 #### Test Plan - [x] :muscle: Manual - [x] :zap: Unit test --- CHANGELOG.md | 3 +- src/cli/utils/testdata/opts.go | 16 +++--- src/pkg/selectors/exchange.go | 11 +++- src/pkg/selectors/exchange_test.go | 80 ++++++++++++++++++++---------- 4 files changed, 74 insertions(+), 36 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fe83ff090..c85ae536d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,8 +13,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Graph requests now automatically retry in case of a Bad Gateway or Gateway Timeout. - POST Retries following certain status codes (500, 502, 504) will re-use the post body instead of retrying with a no-content request. - Fix nil pointer exception when running an incremental backup on SharePoint where the base backup used an older index data format. -- --user and --mailbox flags (already not supported) have been removed from CLI examples for details and restore commands. +- --user and --mailbox flags have been removed from CLI examples for details and restore commands (they were already not supported, this only updates the docs). - Improve restore time on large restores by optimizing how items are loaded from the remote repository. +- Remove exchange item filtering based on m365 item ID via the CLI. ## [v0.7.0] (beta) - 2023-05-02 diff --git a/src/cli/utils/testdata/opts.go b/src/cli/utils/testdata/opts.go index 0f52f64b4..cde3023fd 100644 --- a/src/cli/utils/testdata/opts.go +++ b/src/cli/utils/testdata/opts.go @@ -198,13 +198,6 @@ var ( EmailReceivedBefore: dttm.Format(testdata.Time1.Add(time.Second)), }, }, - { - Name: "MailItemRef", - Expected: []details.Entry{testdata.ExchangeEmailItems[0]}, - Opts: utils.ExchangeOpts{ - Email: []string{testdata.ExchangeEmailItems[0].ItemRef}, - }, - }, { Name: "MailShortRef", Expected: []details.Entry{testdata.ExchangeEmailItems[0]}, @@ -212,6 +205,15 @@ var ( Email: []string{testdata.ExchangeEmailItemPath1.RR.ShortRef()}, }, }, + { + Name: "BadMailItemRef", + // no matches are expected, since exchange ItemRefs + // are not matched when using the CLI's selectors. + Expected: []details.Entry{}, + Opts: utils.ExchangeOpts{ + Email: []string{testdata.ExchangeEmailItems[0].ItemRef}, + }, + }, { Name: "MultipleMailShortRef", Expected: []details.Entry{ diff --git a/src/pkg/selectors/exchange.go b/src/pkg/selectors/exchange.go index 777e41314..b5463f5d1 100644 --- a/src/pkg/selectors/exchange.go +++ b/src/pkg/selectors/exchange.go @@ -617,6 +617,15 @@ func (ec exchangeCategory) pathValues( item = repo.Item() } + items := []string{ent.ShortRef, item} + + // only include the item ID when the user is NOT matching + // item names. Exchange data does not contain an item name, + // only an ID, and we don't want to mix up the two. + if cfg.OnlyMatchItemNames { + items = []string{ent.ShortRef} + } + // Will hit the if-condition when we're at a top-level folder, but we'll get // the same result when we extract from the RepoRef. folder := ent.LocationRef @@ -626,7 +635,7 @@ func (ec exchangeCategory) pathValues( result := map[categorizer][]string{ folderCat: {folder}, - itemCat: {item, ent.ShortRef}, + itemCat: items, } return result, nil diff --git a/src/pkg/selectors/exchange_test.go b/src/pkg/selectors/exchange_test.go index 032c6a3fe..0473c522e 100644 --- a/src/pkg/selectors/exchange_test.go +++ b/src/pkg/selectors/exchange_test.go @@ -1492,48 +1492,74 @@ func (suite *ExchangeSelectorSuite) TestExchangeCategory_leafCat() { func (suite *ExchangeSelectorSuite) TestExchangeCategory_PathValues() { t := suite.T() - contactPath := stubPath(t, "user", []string{"cfolder.d", "contactitem.d"}, path.ContactsCategory) - contactLoc := stubPath(t, "user", []string{"cfolder", "contactitem"}, path.ContactsCategory) - contactMap := map[categorizer][]string{ - ExchangeContactFolder: {contactLoc.Folder(false)}, - ExchangeContact: {contactPath.Item(), "short"}, - } - eventPath := stubPath(t, "user", []string{"ecalendar.d", "eventitem.d"}, path.EventsCategory) - eventLoc := stubPath(t, "user", []string{"ecalendar", "eventitem"}, path.EventsCategory) - eventMap := map[categorizer][]string{ - ExchangeEventCalendar: {eventLoc.Folder(false)}, - ExchangeEvent: {eventPath.Item(), "short"}, - } - mailPath := stubPath(t, "user", []string{"mfolder.d", "mailitem.d"}, path.EmailCategory) - mailLoc := stubPath(t, "user", []string{"mfolder", "mailitem"}, path.EmailCategory) - mailMap := map[categorizer][]string{ - ExchangeMailFolder: {mailLoc.Folder(false)}, - ExchangeMail: {mailPath.Item(), "short"}, - } + var ( + contactPath = stubPath(t, "u", []string{"cfolder.d", "contactitem.d"}, path.ContactsCategory) + contactLoc = stubPath(t, "u", []string{"cfolder", "contactitem"}, path.ContactsCategory) + contactMap = map[categorizer][]string{ + ExchangeContactFolder: {contactLoc.Folder(false)}, + ExchangeContact: {contactPath.Item(), "contact-short"}, + } + contactOnlyNameMap = map[categorizer][]string{ + ExchangeContactFolder: {contactLoc.Folder(false)}, + ExchangeContact: {"contact-short"}, + } + eventPath = stubPath(t, "u", []string{"ecalendar.d", "eventitem.d"}, path.EventsCategory) + eventLoc = stubPath(t, "u", []string{"ecalendar", "eventitem"}, path.EventsCategory) + eventMap = map[categorizer][]string{ + ExchangeEventCalendar: {eventLoc.Folder(false)}, + ExchangeEvent: {eventPath.Item(), "event-short"}, + } + eventOnlyNameMap = map[categorizer][]string{ + ExchangeEventCalendar: {eventLoc.Folder(false)}, + ExchangeEvent: {"event-short"}, + } + mailPath = stubPath(t, "u", []string{"mfolder.d", "mailitem.d"}, path.EmailCategory) + mailLoc = stubPath(t, "u", []string{"mfolder", "mailitem"}, path.EmailCategory) + mailMap = map[categorizer][]string{ + ExchangeMailFolder: {mailLoc.Folder(false)}, + ExchangeMail: {mailPath.Item(), "mail-short"}, + } + mailOnlyNameMap = map[categorizer][]string{ + ExchangeMailFolder: {mailLoc.Folder(false)}, + ExchangeMail: {"mail-short"}, + } + ) table := []struct { - cat exchangeCategory - path path.Path - loc path.Path - expect map[categorizer][]string + cat exchangeCategory + path path.Path + loc path.Path + short string + expect map[categorizer][]string + expectOnlyName map[categorizer][]string }{ - {ExchangeContact, contactPath, contactLoc, contactMap}, - {ExchangeEvent, eventPath, eventLoc, eventMap}, - {ExchangeMail, mailPath, mailLoc, mailMap}, + {ExchangeContact, contactPath, contactLoc, "contact-short", contactMap, contactOnlyNameMap}, + {ExchangeEvent, eventPath, eventLoc, "event-short", eventMap, eventOnlyNameMap}, + {ExchangeMail, mailPath, mailLoc, "mail-short", mailMap, mailOnlyNameMap}, } for _, test := range table { suite.Run(string(test.cat), func() { t := suite.T() ent := details.Entry{ RepoRef: test.path.String(), - ShortRef: "short", + ShortRef: test.short, LocationRef: test.loc.Folder(true), ItemRef: test.path.Item(), } pvs, err := test.cat.pathValues(test.path, ent, Config{}) require.NoError(t, err) - assert.Equal(t, test.expect, pvs) + + for k := range test.expect { + assert.ElementsMatch(t, test.expect[k], pvs[k]) + } + + pvs, err = test.cat.pathValues(test.path, ent, Config{OnlyMatchItemNames: true}) + require.NoError(t, err) + + for k := range test.expectOnlyName { + assert.ElementsMatch(t, test.expectOnlyName[k], pvs[k], k) + } }) } }