Skip to content

Commit

Permalink
Add test file needed for testing CaC content
Browse files Browse the repository at this point in the history
Add required test file so we can test if datastream can be parsed correctly by parser.
  • Loading branch information
Vincent056 committed Feb 22, 2024
1 parent 479601a commit d6da4f9
Showing 1 changed file with 73 additions and 0 deletions.
73 changes: 73 additions & 0 deletions pkg/utils/parse_arf_result_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

0 comments on commit d6da4f9

Please sign in to comment.