From 14aef408e8a7871732423dafe5764bd551bc7f18 Mon Sep 17 00:00:00 2001 From: Yoav Rotem Date: Wed, 23 Jun 2021 18:01:24 +0300 Subject: [PATCH] Fix Junit missing testsuites (#920) Fix issue https://github.com/aquasecurity/kube-bench/issues/883 but also bug with overriding output when --outputfile is effective and only write the last controls --- cmd/common.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/cmd/common.go b/cmd/common.go index 2cade9a..60f2913 100644 --- a/cmd/common.go +++ b/cmd/common.go @@ -437,13 +437,19 @@ func writeJSONOutput(controlsCollection []*check.Controls) { } func writeJunitOutput(controlsCollection []*check.Controls) { + // QuickFix for issue https://github.com/aquasecurity/kube-bench/issues/883 + // Should consider to deprecate of switch to using Junit template + prefix := "\n" + suffix := "\n" + var outputAllControls []byte for _, controls := range controlsCollection { - out, err := controls.JUnit() + tempOut, err := controls.JUnit() + outputAllControls = append(outputAllControls[:], tempOut[:]...) if err != nil { exitWithError(fmt.Errorf("failed to output in JUnit format: %v", err)) } - printOutput(string(out), outputFile) } + printOutput(prefix+string(outputAllControls)+suffix, outputFile) } func writePgsqlOutput(controlsCollection []*check.Controls) {