forked from corazawaf/coraza
-
Notifications
You must be signed in to change notification settings - Fork 0
/
e2e_test.go
52 lines (40 loc) · 1.05 KB
/
e2e_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// Copyright 2023 Juan Pablo Tosso and the OWASP Coraza contributors
// SPDX-License-Identifier: Apache-2.0
// These benchmarks don't currently compile with TinyGo
//go:build !tinygo
// +build !tinygo
package e2e_test
import (
_ "embed"
"net/http"
"net/http/httptest"
"testing"
"github.com/mccutchen/go-httpbin/v2/httpbin"
"github.com/corazawaf/coraza/v3"
txhttp "github.com/corazawaf/coraza/v3/http"
"github.com/corazawaf/coraza/v3/http/e2e"
)
func TestE2e(t *testing.T) {
conf := coraza.NewWAFConfig()
conf = conf.
WithDirectives(e2e.Directives)
waf, err := coraza.NewWAF(conf)
if err != nil {
t.Fatal(err)
}
httpbin := httpbin.New()
mux := http.NewServeMux()
mux.Handle("/status/200", httpbin) // Health check
mux.Handle("/", txhttp.WrapHandler(waf, httpbin))
// Create the server with the WAF and the reverse proxy.
s := httptest.NewServer(mux)
defer s.Close()
err = e2e.Run(e2e.Config{
NulledBody: false,
ProxiedEntrypoint: s.URL,
HttpbinEntrypoint: s.URL,
})
if err != nil {
t.Fatalf("e2e tests failed: %v", err)
}
}