-
Notifications
You must be signed in to change notification settings - Fork 30
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
Showing
1 changed file
with
43 additions
and
33 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,46 @@ | ||
package test | ||
|
||
// TODO: bring this test back | ||
//func TestAVDIDs(t *testing.T) { | ||
// existing := make(map[string]struct{}) | ||
// for _, rule := range rules.GetRegistered(framework.ALL) { | ||
// t.Run(rule.LongID(), func(t *testing.T) { | ||
// if rule.GetRule().AVDID == "" { | ||
// t.Errorf("Rule has no AVD ID: %#v", rule) | ||
// return | ||
// } | ||
// if _, ok := existing[rule.GetRule().AVDID]; ok { | ||
// t.Errorf("Rule detected with duplicate AVD ID: %s", rule.GetRule().AVDID) | ||
// } | ||
// }) | ||
// existing[rule.GetRule().AVDID] = struct{}{} | ||
// } | ||
//} | ||
import ( | ||
"fmt" | ||
"os" | ||
"path/filepath" | ||
"strings" | ||
"testing" | ||
|
||
// TODO: bring this test back | ||
//func TestRulesAgainstExampleCode(t *testing.T) { | ||
// for _, rule := range rules.GetRegistered(framework.ALL) { | ||
// testName := fmt.Sprintf("%s/%s", rule.GetRule().AVDID, rule.LongID()) | ||
// t.Run(testName, func(t *testing.T) { | ||
// rule := rule | ||
// t.Parallel() | ||
// | ||
// t.Run("avd docs", func(t *testing.T) { | ||
// provider := strings.ToLower(rule.GetRule().Provider.ConstName()) | ||
// service := strings.ToLower(strings.ReplaceAll(rule.GetRule().Service, "-", "")) | ||
// _, err := os.Stat(filepath.Join("..", "avd_docs", provider, service, rule.GetRule().AVDID, "docs.md")) | ||
// require.NoError(t, err) | ||
// }) | ||
// }) | ||
// } | ||
//} | ||
"github.com/aquasecurity/defsec/pkg/framework" | ||
"github.com/aquasecurity/defsec/pkg/rules" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestAVDIDs(t *testing.T) { | ||
existing := make(map[string]struct{}) | ||
for _, rule := range rules.GetRegistered(framework.ALL) { | ||
t.Run(rule.LongID(), func(t *testing.T) { | ||
if rule.GetRule().AVDID == "" { | ||
t.Errorf("Rule has no AVD ID: %#v", rule) | ||
return | ||
} | ||
if _, ok := existing[rule.GetRule().AVDID]; ok { | ||
t.Errorf("Rule detected with duplicate AVD ID: %s", rule.GetRule().AVDID) | ||
} | ||
}) | ||
existing[rule.GetRule().AVDID] = struct{}{} | ||
} | ||
} | ||
|
||
func TestRulesAgainstExampleCode(t *testing.T) { | ||
for _, rule := range rules.GetRegistered(framework.ALL) { | ||
testName := fmt.Sprintf("%s/%s", rule.GetRule().AVDID, rule.LongID()) | ||
t.Run(testName, func(t *testing.T) { | ||
rule := rule | ||
t.Parallel() | ||
|
||
t.Run("avd docs", func(t *testing.T) { | ||
provider := strings.ToLower(rule.GetRule().Provider.ConstName()) | ||
service := strings.ToLower(strings.ReplaceAll(rule.GetRule().Service, "-", "")) | ||
_, err := os.Stat(filepath.Join("..", "avd_docs", provider, service, rule.GetRule().AVDID, "docs.md")) | ||
require.NoError(t, err) | ||
}) | ||
}) | ||
} | ||
} |