From 2d01e4680f740d74f9629f602a4accdd79f03468 Mon Sep 17 00:00:00 2001 From: bui Date: Mon, 20 Nov 2023 14:25:33 +0100 Subject: [PATCH] do not error if no waap rules are present --- pkg/hubtest/hubtest_item.go | 8 ++++++-- pkg/waf/loader.go | 3 +-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/pkg/hubtest/hubtest_item.go b/pkg/hubtest/hubtest_item.go index 65c95a2bc..b1a6c30ad 100644 --- a/pkg/hubtest/hubtest_item.go +++ b/pkg/hubtest/hubtest_item.go @@ -827,8 +827,8 @@ func (t *HubTestItem) Run() error { return fmt.Errorf("unable to create folder '%s': %+v", t.RuntimePath, err) } - // copy the waap-config file and acquis *only* if nuclei template is set -> it means we're testing waap - if t.Config.NucleiTemplate != "" { + //if it's a waap rule test, we need acquis and waap profile + if len(t.Config.WaapRules) > 0 { // copy template acquis file to runtime folder log.Infof("copying %s to %s", t.TemplateAcquisPath, t.RuntimeAcquisFilePath) if err = Copy(t.TemplateAcquisPath, t.RuntimeAcquisFilePath); err != nil { @@ -840,6 +840,10 @@ func (t *HubTestItem) Run() error { if err = Copy(t.TemplateWaapProfilePath, filepath.Join(t.RuntimePath, "waap-configs", "config.yaml")); err != nil { return fmt.Errorf("unable to copy '%s' to '%s': %v", t.TemplateWaapProfilePath, filepath.Join(t.RuntimePath, "waap-configs", "config.yaml"), err) } + } else { //otherwise we drop a blank acquis file + if err = os.WriteFile(t.RuntimeAcquisFilePath, []byte(""), os.ModePerm); err != nil { + return fmt.Errorf("unable to write blank acquis file '%s': %s", t.RuntimeAcquisFilePath, err) + } } // install the hub in the runtime folder diff --git a/pkg/waf/loader.go b/pkg/waf/loader.go index ffddea121..43c56411c 100644 --- a/pkg/waf/loader.go +++ b/pkg/waf/loader.go @@ -1,7 +1,6 @@ package waf import ( - "fmt" "os" "github.com/crowdsecurity/crowdsec/pkg/cwhub" @@ -53,7 +52,7 @@ func LoadWaapRules(hubInstance *cwhub.Hub) error { } if len(waapRules) == 0 { - return fmt.Errorf("no waap rules found in hub") + log.Debugf("No waap rules found") } return nil }