Skip to content

Commit 29ebea0

Browse files
committed
test add_rules_from_file
Signed-off-by: William Zhang <wtzhang23@gmail.com>
1 parent e6d5abd commit 29ebea0

1 file changed

Lines changed: 36 additions & 0 deletions

File tree

libcoraza/coraza_test.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff 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+
89125
func TestCoraza_add_get_args(t *testing.T) {
90126
config := coraza_new_waf_config()
91127
waf := coraza_new_waf(config, nil)

0 commit comments

Comments
 (0)