CI / Docker image (build and smoke test) (push) Skipped
CI / Format and vet (push) Successful in 24s
CI / Tests (Linux, race detector) (push) Successful in 34s
CI / Dependency audit (push) Successful in 14s
Release / Plan (reuse the published image?) (push) Successful in 3s
Release / ci (push) Skipped
Release / Build image (amd64) (push) Skipped
Release / Build image (arm64) (push) Skipped
Release / Publish tags (push) Successful in 13s
Release / Gitea release (push) Successful in 4s
Peer events and summary rows are rebuilt from validated fields (address, country code, category) and the forged/unban flags from peers are ignored. The live relay drops a peer that exceeds about 1 MB/s, also within a single window. --peer-blocklist=off keeps the hub's blocklist to local observations. UI polish: plural forms, blocklist preview and downloads follow the active slice, compact IP cards on phones. Docs for the 1.1.0 interface. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
59 lines
2.0 KiB
Go
59 lines
2.0 KiB
Go
package store
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestParseLocation(t *testing.T) {
|
|
l, err := ParseLocation("-8.05, -34.9, Recife, PE")
|
|
if err != nil || l.Lat != -8.05 || l.Lon != -34.9 || l.Label != "Recife, PE" {
|
|
t.Fatal(l, err)
|
|
}
|
|
if l, err := ParseLocation(""); l != nil || err != nil {
|
|
t.Fatal("empty is unset")
|
|
}
|
|
for _, bad := range []string{"1", "a,b", "91,0", "0,181", "NaN,0", "0,0,x\x01y", "0,0," + strings.Repeat("a", 65)} {
|
|
if _, err := ParseLocation(bad); err == nil {
|
|
t.Errorf("%q must be refused", bad)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestPeerLocationAndLiveSanitize(t *testing.T) {
|
|
e := PeerExport{V: ExportVersion, Summary: Summary{Hosts: []HostInfo{{Name: "x", Location: &Location{Lat: 95, Lon: 0}}}}}
|
|
if e.Sanitize("24h"); e.Summary.Hosts[0].Location != nil {
|
|
t.Fatal("invalid location must be dropped")
|
|
}
|
|
e = PeerExport{V: ExportVersion, Summary: Summary{Hosts: []HostInfo{{Name: "x", Location: &Location{Lat: 1, Lon: 2, Label: "a\x00" + strings.Repeat("b", 100)}}}}}
|
|
e.Sanitize("24h")
|
|
if l := e.Summary.Hosts[0].Location; l == nil || len(l.Label) != 64 || strings.ContainsRune(l.Label, 0) {
|
|
t.Fatalf("%+v", l)
|
|
}
|
|
le := LiveEvent{FeedEvent: FeedEvent{IP: "::ffff:1.2.3.4", Cat: "scanner", T: 1}}
|
|
if !le.Sanitize(1_800_000_000) || le.IP != "1.2.3.4" || le.T != 1_800_000_000 {
|
|
t.Fatalf("%+v", le)
|
|
}
|
|
}
|
|
|
|
func TestPeerRowsAreSanitized(t *testing.T) {
|
|
le := LiveEvent{FeedEvent: FeedEvent{IP: "1.2.3.4", Cat: "scanner", T: 1, Forged: true, Unban: true, CC: "<s"}}
|
|
if !le.Sanitize(1_800_000_000) || le.Forged || le.Unban || le.CC != "" {
|
|
t.Fatalf("%+v", le)
|
|
}
|
|
e := PeerExport{V: ExportVersion, Summary: Summary{
|
|
Recent: []FeedEvent{{IP: "<script>", Cat: "scanner"}, {IP: "5.6.7.8", Cat: "scanner", CC: "<s", Forged: true}},
|
|
IPs: []IPSummary{{IP: "9.9.9.9", CC: "<s", Score: 1}},
|
|
}}
|
|
if err := e.Sanitize("24h"); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
r := e.Summary.Recent
|
|
if len(r) != 1 || r[0].IP != "5.6.7.8" || r[0].CC != "" || r[0].Forged {
|
|
t.Fatalf("%+v", r)
|
|
}
|
|
if e.Summary.IPs[0].CC != "" {
|
|
t.Fatal("cc must be validated")
|
|
}
|
|
}
|