You've already forked caddy-opnsense-blocker
Simplify the dashboard recent IP view
This commit is contained in:
@@ -19,7 +19,21 @@ func TestHandlerServesOverviewAndManualActions(t *testing.T) {
|
||||
handler := NewHandler(app)
|
||||
|
||||
recorder := httptest.NewRecorder()
|
||||
request := httptest.NewRequest(http.MethodGet, "/api/overview?limit=10", nil)
|
||||
request := httptest.NewRequest(http.MethodGet, "/api/recent-ips?hours=24&limit=10", nil)
|
||||
handler.ServeHTTP(recorder, request)
|
||||
if recorder.Code != http.StatusOK {
|
||||
t.Fatalf("unexpected recent ip status: %d body=%s", recorder.Code, recorder.Body.String())
|
||||
}
|
||||
var recentIPs []model.RecentIPRow
|
||||
if err := json.Unmarshal(recorder.Body.Bytes(), &recentIPs); err != nil {
|
||||
t.Fatalf("decode recent ips payload: %v", err)
|
||||
}
|
||||
if len(recentIPs) != 1 || recentIPs[0].IP != "203.0.113.10" {
|
||||
t.Fatalf("unexpected recent ips payload: %+v", recentIPs)
|
||||
}
|
||||
|
||||
recorder = httptest.NewRecorder()
|
||||
request = httptest.NewRequest(http.MethodGet, "/api/overview?limit=10", nil)
|
||||
handler.ServeHTTP(recorder, request)
|
||||
if recorder.Code != http.StatusOK {
|
||||
t.Fatalf("unexpected overview status: %d", recorder.Code)
|
||||
@@ -60,6 +74,9 @@ func TestHandlerServesOverviewAndManualActions(t *testing.T) {
|
||||
if !strings.Contains(recorder.Body.String(), "Local-only review and enforcement console") {
|
||||
t.Fatalf("overview page did not render expected content")
|
||||
}
|
||||
if strings.Contains(recorder.Body.String(), "Recent events") {
|
||||
t.Fatalf("overview page should no longer render recent events block")
|
||||
}
|
||||
}
|
||||
|
||||
type stubApp struct {
|
||||
@@ -100,6 +117,22 @@ func (s *stubApp) ListIPs(ctx context.Context, limit int, state string) ([]model
|
||||
return overview.RecentIPs, nil
|
||||
}
|
||||
|
||||
func (s *stubApp) ListRecentIPs(ctx context.Context, since time.Time, limit int) ([]model.RecentIPRow, error) {
|
||||
_ = ctx
|
||||
_ = since
|
||||
_ = limit
|
||||
now := time.Now().UTC()
|
||||
return []model.RecentIPRow{{
|
||||
IP: "203.0.113.10",
|
||||
SourceName: "main",
|
||||
State: model.IPStateBlocked,
|
||||
Events: 3,
|
||||
LastSeenAt: now,
|
||||
Reason: "php_path",
|
||||
Actions: model.ActionAvailability{CanUnblock: true},
|
||||
}}, nil
|
||||
}
|
||||
|
||||
func (s *stubApp) GetIPDetails(context.Context, string) (model.IPDetails, error) {
|
||||
now := time.Now().UTC()
|
||||
return model.IPDetails{
|
||||
|
||||
Reference in New Issue
Block a user