MCPcopy Create free account
hub / github.com/PascalMinder/geoblock / TestMultipleIpAddressesReverse

Function TestMultipleIpAddressesReverse

geoblock_test.go:334–363  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

332}
333
334func TestMultipleIpAddressesReverse(t *testing.T) {
335 mockServer := createMockAPIServer(t, map[string][]byte{caExampleIP: []byte(`CA`), chExampleIP: []byte(`CH`)})
336 defer mockServer.Close()
337
338 cfg := createTesterConfig()
339
340 cfg.Countries = append(cfg.Countries, "CH")
341 cfg.API = mockServer.URL + "/{ip}"
342
343 ctx := context.Background()
344 next := http.HandlerFunc(func(_ http.ResponseWriter, _ *http.Request) {})
345
346 handler, err := geoblock.New(ctx, next, cfg, "GeoBlock")
347 if err != nil {
348 t.Fatal(err)
349 }
350
351 recorder := httptest.NewRecorder()
352
353 req, err := http.NewRequestWithContext(ctx, http.MethodGet, "http://localhost", nil)
354 if err != nil {
355 t.Fatal(err)
356 }
357
358 req.Header.Add(xForwardedFor, strings.Join([]string{caExampleIP, chExampleIP}, ","))
359
360 handler.ServeHTTP(recorder, req)
361
362 assertStatusCode(t, recorder.Result(), http.StatusForbidden)
363}
364
365func TestMultipleIpAddressesProxy(t *testing.T) {
366 mockServer := createMockAPIServer(t, map[string][]byte{caExampleIP: []byte(`CA`)})

Callers

nothing calls this directly

Calls 6

NewFunction · 0.92
createMockAPIServerFunction · 0.85
createTesterConfigFunction · 0.85
assertStatusCodeFunction · 0.85
AddMethod · 0.65
ServeHTTPMethod · 0.45

Tested by

no test coverage detected