Audit log: every change through the admin API and the administration pages, with ctl audit
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
bcd2413535
commit
f8fcecd640
18 files changed
+681
-7
No files matched your search
@@ -4,8 +4,10 @@ import (
|
||||
"context"
|
||||
"slices"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"gitea.mynodes.xyz/ilker/llmgw/internal/guard"
|
||||
"gitea.mynodes.xyz/ilker/llmgw/internal/store"
|
||||
)
|
||||
|
||||
type memGuard struct{ att []guard.Attachment }
|
||||
@@ -57,3 +59,26 @@ func TestGuardPoliciesAreAttachedByTarget(t *testing.T) {
|
||||
t.Errorf("detach again: %d", code)
|
||||
}
|
||||
}
|
||||
|
||||
type memAudit struct{ f store.AuditFilter }
|
||||
|
||||
func (m *memAudit) AuditEvents(_ context.Context, f store.AuditFilter) ([]store.AuditEvent, error) {
|
||||
m.f = f
|
||||
return []store.AuditEvent{{Actor: "ilker", Action: "POST /api/v1/models"}}, nil
|
||||
}
|
||||
|
||||
func TestTheAuditLogIsReadWithFilters(t *testing.T) {
|
||||
a, _ := setup(t, testModels())
|
||||
m := &memAudit{}
|
||||
a.SetAudit(m)
|
||||
var ev []store.AuditEvent
|
||||
if code := call(t, a, "GET", "/api/v1/audit?since=2d&actor=ilker&contains=models&limit=5", "", &ev); code != 200 || len(ev) != 1 {
|
||||
t.Fatalf("%d %v", code, ev)
|
||||
}
|
||||
if m.f.Actor != "ilker" || m.f.Contains != "models" || m.f.Limit != 5 || time.Since(m.f.Since) < 47*time.Hour {
|
||||
t.Errorf("filter %+v", m.f)
|
||||
}
|
||||
if code := call(t, a, "GET", "/api/v1/audit?since=soon", "", nil); code != 400 {
|
||||
t.Errorf("a bad since: %d", code)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user