MCPcopy Index your code
hub / github.com/coder/coder / TestExtractAddress

Function TestExtractAddress

coderd/httpmw/realip_test.go:19–223  ·  view source on GitHub ↗

TestExtractAddress checks the ExtractAddress function.

(t *testing.T)

Source from the content-addressed store, hash-verified

17
18// TestExtractAddress checks the ExtractAddress function.
19func TestExtractAddress(t *testing.T) {
20 t.Parallel()
21
22 tests := []struct {
23 Name string
24 Config *httpmw.RealIPConfig
25 Header http.Header
26 RemoteAddr string
27 TLS bool
28 ExpectedRemoteAddr string
29 ExpectedTLS bool
30 }{
31 {
32 Name: "default-nil-config",
33 RemoteAddr: "123.45.67.89",
34 ExpectedRemoteAddr: "123.45.67.89",
35 },
36 {
37 Name: "default-empty-config",
38 RemoteAddr: "123.45.67.89",
39 ExpectedRemoteAddr: "123.45.67.89",
40 Config: &httpmw.RealIPConfig{},
41 },
42 {
43 Name: "default-filter-headers",
44 Config: &httpmw.RealIPConfig{
45 TrustedOrigins: []*net.IPNet{
46 {
47 IP: net.ParseIP("10.0.0.0"),
48 Mask: net.CIDRMask(8, 32),
49 },
50 },
51 },
52 RemoteAddr: "123.45.67.89",
53 Header: http.Header{
54 "X-Forwarded-For": []string{
55 "127.0.0.1",
56 "10.0.0.5",
57 "10.0.0.5,4.4.4.4",
58 },
59 },
60 ExpectedRemoteAddr: "123.45.67.89",
61 },
62 {
63 Name: "multiple-x-forwarded-for",
64 Config: &httpmw.RealIPConfig{
65 TrustedOrigins: []*net.IPNet{
66 {
67 IP: net.ParseIP("0.0.0.0"),
68 Mask: net.CIDRMask(0, 32),
69 },
70 },
71 TrustedHeaders: []string{
72 "X-Forwarded-For",
73 },
74 },
75 RemoteAddr: "123.45.67.89",
76 Header: http.Header{

Callers

nothing calls this directly

Calls 4

ExtractRealIPAddressFunction · 0.92
RunMethod · 0.65
EqualMethod · 0.45
StringMethod · 0.45

Tested by

no test coverage detected