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>
66 lines
2.5 KiB
Go
66 lines
2.5 KiB
Go
package server
|
|
|
|
import (
|
|
"encoding/json"
|
|
"net/http"
|
|
"testing"
|
|
"time"
|
|
|
|
"git.lucasrguerra.dev.br/ciberfauna/urutau/internal/core"
|
|
"git.lucasrguerra.dev.br/ciberfauna/urutau/internal/store"
|
|
)
|
|
|
|
func TestServicesAndErrorsAPI(t *testing.T) {
|
|
st := store.New(store.Config{Name: "oracle", Version: "t", Retention: 720 * time.Hour})
|
|
now := time.Now()
|
|
mk := func(status, origin int, path, ref string, cat core.Category) core.Event {
|
|
return core.Event{Time: now.Add(-30 * time.Minute), IP: "20.0.0.9", Cat: cat, Source: "traefik", Domain: "a.example", Method: "GET", Path: path, Referer: ref,
|
|
UA: "Mozilla/5.0 x", Status: status, OriginStatus: origin, DurationNS: 30e6, OriginNS: 28e6, Router: "r-app@docker", Service: "r-app@docker",
|
|
Proto: "HTTP/2.0", Scheme: "https", TLSVer: "1.3", TLSCiph: "TLS_AES_128_GCM_SHA256", E: core.Enrich{Device: "desktop"}}
|
|
}
|
|
for i := 0; i < 8; i++ {
|
|
st.ObserveService(mk(200, 200, "/", "", core.OK))
|
|
}
|
|
st.ObserveService(mk(500, 500, "/api/a", "", core.OK))
|
|
st.ObserveService(mk(404, 404, "/gone", "https://a.example/", core.NotFound))
|
|
st.ObserveService(mk(404, 404, "/.env", "", core.Scanner))
|
|
h := New(Options{Token: userTok, Version: "t", Store: st})
|
|
auth := map[string]string{"Authorization": "Bearer " + userTok}
|
|
|
|
e := getJSON(t, h, "/api/v1/errors?range=24h", auth)
|
|
cl := e["classes"].(map[string]any)
|
|
if cl["app"].(float64) != 1 || cl["attack"].(float64) != 1 || cl["client"].(float64) != 1 || e["errors"].(float64) != 3 {
|
|
t.Fatalf("errors: %v", e)
|
|
}
|
|
if len(e["broken"].([]any)) != 1 || len(e["top_routes"].([]any)) != 3 {
|
|
t.Fatalf("lists: %v", e)
|
|
}
|
|
s := getJSONList(t, h, "/api/v1/services?range=24h", auth)
|
|
if len(s) != 1 || s[0].(map[string]any)["svc"] != "r-app" {
|
|
t.Fatalf("services: %v", s)
|
|
}
|
|
d := getJSON(t, h, "/api/v1/services/r-app?range=24h", auth)
|
|
if d["histograms"] == nil || d["timeline"] == nil {
|
|
t.Fatalf("service: %v", d)
|
|
}
|
|
if w := do(h, "GET", "/api/v1/services/nope?range=24h", cloneHdr(auth), nil); w.Code != 404 {
|
|
t.Fatalf("404 expected, got %d", w.Code)
|
|
}
|
|
p := getJSON(t, h, "/api/v1/protocols?range=24h", auth)
|
|
if p["protocols"].(map[string]any)["http2"] == nil || p["scheme"].(map[string]any)["https"].(float64) != 11 {
|
|
t.Fatalf("protocols: %v", p)
|
|
}
|
|
}
|
|
|
|
func getJSONList(t *testing.T, h http.Handler, path string, hd map[string]string) []any {
|
|
w := do(h, "GET", path, cloneHdr(hd), nil)
|
|
if w.Code != 200 {
|
|
t.Fatalf("%s: %d %s", path, w.Code, w.Body)
|
|
}
|
|
var m []any
|
|
if err := json.Unmarshal(w.Body.Bytes(), &m); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
return m
|
|
}
|