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
@@ -2,6 +2,9 @@ package enforce
|
||||
|
||||
import (
|
||||
"net/netip"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@@ -177,3 +180,54 @@ func itoa(n int) string {
|
||||
}
|
||||
return s
|
||||
}
|
||||
|
||||
func TestOperatorAllowBlocksBansAndExpires(t *testing.T) {
|
||||
r := histRig(t, func(c *Config) { c.UnbanPath = filepath.Join(t.TempDir(), "u", "unban.log") })
|
||||
ip := netip.MustParseAddr("203.0.114.80")
|
||||
r.hits(ip.String(), 5, "/x", 404)
|
||||
if len(r.lines(t)) != 1 {
|
||||
t.Fatalf("expected a ban: %v", r.lines(t))
|
||||
}
|
||||
if err := r.e.Unban(ip, 3600, "local"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if b, _ := os.ReadFile(r.e.UnbanLogPath()); !strings.HasSuffix(string(b), " urutau unban ip=203.0.114.80 allow=3600\n") {
|
||||
t.Fatalf("file %q", b)
|
||||
}
|
||||
r.now = r.now.Add(time.Minute)
|
||||
r.hits(ip.String(), 8, "/y", 404)
|
||||
if len(r.lines(t)) != 1 {
|
||||
t.Fatalf("allowed address was banned: %v", r.lines(t))
|
||||
}
|
||||
if r.e.counts.Skipped[SkipOperator] == 0 {
|
||||
t.Fatal("skip not counted")
|
||||
}
|
||||
// survives a restart
|
||||
e2 := New(Config{Mode: ModeOn, Path: r.log, StatePath: r.e.cfg.StatePath, Now: func() time.Time { return r.now }})
|
||||
if len(e2.Allows()) != 1 {
|
||||
t.Fatal("allow not persisted")
|
||||
}
|
||||
// expires by itself
|
||||
r.now = r.now.Add(2 * time.Hour)
|
||||
if len(r.e.Allows()) != 0 {
|
||||
t.Fatal("allow did not expire")
|
||||
}
|
||||
r.hits(ip.String(), 8, "/z", 404)
|
||||
if len(r.lines(t)) != 2 {
|
||||
t.Fatalf("not banned after expiry: %v", r.lines(t))
|
||||
}
|
||||
// ending early lets the engine decide again
|
||||
r.e.Unban(ip, 3600, "local")
|
||||
if !r.e.EndAllow(ip) || r.e.EndAllow(ip) {
|
||||
t.Fatal("EndAllow")
|
||||
}
|
||||
if got := r.e.UnbansSince(0); len(got) != 2 || got[0].IP != ip.String() {
|
||||
t.Fatalf("unbans for peers: %v", got)
|
||||
}
|
||||
if rep := r.e.Report(0); rep.Recent[0].Action != "unban" {
|
||||
t.Fatalf("recent: %+v", rep.Recent[0])
|
||||
}
|
||||
if err := New(Config{Mode: ModeOn, Path: r.log}).Unban(ip, 0, "local"); err != ErrNoUnbanLog {
|
||||
t.Fatalf("no file: %v", err)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user