@@ -100,6 +100,48 @@ func TestAdminServer_MethodNotAllowed(t *testing.T) {
100100 assert .Equal (t , http .StatusMethodNotAllowed , rr .Code )
101101}
102102
103+ func TestAdminServer_HealthHandler (t * testing.T ) {
104+ stub := & stubAPIServer {}
105+ s := NewServer (& config.AdminServerConfig {Port : 9092 , AllowedIPs : []string {"*" }}, stub , slog .Default ())
106+
107+ req := httptest .NewRequest (http .MethodGet , "/health" , nil )
108+ req .RemoteAddr = "127.0.0.1:12345"
109+ rr := httptest .NewRecorder ()
110+
111+ s .httpSrv .Handler .ServeHTTP (rr , req )
112+ assert .Equal (t , http .StatusOK , rr .Code )
113+
114+ var body map [string ]string
115+ assert .NoError (t , json .NewDecoder (rr .Body ).Decode (& body ))
116+ assert .Equal (t , "healthy" , body ["status" ])
117+ assert .NotEmpty (t , body ["timestamp" ])
118+ }
119+
120+ func TestAdminServer_HealthHandler_MethodNotAllowed (t * testing.T ) {
121+ stub := & stubAPIServer {}
122+ s := NewServer (& config.AdminServerConfig {Port : 9092 , AllowedIPs : []string {"*" }}, stub , slog .Default ())
123+
124+ req := httptest .NewRequest (http .MethodPost , "/health" , nil )
125+ req .RemoteAddr = "127.0.0.1:12345"
126+ rr := httptest .NewRecorder ()
127+
128+ s .httpSrv .Handler .ServeHTTP (rr , req )
129+ assert .Equal (t , http .StatusMethodNotAllowed , rr .Code )
130+ }
131+
132+ func TestAdminServer_HealthHandler_NoIPWhitelist (t * testing.T ) {
133+ stub := & stubAPIServer {}
134+ // Restrict IPs to only 127.0.0.1 — health should still be accessible from other IPs
135+ s := NewServer (& config.AdminServerConfig {Port : 9092 , AllowedIPs : []string {"127.0.0.1" }}, stub , slog .Default ())
136+
137+ req := httptest .NewRequest (http .MethodGet , "/health" , nil )
138+ req .RemoteAddr = "192.168.1.10:12345"
139+ rr := httptest .NewRecorder ()
140+
141+ s .httpSrv .Handler .ServeHTTP (rr , req )
142+ assert .Equal (t , http .StatusOK , rr .Code )
143+ }
144+
103145func TestIsIPAllowed (t * testing.T ) {
104146 assert .True (t , isIPAllowed ("127.0.0.1" , []string {"*" }))
105147 assert .True (t , isIPAllowed ("127.0.0.1" , []string {"0.0.0.0/0" }))
0 commit comments