From deb183278ce0726d06cc0f92677e41b09f937acd Mon Sep 17 00:00:00 2001 From: Keepers Date: Tue, 1 Aug 2023 09:44:22 -0600 Subject: [PATCH] fix loop in restore config conceal (#3939) #### Type of change - [x] :bug: Bugfix #### Test Plan - [x] :zap: Unit test --- src/pkg/control/restore.go | 6 ++-- src/pkg/control/restore_test.go | 61 +++++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+), 3 deletions(-) diff --git a/src/pkg/control/restore.go b/src/pkg/control/restore.go index cce3bea9b..01491ad91 100644 --- a/src/pkg/control/restore.go +++ b/src/pkg/control/restore.go @@ -121,9 +121,9 @@ func (rc RestoreConfig) marshal() string { func (rc RestoreConfig) concealed() RestoreConfig { return RestoreConfig{ OnCollision: rc.OnCollision, - ProtectedResource: clues.Hide(rc.ProtectedResource).Conceal(), + ProtectedResource: clues.Conceal(rc.ProtectedResource), Location: path.LoggableDir(rc.Location), - Drive: clues.Hide(rc.Drive).Conceal(), + Drive: clues.Conceal(rc.Drive), IncludePermissions: rc.IncludePermissions, } } @@ -138,7 +138,7 @@ func (rc RestoreConfig) Conceal() string { // used within a PrintF, suitable for logging, storing in errors, // and other output. func (rc RestoreConfig) Format(fs fmt.State, _ rune) { - fmt.Fprint(fs, rc.concealed()) + fmt.Fprint(fs, rc.concealed().marshal()) } // String returns a plain text version of the restoreConfig. diff --git a/src/pkg/control/restore_test.go b/src/pkg/control/restore_test.go index 0690d1fda..e239c6663 100644 --- a/src/pkg/control/restore_test.go +++ b/src/pkg/control/restore_test.go @@ -1,13 +1,18 @@ package control_test import ( + "fmt" "testing" + "github.com/alcionai/clues" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/stretchr/testify/suite" + "github.com/alcionai/corso/src/internal/common/dttm" "github.com/alcionai/corso/src/internal/tester" "github.com/alcionai/corso/src/pkg/control" + "github.com/alcionai/corso/src/pkg/path" ) type RestoreUnitSuite struct { @@ -97,3 +102,59 @@ func (suite *RestoreUnitSuite) TestEnsureRestoreConfigDefaults() { }) } } + +func (suite *RestoreUnitSuite) TestRestoreConfig_piiHandling() { + p, err := path.Build("tid", "ro", path.ExchangeService, path.EmailCategory, true, "foo", "bar", "baz") + require.NoError(suite.T(), err, clues.ToCore(err)) + + cdrc := control.DefaultRestoreConfig(dttm.HumanReadable) + + table := []struct { + name string + rc control.RestoreConfig + expectSafe string + expectPlain string + }{ + { + name: "empty", + expectSafe: `{"onCollision":"","protectedResource":"","location":"","drive":"","includePermissions":false}`, + expectPlain: `{"onCollision":"","protectedResource":"","location":"","drive":"","includePermissions":false}`, + }, + { + name: "defaults", + rc: cdrc, + expectSafe: `{"onCollision":"skip","protectedResource":"","location":"***","drive":"","includePermissions":false}`, + expectPlain: `{"onCollision":"skip","protectedResource":"","location":"` + + cdrc.Location + `","drive":"","includePermissions":false}`, + }, + { + name: "populated", + rc: control.RestoreConfig{ + OnCollision: control.Copy, + ProtectedResource: "snoob", + Location: p.String(), + Drive: "somedriveid", + IncludePermissions: true, + }, + expectSafe: `{"onCollision":"copy","protectedResource":"***","location":"***/exchange/***/email/***/***/***",` + + `"drive":"***","includePermissions":true}`, + expectPlain: `{"onCollision":"copy","protectedResource":"snoob","location":"tid/exchange/ro/email/foo/bar/baz",` + + `"drive":"somedriveid","includePermissions":true}`, + }, + } + for _, test := range table { + suite.Run(test.name, func() { + t := suite.T() + + clues.SetHasher(clues.HashCfg{HashAlg: clues.Flatmask}) + + assert.Equal(t, test.expectSafe, test.rc.Conceal(), "conceal") + assert.Equal(t, test.expectPlain, test.rc.String(), "string") + assert.Equal(t, test.expectSafe, fmt.Sprintf("%s", test.rc), "fmt %%s") + assert.Equal(t, test.expectSafe, fmt.Sprintf("%+v", test.rc), "fmt %%+v") + assert.Equal(t, test.expectPlain, test.rc.PlainString(), "plain") + + clues.SetHasher(clues.NoHash()) + }) + } +}