You've already forked caddy-opnsense-blocker
Simplify the dashboard recent IP view
This commit is contained in:
@@ -126,6 +126,21 @@ sources:
|
||||
t.Fatalf("expected observed state, got %+v", observedState)
|
||||
}
|
||||
|
||||
recentRows, err := svc.ListRecentIPs(context.Background(), time.Now().UTC().Add(-time.Hour), 10)
|
||||
if err != nil {
|
||||
t.Fatalf("list recent ips: %v", err)
|
||||
}
|
||||
blockedRow, found := findRecentIPRow(recentRows, "203.0.113.10")
|
||||
if !found {
|
||||
t.Fatalf("expected blocked IP row in recent rows: %+v", recentRows)
|
||||
}
|
||||
if blockedRow.SourceName != "main" || blockedRow.Events != 1 {
|
||||
t.Fatalf("unexpected blocked recent row: %+v", blockedRow)
|
||||
}
|
||||
if !blockedRow.Actions.CanUnblock || blockedRow.Actions.CanBlock {
|
||||
t.Fatalf("unexpected blocked recent row actions: %+v", blockedRow.Actions)
|
||||
}
|
||||
|
||||
if err := svc.ForceAllow(context.Background(), "203.0.113.10", "test", "manual unblock"); err != nil {
|
||||
t.Fatalf("force allow: %v", err)
|
||||
}
|
||||
@@ -245,3 +260,12 @@ func waitFor(t *testing.T, timeout time.Duration, condition func() bool) {
|
||||
}
|
||||
t.Fatalf("condition was not met within %s", timeout)
|
||||
}
|
||||
|
||||
func findRecentIPRow(items []model.RecentIPRow, ip string) (model.RecentIPRow, bool) {
|
||||
for _, item := range items {
|
||||
if item.IP == ip {
|
||||
return item, true
|
||||
}
|
||||
}
|
||||
return model.RecentIPRow{}, false
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user