feat(ui): implement public status endpoint and update UI components
Some checks failed
CI / build-and-test (push) Failing after -30m49s
Some checks failed
CI / build-and-test (push) Failing after -30m49s
* add public status handler and response types * modify status API to restrict access and update client tracking * adjust UI components to display public status information * update routing to include public status endpoint
This commit is contained in:
@@ -43,11 +43,8 @@ func TestStatusSnapshotShowsTrackedAccess(t *testing.T) {
|
||||
if snapshot.ConnectedCount != 1 {
|
||||
t.Fatalf("ConnectedCount = %d, want 1", snapshot.ConnectedCount)
|
||||
}
|
||||
if len(snapshot.Entries) != 1 {
|
||||
t.Fatalf("len(Entries) = %d, want 1", len(snapshot.Entries))
|
||||
}
|
||||
if snapshot.Entries[0].KeyID != "client-a" || snapshot.Entries[0].LastPath != "/files" {
|
||||
t.Fatalf("entry = %+v, want keyID client-a and path /files", snapshot.Entries[0])
|
||||
if len(snapshot.Entries) != 0 {
|
||||
t.Fatalf("len(Entries) = %d, want 0 for counts-only status", len(snapshot.Entries))
|
||||
}
|
||||
if snapshot.Metrics.TotalRequests != 1 {
|
||||
t.Fatalf("Metrics.TotalRequests = %d, want 1", snapshot.Metrics.TotalRequests)
|
||||
@@ -61,6 +58,9 @@ func TestStatusSnapshotShowsTrackedAccess(t *testing.T) {
|
||||
if snapshot.Metrics.UniqueTools != 1 {
|
||||
t.Fatalf("Metrics.UniqueTools = %d, want 1", snapshot.Metrics.UniqueTools)
|
||||
}
|
||||
if len(snapshot.Metrics.TopIPs) != 0 || len(snapshot.Metrics.TopAgents) != 0 || len(snapshot.Metrics.TopTools) != 0 {
|
||||
t.Fatalf("Top breakdowns should be hidden in counts-only status: %+v", snapshot.Metrics)
|
||||
}
|
||||
}
|
||||
|
||||
func TestStatusAPIHandlerReturnsJSON(t *testing.T) {
|
||||
@@ -86,23 +86,49 @@ func TestStatusAPIHandlerReturnsJSON(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestStatusAPIHandlerSupportsStatusPath(t *testing.T) {
|
||||
func TestStatusAPIHandlerRejectsStatusPath(t *testing.T) {
|
||||
handler := statusAPIHandler(buildinfo.Info{Version: "v1"}, auth.NewAccessTracker(), true)
|
||||
req := httptest.NewRequest(http.MethodGet, "/status", nil)
|
||||
rec := httptest.NewRecorder()
|
||||
|
||||
handler.ServeHTTP(rec, req)
|
||||
|
||||
if rec.Code != http.StatusNotFound {
|
||||
t.Fatalf("status = %d, want %d", rec.Code, http.StatusNotFound)
|
||||
}
|
||||
}
|
||||
|
||||
func TestPublicStatusHandlerReturnsConnectedClientsOnly(t *testing.T) {
|
||||
tracker := auth.NewAccessTracker()
|
||||
now := time.Now().UTC()
|
||||
tracker.Record("recent-client", "/mcp", "127.0.0.1:1234", "tester", "list_projects", now.Add(-2*time.Minute))
|
||||
tracker.Record("stale-client", "/mcp", "127.0.0.1:9999", "tester", "list_projects", now.Add(-30*time.Minute))
|
||||
|
||||
handler := publicStatusHandler(tracker)
|
||||
req := httptest.NewRequest(http.MethodGet, "/status", nil)
|
||||
rec := httptest.NewRecorder()
|
||||
|
||||
handler.ServeHTTP(rec, req)
|
||||
|
||||
if rec.Code != http.StatusOK {
|
||||
t.Fatalf("status = %d, want %d", rec.Code, http.StatusOK)
|
||||
}
|
||||
|
||||
var payload statusAPIResponse
|
||||
var payload publicStatusResponse
|
||||
if err := json.Unmarshal(rec.Body.Bytes(), &payload); err != nil {
|
||||
t.Fatalf("json.Unmarshal() error = %v", err)
|
||||
}
|
||||
if payload.Version != "v1" {
|
||||
t.Fatalf("version = %q, want %q", payload.Version, "v1")
|
||||
if payload.ConnectedCount != 1 {
|
||||
t.Fatalf("ConnectedCount = %d, want 1", payload.ConnectedCount)
|
||||
}
|
||||
if len(payload.Entries) != 1 {
|
||||
t.Fatalf("len(Entries) = %d, want 1", len(payload.Entries))
|
||||
}
|
||||
if payload.Entries[0].KeyID != "recent-client" {
|
||||
t.Fatalf("Entries[0].KeyID = %q, want %q", payload.Entries[0].KeyID, "recent-client")
|
||||
}
|
||||
if payload.Entries[0].LastAccessedAt.Before(now.Add(-11 * time.Minute)) {
|
||||
t.Fatalf("Entries[0].LastAccessedAt = %v, expected recent timestamp", payload.Entries[0].LastAccessedAt)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user