fix loop in restore config conceal (#3939)
#### Type of change - [x] 🐛 Bugfix #### Test Plan - [x] ⚡ Unit test
This commit is contained in:
parent
5751163572
commit
deb183278c
@ -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.
|
||||
|
||||
@ -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())
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user