mirror of
https://github.com/securego/gosec.git
synced 2025-07-13 01:00:25 +02:00
Add support for suppressing the findings
This commit is contained in:
@ -486,4 +486,53 @@ var _ = Describe("Formatter", func() {
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
Context("When converting suppressed issues", func() {
|
||||
ruleID := "G101"
|
||||
cwe := gosec.GetCweByRule(ruleID)
|
||||
suppressions := []gosec.SuppressionInfo{
|
||||
{
|
||||
Kind: "kind",
|
||||
Justification: "justification",
|
||||
},
|
||||
}
|
||||
suppressedIssue := createIssue(ruleID, cwe)
|
||||
suppressedIssue.WithSuppressions(suppressions)
|
||||
|
||||
It("text formatted report should contain the suppressed issues", func() {
|
||||
error := map[string][]gosec.Error{}
|
||||
reportInfo := gosec.NewReportInfo([]*gosec.Issue{&suppressedIssue}, &gosec.Metrics{}, error)
|
||||
|
||||
buf := new(bytes.Buffer)
|
||||
err := CreateReport(buf, "text", false, []string{}, reportInfo)
|
||||
Expect(err).ShouldNot(HaveOccurred())
|
||||
|
||||
result := stripString(buf.String())
|
||||
Expect(result).To(ContainSubstring("Results:Summary"))
|
||||
})
|
||||
|
||||
It("sarif formatted report should contain the suppressed issues", func() {
|
||||
error := map[string][]gosec.Error{}
|
||||
reportInfo := gosec.NewReportInfo([]*gosec.Issue{&suppressedIssue}, &gosec.Metrics{}, error)
|
||||
|
||||
buf := new(bytes.Buffer)
|
||||
err := CreateReport(buf, "sarif", false, []string{}, reportInfo)
|
||||
Expect(err).ShouldNot(HaveOccurred())
|
||||
|
||||
result := stripString(buf.String())
|
||||
Expect(result).To(ContainSubstring(`"results":[{`))
|
||||
})
|
||||
|
||||
It("json formatted report should contain the suppressed issues", func() {
|
||||
error := map[string][]gosec.Error{}
|
||||
reportInfo := gosec.NewReportInfo([]*gosec.Issue{&suppressedIssue}, &gosec.Metrics{}, error)
|
||||
|
||||
buf := new(bytes.Buffer)
|
||||
err := CreateReport(buf, "json", false, []string{}, reportInfo)
|
||||
Expect(err).ShouldNot(HaveOccurred())
|
||||
|
||||
result := stripString(buf.String())
|
||||
Expect(result).To(ContainSubstring(`"Issues":[{`))
|
||||
})
|
||||
})
|
||||
})
|
||||
|
Reference in New Issue
Block a user