MCPcopy
hub / github.com/go-chi/chi / TestInvalidIP

Function TestInvalidIP

middleware/realip_test.go:93–115  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

91}
92
93func TestInvalidIP(t *testing.T) {
94 req, _ := http.NewRequest("GET", "/", nil)
95 req.Header.Add("X-Real-IP", "100.100.100.1000")
96 w := httptest.NewRecorder()
97
98 r := chi.NewRouter()
99 r.Use(RealIP)
100
101 realIP := ""
102 r.Get("/", func(w http.ResponseWriter, r *http.Request) {
103 realIP = r.RemoteAddr
104 w.Write([]byte("Hello World"))
105 })
106 r.ServeHTTP(w, req)
107
108 if w.Code != 200 {
109 t.Fatal("Response Code should be 200")
110 }
111
112 if realIP != "" {
113 t.Fatal("Invalid IP used.")
114 }
115}

Callers

nothing calls this directly

Calls 5

UseMethod · 0.95
GetMethod · 0.95
AddMethod · 0.80
WriteMethod · 0.65
ServeHTTPMethod · 0.45

Tested by

no test coverage detected