@@ -31,6 +31,9 @@ func TestTrimKey(t *testing.T) {
3131 {"input.git.tag[0]" , "git.tag" },
3232 {"input.image.provenance.materials[0].image.hasProvenance" , "image.provenance.materials[0].image.hasProvenance" },
3333 {"image.provenance.materials[0].image.labels" , "image.provenance.materials[0].image.labels" },
34+ {"input.image.provenance.materials[0].image.provenance.predicateType" , "image.provenance.materials[0].image.provenance.predicateType" },
35+ {"input.image.provenance.materials[0].image.signatures[0].signer.certificateIssuer" , "image.provenance.materials[0].image.signatures[0].signer.certificateIssuer" },
36+ {"input.image.provenance.materials[10].image.hasProvenance" , "image.provenance.materials[10].image.hasProvenance" },
3437
3538 {"a.b.c" , "a.b" },
3639 }
@@ -61,6 +64,47 @@ func TestCollectUnknowns(t *testing.T) {
6164 require .ElementsMatch (t , []string {"image.signatures" , "image.provenance.materials[0].image.hasProvenance" }, filtered )
6265}
6366
67+ func TestCollectUnknownsParentAllowedMatchesChildRef (t * testing.T ) {
68+ mod , err := ast .ParseModule ("x.rego" , `
69+ package x
70+ p if {
71+ input.image.provenance.materials[0].image.provenance.predicateType != ""
72+ input.image.provenance.materials[0].image.signatures[0].signer.certificateIssuer != ""
73+ input.image.provenance.materials[0].git.tag.name != ""
74+ input.foo.bar != ""
75+ input.image.provenance.materials[10].image.hasProvenance
76+ }
77+ ` )
78+ require .NoError (t , err )
79+
80+ filtered := collectUnknowns ([]* ast.Module {mod }, []string {
81+ "input.image.provenance.materials[0].image.provenance" ,
82+ "input.image.provenance.materials[0].image.signatures" ,
83+ "input.image.provenance.materials[0].git.tag" ,
84+ "input.foo.b" ,
85+ "input.image.provenance.materials[1].image" ,
86+ })
87+
88+ require .ElementsMatch (t , []string {
89+ "image.provenance.materials[0].image.provenance" ,
90+ "image.provenance.materials[0].image.signatures" ,
91+ "image.provenance.materials[0].git.tag" ,
92+ }, filtered )
93+ }
94+
95+ func TestMatchAllowedOrParentBoundary (t * testing.T ) {
96+ allowed := map [string ]struct {}{
97+ "foo.b" : {},
98+ "image.provenance.materials[1].image" : {},
99+ }
100+
101+ _ , ok := matchAllowedOrParent ("foo.bar" , allowed )
102+ require .False (t , ok )
103+
104+ _ , ok = matchAllowedOrParent ("image.provenance.materials[10].image.hasProvenance" , allowed )
105+ require .False (t , ok )
106+ }
107+
64108func TestRuntimeUnknownInputRefs (t * testing.T ) {
65109 require .Nil (t , runtimeUnknownInputRefs (nil ))
66110 require .Nil (t , runtimeUnknownInputRefs (& state {}))
0 commit comments