(t *testing.T)
| 332 | } |
| 333 | |
| 334 | func 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 | |
| 365 | func TestMultipleIpAddressesProxy(t *testing.T) { |
| 366 | mockServer := createMockAPIServer(t, map[string][]byte{caExampleIP: []byte(`CA`)}) |
nothing calls this directly
no test coverage detected