Narrow the source-fact /facts fetch to the query's certnames
ci/woodpecker/pr/build Pipeline was successful
ci/woodpecker/pr/pre-commit Pipeline was successful
ci/woodpecker/pr/test Pipeline was successful

This commit is contained in:
2026-10-09 23:47:56 +11:00
parent 0aff1746e2
commit 97ddc378ff
6 changed files with 143 additions and 7 deletions
+22
View File
@@ -637,3 +637,25 @@ func TestSourceInjector_SourceQuery(t *testing.T) {
t.Error("disabled injector selected a query")
}
}
func TestCertnameScope(t *testing.T) {
tests := map[string]string{
`["=","name","x"]`: ``,
`["and",["=","name","x"],["=","environment","prod"]]`: ``,
`["or",["=","certname","h1"],["=","name","x"]]`: ``,
`["and",["not",["=","certname","h1"]],["=","name","x"]]`: ``,
`["and",["=","certname","h1"],["=","name","x"]]`: `["=","certname","h1"]`,
`["and",["~","certname","["],["=","name","x"]]`: ``,
`["and",["in","certname",["extract","certname",["=","a","b"]]],["=","name","x"]]`: ``,
`["and",["in","certname",["array",["h1","h2"]]],["~","certname","^h"],["=","name","x"]]`: `["and",["in","certname",["array",["h1","h2"]]],["~","certname","^h"]]`,
}
for in, want := range tests {
var ast []json.RawMessage
if err := json.Unmarshal([]byte(in), &ast); err != nil {
t.Fatal(err)
}
if got := certnameScope(ast); got != want {
t.Errorf("certnameScope(%s) = %q, want %q", in, got, want)
}
}
}