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

Function TestCheckIPWithResponseRules

internal/check/dnsbl/dnsbl_test.go:215–374  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

213}
214
215func TestCheckIPWithResponseRules(t *testing.T) {
216 test := func(zones map[string]mockdns.Zone, cfg List, ip net.IP, expectedErr error) {
217 t.Helper()
218 resolver := mockdns.Resolver{Zones: zones}
219 err := checkIP(context.Background(), &resolver, cfg, ip)
220 if expectedErr == nil {
221 if err != nil {
222 t.Errorf("expected no error, got '%#v'", err)
223 }
224 } else {
225 if err == nil {
226 t.Errorf("expected err to be '%#v', got nil", expectedErr)
227 } else {
228 expectedLE, okExpected := expectedErr.(ListedErr)
229 actualLE, okActual := err.(ListedErr)
230 if !okExpected || !okActual {
231 t.Errorf("expected err to be '%#v', got '%#v'", expectedErr, err)
232 } else {
233 if expectedLE.Identity != actualLE.Identity ||
234 expectedLE.List != actualLE.List ||
235 expectedLE.Score != actualLE.Score ||
236 expectedLE.Message != actualLE.Message {
237 t.Errorf("expected err to be '%#v', got '%#v'", expectedErr, err)
238 }
239 }
240 }
241 }
242 }
243
244 // Test single response code with score and message
245 test(map[string]mockdns.Zone{
246 "4.3.2.1.example.org.": {
247 A: []string{"127.0.0.2"},
248 },
249 }, List{
250 Zone: "example.org",
251 ClientIPv4: true,
252 ResponseRules: []ResponseRule{
253 {
254 Networks: []net.IPNet{
255 {IP: net.IPv4(127, 0, 0, 2), Mask: net.IPv4Mask(255, 255, 255, 255)},
256 },
257 Score: 10,
258 Message: "Listed in SBL",
259 },
260 },
261 }, net.IPv4(1, 2, 3, 4), ListedErr{
262 Identity: "1.2.3.4",
263 List: "example.org",
264 Score: 10,
265 Message: "Listed in SBL",
266 })
267
268 // Test multiple response codes with different scores - scores should sum
269 test(map[string]mockdns.Zone{
270 "4.3.2.1.example.org.": {
271 A: []string{"127.0.0.2", "127.0.0.11"},
272 },

Callers

nothing calls this directly

Calls 2

checkIPFunction · 0.85
testStruct · 0.85

Tested by

no test coverage detected