diff --git a/pkg/utils/parse_arf_result_test.go b/pkg/utils/parse_arf_result_test.go index c114bc3b5..693f06ced 100644 --- a/pkg/utils/parse_arf_result_test.go +++ b/pkg/utils/parse_arf_result_test.go @@ -882,4 +882,77 @@ Server 3.fedora.pool.ntp.org` }) }) + + Describe("Testing for correct content parsing", func() { + Describe("Testing new content used", func() { + Context("Valid XCCDF", func() { + if os.Getenv("DEFAULT_CONTENT_DS_FILE_PATH") != "" { + dsFilename = os.Getenv("DEFAULT_CONTENT_DS_FILE_PATH") + } else { + dsFilename = "RELACE_WITH_PATH_TO_DS_FILE" + } + if dsFilename != "RELACE_WITH_PATH_TO_DS_FILE" { + ds, err := os.Open(dsFilename) + Expect(err).NotTo(HaveOccurred()) + dsDom, err := ParseContent(ds) + Expect(err).NotTo(HaveOccurred()) + It("Should parse the XCCDF without errors", func() { + Expect(err).NotTo(HaveOccurred()) + }) + // printout dsDom xml structure + fmt.Println("dsDom structure") + printUniquePaths(dsDom, "", make(map[string]bool)) + It("Should parse rules without errors", func() { + ruleTable := newRuleHashTable(dsDom) + Expect(ruleTable).NotTo(BeEmpty()) + }) + It("Should parse questionsTable without errors", func() { + questionsTable := NewOcilQuestionTable(dsDom) + Expect(questionsTable).NotTo(BeEmpty()) + }) + It("Should parse defTable without errors", func() { + defTable := NewDefHashTable(dsDom) + Expect(defTable).NotTo(BeEmpty()) + }) + It("Should parse ovalTestVarTable without errors", func() { + statesTable := newStateHashTable(dsDom) + Expect(statesTable).NotTo(BeEmpty()) + objsTable := newObjHashTable(dsDom) + Expect(objsTable).NotTo(BeEmpty()) + ovalTestVarTable := newValueListTable(dsDom, statesTable, objsTable) + Expect(ovalTestVarTable).NotTo(BeEmpty()) + }) + } else { + fmt.Println("Skipping test for new content parsing as dsFilename is not set") + } + }) + }) + }) }) + +// printUniquePaths prints all unique paths within an XML document, starting from a given node. +func printUniquePaths(node *xmlquery.Node, currentPath string, visitedPaths map[string]bool) { + // Construct the path for the current node. + path := currentPath + if node.Type == xmlquery.ElementNode { // Ensure it's an element node. + if path != "" { + path += "/" + } + // Append the namespace prefix if available. + if node.Prefix != "" { + path += node.Prefix + ":" + } + path += node.Data + } + + // Print the path if it hasn't been visited yet. + if _, visited := visitedPaths[path]; !visited && path != "" { + fmt.Println(path) + visitedPaths[path] = true + } + + // Recurse for each child node. + for child := node.FirstChild; child != nil; child = child.NextSibling { + printUniquePaths(child, path, visitedPaths) + } +}