Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix CRS 4.0.0 rc2 adding a cleanup phase #9

Merged
merged 3 commits into from
Nov 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion example/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package main
import (
"fmt"

"github.com/corazawaf/coraza-coreruleset"
coreruleset "github.com/corazawaf/coraza-coreruleset"
"github.com/corazawaf/coraza/v3"
)
Expand Down
34 changes: 32 additions & 2 deletions magefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,18 @@ import (
func DownloadCRS() error {
rulesDir := "rules"
rulesDstDir := rulesDir + "/@owasp_crs"
if err := os.MkdirAll(rulesDstDir, os.ModePerm); err != nil {
testsDir := "tests"

// Before downloading, we need to remove:
// - old rules under rules/@owasp_crs
// - all the related tests
if err := cleanupOldCRS(rulesDstDir, testsDir); err != nil {
return err
}

testsDir := "tests"
if err := os.MkdirAll(rulesDstDir, os.ModePerm); err != nil {
return err
}

uri := fmt.Sprintf("https://github.com/coreruleset/coreruleset/archive/%s.zip", crsVersion)

Expand Down Expand Up @@ -158,6 +165,29 @@ func copyFile(f *zip.File, dstPath string) error {
return nil
}

func cleanupOldCRS(rulesDstDir, testsDir string) error {
if err := os.RemoveAll(rulesDstDir); err != nil {
return err
}
if err := filepath.WalkDir(testsDir, func(path string, d os.DirEntry, err error) error {
if err != nil {
return err
}

// tests folder contains go files related to the coraza-coreruleset repo that we don't want to remove
if d.Name() != "tests.go" && d.Name() != "tests_test.go" && path != testsDir {
if err := os.RemoveAll(path); err != nil {
return err
}
return filepath.SkipDir
}
return nil
}); err != nil {
return err
}
return nil
}

func Test() error {
return sh.RunV("go", "test", "./...")
}
34 changes: 0 additions & 34 deletions rules/@owasp_crs/crawlers-user-agents.data

This file was deleted.

8 changes: 0 additions & 8 deletions rules/@owasp_crs/scanners-headers.data

This file was deleted.

17 changes: 0 additions & 17 deletions rules/@owasp_crs/scanners-urls.data

This file was deleted.

27 changes: 0 additions & 27 deletions rules/@owasp_crs/scripting-user-agents.data

This file was deleted.

39 changes: 0 additions & 39 deletions tests/REQUEST-913-SCANNER-DETECTION/913101.yaml

This file was deleted.

23 changes: 0 additions & 23 deletions tests/REQUEST-913-SCANNER-DETECTION/913102.yaml

This file was deleted.

44 changes: 0 additions & 44 deletions tests/REQUEST-913-SCANNER-DETECTION/913110.yaml

This file was deleted.

57 changes: 0 additions & 57 deletions tests/REQUEST-913-SCANNER-DETECTION/913120.yaml

This file was deleted.

Loading