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>
81 lines
2.1 KiB
Go
81 lines
2.1 KiB
Go
package server
|
|
|
|
import (
|
|
"encoding/json"
|
|
"testing"
|
|
)
|
|
|
|
var opsAuth = map[string]string{"Authorization": "Bearer user-token-0123456789-abcdefghijklmnop"}
|
|
|
|
func TestIntegrityAPI(t *testing.T) {
|
|
h, _ := setup(t)
|
|
if w := do(h, "GET", "/api/v1/integrity?range=24h", nil, nil); w.Code != 401 && w.Code != 403 {
|
|
t.Fatalf("closed without token: %d", w.Code)
|
|
}
|
|
w := do(h, "GET", "/api/v1/integrity?range=24h", copyHdr(opsAuth), nil)
|
|
if w.Code != 200 {
|
|
t.Fatalf("%d %s", w.Code, w.Body)
|
|
}
|
|
var o struct {
|
|
Hosts []struct {
|
|
Name string `json:"name"`
|
|
Online bool `json:"online"`
|
|
Hourly []uint32 `json:"hourly"`
|
|
} `json:"hosts"`
|
|
Peers []any `json:"peers"`
|
|
}
|
|
if err := json.Unmarshal(w.Body.Bytes(), &o); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if len(o.Hosts) != 1 || o.Hosts[0].Name != "oracle" || !o.Hosts[0].Online || len(o.Hosts[0].Hourly) < 24 {
|
|
t.Fatalf("%+v", o)
|
|
}
|
|
var sum uint32
|
|
for _, v := range o.Hosts[0].Hourly {
|
|
sum += v
|
|
}
|
|
if sum == 0 {
|
|
t.Fatal("the ingested event must show in the hourly series")
|
|
}
|
|
if w := do(h, "GET", "/api/v1/integrity?host=nope", copyHdr(opsAuth), nil); w.Code != 404 {
|
|
t.Fatalf("unknown host: %d", w.Code)
|
|
}
|
|
}
|
|
|
|
func TestReportAPI(t *testing.T) {
|
|
h, _ := setup(t)
|
|
w := do(h, "GET", "/api/v1/report?range=7d&format=json", copyHdr(opsAuth), nil)
|
|
if w.Code != 200 {
|
|
t.Fatalf("%d %s", w.Code, w.Body)
|
|
}
|
|
var o struct {
|
|
Hosts []string `json:"hosts"`
|
|
Summary struct {
|
|
Attacks uint64 `json:"attacks"`
|
|
} `json:"summary"`
|
|
TopIPs []struct {
|
|
IP string `json:"ip"`
|
|
} `json:"top_ips"`
|
|
}
|
|
if err := json.Unmarshal(w.Body.Bytes(), &o); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if o.Summary.Attacks != 1 || len(o.TopIPs) != 1 || len(o.Hosts) != 1 {
|
|
t.Fatalf("%s", w.Body)
|
|
}
|
|
if w := do(h, "GET", "/api/v1/report?format=pdf", copyHdr(opsAuth), nil); w.Code != 400 {
|
|
t.Fatalf("format: %d", w.Code)
|
|
}
|
|
if w := do(h, "GET", "/api/v1/report?host=nope", copyHdr(opsAuth), nil); w.Code != 404 {
|
|
t.Fatalf("host: %d", w.Code)
|
|
}
|
|
}
|
|
|
|
func copyHdr(m map[string]string) map[string]string {
|
|
c := map[string]string{}
|
|
for k, v := range m {
|
|
c[k] = v
|
|
}
|
|
return c
|
|
}
|