MCPcopy Index your code
hub / github.com/VictoriaMetrics/VictoriaLogs / TestGetQuotedRemoteAddr

Function TestGetQuotedRemoteAddr

lib/httpserver/httpserver_test.go:13–40  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

11)
12
13func TestGetQuotedRemoteAddr(t *testing.T) {
14 f := func(remoteAddr, xForwardedFor, expectedAddr string) {
15 t.Helper()
16
17 req := &http.Request{
18 RemoteAddr: remoteAddr,
19 }
20 if xForwardedFor != "" {
21 req.Header = map[string][]string{
22 "X-Forwarded-For": {xForwardedFor},
23 }
24 }
25 addr := GetQuotedRemoteAddr(req)
26 if addr != expectedAddr {
27 t.Fatalf("unexpected remote addr;\ngot\n%s\nwant\n%s", addr, expectedAddr)
28 }
29
30 // Verify that the addr can be unmarshaled as JSON string
31 var s string
32 if err := json.Unmarshal([]byte(addr), &s); err != nil {
33 t.Fatalf("cannot unmarshal addr: %s", err)
34 }
35 }
36
37 f("1.2.3.4", "", `"1.2.3.4"`)
38 f("1.2.3.4", "foo.bar", `"1.2.3.4, X-Forwarded-For: foo.bar"`)
39 f("1.2\n\"3.4", "foo\nb\"ar", `"1.2\n\"3.4, X-Forwarded-For: foo\nb\"ar"`)
40}
41
42func TestBasicAuthMetrics(t *testing.T) {
43 origUsername := *httpAuthUsername

Callers

nothing calls this directly

Calls 3

GetQuotedRemoteAddrFunction · 0.85
UnmarshalMethod · 0.65
fFunction · 0.50

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…