roam_events_test.go 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. // roam_events_test.go — filtro ?mac de GET /api/roam-events.
  2. package httpapi_test
  3. import (
  4. "net/http"
  5. "testing"
  6. )
  7. // TestRoamEventsNormalizesMAC: ?mac acepta guiones/minúsculas (también en
  8. // lista separada por comas) y rechaza valores que no son una MAC.
  9. func TestRoamEventsNormalizesMAC(t *testing.T) {
  10. srv := makeTestServer(t)
  11. if _, err := srv.db.Exec(
  12. "INSERT INTO roam_events (ts_ms, router_id, type, mac, iface, detail, content_hash) VALUES (?,?,?,?,?,?,?)",
  13. 1000, "rt1", "assoc", "AA:BB:CC:DD:EE:01", "phy0-ap0", "", "h1",
  14. ); err != nil {
  15. t.Fatalf("seed: %v", err)
  16. }
  17. _, cookie, _ := loginCookie(t, srv.URL, "admin", "test123456")
  18. for _, q := range []string{
  19. "aa-bb-cc-dd-ee-01",
  20. "aa:bb:cc:dd:ee:01",
  21. "aa-bb-cc-dd-ee-01,11:22:33:44:55:66",
  22. } {
  23. res := get(t, srv.URL, "/api/roam-events?mac="+q, cookie)
  24. if res.StatusCode != http.StatusOK {
  25. t.Fatalf("mac=%s: got %d want 200", q, res.StatusCode)
  26. }
  27. events, _ := readJSON(t, res)["events"].([]any)
  28. if len(events) != 1 {
  29. t.Fatalf("mac=%s: esperaba 1 evento, obtuve %v", q, events)
  30. }
  31. }
  32. res := get(t, srv.URL, "/api/roam-events?mac=nope", cookie)
  33. if res.StatusCode != http.StatusBadRequest {
  34. t.Fatalf("mac inválida: got %d want 400", res.StatusCode)
  35. }
  36. }