MCPcopy
hub / github.com/hashicorp/memberlist / Test_IsValidAddressOverride

Function Test_IsValidAddressOverride

config_test.go:37–95  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

35}
36
37func Test_IsValidAddressOverride(t *testing.T) {
38 t.Parallel()
39 cases := []struct {
40 name string
41 allow []string
42 success []string
43 fail []string
44 }{
45 {
46 name: "Default, nil allows all",
47 allow: nil,
48 success: []string{"127.0.0.5", "10.0.0.9", "192.168.1.7", "::1"},
49 fail: []string{},
50 },
51 {
52 name: "Only IPv4",
53 allow: []string{"0.0.0.0/0"},
54 success: []string{"127.0.0.5", "10.0.0.9", "192.168.1.7"},
55 fail: []string{"fe80::38bc:4dff:fe62:b1ae", "::1"},
56 },
57 {
58 name: "Only IPv6",
59 allow: []string{"::0/0"},
60 success: []string{"fe80::38bc:4dff:fe62:b1ae", "::1"},
61 fail: []string{"127.0.0.5", "10.0.0.9", "192.168.1.7"},
62 },
63 {
64 name: "Only 127.0.0.0/8 and ::1",
65 allow: []string{"::1/128", "127.0.0.0/8"},
66 success: []string{"127.0.0.5", "::1"},
67 fail: []string{"::2", "178.250.0.187", "10.0.0.9", "192.168.1.7", "fe80::38bc:4dff:fe62:b1ae"},
68 },
69 }
70
71 for _, testCase := range cases {
72 t.Run(testCase.name, func(t *testing.T) {
73 config := DefaultLANConfig()
74 var err error
75 config.CIDRsAllowed, err = ParseCIDRs(testCase.allow)
76 if err != nil {
77 t.Fatalf("failed parsing %s", testCase.allow)
78 }
79 for _, ips := range testCase.success {
80 ip := net.ParseIP(ips)
81 if err := config.IPAllowed(ip); err != nil {
82 t.Fatalf("Test case with %s should pass", ip)
83 }
84 }
85 for _, ips := range testCase.fail {
86 ip := net.ParseIP(ips)
87 if err := config.IPAllowed(ip); err == nil {
88 t.Fatalf("Test case with %s should fail", ip)
89 }
90 }
91 })
92
93 }
94

Callers

nothing calls this directly

Calls 4

DefaultLANConfigFunction · 0.85
ParseCIDRsFunction · 0.85
FatalfMethod · 0.80
IPAllowedMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…