summaryrefslogtreecommitdiffstats
path: root/internal/handler/websocket
diff options
context:
space:
mode:
Diffstat (limited to 'internal/handler/websocket')
-rw-r--r--internal/handler/websocket/handler.go14
-rw-r--r--internal/handler/websocket/handler_test.go7
2 files changed, 19 insertions, 2 deletions
diff --git a/internal/handler/websocket/handler.go b/internal/handler/websocket/handler.go
index dfe7b9e..909e2ec 100644
--- a/internal/handler/websocket/handler.go
+++ b/internal/handler/websocket/handler.go
@@ -348,7 +348,12 @@ func (h *Handler) handleEvent(ctx context.Context, conn *websocket.Conn, raw []j
348 348
349 h.subs.MatchAndFan(pbEvent) 349 h.subs.MatchAndFan(pbEvent)
350 350
351 status = "ok" 351 // Track whether request was authenticated for metrics
352 if state.authenticatedPubkey != "" {
353 status = "authorized"
354 } else {
355 status = "ok"
356 }
352 h.sendOK(ctx, conn, event.ID, true, "") 357 h.sendOK(ctx, conn, event.ID, true, "")
353 return nil 358 return nil
354} 359}
@@ -448,7 +453,12 @@ func (h *Handler) handleReq(ctx context.Context, conn *websocket.Conn, raw []jso
448 453
449 go h.streamEvents(ctx, conn, sub) 454 go h.streamEvents(ctx, conn, sub)
450 455
451 status = "ok" 456 // Track whether request was authenticated for metrics
457 if state.authenticatedPubkey != "" {
458 status = "authorized"
459 } else {
460 status = "ok"
461 }
452 return nil 462 return nil
453} 463}
454 464
diff --git a/internal/handler/websocket/handler_test.go b/internal/handler/websocket/handler_test.go
index 10405b2..604a190 100644
--- a/internal/handler/websocket/handler_test.go
+++ b/internal/handler/websocket/handler_test.go
@@ -305,6 +305,13 @@ func TestAuthRequired(t *testing.T) {
305 t.Errorf("Expected OK true after auth, got false: %v", msg3[3]) 305 t.Errorf("Expected OK true after auth, got false: %v", msg3[3])
306 } 306 }
307 t.Logf("Publish succeeded after auth") 307 t.Logf("Publish succeeded after auth")
308
309 // Verify authorized requests are tracked in metrics
310 authorizedCount := ts.metrics.getRequestCount("EVENT", "authorized")
311 if authorizedCount == 0 {
312 t.Errorf("Expected authorized requests to be tracked in metrics, got 0")
313 }
314 t.Logf("Metrics: %d authorized requests tracked", authorizedCount)
308} 315}
309 316
310// TestAuthNotInAllowlist verifies that pubkeys not in allowlist are rejected 317// TestAuthNotInAllowlist verifies that pubkeys not in allowlist are rejected