feat: 1.4.6 unban from the UI, operator allows, day-counter fallback for long windows
Release / Publish tags (push) Successful in 16s
Release / Plan (reuse the published image?) (push) Successful in 4s
Release / ci (push) Successful in 1m47s
Release / Build image (amd64) (push) Successful in 21s
Release / Build image (arm64) (push) Successful in 23s
CI / Format and vet (push) Successful in 27s
CI / Tests (Linux, race detector) (push) Successful in 1m20s
CI / Dependency audit (push) Successful in 31s
CI / Docker image (build and smoke test) (push) Skipped
Release / Gitea release (push) Successful in 5s
Release / Publish tags (push) Successful in 16s
Release / Plan (reuse the published image?) (push) Successful in 4s
Release / ci (push) Successful in 1m47s
Release / Build image (amd64) (push) Successful in 21s
Release / Build image (arm64) (push) Successful in 23s
CI / Format and vet (push) Successful in 27s
CI / Tests (Linux, race detector) (push) Successful in 1m20s
CI / Dependency audit (push) Successful in 31s
CI / Docker image (build and smoke test) (push) Skipped
Release / Gitea release (push) Successful in 5s
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
1ef5a0ce9f
commit
da333d70f1
25 files changed
+841
-33
No files matched your search
@@ -0,0 +1,103 @@
|
||||
package enforce
|
||||
|
||||
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 TestSweepWithRealStoreAndRegistry(t *testing.T) {
|
||||
now := time.Now()
|
||||
s := store.New(store.Config{Name: "oracle", Version: "t", Retention: 720 * time.Hour})
|
||||
l, err := evlog.Open(evlog.Options{Dir: filepath.Join(t.TempDir(), "ev")})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
s.SetEventLog(l)
|
||||
for i := 0; i < 41; i++ {
|
||||
s.Ingest(core.Event{Time: now.Add(-time.Duration(20+i) * time.Minute), IP: "43.139.48.108", Cat: core.SSHFail, Source: "ssh", User: "root"})
|
||||
}
|
||||
for i := 0; i < 30; i++ {
|
||||
s.Ingest(core.Event{Time: now.Add(-time.Duration(30+i) * time.Minute), IP: "129.213.151.234", Cat: core.Scanner, Source: "traefik",
|
||||
Domain: "a.example", Method: "GET", Path: "/.env", Status: 404, UA: "curl/8"})
|
||||
}
|
||||
l.Flush()
|
||||
r := newRig(t, ModeOn, func(c *Config) {
|
||||
c.Now = time.Now
|
||||
c.Rep = s.Reputation
|
||||
c.Roster = func(from int64) []Seen {
|
||||
var out []Seen
|
||||
for _, x := range s.AttackRoster(from) {
|
||||
out = append(out, Seen{IP: x.IP, Score: x.Score, Level: x.Level, Jails: x.Jails})
|
||||
}
|
||||
return out
|
||||
}
|
||||
c.Tallies = func(from int64) map[string]Tally {
|
||||
out := map[string]Tally{}
|
||||
for k, v := range s.AttackTallies(from) {
|
||||
out[k] = Tally{SSH: v.SSH, Web: v.Web}
|
||||
}
|
||||
return out
|
||||
}
|
||||
})
|
||||
r.e.Sweep()
|
||||
r.e.drain()
|
||||
if n := len(r.lines(t)); n != 2 {
|
||||
t.Fatalf("lines %d: %v / roster %+v / tallies %+v", n, r.lines(t), s.AttackRoster(0), s.AttackTallies(0))
|
||||
}
|
||||
}
|
||||
|
||||
func TestTalliesAfterCompression(t *testing.T) {
|
||||
real := time.Now()
|
||||
shift := time.Duration(0)
|
||||
s := store.New(store.Config{Name: "oracle", Version: "t", Retention: 720 * time.Hour})
|
||||
l, err := evlog.Open(evlog.Options{Dir: filepath.Join(t.TempDir(), "ev"), Now: func() time.Time { return real.Add(shift) }})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
s.SetEventLog(l)
|
||||
for i := 0; i < 41; i++ {
|
||||
s.Ingest(core.Event{Time: real.Add(-time.Duration(20+i) * time.Minute), IP: "43.139.48.108", Cat: core.SSHFail, Source: "ssh", User: "root"})
|
||||
}
|
||||
l.Flush()
|
||||
shift = 36 * time.Hour // the day ends; Maintain compresses it
|
||||
l.Maintain()
|
||||
shift = 0
|
||||
m := s.AttackTallies(real.Add(-24 * time.Hour).Unix())
|
||||
if m["43.139.48.108"].SSH != 41 {
|
||||
t.Fatalf("tallies: %+v", m)
|
||||
}
|
||||
}
|
||||
|
||||
// The registry may hold less than the store knows (it only records live events):
|
||||
// the per-day counters must still justify the long-window ban.
|
||||
func TestSweepWithoutRegistryUsesDayCounters(t *testing.T) {
|
||||
now := time.Now()
|
||||
s := store.New(store.Config{Name: "oracle", Version: "t", Retention: 720 * time.Hour})
|
||||
for i := 0; i < 41; i++ {
|
||||
s.Ingest(core.Event{Time: now.Add(-time.Duration(20+i) * time.Minute), IP: "43.139.48.108", Cat: core.SSHFail, Source: "ssh", User: "root"})
|
||||
}
|
||||
for i := 0; i < 30; i++ {
|
||||
s.Ingest(core.Event{Time: now.Add(-time.Duration(30+i) * time.Minute), IP: "129.213.151.234", Cat: core.Scanner, Source: "traefik",
|
||||
Domain: "a.example", Method: "GET", Path: "/.env", Status: 404, UA: "curl/8"})
|
||||
}
|
||||
r := newRig(t, ModeOn, func(c *Config) {
|
||||
c.Now = time.Now
|
||||
c.Roster = func(from int64) []Seen {
|
||||
var out []Seen
|
||||
for _, x := range s.AttackRoster(from) {
|
||||
out = append(out, Seen{IP: x.IP, Score: x.Score, Level: x.Level, Jails: x.Jails, Est: Tally{SSH: x.Est.SSH, Web: x.Est.Web}})
|
||||
}
|
||||
return out
|
||||
}
|
||||
})
|
||||
r.e.Sweep()
|
||||
r.e.drain()
|
||||
if n := len(r.lines(t)); n != 2 {
|
||||
t.Fatalf("lines %d: %v", n, r.lines(t))
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user