Each server runs an ultralight probe (scratch image, ~7 MiB RSS) that tails the logs, ships raw lines to the hub over HTTPS with an on-disk spool, and applies enforce decisions locally. The hub keeps one node per probe (primary node = the 1.x data dir, unchanged), does all analysis and serves the UI. Peer federation is removed. 'urutau import' brings 1.x data dirs in with hash and count verification. UI: probes page, host qualified incidents, IPs never wrap, egress heatmap labels, live and replay globes no longer auto-rotate, replay repeat, live traffic metrics. BREAKING CHANGE: URUTAU_PEERS, URUTAU_PEER_* and /api/v1/peer/* are gone; log path variables move from the hub to the probe. See docs/migration-2.0.md. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
60 lines
1.4 KiB
Go
60 lines
1.4 KiB
Go
package hub
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestRegistryHashOnlyAndRevoke(t *testing.T) {
|
|
p := filepath.Join(t.TempDir(), "probes.json")
|
|
r, err := OpenRegistry(p)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
tok, err := r.Create("hostinger")
|
|
if err != nil || !strings.HasPrefix(tok, "urp_") || len(tok) != 47 {
|
|
t.Fatalf("%q %v", tok, err)
|
|
}
|
|
if b, _ := os.ReadFile(p); strings.Contains(string(b), tok) {
|
|
t.Fatal("token stored")
|
|
}
|
|
if fi, _ := os.Stat(p); fi.Mode().Perm() != 0o600 {
|
|
t.Fatal(fi.Mode())
|
|
}
|
|
if !r.Verify("hostinger", tok) || r.Verify("hostinger", tok+"x") || r.Verify("other", tok) {
|
|
t.Fatal("verify")
|
|
}
|
|
if _, err := r.Create("hostinger"); err != ErrExists {
|
|
t.Fatal(err)
|
|
}
|
|
if _, err := r.Create("All"); err != ErrName {
|
|
t.Fatal(err)
|
|
}
|
|
r.Revoke("hostinger")
|
|
if r.Verify("hostinger", tok) {
|
|
t.Fatal("revoked token accepted")
|
|
}
|
|
}
|
|
|
|
func TestQueuePersistsAndPrunes(t *testing.T) {
|
|
p := filepath.Join(t.TempDir(), "commands.json")
|
|
q, _ := OpenQueue(p)
|
|
line := "2026-11-15T10:00:00Z urutau unban ip=203.0.113.9 allow=60\n"
|
|
for i := 0; i < 3; i++ {
|
|
if err := q.Enqueue("unban", line); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
if q.Enqueue("unban", "rm -rf /\n") == nil {
|
|
t.Fatal("invalid line queued")
|
|
}
|
|
q.Close()
|
|
q2, _ := OpenQueue(p)
|
|
defer q2.Close()
|
|
if q2.Last() != 3 || q2.Pending(1) != 2 {
|
|
t.Fatalf("%d %d", q2.Last(), q2.Pending(1))
|
|
}
|
|
}
|