Release / Plan (reuse the published image?) (push) Successful in 3s
CI / Docker image (build and smoke test) (push) Skipped
CI / Format and vet (push) Successful in 28s
CI / Dependency audit (push) Successful in 20s
CI / Tests (Linux, race detector) (push) Successful in 1m10s
Release / ci (push) Successful in 1m10s
Release / Build image (arm64) (push) Successful in 55s
Release / Build image (amd64) (push) Successful in 1m16s
Release / Publish tags (push) Successful in 14s
Release / Gitea release (push) Skipped
New pages grouped in the rail (Monitor, Investigate, Analyze, Operate, Reports): Services (SLO, Apdex, latency app vs proxy), Sessions (stage funnel), Campaigns, Event search, MITRE ATT&CK matrix, Evolution, Concentration (Pareto, Gini), Survival (Kaplan-Meier per attack episode, recidivists), Where errors come from (application vs failed attack vs proxy vs client), Protocols and TLS, Defense (fail2ban, SSH, blocklist), Integrity, and a printable executive report. Chart library (donut, radar, stacked area, bars, heatmap, gauge), glossary with accessible "?" tooltips, self-explanatory category names (nonexistent page 404), page loader through pages.json. Unique visitors fixed: real browsers opening a page, one per IP per day, deduplicated across domains, with non-human clients counted apart. Anonymous legitimate visits on the Live page (?visits=1, no IP). Traefik origin, service, protocol and TLS fields parsed. Paths and Referer paths drop e-mail and token segments. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
62 lines
2.5 KiB
Go
62 lines
2.5 KiB
Go
package server
|
|
|
|
import (
|
|
"path/filepath"
|
|
"testing"
|
|
"time"
|
|
|
|
"git.lucasrguerra.dev.br/ciberfauna/urutau/internal/core"
|
|
"git.lucasrguerra.dev.br/ciberfauna/urutau/internal/evlog"
|
|
"git.lucasrguerra.dev.br/ciberfauna/urutau/internal/store"
|
|
)
|
|
|
|
func TestDefenseAndTechniquesAPI(t *testing.T) {
|
|
st := store.New(store.Config{Name: "oracle", Version: "t", Retention: 720 * time.Hour, AdminUsers: []string{"lucas"}})
|
|
l, _ := evlog.Open(evlog.Options{Dir: filepath.Join(t.TempDir(), "events")})
|
|
st.SetEventLog(l)
|
|
now := time.Now()
|
|
for i := 0; i < 5; i++ {
|
|
st.Ingest(core.Event{Time: now.Add(-time.Duration(50-i) * time.Minute), IP: "8.8.4.4", Cat: core.Scanner, Source: "traefik", Method: "GET", Path: "/.env", Status: 404, UA: "nuclei"})
|
|
}
|
|
st.Ingest(core.Event{Time: now.Add(-30 * time.Minute), IP: "8.8.4.4", Cat: core.Ban, Source: "fail2ban", Jail: "sshd"})
|
|
st.Ingest(core.Event{Time: now.Add(-10 * time.Minute), IP: "8.8.4.4", Cat: core.Scanner, Source: "traefik", Method: "GET", Path: "/.env", Status: 404})
|
|
for _, u := range []string{"root", "lucas", "root"} {
|
|
st.Ingest(core.Event{Time: now.Add(-20 * time.Minute), IP: "9.9.9.9", Cat: core.SSHFail, Source: "ssh", User: u})
|
|
}
|
|
h := New(Options{Token: userTok, Version: "t", Store: st})
|
|
auth := map[string]string{"Authorization": "Bearer " + userTok}
|
|
|
|
d := getJSON(t, h, "/api/v1/defense?range=24h", auth)
|
|
if d["bans_total"].(float64) != 1 || d["bans_active"].(float64) != 1 {
|
|
t.Fatalf("bans %v", d)
|
|
}
|
|
ssh := d["ssh"].(map[string]any)
|
|
if ssh["fails"].(float64) != 3 || ssh["sources"].(float64) != 1 {
|
|
t.Fatalf("ssh %v", ssh)
|
|
}
|
|
us := ssh["users"].([]any)
|
|
if us[0].(map[string]any)["user"] != "root" || us[0].(map[string]any)["admin"] != false || us[1].(map[string]any)["admin"] != true {
|
|
t.Fatalf("users %v", us)
|
|
}
|
|
if d["leak"].(map[string]any)["ips"].(float64) != 1 {
|
|
t.Fatalf("leak %v", d["leak"])
|
|
}
|
|
if d["ttb"].(map[string]any)["median_s"].(float64) <= 0 {
|
|
t.Fatalf("ttb %v", d["ttb"])
|
|
}
|
|
if w := do(h, "GET", "/api/v1/defense?range=nope", cloneHdr(auth), nil); w.Code != 400 {
|
|
t.Fatalf("bad range: %d", w.Code)
|
|
}
|
|
if w := do(h, "GET", "/api/v1/defense?range=24h&host=zzz", cloneHdr(auth), nil); w.Code != 404 {
|
|
t.Fatalf("unknown host: %d", w.Code)
|
|
}
|
|
|
|
tq := getJSON(t, h, "/api/v1/techniques?range=24h", auth)
|
|
if tq["total"].(float64) < 1 || len(tq["tactics"].([]any)) == 0 {
|
|
t.Fatalf("techniques %v", tq)
|
|
}
|
|
if w := do(h, "GET", "/api/v1/techniques?range=24h", nil, nil); w.Code != 401 {
|
|
t.Fatalf("anonymous: %d", w.Code)
|
|
}
|
|
}
|