47 lines
1.2 KiB
Go
47 lines
1.2 KiB
Go
package store
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func TestAuditInsertAndRecent(t *testing.T) {
|
|
s := openTemp(t)
|
|
now := time.Date(2026, 6, 21, 12, 0, 0, 0, time.UTC)
|
|
err := s.Audit(now, AuditEntry{
|
|
Account: "work", Action: "list", Target: "INBOX", Result: "allowed",
|
|
})
|
|
if err != nil {
|
|
t.Fatalf("Audit: %v", err)
|
|
}
|
|
got, err := s.RecentAudit(10)
|
|
if err != nil || len(got) != 1 {
|
|
t.Fatalf("recent: %v len=%d", err, len(got))
|
|
}
|
|
if got[0].Action != "list" || got[0].Result != "allowed" {
|
|
t.Fatalf("entry wrong: %+v", got[0])
|
|
}
|
|
}
|
|
|
|
func TestPurgeRespectsRetention(t *testing.T) {
|
|
s := openTemp(t)
|
|
_ = s.SetSetting("audit_retention_days", "30")
|
|
now := time.Date(2026, 6, 21, 12, 0, 0, 0, time.UTC)
|
|
old := now.AddDate(0, 0, -31)
|
|
recent := now.AddDate(0, 0, -5)
|
|
_ = s.Audit(old, AuditEntry{Account: "a", Action: "list", Target: "INBOX", Result: "allowed"})
|
|
_ = s.Audit(recent, AuditEntry{Account: "a", Action: "list", Target: "INBOX", Result: "allowed"})
|
|
|
|
n, err := s.PurgeAudit(now)
|
|
if err != nil {
|
|
t.Fatalf("purge: %v", err)
|
|
}
|
|
if n != 1 {
|
|
t.Fatalf("want 1 purged, got %d", n)
|
|
}
|
|
got, _ := s.RecentAudit(10)
|
|
if len(got) != 1 {
|
|
t.Fatalf("want 1 remaining, got %d", len(got))
|
|
}
|
|
}
|