Skip to content

Commit b9dcc61

Browse files
author
vcarvajal
committed
Adding TestNewRPCMsgInWithModuleConfigFromRequest to module_test
1 parent 80d3632 commit b9dcc61

File tree

1 file changed

+69
-0
lines changed

1 file changed

+69
-0
lines changed

module_test.go

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,75 @@ import (
1515
"time"
1616
)
1717

18+
func TestNewRPCMsgInWithModuleConfigFromRequest(t *testing.T) {
19+
20+
c, err := NewModuleConfig(
21+
AllowUnknownContentLength(true),
22+
ServerFlavor("SugarAndSpice"),
23+
AltResponseCodes(403),
24+
AnomalyDuration(10*time.Second),
25+
AnomalySize(8192),
26+
CustomInspector(&RPCInspector{}, func(_ *http.Request) bool { return true }, func(_ *http.Request) {}),
27+
CustomHeaderExtractor(func(_ *http.Request) (http.Header, error) { return nil, nil }),
28+
Debug(true),
29+
MaxContentLength(500000),
30+
Socket("tcp", "0.0.0.0:1234"),
31+
Timeout(10*time.Millisecond),
32+
)
33+
if err != nil {
34+
t.Fatalf("Failed to create module config: %s", err)
35+
}
36+
37+
b := bytes.Buffer{}
38+
b.WriteString("test")
39+
r, err := http.NewRequest("GET", "http://localhost/", &b)
40+
if err != nil {
41+
t.Fatal(err)
42+
}
43+
r.RemoteAddr = "127.0.0.1"
44+
r.Header.Add("If-None-Match", `W/"wyzzy"`)
45+
r.RequestURI = "http://localhost/"
46+
r.TLS = &tls.ConnectionState{}
47+
48+
want := RPCMsgIn{
49+
ServerName: "localhost",
50+
ServerFlavor: "SugarAndSpice",
51+
Method: "GET",
52+
Scheme: "https",
53+
URI: "http://localhost/",
54+
Protocol: "HTTP/1.1",
55+
RemoteAddr: "127.0.0.1",
56+
HeadersIn: [][2]string{{"Host", "localhost"}, {"If-None-Match", `W/"wyzzy"`}},
57+
}
58+
eq := func(got, want RPCMsgIn) (ne string, equal bool) {
59+
switch {
60+
case got.ServerName != want.ServerName:
61+
return "ServerHostname", false
62+
case got.Method != want.Method:
63+
return "Method", false
64+
case got.Scheme != want.Scheme:
65+
return "Scheme", false
66+
case got.URI != want.URI:
67+
return "URI", false
68+
case got.Protocol != want.Protocol:
69+
return "Protocol", false
70+
case got.RemoteAddr != want.RemoteAddr:
71+
return "RemoteAddr", false
72+
case !reflect.DeepEqual(got.HeadersIn, want.HeadersIn):
73+
return "HeadersIn", false
74+
case got.ServerFlavor != want.ServerFlavor:
75+
return "ServerFlavor", false
76+
default:
77+
return "", true
78+
}
79+
}
80+
81+
got := NewRPCMsgInWithModuleConfig(c, r, nil)
82+
if ne, equal := eq(*got, want); !equal {
83+
t.Errorf("NewRPCMsgInWithModuleConfig: incorrect %q", ne)
84+
}
85+
}
86+
1887
func TestNewRPCMsgFromRequest(t *testing.T) {
1988
b := bytes.Buffer{}
2089
b.WriteString("test")

0 commit comments

Comments
 (0)