This repository has been archived by the owner on Jun 1, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3aea3c5
commit 1b0690e
Showing
2 changed files
with
78 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package test | ||
|
||
import ( | ||
"strings" | ||
"testing" | ||
|
||
"github.com/aquasecurity/cfsec/internal/app/cfsec/adapter" | ||
"github.com/aquasecurity/cfsec/internal/app/cfsec/parser" | ||
"github.com/aquasecurity/cfsec/internal/app/cfsec/scanner" | ||
) | ||
|
||
func Test_PanicTeasing(t *testing.T) { | ||
for _, rule := range scanner.GetRegisteredRules() { | ||
for _, code := range append(mutateYAML(rule.BadExample...), mutateYAML(rule.GoodExample...)...) { | ||
func() { | ||
defer func() { | ||
if err := recover(); err != nil { | ||
t.Fatalf("Panic encountered for code:\n\n%s\n\nPanic: %s", code, err) | ||
} | ||
}() | ||
ctx, err := parser.Parse(strings.NewReader(code), "test.yaml") | ||
if err != nil { | ||
t.Fatalf("Failed to parse YAML:\n\n%s\n\nError: %s", code, err) | ||
} | ||
state := adapter.Adapt(*ctx) | ||
_ = rule.Base.Evaluate(state) | ||
}() | ||
} | ||
} | ||
|
||
} | ||
|
||
func mutateYAML(input ...string) []string { | ||
return input | ||
} |