@@ -13,6 +13,11 @@ import (
1313 "github.com/corazawaf/coraza/v3/types"
1414)
1515
16+ // wafWithRules mirrors experimental.WAFWithRules for testing without import cycle.
17+ type wafWithRules interface {
18+ RulesCount () int
19+ }
20+
1621func TestRequestBodyLimit (t * testing.T ) {
1722 testCases := map [string ]struct {
1823 expectedErr error
@@ -178,3 +183,33 @@ func TestPopulateAuditLog(t *testing.T) {
178183 })
179184 }
180185}
186+
187+ func TestRulesCount (t * testing.T ) {
188+ waf , err := NewWAF (NewWAFConfig ())
189+ if err != nil {
190+ t .Fatal (err )
191+ }
192+
193+ rules , ok := waf .(wafWithRules )
194+ if ! ok {
195+ t .Fatal ("WAF does not implement WAFWithRules" )
196+ }
197+ if rules .RulesCount () != 0 {
198+ t .Fatalf ("expected 0 rules, got %d" , rules .RulesCount ())
199+ }
200+
201+ waf , err = NewWAF (NewWAFConfig ().
202+ WithDirectives (`SecRule REMOTE_ADDR "127.0.0.1" "id:1,phase:1,deny,status:403"` ).
203+ WithDirectives (`SecRule REQUEST_URI "/test" "id:2,phase:1,deny,status:403"` ))
204+ if err != nil {
205+ t .Fatal (err )
206+ }
207+
208+ rules , ok = waf .(wafWithRules )
209+ if ! ok {
210+ t .Fatal ("WAF does not implement WAFWithRules" )
211+ }
212+ if rules .RulesCount () != 2 {
213+ t .Fatalf ("expected 2 rules, got %d" , rules .RulesCount ())
214+ }
215+ }
0 commit comments