MCPcopy Create free account
hub / github.com/foxcpp/maddy / TestCheckIP

Function TestCheckIP

internal/check/dnsbl/common_test.go:119–238  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

117}
118
119func TestCheckIP(t *testing.T) {
120 test := func(zones map[string]mockdns.Zone, cfg List, ip net.IP, expectedErr error) {
121 t.Helper()
122 resolver := mockdns.Resolver{Zones: zones}
123 err := checkIP(context.Background(), &resolver, cfg, ip)
124 if !reflect.DeepEqual(err, expectedErr) {
125 t.Errorf("expected err to be '%#v', got '%#v'", expectedErr, err)
126 }
127 }
128
129 test(nil, List{Zone: "example.org"}, net.IPv4(1, 2, 3, 4), nil)
130 test(nil, List{Zone: "example.org", ClientIPv4: true}, net.IPv4(1, 2, 3, 4), nil)
131 test(map[string]mockdns.Zone{
132 "4.3.2.1.example.org.": {
133 A: []string{"127.0.0.1"},
134 },
135 }, List{Zone: "example.org", ClientIPv4: true}, net.IPv4(1, 2, 3, 4), ListedErr{
136 Identity: "1.2.3.4",
137 List: "example.org",
138 Reason: "127.0.0.1",
139 })
140 test(map[string]mockdns.Zone{
141 "4.3.2.1.example.org.": {
142 A: []string{"128.0.0.1"},
143 },
144 }, List{
145 Zone: "example.org",
146 ClientIPv4: true,
147 Responses: []net.IPNet{
148 {
149 IP: net.IPv4(127, 0, 0, 1),
150 Mask: net.IPv4Mask(255, 255, 255, 0),
151 },
152 },
153 }, net.IPv4(1, 2, 3, 4), nil)
154 test(map[string]mockdns.Zone{
155 "4.3.2.1.example.org.": {
156 A: []string{"128.0.0.1"},
157 },
158 }, List{
159 Zone: "example.org",
160 ClientIPv4: true,
161 Responses: []net.IPNet{
162 {
163 IP: net.IPv4(127, 0, 0, 0),
164 Mask: net.IPv4Mask(255, 255, 255, 0),
165 },
166 {
167 IP: net.IPv4(128, 0, 0, 0),
168 Mask: net.IPv4Mask(255, 255, 255, 0),
169 },
170 },
171 }, net.IPv4(1, 2, 3, 4), ListedErr{
172 Identity: "1.2.3.4",
173 List: "example.org",
174 Reason: "128.0.0.1",
175 })
176 test(map[string]mockdns.Zone{

Callers

nothing calls this directly

Calls 2

checkIPFunction · 0.85
testStruct · 0.85

Tested by

no test coverage detected