ContainsSensitive must descend into nested objects

This commit is contained in:
Kristin Laemmert 2021-02-11 10:32:31 -05:00
parent 77af601543
commit 6aa90a51d0
2 changed files with 65 additions and 0 deletions

View File

@ -71,6 +71,9 @@ func (o *Object) ContainsSensitive() bool {
if attrS.Sensitive {
return true
}
if attrS.NestedType != nil {
return attrS.NestedType.ContainsSensitive()
}
}
return false
}

View File

@ -178,3 +178,65 @@ func TestObjectImpliedType(t *testing.T) {
})
}
}
func TestObjectContainsSensitive(t *testing.T) {
tests := map[string]struct {
Schema *Object
Want bool
}{
"object contains sensitive": {
&Object{
Attributes: map[string]*Attribute{
"sensitive": {Sensitive: true},
},
},
true,
},
"no sensitive attrs": {
&Object{
Attributes: map[string]*Attribute{
"insensitive": {},
},
},
false,
},
"nested object contains sensitive": {
&Object{
Attributes: map[string]*Attribute{
"nested": {
NestedType: &Object{
Attributes: map[string]*Attribute{
"sensitive": {Sensitive: true},
},
},
},
},
},
true,
},
"nested obj, no sensitive attrs": {
&Object{
Attributes: map[string]*Attribute{
"nested": {
NestedType: &Object{
Attributes: map[string]*Attribute{
"public": {},
},
},
},
},
},
false,
},
}
for name, test := range tests {
t.Run(name, func(t *testing.T) {
got := test.Schema.ContainsSensitive()
if got != test.Want {
t.Errorf("wrong result\ngot: %#v\nwant: %#v", got, test.Want)
}
})
}
}