Collect sensitivity directly from document trees
This commit is contained in:
@@ -9,17 +9,10 @@ type secretDependency struct {
|
||||
|
||||
func classifySecretPaths(schema *schemaDescriptor, predicate func(Path) bool, metadata Metadata, final *document.Node, applications []historyApplication, projections ...*document.Node) map[string]bool {
|
||||
paths := make(map[string]Path)
|
||||
finalPaths := make(map[string]*document.Node)
|
||||
indexDocument(final, Path{}, finalPaths)
|
||||
for pointer := range finalPaths {
|
||||
addSecretPath(paths, pointer)
|
||||
}
|
||||
for _, application := range applications {
|
||||
applicationPaths := make(map[string]*document.Node)
|
||||
indexDocument(application.value, application.path, applicationPaths)
|
||||
for pointer := range applicationPaths {
|
||||
addSecretPath(paths, pointer)
|
||||
}
|
||||
walkDocument(application.value, application.path, func(path Path, _ *document.Node) {
|
||||
addSecretPath(paths, path.String())
|
||||
})
|
||||
}
|
||||
var dependencies []secretDependency
|
||||
for pointer, history := range metadata.history {
|
||||
@@ -65,16 +58,19 @@ func classifySecretPaths(schema *schemaDescriptor, predicate func(Path) bool, me
|
||||
}
|
||||
|
||||
secret := make(map[string]bool)
|
||||
for _, tree := range append(projections, final) {
|
||||
projected := make(map[string]*document.Node)
|
||||
indexDocument(tree, Path{}, projected)
|
||||
for pointer, node := range projected {
|
||||
classifyProjection := func(tree *document.Node) {
|
||||
walkDocument(tree, Path{}, func(path Path, node *document.Node) {
|
||||
pointer := path.String()
|
||||
addSecretPath(paths, pointer)
|
||||
if node.Sensitive {
|
||||
secret[pointer] = true
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
for _, tree := range projections {
|
||||
classifyProjection(tree)
|
||||
}
|
||||
classifyProjection(final)
|
||||
for pointer, path := range paths {
|
||||
if root, ok := schemaSecretRoot(schema, path); ok {
|
||||
secret[root.String()] = true
|
||||
|
||||
23
internal/engine/secret_classification_test.go
Normal file
23
internal/engine/secret_classification_test.go
Normal file
@@ -0,0 +1,23 @@
|
||||
package engine
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestSecretPredicateReceivesDetachedHistoricalPath(t *testing.T) {
|
||||
path := Keys("records").Key("1")
|
||||
metadata := Metadata{history: map[string][]Change{
|
||||
path.String(): {{Path: path}},
|
||||
}}
|
||||
seen := false
|
||||
classified := classifySecretPaths(nil, func(candidate Path) bool {
|
||||
if candidate.String() != path.String() {
|
||||
return false
|
||||
}
|
||||
seen = true
|
||||
candidate.segments[0].key = "changed"
|
||||
return true
|
||||
}, metadata, nil, nil)
|
||||
|
||||
if !seen || !classified[path.String()] || classified["/changed/1"] {
|
||||
t.Fatalf("classification after predicate mutation = %#v, predicate called: %v", classified, seen)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user