|
@@ -19,6 +19,9 @@ import (
|
|
)
|
|
)
|
|
|
|
|
|
var HubTest hubtest.HubTest
|
|
var HubTest hubtest.HubTest
|
|
|
|
+var HubAppsecTests hubtest.HubTest
|
|
|
|
+var hubPtr *hubtest.HubTest
|
|
|
|
+var isAppsecTest bool
|
|
|
|
|
|
func NewHubTestCmd() *cobra.Command {
|
|
func NewHubTestCmd() *cobra.Command {
|
|
var hubPath string
|
|
var hubPath string
|
|
@@ -33,11 +36,20 @@ func NewHubTestCmd() *cobra.Command {
|
|
DisableAutoGenTag: true,
|
|
DisableAutoGenTag: true,
|
|
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
|
|
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
|
|
var err error
|
|
var err error
|
|
- HubTest, err = hubtest.NewHubTest(hubPath, crowdsecPath, cscliPath)
|
|
|
|
|
|
+ HubTest, err = hubtest.NewHubTest(hubPath, crowdsecPath, cscliPath, false)
|
|
if err != nil {
|
|
if err != nil {
|
|
return fmt.Errorf("unable to load hubtest: %+v", err)
|
|
return fmt.Errorf("unable to load hubtest: %+v", err)
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ HubAppsecTests, err = hubtest.NewHubTest(hubPath, crowdsecPath, cscliPath, true)
|
|
|
|
+ if err != nil {
|
|
|
|
+ return fmt.Errorf("unable to load appsec specific hubtest: %+v", err)
|
|
|
|
+ }
|
|
|
|
+ /*commands will use the hubPtr, will point to the default hubTest object, or the one dedicated to appsec tests*/
|
|
|
|
+ hubPtr = &HubTest
|
|
|
|
+ if isAppsecTest {
|
|
|
|
+ hubPtr = &HubAppsecTests
|
|
|
|
+ }
|
|
return nil
|
|
return nil
|
|
},
|
|
},
|
|
}
|
|
}
|
|
@@ -45,6 +57,7 @@ func NewHubTestCmd() *cobra.Command {
|
|
cmdHubTest.PersistentFlags().StringVar(&hubPath, "hub", ".", "Path to hub folder")
|
|
cmdHubTest.PersistentFlags().StringVar(&hubPath, "hub", ".", "Path to hub folder")
|
|
cmdHubTest.PersistentFlags().StringVar(&crowdsecPath, "crowdsec", "crowdsec", "Path to crowdsec")
|
|
cmdHubTest.PersistentFlags().StringVar(&crowdsecPath, "crowdsec", "crowdsec", "Path to crowdsec")
|
|
cmdHubTest.PersistentFlags().StringVar(&cscliPath, "cscli", "cscli", "Path to cscli")
|
|
cmdHubTest.PersistentFlags().StringVar(&cscliPath, "cscli", "cscli", "Path to cscli")
|
|
|
|
+ cmdHubTest.PersistentFlags().BoolVar(&isAppsecTest, "appsec", false, "Command relates to appsec tests")
|
|
|
|
|
|
cmdHubTest.AddCommand(NewHubTestCreateCmd())
|
|
cmdHubTest.AddCommand(NewHubTestCreateCmd())
|
|
cmdHubTest.AddCommand(NewHubTestRunCmd())
|
|
cmdHubTest.AddCommand(NewHubTestRunCmd())
|
|
@@ -76,7 +89,7 @@ cscli hubtest create my-scenario-test --parsers crowdsecurity/nginx --scenarios
|
|
DisableAutoGenTag: true,
|
|
DisableAutoGenTag: true,
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
testName := args[0]
|
|
testName := args[0]
|
|
- testPath := filepath.Join(HubTest.HubTestPath, testName)
|
|
|
|
|
|
+ testPath := filepath.Join(hubPtr.HubTestPath, testName)
|
|
if _, err := os.Stat(testPath); os.IsExist(err) {
|
|
if _, err := os.Stat(testPath); os.IsExist(err) {
|
|
return fmt.Errorf("test '%s' already exists in '%s', exiting", testName, testPath)
|
|
return fmt.Errorf("test '%s' already exists in '%s', exiting", testName, testPath)
|
|
}
|
|
}
|
|
@@ -89,53 +102,76 @@ cscli hubtest create my-scenario-test --parsers crowdsecurity/nginx --scenarios
|
|
return fmt.Errorf("unable to create folder '%s': %+v", testPath, err)
|
|
return fmt.Errorf("unable to create folder '%s': %+v", testPath, err)
|
|
}
|
|
}
|
|
|
|
|
|
- // create empty log file
|
|
|
|
- logFileName := fmt.Sprintf("%s.log", testName)
|
|
|
|
- logFilePath := filepath.Join(testPath, logFileName)
|
|
|
|
- logFile, err := os.Create(logFilePath)
|
|
|
|
- if err != nil {
|
|
|
|
- return err
|
|
|
|
- }
|
|
|
|
- logFile.Close()
|
|
|
|
|
|
+ configFilePath := filepath.Join(testPath, "config.yaml")
|
|
|
|
|
|
- // create empty parser assertion file
|
|
|
|
- parserAssertFilePath := filepath.Join(testPath, hubtest.ParserAssertFileName)
|
|
|
|
- parserAssertFile, err := os.Create(parserAssertFilePath)
|
|
|
|
- if err != nil {
|
|
|
|
- return err
|
|
|
|
- }
|
|
|
|
- parserAssertFile.Close()
|
|
|
|
|
|
+ configFileData := &hubtest.HubTestItemConfig{}
|
|
|
|
+ if logType == "appsec" {
|
|
|
|
+ //create empty nuclei template file
|
|
|
|
+ nucleiFileName := fmt.Sprintf("%s.yaml", testName)
|
|
|
|
+ nucleiFilePath := filepath.Join(testPath, nucleiFileName)
|
|
|
|
+ nucleiFile, err := os.Create(nucleiFilePath)
|
|
|
|
+ if err != nil {
|
|
|
|
+ return err
|
|
|
|
+ }
|
|
|
|
+ nucleiFile.Close()
|
|
|
|
+ configFileData.AppsecRules = []string{"your_rule_here.yaml"}
|
|
|
|
+ configFileData.NucleiTemplate = nucleiFileName
|
|
|
|
+ fmt.Println()
|
|
|
|
+ fmt.Printf(" Test name : %s\n", testName)
|
|
|
|
+ fmt.Printf(" Test path : %s\n", testPath)
|
|
|
|
+ fmt.Printf(" Nuclei Template : %s\n", nucleiFileName)
|
|
|
|
+ } else {
|
|
|
|
+ // create empty log file
|
|
|
|
+ logFileName := fmt.Sprintf("%s.log", testName)
|
|
|
|
+ logFilePath := filepath.Join(testPath, logFileName)
|
|
|
|
+ logFile, err := os.Create(logFilePath)
|
|
|
|
+ if err != nil {
|
|
|
|
+ return err
|
|
|
|
+ }
|
|
|
|
+ logFile.Close()
|
|
|
|
|
|
- // create empty scenario assertion file
|
|
|
|
- scenarioAssertFilePath := filepath.Join(testPath, hubtest.ScenarioAssertFileName)
|
|
|
|
- scenarioAssertFile, err := os.Create(scenarioAssertFilePath)
|
|
|
|
- if err != nil {
|
|
|
|
- return err
|
|
|
|
- }
|
|
|
|
- scenarioAssertFile.Close()
|
|
|
|
|
|
+ // create empty parser assertion file
|
|
|
|
+ parserAssertFilePath := filepath.Join(testPath, hubtest.ParserAssertFileName)
|
|
|
|
+ parserAssertFile, err := os.Create(parserAssertFilePath)
|
|
|
|
+ if err != nil {
|
|
|
|
+ return err
|
|
|
|
+ }
|
|
|
|
+ parserAssertFile.Close()
|
|
|
|
+ // create empty scenario assertion file
|
|
|
|
+ scenarioAssertFilePath := filepath.Join(testPath, hubtest.ScenarioAssertFileName)
|
|
|
|
+ scenarioAssertFile, err := os.Create(scenarioAssertFilePath)
|
|
|
|
+ if err != nil {
|
|
|
|
+ return err
|
|
|
|
+ }
|
|
|
|
+ scenarioAssertFile.Close()
|
|
|
|
|
|
- parsers = append(parsers, "crowdsecurity/syslog-logs")
|
|
|
|
- parsers = append(parsers, "crowdsecurity/dateparse-enrich")
|
|
|
|
|
|
+ parsers = append(parsers, "crowdsecurity/syslog-logs")
|
|
|
|
+ parsers = append(parsers, "crowdsecurity/dateparse-enrich")
|
|
|
|
|
|
- if len(scenarios) == 0 {
|
|
|
|
- scenarios = append(scenarios, "")
|
|
|
|
- }
|
|
|
|
|
|
+ if len(scenarios) == 0 {
|
|
|
|
+ scenarios = append(scenarios, "")
|
|
|
|
+ }
|
|
|
|
|
|
- if len(postoverflows) == 0 {
|
|
|
|
- postoverflows = append(postoverflows, "")
|
|
|
|
- }
|
|
|
|
|
|
+ if len(postoverflows) == 0 {
|
|
|
|
+ postoverflows = append(postoverflows, "")
|
|
|
|
+ }
|
|
|
|
+ configFileData.Parsers = parsers
|
|
|
|
+ configFileData.Scenarios = scenarios
|
|
|
|
+ configFileData.PostOverflows = postoverflows
|
|
|
|
+ configFileData.LogFile = logFileName
|
|
|
|
+ configFileData.LogType = logType
|
|
|
|
+ configFileData.IgnoreParsers = ignoreParsers
|
|
|
|
+ configFileData.Labels = labels
|
|
|
|
+ fmt.Println()
|
|
|
|
+ fmt.Printf(" Test name : %s\n", testName)
|
|
|
|
+ fmt.Printf(" Test path : %s\n", testPath)
|
|
|
|
+ fmt.Printf(" Log file : %s (please fill it with logs)\n", logFilePath)
|
|
|
|
+ fmt.Printf(" Parser assertion file : %s (please fill it with assertion)\n", parserAssertFilePath)
|
|
|
|
+ fmt.Printf(" Scenario assertion file : %s (please fill it with assertion)\n", scenarioAssertFilePath)
|
|
|
|
+ fmt.Printf(" Configuration File : %s (please fill it with parsers, scenarios...)\n", configFilePath)
|
|
|
|
|
|
- configFileData := &hubtest.HubTestItemConfig{
|
|
|
|
- Parsers: parsers,
|
|
|
|
- Scenarios: scenarios,
|
|
|
|
- PostOVerflows: postoverflows,
|
|
|
|
- LogFile: logFileName,
|
|
|
|
- LogType: logType,
|
|
|
|
- IgnoreParsers: ignoreParsers,
|
|
|
|
- Labels: labels,
|
|
|
|
}
|
|
}
|
|
|
|
|
|
- configFilePath := filepath.Join(testPath, "config.yaml")
|
|
|
|
fd, err := os.Create(configFilePath)
|
|
fd, err := os.Create(configFilePath)
|
|
if err != nil {
|
|
if err != nil {
|
|
return fmt.Errorf("open: %s", err)
|
|
return fmt.Errorf("open: %s", err)
|
|
@@ -151,14 +187,6 @@ cscli hubtest create my-scenario-test --parsers crowdsecurity/nginx --scenarios
|
|
if err := fd.Close(); err != nil {
|
|
if err := fd.Close(); err != nil {
|
|
return fmt.Errorf("close: %s", err)
|
|
return fmt.Errorf("close: %s", err)
|
|
}
|
|
}
|
|
- fmt.Println()
|
|
|
|
- fmt.Printf(" Test name : %s\n", testName)
|
|
|
|
- fmt.Printf(" Test path : %s\n", testPath)
|
|
|
|
- fmt.Printf(" Log file : %s (please fill it with logs)\n", logFilePath)
|
|
|
|
- fmt.Printf(" Parser assertion file : %s (please fill it with assertion)\n", parserAssertFilePath)
|
|
|
|
- fmt.Printf(" Scenario assertion file : %s (please fill it with assertion)\n", scenarioAssertFilePath)
|
|
|
|
- fmt.Printf(" Configuration File : %s (please fill it with parsers, scenarios...)\n", configFilePath)
|
|
|
|
-
|
|
|
|
return nil
|
|
return nil
|
|
},
|
|
},
|
|
}
|
|
}
|
|
@@ -188,12 +216,12 @@ func NewHubTestRunCmd() *cobra.Command {
|
|
}
|
|
}
|
|
|
|
|
|
if runAll {
|
|
if runAll {
|
|
- if err := HubTest.LoadAllTests(); err != nil {
|
|
|
|
|
|
+ if err := hubPtr.LoadAllTests(); err != nil {
|
|
return fmt.Errorf("unable to load all tests: %+v", err)
|
|
return fmt.Errorf("unable to load all tests: %+v", err)
|
|
}
|
|
}
|
|
} else {
|
|
} else {
|
|
for _, testName := range args {
|
|
for _, testName := range args {
|
|
- _, err := HubTest.LoadTestItem(testName)
|
|
|
|
|
|
+ _, err := hubPtr.LoadTestItem(testName)
|
|
if err != nil {
|
|
if err != nil {
|
|
return fmt.Errorf("unable to load test '%s': %s", testName, err)
|
|
return fmt.Errorf("unable to load test '%s': %s", testName, err)
|
|
}
|
|
}
|
|
@@ -202,8 +230,7 @@ func NewHubTestRunCmd() *cobra.Command {
|
|
|
|
|
|
// set timezone to avoid DST issues
|
|
// set timezone to avoid DST issues
|
|
os.Setenv("TZ", "UTC")
|
|
os.Setenv("TZ", "UTC")
|
|
-
|
|
|
|
- for _, test := range HubTest.Tests {
|
|
|
|
|
|
+ for _, test := range hubPtr.Tests {
|
|
if csConfig.Cscli.Output == "human" {
|
|
if csConfig.Cscli.Output == "human" {
|
|
log.Infof("Running test '%s'", test.Name)
|
|
log.Infof("Running test '%s'", test.Name)
|
|
}
|
|
}
|
|
@@ -218,8 +245,8 @@ func NewHubTestRunCmd() *cobra.Command {
|
|
PersistentPostRunE: func(cmd *cobra.Command, args []string) error {
|
|
PersistentPostRunE: func(cmd *cobra.Command, args []string) error {
|
|
success := true
|
|
success := true
|
|
testResult := make(map[string]bool)
|
|
testResult := make(map[string]bool)
|
|
- for _, test := range HubTest.Tests {
|
|
|
|
- if test.AutoGen {
|
|
|
|
|
|
+ for _, test := range hubPtr.Tests {
|
|
|
|
+ if test.AutoGen && !isAppsecTest {
|
|
if test.ParserAssert.AutoGenAssert {
|
|
if test.ParserAssert.AutoGenAssert {
|
|
log.Warningf("Assert file '%s' is empty, generating assertion:", test.ParserAssert.File)
|
|
log.Warningf("Assert file '%s' is empty, generating assertion:", test.ParserAssert.File)
|
|
fmt.Println()
|
|
fmt.Println()
|
|
@@ -341,7 +368,7 @@ func NewHubTestCleanCmd() *cobra.Command {
|
|
DisableAutoGenTag: true,
|
|
DisableAutoGenTag: true,
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
for _, testName := range args {
|
|
for _, testName := range args {
|
|
- test, err := HubTest.LoadTestItem(testName)
|
|
|
|
|
|
+ test, err := hubPtr.LoadTestItem(testName)
|
|
if err != nil {
|
|
if err != nil {
|
|
return fmt.Errorf("unable to load test '%s': %s", testName, err)
|
|
return fmt.Errorf("unable to load test '%s': %s", testName, err)
|
|
}
|
|
}
|
|
@@ -364,17 +391,23 @@ func NewHubTestInfoCmd() *cobra.Command {
|
|
Args: cobra.MinimumNArgs(1),
|
|
Args: cobra.MinimumNArgs(1),
|
|
DisableAutoGenTag: true,
|
|
DisableAutoGenTag: true,
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
|
|
+
|
|
for _, testName := range args {
|
|
for _, testName := range args {
|
|
- test, err := HubTest.LoadTestItem(testName)
|
|
|
|
|
|
+ test, err := hubPtr.LoadTestItem(testName)
|
|
if err != nil {
|
|
if err != nil {
|
|
return fmt.Errorf("unable to load test '%s': %s", testName, err)
|
|
return fmt.Errorf("unable to load test '%s': %s", testName, err)
|
|
}
|
|
}
|
|
fmt.Println()
|
|
fmt.Println()
|
|
fmt.Printf(" Test name : %s\n", test.Name)
|
|
fmt.Printf(" Test name : %s\n", test.Name)
|
|
fmt.Printf(" Test path : %s\n", test.Path)
|
|
fmt.Printf(" Test path : %s\n", test.Path)
|
|
- fmt.Printf(" Log file : %s\n", filepath.Join(test.Path, test.Config.LogFile))
|
|
|
|
- fmt.Printf(" Parser assertion file : %s\n", filepath.Join(test.Path, hubtest.ParserAssertFileName))
|
|
|
|
- fmt.Printf(" Scenario assertion file : %s\n", filepath.Join(test.Path, hubtest.ScenarioAssertFileName))
|
|
|
|
|
|
+ if isAppsecTest {
|
|
|
|
+ fmt.Printf(" Nuclei Template : %s\n", test.Config.NucleiTemplate)
|
|
|
|
+ fmt.Printf(" Appsec Rules : %s\n", strings.Join(test.Config.AppsecRules, ", "))
|
|
|
|
+ } else {
|
|
|
|
+ fmt.Printf(" Log file : %s\n", filepath.Join(test.Path, test.Config.LogFile))
|
|
|
|
+ fmt.Printf(" Parser assertion file : %s\n", filepath.Join(test.Path, hubtest.ParserAssertFileName))
|
|
|
|
+ fmt.Printf(" Scenario assertion file : %s\n", filepath.Join(test.Path, hubtest.ScenarioAssertFileName))
|
|
|
|
+ }
|
|
fmt.Printf(" Configuration File : %s\n", filepath.Join(test.Path, "config.yaml"))
|
|
fmt.Printf(" Configuration File : %s\n", filepath.Join(test.Path, "config.yaml"))
|
|
}
|
|
}
|
|
|
|
|
|
@@ -391,15 +424,15 @@ func NewHubTestListCmd() *cobra.Command {
|
|
Short: "list",
|
|
Short: "list",
|
|
DisableAutoGenTag: true,
|
|
DisableAutoGenTag: true,
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
- if err := HubTest.LoadAllTests(); err != nil {
|
|
|
|
|
|
+ if err := hubPtr.LoadAllTests(); err != nil {
|
|
return fmt.Errorf("unable to load all tests: %s", err)
|
|
return fmt.Errorf("unable to load all tests: %s", err)
|
|
}
|
|
}
|
|
|
|
|
|
switch csConfig.Cscli.Output {
|
|
switch csConfig.Cscli.Output {
|
|
case "human":
|
|
case "human":
|
|
- hubTestListTable(color.Output, HubTest.Tests)
|
|
|
|
|
|
+ hubTestListTable(color.Output, hubPtr.Tests)
|
|
case "json":
|
|
case "json":
|
|
- j, err := json.MarshalIndent(HubTest.Tests, " ", " ")
|
|
|
|
|
|
+ j, err := json.MarshalIndent(hubPtr.Tests, " ", " ")
|
|
if err != nil {
|
|
if err != nil {
|
|
return err
|
|
return err
|
|
}
|
|
}
|
|
@@ -419,23 +452,27 @@ func NewHubTestCoverageCmd() *cobra.Command {
|
|
var showParserCov bool
|
|
var showParserCov bool
|
|
var showScenarioCov bool
|
|
var showScenarioCov bool
|
|
var showOnlyPercent bool
|
|
var showOnlyPercent bool
|
|
|
|
+ var showAppsecCov bool
|
|
|
|
|
|
var cmdHubTestCoverage = &cobra.Command{
|
|
var cmdHubTestCoverage = &cobra.Command{
|
|
Use: "coverage",
|
|
Use: "coverage",
|
|
Short: "coverage",
|
|
Short: "coverage",
|
|
DisableAutoGenTag: true,
|
|
DisableAutoGenTag: true,
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
|
|
+ //for this one we explicitly don't do for appsec
|
|
if err := HubTest.LoadAllTests(); err != nil {
|
|
if err := HubTest.LoadAllTests(); err != nil {
|
|
return fmt.Errorf("unable to load all tests: %+v", err)
|
|
return fmt.Errorf("unable to load all tests: %+v", err)
|
|
}
|
|
}
|
|
var err error
|
|
var err error
|
|
scenarioCoverage := []hubtest.Coverage{}
|
|
scenarioCoverage := []hubtest.Coverage{}
|
|
parserCoverage := []hubtest.Coverage{}
|
|
parserCoverage := []hubtest.Coverage{}
|
|
|
|
+ appsecRuleCoverage := []hubtest.Coverage{}
|
|
scenarioCoveragePercent := 0
|
|
scenarioCoveragePercent := 0
|
|
parserCoveragePercent := 0
|
|
parserCoveragePercent := 0
|
|
|
|
+ appsecRuleCoveragePercent := 0
|
|
|
|
|
|
// if both are false (flag by default), show both
|
|
// if both are false (flag by default), show both
|
|
- showAll := !showScenarioCov && !showParserCov
|
|
|
|
|
|
+ showAll := !showScenarioCov && !showParserCov && !showAppsecCov
|
|
|
|
|
|
if showParserCov || showAll {
|
|
if showParserCov || showAll {
|
|
parserCoverage, err = HubTest.GetParsersCoverage()
|
|
parserCoverage, err = HubTest.GetParsersCoverage()
|
|
@@ -467,13 +504,30 @@ func NewHubTestCoverageCmd() *cobra.Command {
|
|
scenarioCoveragePercent = int(math.Round((float64(scenarioTested) / float64(len(scenarioCoverage)) * 100)))
|
|
scenarioCoveragePercent = int(math.Round((float64(scenarioTested) / float64(len(scenarioCoverage)) * 100)))
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ if showAppsecCov || showAll {
|
|
|
|
+ appsecRuleCoverage, err = HubTest.GetAppsecCoverage()
|
|
|
|
+ if err != nil {
|
|
|
|
+ return fmt.Errorf("while getting scenario coverage: %s", err)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ appsecRuleTested := 0
|
|
|
|
+ for _, test := range appsecRuleCoverage {
|
|
|
|
+ if test.TestsCount > 0 {
|
|
|
|
+ appsecRuleTested++
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ appsecRuleCoveragePercent = int(math.Round((float64(appsecRuleTested) / float64(len(appsecRuleCoverage)) * 100)))
|
|
|
|
+ }
|
|
|
|
+
|
|
if showOnlyPercent {
|
|
if showOnlyPercent {
|
|
if showAll {
|
|
if showAll {
|
|
- fmt.Printf("parsers=%d%%\nscenarios=%d%%", parserCoveragePercent, scenarioCoveragePercent)
|
|
|
|
|
|
+ fmt.Printf("parsers=%d%%\nscenarios=%d%%\nappsec_rules=%d%%", parserCoveragePercent, scenarioCoveragePercent, appsecRuleCoveragePercent)
|
|
} else if showParserCov {
|
|
} else if showParserCov {
|
|
fmt.Printf("parsers=%d%%", parserCoveragePercent)
|
|
fmt.Printf("parsers=%d%%", parserCoveragePercent)
|
|
} else if showScenarioCov {
|
|
} else if showScenarioCov {
|
|
fmt.Printf("scenarios=%d%%", scenarioCoveragePercent)
|
|
fmt.Printf("scenarios=%d%%", scenarioCoveragePercent)
|
|
|
|
+ } else if showAppsecCov {
|
|
|
|
+ fmt.Printf("appsec_rules=%d%%", appsecRuleCoveragePercent)
|
|
}
|
|
}
|
|
os.Exit(0)
|
|
os.Exit(0)
|
|
}
|
|
}
|
|
@@ -487,6 +541,11 @@ func NewHubTestCoverageCmd() *cobra.Command {
|
|
if showScenarioCov || showAll {
|
|
if showScenarioCov || showAll {
|
|
hubTestScenarioCoverageTable(color.Output, scenarioCoverage)
|
|
hubTestScenarioCoverageTable(color.Output, scenarioCoverage)
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ if showAppsecCov || showAll {
|
|
|
|
+ hubTestAppsecRuleCoverageTable(color.Output, appsecRuleCoverage)
|
|
|
|
+ }
|
|
|
|
+
|
|
fmt.Println()
|
|
fmt.Println()
|
|
if showParserCov || showAll {
|
|
if showParserCov || showAll {
|
|
fmt.Printf("PARSERS : %d%% of coverage\n", parserCoveragePercent)
|
|
fmt.Printf("PARSERS : %d%% of coverage\n", parserCoveragePercent)
|
|
@@ -494,6 +553,9 @@ func NewHubTestCoverageCmd() *cobra.Command {
|
|
if showScenarioCov || showAll {
|
|
if showScenarioCov || showAll {
|
|
fmt.Printf("SCENARIOS : %d%% of coverage\n", scenarioCoveragePercent)
|
|
fmt.Printf("SCENARIOS : %d%% of coverage\n", scenarioCoveragePercent)
|
|
}
|
|
}
|
|
|
|
+ if showAppsecCov || showAll {
|
|
|
|
+ fmt.Printf("APPSEC RULES : %d%% of coverage\n", appsecRuleCoveragePercent)
|
|
|
|
+ }
|
|
case "json":
|
|
case "json":
|
|
dump, err := json.MarshalIndent(parserCoverage, "", " ")
|
|
dump, err := json.MarshalIndent(parserCoverage, "", " ")
|
|
if err != nil {
|
|
if err != nil {
|
|
@@ -505,6 +567,11 @@ func NewHubTestCoverageCmd() *cobra.Command {
|
|
return err
|
|
return err
|
|
}
|
|
}
|
|
fmt.Printf("%s", dump)
|
|
fmt.Printf("%s", dump)
|
|
|
|
+ dump, err = json.MarshalIndent(appsecRuleCoverage, "", " ")
|
|
|
|
+ if err != nil {
|
|
|
|
+ return err
|
|
|
|
+ }
|
|
|
|
+ fmt.Printf("%s", dump)
|
|
default:
|
|
default:
|
|
return fmt.Errorf("only human/json output modes are supported")
|
|
return fmt.Errorf("only human/json output modes are supported")
|
|
}
|
|
}
|
|
@@ -516,6 +583,7 @@ func NewHubTestCoverageCmd() *cobra.Command {
|
|
cmdHubTestCoverage.PersistentFlags().BoolVar(&showOnlyPercent, "percent", false, "Show only percentages of coverage")
|
|
cmdHubTestCoverage.PersistentFlags().BoolVar(&showOnlyPercent, "percent", false, "Show only percentages of coverage")
|
|
cmdHubTestCoverage.PersistentFlags().BoolVar(&showParserCov, "parsers", false, "Show only parsers coverage")
|
|
cmdHubTestCoverage.PersistentFlags().BoolVar(&showParserCov, "parsers", false, "Show only parsers coverage")
|
|
cmdHubTestCoverage.PersistentFlags().BoolVar(&showScenarioCov, "scenarios", false, "Show only scenarios coverage")
|
|
cmdHubTestCoverage.PersistentFlags().BoolVar(&showScenarioCov, "scenarios", false, "Show only scenarios coverage")
|
|
|
|
+ cmdHubTestCoverage.PersistentFlags().BoolVar(&showAppsecCov, "appsec", false, "Show only appsec coverage")
|
|
|
|
|
|
return cmdHubTestCoverage
|
|
return cmdHubTestCoverage
|
|
}
|
|
}
|
|
@@ -529,7 +597,7 @@ func NewHubTestEvalCmd() *cobra.Command {
|
|
DisableAutoGenTag: true,
|
|
DisableAutoGenTag: true,
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
for _, testName := range args {
|
|
for _, testName := range args {
|
|
- test, err := HubTest.LoadTestItem(testName)
|
|
|
|
|
|
+ test, err := hubPtr.LoadTestItem(testName)
|
|
if err != nil {
|
|
if err != nil {
|
|
return fmt.Errorf("can't load test: %+v", err)
|
|
return fmt.Errorf("can't load test: %+v", err)
|
|
}
|
|
}
|