diff --git a/internal/seclang/parser.go b/internal/seclang/parser.go index 2532d9eaf..8a34d21c4 100644 --- a/internal/seclang/parser.go +++ b/internal/seclang/parser.go @@ -34,7 +34,8 @@ type Parser struct { // It will return error if any directive fails to parse // or the file does not exist. // If the path contains a *, it will be expanded to all -// files in the directory matching the pattern +// files in the directory matching the pattern. +// It will rereturn an error if there are no files matching the pattern. func (p *Parser) FromFile(profilePath string) error { originalDir := p.currentDir @@ -45,6 +46,9 @@ func (p *Parser) FromFile(profilePath string) error { if err != nil { return fmt.Errorf("failed to glob: %s", err.Error()) } + if len(files) == 0 { + return fmt.Errorf("empty glob: %s does not match any file", profilePath) + } } else { files = append(files, profilePath) } diff --git a/internal/seclang/parser_test.go b/internal/seclang/parser_test.go index d2a0c5fe0..21514f2ac 100644 --- a/internal/seclang/parser_test.go +++ b/internal/seclang/parser_test.go @@ -102,6 +102,11 @@ func TestLoadConfigurationFile(t *testing.T) { if err != nil { t.Errorf("unexpected error: %s", err.Error()) } + + err = p.FromFile("./testdata/glob/*.comf") + if err == nil { + t.Errorf("expected an error as glob does not match any file") + } } // Connectors are supporting embedding github.com/corazawaf/coraza-coreruleset to ease CRS integration