Files
MrAlders0n 03f66d1ae4 Database pools by workload, plan router, observe-only guards, metrics (rest of #237) (#238)
* feat(db): five pgx pools with fixed session settings and Prometheus tracing

* feat(guards): per-family observe/enforce guards with client slots, deadlines and a shadow budget

* fix(guards): attribute only guard deadlines and classify like the handlers

* feat(db): route API statements by sqlc name; class C always unnamed

* feat(admin): statement statistics by sqlc name; create pg_stat_statements where allowed

* fix(db): skip pg_stat_statements when no schema is creatable

* feat(background): index health against post-rebuild baselines, Postgres activity, job and ingest metrics

* feat: separate API, ingest and maintenance stores; guards on the public API; metrics listener

* fix(db): keep ingest writes waiting, size the ingest pool to the host, tidy

* test(db): give the statements probe a query id of its own
2026-10-19 07:52:51 -04:00

47 lines
1.6 KiB
Go

// Copyright 2026 Beacon Contributors
// SPDX-License-Identifier: AGPL-3.0-or-later
package handlers
import (
"net/http/httptest"
"testing"
"github.com/MeshCore-Beacon/beacon-server/internal/guards"
)
// TestGuardsClassifyReadsQueryLikeHandlers pins the guard classifier to the way
// the packet and directory handlers read since/until and the region filters,
// including repeated and blank values.
func TestGuardsClassifyReadsQueryLikeHandlers(t *testing.T) {
for _, raw := range []string{
"", "since=1", "since=", "since=&since=1", "since=1&since=", "until=2", "until=&until=2",
"iata=YOW", "iata=", "iata=&iata=YOW", "iata=%20", "iatas=,", "iatas=,%20,", "iatas=YVR,", "iatas=&iatas=YVR",
"iatas=,&iata=YOW", "iatas=&iata=YOW", "region=bc", "region=&region=bc", "regionId=3", "regionId=&regionId=3",
"hashPrefix=ab", "iatas=YVR&since=1",
} {
r := httptest.NewRequest("GET", "/api/v1/packets?"+raw, nil)
q := r.URL.Query()
region := len(parseIATAs(r)) > 0 || q.Get("regionId") != "" || q.Get("region") != ""
want := guards.PacketsGlobal
switch {
case q.Get("since") != "" || q.Get("until") != "":
want = guards.PacketsWindow
case region:
want = guards.PacketsRegion
}
if f, _ := guards.Classify(r); f != want {
t.Errorf("packets?%s: Classify = %s, want %s", raw, f, want)
}
d := httptest.NewRequest("GET", "/api/v1/observers/directory?"+raw, nil)
wantClass := guards.Aggregation
if region {
wantClass = guards.List
}
if _, c := guards.Classify(d); c != wantClass {
t.Errorf("observers/directory?%s: class = %s, want %s", raw, c, wantClass)
}
}
}