Skip to content

Commit

Permalink
feat: ✅ Add integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
adrienyhuel committed Jan 8, 2025
1 parent 2014388 commit c43da2a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
21 changes: 21 additions & 0 deletions coraza_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,27 @@ func TestPostMultipart(t *testing.T) {
time.Sleep(1 * time.Second)
}

func TestClientIpRule(t *testing.T) {
tester, err := newTester("test.init.config", t)
if err != nil {
t.Fatal(err)
}

// client_ip will be 127.0.0.1
req, _ := http.NewRequest("GET", baseURL+"/", nil)
tester.AssertResponseCode(req, 200)

time.Sleep(1 * time.Second)

// client_ip will be 127.0.0.2
req, _ = http.NewRequest("GET", baseURL+"/", nil)
req.Header.Add("X-Forwarded-For", "127.0.0.2")
tester.AssertResponseCode(req, 403)

time.Sleep(1 * time.Second)

}

func multipartRequest(req *http.Request) error {
var b bytes.Buffer
w := multipart.NewWriter(&b)
Expand Down
4 changes: 4 additions & 0 deletions test.init.config
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
debug
auto_https off
order coraza_waf first
servers {
trusted_proxies static private_ranges
}
}

:8080 {
Expand All @@ -11,6 +14,7 @@
SecAction "id:149,pass,log, msg:'Some test msg',logdata:'logdata'"
SecRule REQUEST_URI "test5" "id:2, deny, log, phase:1,status:403"
SecRule REQUEST_URI "test6" "id:4, deny, log, phase:3,status:403"
SecRule REMOTE_ADDR "@ipMatch 127.0.0.2" "id:5, deny, log, phase:1,status:403"
Include testdata/sample1.conf
Include testdata/sample2.conf
`
Expand Down

0 comments on commit c43da2a

Please sign in to comment.