File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -86,6 +86,42 @@ func TestAddRulesToWaf(t *testing.T) {
8686 }
8787}
8888
89+ func TestAddRulesFromFileToWaf (t * testing.T ) {
90+ tests := []struct {
91+ name string
92+ file string
93+ canCreateWaf bool
94+ }{
95+ {
96+ name : "test.conf" ,
97+ file : "testdata/test.conf" ,
98+ canCreateWaf : true ,
99+ },
100+ {
101+ name : "nonexistent.conf" ,
102+ file : "testdata/nonexistent.conf" ,
103+ canCreateWaf : false ,
104+ },
105+ }
106+ for _ , test := range tests {
107+ t .Run (test .name , func (t * testing.T ) {
108+ config := coraza_new_waf_config ()
109+ rv := coraza_rules_add_file (config , stringToC (test .file ))
110+ if rv != 0 {
111+ t .Fatalf ("Rules addition failed: %d" , rv )
112+ }
113+
114+ er := stringToC ("" )
115+ waf := coraza_new_waf (config , & er )
116+ if test .canCreateWaf && (waf == 0 || stringFromC (er ) != "" ) {
117+ t .Fatalf ("Waf creation failed: %d" , waf )
118+ } else if ! test .canCreateWaf && (waf != 0 || stringFromC (er ) == "" ) {
119+ t .Fatalf ("Waf creation should have failed: %d" , waf )
120+ }
121+ })
122+ }
123+ }
124+
89125func TestCoraza_add_get_args (t * testing.T ) {
90126 config := coraza_new_waf_config ()
91127 waf := coraza_new_waf (config , nil )
You can’t perform that action at this time.
0 commit comments