fix(ip): show egress destination view instead of ambiguous 404

Add GET /api/v1/ip/{ip}/egress and Engine.Dst; the IP page renders who
connected, findings and linked incidents, or a definitive never-seen message.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
Lucas RayanandClaude Sonnet 5.5 committed 2026-11-16 20:22:20 -03:00
1 parent 19afd221e2
commit 0db50c05c4
5 files changed
+351 -6

No files matched your search

+41
View File
@@ -1,7 +1,9 @@
package server
import (
"git.lucasrguerra.dev.br/ciberfauna/urutau/internal/incidents"
"net/netip"
"path/filepath"
"strconv"
"testing"
"time"
@@ -68,3 +70,42 @@ func TestEgressAPI(t *testing.T) {
t.Fatalf("peer token must not open the user route")
}
}
func TestIPEgressAPI(t *testing.T) {
st := store.New(store.Config{Name: "oracle", Version: "t", Retention: 720 * time.Hour})
inc, err := incidents.Open(filepath.Join(t.TempDir(), "incidents.json"), nil)
if err != nil {
t.Fatal(err)
}
h := New(Options{Token: userTok, Version: "t", Store: st, Incidents: inc})
auth := map[string]string{"Authorization": "Bearer " + userTok}
e, err := egress.New(egress.Config{Workloads: "ciberlab=10.0.5.0/24:scanner"})
if err != nil {
t.Fatal(err)
}
SetEgress(e)
defer SetEgress(nil)
now := time.Now()
e.IngestEvent(egress.Event{Time: now.Add(-time.Hour), Src: netip.MustParseAddr("10.0.5.2"), Dst: netip.MustParseAddr("203.0.113.7"), Proto: "tcp", DPort: 6667, In: "br-1"})
inc.Sync([]incidents.Finding{{Host: "oracle", Kind: "beacon", Severity: "high", Workload: "ciberlab", Dst: "203.0.113.7", Proto: "tcp", DPort: 6667, First: now.Add(-time.Hour).Unix(), Last: now.Unix(), Count: 9}})
d := getJSON(t, h, "/api/v1/ip/203.0.113.7/egress?range=24h", auth)
eg := d["egress"].([]any)
if len(eg) != 1 || eg[0].(map[string]any)["host"] != "oracle" || eg[0].(map[string]any)["conns"].(float64) != 1 {
t.Fatalf("egress: %v", d)
}
ics := d["incidents"].([]any)
if len(ics) != 1 || ics[0].(map[string]any)["id"] != "oracle/INC-1" {
t.Fatalf("incidents: %v", d["incidents"])
}
if d["last_seen_inbound"].(float64) != 0 {
t.Fatalf("inbound: %v", d)
}
d = getJSON(t, h, "/api/v1/ip/203.0.113.99/egress?range=24h", auth)
if len(d["egress"].([]any)) != 0 || len(d["incidents"].([]any)) != 0 || len(d["findings"].([]any)) != 0 {
t.Fatalf("empty: %v", d)
}
if w := do(h, "GET", "/api/v1/ip/nope/egress", cloneHdr(auth), nil); w.Code != 400 {
t.Fatalf("bad ip: %d", w.Code)
}
}