-
Notifications
You must be signed in to change notification settings - Fork 0
/
banjax_performance_test.go
65 lines (58 loc) · 1.73 KB
/
banjax_performance_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
53
54
55
56
57
58
59
60
61
62
63
64
65
//go:build performance
package main
import (
"net/http"
"os"
"testing"
)
func TestMain(m *testing.M) {
setUp()
exit_code := m.Run()
tearDown()
os.Exit(exit_code)
}
func BenchmarkAuthRequest(b *testing.B) {
var resp *http.Response
client := http.Client{}
for i := 0; i < b.N; i++ {
resp = httpRequest(
&client,
TestResource{"GET", "/auth_request", 0, randomXClientIP(), nil},
)
if resp != nil && resp.Body != nil {
resp.Body.Close()
}
}
}
func BenchmarkProtectedPaths(b *testing.B) {
var resp *http.Response
client := http.Client{}
prefix := "/auth_request?path="
protected_paths := []TestResource{
// protected resources
{"GET", prefix + "wp-admin", 0, randomXClientIP(), nil},
{"GET", prefix + "/wp-admin", 0, randomXClientIP(), nil},
{"GET", prefix + "/wp-admin//", 0, randomXClientIP(), nil},
{"GET", prefix + "wp-admin/admin.php", 0, randomXClientIP(), nil},
{"GET", prefix + "wp-admin/admin.php#test", 0, randomXClientIP(), nil},
{"GET", prefix + "wp-admin/admin.php?a=1&b=2", 0, randomXClientIP(), nil},
// exceptions
{"GET", prefix + "wp-admin/admin-ajax.php", 0, randomXClientIP(), nil},
{"GET", prefix + "/wp-admin/admin-ajax.php", 0, randomXClientIP(), nil},
{"GET", prefix + "/wp-admin/admin-ajax.php?a=1", 0, randomXClientIP(), nil},
{"GET", prefix + "/wp-admin/admin-ajax.php?a=1&b=2", 0, randomXClientIP(), nil},
{"GET", prefix + "/wp-admin/admin-ajax.php#test", 0, randomXClientIP(), nil},
{"GET", prefix + "wp-admin/admin-ajax.php/", 0, randomXClientIP(), nil},
}
for i := 0; i < b.N; i++ {
for _, protected_resource := range protected_paths {
resp = httpRequest(
&client,
protected_resource,
)
if resp != nil && resp.Body != nil {
resp.Body.Close()
}
}
}
}